Use the up, down, and side keys to move Tom Nook across the screen.
xxxxxxxxxx
let tomnook_x
let tomnook_y
let bluebutterfly_x
let bluebutterfly_y
let greenbutterfly_x
let greenbutterfly_y
let tomnook
var bluebutterfly
var greenbutterfly
var pinkbutterflty
var acbackground
var song
function preload (){
moth = loadImage ('moth.png')
tomnook = loadImage ('tomnook.png')
bluebutterfly = loadImage ('bluebutterfly.png')
pinkbutterfly = loadImage ('pinkbutterfly.png')
acbackground = loadImage ('acbackground.png')
song = loadSound ('acsound.mp3')
}
function setup() {
createCanvas(1000,1000)
//song
song.play()
image_number=1
}
//tom nook movement
tomnook_x = 100
tomnook_y = 250
//end of tomnook movement
bluebutterfly.resize(1,1)
pinkputterfly.resize(2,2)
moth.resize(3,3);
//end of setup
function draw() {
background(0, 255, 0)
image (acbackground, 200, 250,450,400)
//end of background
image (moth, 150, 100)
image (pinkbutterfly, 100, 500)
image (bluebutterfly, 500, 500)
//end of butterflies
if (image_number==1){
image (tomnook, tomnook_x, tomnook_y, 150, 150)
textSize (20)
fill (5)
stroke (255, 255, 255)
strokeWeight (7)
text ('Maneuver Tom Nook past the evil butterflies to the end of the screen. Press the left, right, up, and down arrows to move him away from the butterflies.', 50, 25)
}// end if statement
if(tomnook_x < 70){
image(checkmark,225,60,150,75)
} // end if 5
if(tomnook_y < 100){
image(checkmark,225,60,150,75)
}
} //end draw
function keyPressed(){
if(keyCode ==LEFT_ARROW){
tomnook_x-=10
}
if(keyCode == RIGHT_ARROW){
tomnook_x+=10
}
if(keyCode ==UP_ARROW){
tomnook_y-=10
}
if(keyCode ==DOWN_ARROW){
tomnook_y+=10
}
}
function keyTyped (){
if (key== 'a'){
image_number = 1
}
}