ForumsProgramming ForumHappy Blocks - hero blitting and movement

0 8394
weirdlike
offline
weirdlike
1,299 posts
Prince

http://i.imgur.com/9h05s6M.png

download the img above and place into your assets folder then open your programming software and gear it up for the game engine

you will need to create a new class and name it GameClass.

This is where the core of the game engine will be. For the rules of this game the hero will have 4 states which is represented by the colors. The hero will also need to change colors on mouse click and will be follow the mouse position.

This is a very simple and clean setup of the rules described. Now to get to the gritty part of how the hero is displayed correctly.

Create your new class named HeroClass. You will need to embed the img and create a temporary class

this line

private var hero:BlittingTool = new BlittingTool(bitmap, 32, 32);

is referencing a BlittingTool class which we will get into here in a minute. It is passing 3 variables as an argument to the BlittingTool.

BlittingTool(bitmap, 32, 32);

the bitmap is the newly created bitmap img and the size of the hero which is 32x32. The full dimensions of the img is actually 64x64. Here is an example by michael james williams to give you a visual of how the dimensions work

http://gamedev.michaeljameswilliams.com/images/tutorials/AvoiderGame/part1/AvoiderGame_Part1_20.jpg

After you add the hero you can change the colors via numbers. The numbers are a representation of each color in the order that the BlittingTool draws them. A simple look at the img shows that there are 4 colors. This will be split up as 0, 1, 2, 3 numerically.

var tempNumber:Number = hero.currentSprite();
if (tempNumber == 3)
{
hero.drawSprite(0);
}
else
{
hero.drawSprite(tempNumber+1);
}

The complete class will look like this

now for the BlittingTool. The tool will take the measurements and divide up the areas into the numbers based on rows and columns. This method is used in a wide variety of games. Here is a sample of mario sprite

http://fc02.deviantart.net/fs70/f/2014/033/5/a/mecha_mario_sprites_wip_by_tfpivman-d74tjzs.png

You can see it is setup in rows and columns. For the simplicity of this game there are only 4 sprites to work with.

the BlittingTool is comprised of 3 basic functions.
1.) get the img and create the appropriate dimensions.
2.) draw the corresponding sprite
3.) return the value of the current sprite

it might seem confusing at first glance, but if you look at the 3 functions separately, it should make more sense.

source

Happy Blocks - Adding AI

package
{
	import flash.display.*;
	import flash.events.*;
	
	public class Main extends Sprite
	{
		public function Main():void
		{
			var game:GameClass = new GameClass();
			addChild(game);
		}
	}
}
  • 0 Replies
Showing 1-0 of 0