diff --git a/assets/images/playerdown.png b/assets/images/playerdown.png new file mode 100644 index 0000000..e1f61bc Binary files /dev/null and b/assets/images/playerdown.png differ diff --git a/assets/images/playerleft.png b/assets/images/playerleft.png new file mode 100644 index 0000000..e6b6fc5 Binary files /dev/null and b/assets/images/playerleft.png differ diff --git a/assets/images/playerright.png b/assets/images/playerright.png new file mode 100644 index 0000000..7aa46d7 Binary files /dev/null and b/assets/images/playerright.png differ diff --git a/assets/images/playerup.png b/assets/images/playerup.png new file mode 100644 index 0000000..72f0dbb Binary files /dev/null and b/assets/images/playerup.png differ diff --git a/assets/images/rsz_giphy.gif b/assets/images/rsz_giphy.gif new file mode 100644 index 0000000..4dd1a9a Binary files /dev/null and b/assets/images/rsz_giphy.gif differ diff --git a/js/Game.js b/js/Game.js index 4571c08..0c5a171 100644 --- a/js/Game.js +++ b/js/Game.js @@ -90,10 +90,12 @@ TopDownGame.Game.prototype = { this.player.body.velocity.x = 0; if(this.cursors.up.isDown) { + this.switchSprite('up'); if(this.player.body.velocity.y == 0) this.player.body.velocity.y -= 50; } else if(this.cursors.down.isDown) { + this.switchSprite('down'); if(this.player.body.velocity.y == 0) this.player.body.velocity.y += 50; } @@ -101,9 +103,11 @@ TopDownGame.Game.prototype = { this.player.body.velocity.y = 0; } if(this.cursors.left.isDown) { + this.switchSprite('left'); this.player.body.velocity.x -= 50; } else if(this.cursors.right.isDown) { + this.switchSprite('right'); this.player.body.velocity.x += 50; } }, @@ -116,4 +120,20 @@ TopDownGame.Game.prototype = { enterDoor: function(player, door) { console.log('entering door that will take you to '+door.targetTilemap+' on x:'+door.targetX+' and y:'+door.targetY); }, + switchSprite: function(direction) { + switch (direction) { + case "left": + this.player.loadTexture('playerLeft'); + break; + case "right": + this.player.loadTexture('playerRight'); + break; + case "up": + this.player.loadTexture('playerUp'); + break; + case "down": + this.player.loadTexture('playerDown'); + break; + } + }, }; diff --git a/js/Preload.js b/js/Preload.js index bfad866..5040f80 100644 --- a/js/Preload.js +++ b/js/Preload.js @@ -16,9 +16,12 @@ TopDownGame.Preload.prototype = { this.load.image('gameTiles', 'assets/images/tiles.png'); this.load.image('greencup', 'assets/images/greencup.png'); this.load.image('bluecup', 'assets/images/bluecup.png'); - this.load.image('player', 'assets/images/player.png'); + this.load.image('player', 'assets/images/playerdown.png'); this.load.image('browndoor', 'assets/images/browndoor.png'); - + this.load.image('playerUp', 'assets/images/playerup.png'); + this.load.image('playerDown', 'assets/images/playerdown.png'); + this.load.image('playerLeft', 'assets/images/playerleft.png'); + this.load.image('playerRight', 'assets/images/playerright.png'); }, create: function() { this.state.start('Game');