Well, it’s been a minute, hasn’t it?
Since my last post, we’ve done the first of a few planned updates for Spirit Lake, and finished the prototype of a new game that we hope will come out next year, pending funding. Also, I was working from Belize for a week doing research on a new game that will come out this fall. Good times!
So,let’s go back to making a game using impact and pick up where we left off. You can see all of the code in the first post on making a character. Today, we’ll continue with explaining that code bit by bit.
So, here we are, with functions. The INIT function below only runs once, when the player is initially created, and it sets things like any sound that will be made when the player moves, the animation sheets for moving up, down, right or left. These animations are defined in the INIT function but then they are called in the UPDATE function, which we’ll discuss next time.
// The init function sets the animation, sounds, velocity and direction of movement ;
// None of these are required. You can have a boring entity that doesn't move ;
init: function(x,y,settings){
this.parent(x,y, settings);
// I included a walksound of footsteps in the woods ;
// It’s initialized to false because the player is not initially walking;
this.walksound = new ig.Sound('media/music/walksound.ogg') ;
this.walksound_status = false ;
this.walksound.volume = 1 ;
// These are the locations in the sprite sheet for animation;
// You can see the sprite sheet at the bottom of this post;
// If the player is idle, it's not moving so there is no need to refresh the scene;
// Every second (notice the 1), there is a refresh of the same image;
this.addAnim('idle',1,[0]);
// If the player is walking down, toward the bottom of the screen;
// We’re going to show the first four images – 0,1,2,3, in sequence changing every .1 second ;
this.addAnim('down',0.1,[0,1,2,3,2,1,0]);
// If the player is moving to the left;
// We’re going to show the next four images – 4,5,6,7 in sequence changing every .1 second ;
this.addAnim('left',0.1,[4,5,6,7,6,5,4]);
// Similarly, these next two animations are images for moving right and up ;
this.addAnim('right',0.1,[8,9,10,11,10,9,8]);
this.addAnim('up',0.1,[12,13,14,15,14,13,12]);
// The y velocity is 0 if you are moving right or left, because you are moving across the page, not up or down;
if (this.direction == 'right'){
this.vel.y = 0 ;
}
else if (this.direction == 'left'){
this.vel.y = 0 ;
}
// If the direction is up or down, the x velocity is 0, because you are not moving across the page;
else if (this.direction == 'up'){
this.vel.x = 0 ;
}
else if (this.direction == 'down'){
this.vel.x = 0 ;
}
}
If this is just the intermission between levels we’re working on. Imagine how cool the whole Fish Lake game is? Available for Mac and Windows
If you missed the first seven posts in this series, you can find them here:
Part 3 – Firing up the world master
Part 4 – Permission to make games