Created
June 22, 2017 18:26
-
-
Save lorenzoromagnoli/f7d62b969d1eac9570d45188bb19bd40 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var piccione; | |
var piccioneWalk; | |
var piccioneEat; | |
var backgroundImg; | |
var groundImg; | |
var groundSprite; | |
function preload() { | |
piccioneWalk = loadAnimation("assets/walkL.000.png", | |
"assets/walkL.001.png", | |
"assets/walkL.002.png", | |
"assets/walkL.003.png", | |
"assets/walkL.004.png" | |
); | |
piccioneWalk.frameDelay = 9; | |
piccioneEat = loadAnimation( | |
"assets/eatL.000.png", | |
"assets/eatL.001.png", | |
"assets/eatL.002.png", | |
"assets/eatL.003.png" | |
) | |
piccioneEat.looping=false; | |
backgroundImg=loadImage("assets/background.png"); | |
groundImg=loadImage("assets/ground.png"); | |
} | |
function setup() { | |
createCanvas(800, 600); | |
piccione = createSprite(100,height-90,100,100); | |
piccione.scale = .5; | |
piccione.addAnimation("walk", piccioneWalk); | |
piccione.addAnimation("eat", piccioneEat); | |
//walk.frameDelay=9; | |
groundSprite=createSprite(0,height-40); | |
groundSprite.addImage(groundImg); | |
groundSprite.scale=.5; | |
} | |
function draw() { | |
background(153); | |
camera.off(); | |
image(backgroundImg,0,0,width,height); | |
camera.on(); | |
camera.position.x=piccione.position.x; | |
//drawSprites() | |
drawSprite(groundSprite); | |
drawSprite(piccione); | |
// | |
if( | |
camera.position.x> | |
groundSprite.position.x | |
+groundSprite.width/4 | |
){ | |
groundSprite.position.x+=groundSprite.width/2; | |
} | |
} | |
function keyPressed(){ | |
if (keyCode==UP_ARROW){ | |
piccione.velocity.x=0; | |
piccione.changeAnimation("eat"); | |
piccione.animation.rewind(); | |
piccione.animation.play(); | |
}else if(keyCode==RIGHT_ARROW){ | |
piccione.changeAnimation("walk"); | |
piccione.mirrorX ( -1 ); | |
piccione.velocity.x=10; | |
}else if(keyCode==LEFT_ARROW){ | |
piccione.changeAnimation("walk"); | |
piccione.mirrorX ( 1 ); | |
piccione.velocity.x=-10; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment