Make a Flash game like BoxHead - part 1
One of the most popular Flash games is BoxHead by Sean Cooper, that released the 5th game of the series called The Zombie Wars.
At the moment I am just giving a small prototype of the "hero" controlled with arrow keys and the "zombie" chasing the hero.
One of the interesting things about BoxHead is that all movements are based upon old 8-ways system... this means hero and zombies can walk only on 0, 45, 90, 135, 180, 225, 270 and 315 degrees.
So there is not so much trigonometry involved in it.
-
_root.attachMovie("hero","hero",_root.getNextHighestDepth(),{_x:250, _y:200});
-
_root.attachMovie("zombie","zombie",_root.getNextHighestDepth(),{_x:25, _y:20});
-
hero_speed = 1.5;
-
zombie_speed = 1;
-
zombie.same_rotation = 0;
-
hero.onEnterFrame = function() {
-
xspeed = 0;
-
yspeed = 0;
-
if (Key.isDown(Key.LEFT)) {
-
xspeed -= hero_speed;
-
}
-
if (Key.isDown(Key.RIGHT)) {
-
xspeed += hero_speed;
-
}
-
if (Key.isDown(Key.UP)) {
-
yspeed -= hero_speed;
-
}
-
if (Key.isDown(Key.DOWN)) {
-
yspeed += hero_speed;
-
}
-
if ((xspeed != 0) and (yspeed != 0)) {
-
xspeed *= 0.707;
-
yspeed *= 0.707;
-
}
-
this._x += xspeed;
-
this._y += yspeed;
-
switch (xspeed) {
-
case hero_speed :
-
this._rotation = 90;
-
break;
-
case -hero_speed :
-
this._rotation = -90;
-
break;
-
default :
-
switch (yspeed) {
-
case hero_speed :
-
this._rotation = 180;
-
break;
-
case -hero_speed :
-
this._rotation = 0;
-
break;
-
case hero_speed*0.707 :
-
if (xspeed == hero_speed*0.707) {
-
this._rotation = 135;
-
}
-
if (xspeed -= hero_speed*0.707) {
-
this._rotation = -135;
-
}
-
break;
-
case -hero_speed*0.707 :
-
if (xspeed == hero_speed*0.707) {
-
this._rotation = 45;
-
}
-
if (xspeed -= hero_speed*0.707) {
-
this._rotation = -45;
-
}
-
break;
-
}
-
}
-
};
-
zombie.onEnterFrame = function() {
-
this.same_rotation++;
-
dist_x = this._x-hero._x;
-
dist_y = this._y-hero._y;
-
angle = Math.atan2(dist_y, dist_x);
-
real_rotation = angle*57.2957795-90;
-
this._save_rotation = this._rotation;
-
if (this.same_rotation>15) {
-
this._rotation = Math.round(real_rotation/45)*45;
-
}
-
if (this._rotation != this._save_rotation) {
-
this.same_rotation = 0;
-
}
-
switch (this._rotation) {
-
case 0 :
-
this._y -= zombie_speed;
-
break;
-
case 45 :
-
this._y -= zombie_speed*0.707;
-
this._x += zombie_speed*0.707;
-
break;
-
case 90 :
-
this._x += zombie_speed;
-
break;
-
case 135 :
-
this._y += zombie_speed*0.707;
-
this._x += zombie_speed*0.707;
-
break;
-
case -180 :
-
this._y += zombie_speed;
-
break;
-
case -135 :
-
this._y += zombie_speed*0.707;
-
this._x -= zombie_speed*0.707;
-
break;
-
case -90 :
-
this._x -= zombie_speed;
-
break;
-
case -45 :
-
this._y -= zombie_speed*0.707;
-
this._x -= zombie_speed*0.707;
-
break;
-
}
-
};
I will comment the code later, meanwhile if you have questions post them in the comments.
Download the source code and give me feedback
Tell me what do you think about this post. I'll write better and better entries.
They can be easily customized to meet the unique requirements of your project.
38 Responses to “Make a Flash game like BoxHead - part 1”
Leave a Reply
Trackbacks
-
Managing isometric depths in Flash : Emanuele Feronato - italian geek and PROgrammer on
April 3rd, 2008 9:45 am
[...] in Flash… this is intended to be a stand alone tutorial but it’s also the 2nd part of Make a Flash game like BoxHead [...]


Wow! This is great, Ive always secretly wanted to make a game such as this.
very useful, as always
why didn’t you use the Math.sin(45) method instead of using 0.707? are there any advantages to using a decimal?
Also, can you show us how to create and control multiple enemies? i.e. would we attach loads of zombie movies using the for() and then have each of them its own onEnterFrame = function(){} or is there another method?
the problem with these kinds of games is not making it, it is the huge amount of enemies.
Dude. This is amazing!!!
I LOVE BoxHead… This is going to be the best tutorial series ever…
Bring on the Boxhead clones! Nice one.
the thing i’m really interested in is how you’re going to get enemies to go around obstacles.
as for the original game; i played the the other ones way too much, this does not bode well for my productivity.
Me too. I need an IA…Thanks Emanuele.
@David
Using .707 is faster than Math.sin(45) so it is better when you might be using it many times (e.g. many enemies?)
@styxtwo
I’m guessing that bitmap would be best for many enemies because its faster and you could manage them in a loop. cacheAsBitmap?
Hey emanuele(or someone else who can help me)
ive got a question can i make a hittest with two objects and then flash shows me cordinats where the two are hittesting?(i need this for a kind of gravity)
Excellent article - thanks.
I used 2 play this game all the time, the thing i really want to learn is how to create a certain number of zombies per lvl, like david said, maybe using a for() command with an attachmovieclip function?
@I need help!!!
I can help you, email me:
birdveiw @live.com
(^take away the space)
@Xodus
I simply put it on the stage, the attach thing doesn’t work for me…But, we all have opinions, don’t we?
the game was awesome, and graphics were good.
about the tut, i can’t wait for the next one to come… i think this will also give us the idea of how to create a isometric engine for RPG’s and adventure games.
very nice, i’ve always wanted to know how to make a game like this…thanks emanuele!
oh yeah, maybe make it a little faster with the next tut…
I was testing it out when I thought of something. If there are going to be lots of zombies, then the zombies should be slower, otherwise they are easily going to overpower the hero=(
i tried to do something where if the zombie hit the hero, then it attached a blood spurt movie clip and it had a delay so it only attached every 30 frames. It didn’t work for me, CAN SOMEONE HELP ME? Here was the code I used:
//delay variable
bloodDelay = 29;
.
.
.
//in zombie function at bottom
if(this.hero.hitTest(_x, _y, true)){
bloodDelay++;
if(bloodDelay==30){
bloodDelay = 0;
_root.attachMovie(”blood”, “blood”, _root.getNextHighestDepth(),{_x:this._x, _y:this._y});
}
}
Hey emanuele
will you also create a tutorial for the splitscreen mode of boxhead series?? that would be really cool…..
I can’t wait for the comments on this one.
I’m trying to write my own version of this in AS3, and as always I’m running into problems with the angles.
If I subtract 90 from the degrees version of the angle, the ranges get messed up and it’s no longer half negative, half positive.
Did something change between AVM1 and AVM2?
Whoa! I’ve tracked down the terrain graphics. Not that difficult since there’s a credit in the game.
http://lostgarden.com/2006/07/more-free-game-graphics.html
The artist mentions a copyleft license. Cheers!
Incidentally, lines 65 through 73 are brilliant,
particularly line 69.
I’ve seen a similar technique for getting integers out of a random number function, but I didn’t think to use something like to get a limited number of results to represent the angle range.
Elegantly simple.
nice work!
@xavi-v
no, the hero should move 3x faster
thats just hittest for that
Great job emanuele, great tutorial. I intrigued to see the commented version, it’s always nice to learn.
sorry guy, but BoxHead by Sean Cooper uses profissional programming, it uses AS3 and sean cooper in some classes work in byte and pixel level for the best optimization…you can’t show this in a simple tutorial.
Of course I can’t show this, but I will show enough to make a decent clone
When is the next part comming up? I really want to learn how to have 2 guns and change between them!
wow awesome! who knows when the nxt part is out? oh and EMANUELE F please can you make a simpler platform game tutorial I gat stuck on the last one…PLEASE?
EMANUELLE plese make a simple platform game Im stuck
Hey great tutorial its awesome.
Can you make one where the hero can shoot and more zombies spawn. Or instead of guns you could have force powers and kill the zombies by pushing them into walls and such.
Awesome tutorials anyway.
Another thing…
Has anyone heard of the “game”(more of a simulator but you could consider it one) falling sands?
If you haven’t go to http://www.fallingsands.com. If anyone knows how to program that it would be awesome.
Keep programming . .
/
\___/
http://www.fallingsandsgame.com i meant
Typing error sorry
no s after sand either
im gunna sound like a rite idiot but how do u use the actionscript.
im trying to use the tutorial to make a sort of Resident Evil 4 mercanaries game.
ive downloaded an actionscript program
now what?
hi its me agind
in fat what program would you recomend
and what do you do with the source code cos i cant find anything that opens .fla files