Stack Flash game prototype
During the last days I received a lot of prototypes from different readers.
One I want to mention is something called "a new idea in AS2" by Shival Gupta
That's how he got in contact with me:
Hi Emanuele.
A few days before you published some info on Box2d library in AS3 and one of the examples that it produced was of stacking boxes.
Eventually I developed this weak prototype on stacking in AS2 but it was really messy as each box had its own onEnterFrame function.
But anyways I think that the stacking concept has really great potential in making a game. If you are interested, shall I email that "poor" proto to you?
If you like that concept will you please publish a tutorial on it.
Understand, its a really cool concept and has great potential. I even has some ideas on making a stacking box game.Please reply to this mail with your reply and suggestions.
Best regards
Shiv
Coding a stacking prototype in AS2 is not that easy, and as you will see later in this post, Shival asked me to publish his prototype because "it would be an honour to me to get my work published in emanueleferonato.com" and because the code has some bugs Shival is not able to fix at the moment, so he is asking for help to everybody.
The game concept is simple: you have something like a fan and have to shoot air to some falling colored crates in order to make them stop each one in the colored spot that matches the color of the crate.
The code is split through 5 frames, but the main engine is:
-
// HERES THE STACK! PROTOTYPE//
-
stop();
-
Mouse.hide();
-
// loading values//
-
gravity = 2;
-
fired = 0;
-
shot = 10;
-
xspeed = 0;
-
yspeed = 0;
-
xspeed2 = 0;
-
yspeed2 = 0;
-
xspeed3 = 0;
-
yspeed3 = 0;
-
wind = 0.6;
-
score = 0;
-
// generating items//
-
generate_items();
-
// attaching mouse//
-
attachMovie("crosshair", "crosshair", 1);
-
// telling flash how to generate items//
-
// and what properties should the generated items have//
-
function generate_items() {
-
//generating boxes//
-
junk = _root.attachMovie("rock", "rock"+_root.getNextHighestDepth(), _root.getNextHighestDepth(), {_x:75, _y:25});
-
punk = _root.attachMovie("rock", "rock2"+_root.getNextHighestDepth(), _root.getNextHighestDepth(), {_x:75, _y:0});
-
lunk = _root.attachMovie("rock", "rock3"+_root.getNextHighestDepth(), _root.getNextHighestDepth(), {_x:75, _y:-25});
-
//initializing the colours of the boxes//
-
junk.gotoAndStop(1);
-
punk.gotoAndStop(2);
-
lunk.gotoAndStop(3);
-
// inscribing properties//
-
junk.onEnterFrame = function() {
-
this._y += gravity;
-
this._y += yspeed;
-
this._x += xspeed;
-
this._x += wind;
-
xspeed *= 0.8;
-
while (_root.terrain.hitTest(this._x, this._y+this._height/2, true)) {
-
this._y--;
-
}
-
while (_root.punk.hitTest(this._x, this._y+this._height/2, true)) {
-
this._y--;
-
}
-
while (_root.punk.hitTest(this._x-this._width/2, this._y, true)) {
-
this._x++;
-
}
-
while (_root.punk.hitTest(this._x+this._width/2, this._y, true)) {
-
this._x--;
-
}
-
while (_root.lunk.hitTest(this._x, this._y+this._height/2, true)) {
-
this._y--;
-
}
-
while (_root.lunk.hitTest(this._x-this._width/2, this._y, true)) {
-
this._x++;
-
}
-
while (_root.lunk.hitTest(this._x+this._width/2, this._y, true)) {
-
this._x--;
-
}
-
if (_root.redmat.hitTest(this)) {
-
this._alpha -= 1.5;
-
this._rotation -= 5;
-
this._y -= gravity*2;
-
}
-
if (this._alpha<10) {
-
this.removeMovieClip();
-
score += 50;
-
}
-
if (_root.terrain.conveyer.hitTest(this)) {
-
xspeed++;
-
}
-
};
-
punk.onEnterFrame = function() {
-
this._y += gravity*2;
-
this._y += yspeed2;
-
this._x += xspeed2;
-
this._x += wind;
-
xspeed2 *= 0.8;
-
while (_root.terrain.hitTest(this._x, this._y+this._height/2, true)) {
-
this._y--;
-
}
-
while (_root.junk.hitTest(this._x, this._y+this._height/2, true)) {
-
this._y--;
-
}
-
while (_root.junk.hitTest(this._x-this._width/2, this._y, true)) {
-
this._x++;
-
}
-
while (_root.junk.hitTest(this._x+this._width/2, this._y, true)) {
-
this._x--;
-
}
-
while (_root.lunk.hitTest(this._x, this._y+this._height/2, true)) {
-
this._y--;
-
}
-
while (_root.lunk.hitTest(this._x-this._width/2, this._y, true)) {
-
this._x++;
-
}
-
while (_root.lunk.hitTest(this._x+this._width/2, this._y, true)) {
-
this._x--;
-
}
-
if (_root.blumat.hitTest(this)) {
-
this._alpha -= 1.5;
-
this._rotation -= 5;
-
this._y -= gravity*2;
-
}
-
if (this._alpha<10) {
-
this.removeMovieClip();
-
score += 50;
-
}
-
if (_root.terrain.conveyer.hitTest(this)) {
-
xspeed2++;
-
}
-
};
-
lunk.onEnterFrame = function() {
-
this._y += gravity*2;
-
this._y += yspeed3;
-
this._x += xspeed3;
-
this._x += wind;
-
xspeed3 *= 0.8;
-
while (_root.terrain.hitTest(this._x, this._y+this._height/2, true)) {
-
this._y--;
-
}
-
while (_root.junk.hitTest(this._x, this._y+this._height/2, true)) {
-
this._y--;
-
}
-
while (_root.junk.hitTest(this._x-this._width/2, this._y, true)) {
-
this._x++;
-
}
-
while (_root.junk.hitTest(this._x+this._width/2, this._y, true)) {
-
this._x--;
-
}
-
while (_root.punk.hitTest(this._x, this._y+this._height/2, true)) {
-
this._y--;
-
}
-
while (_root.punk.hitTest(this._x-this._width/2, this._y, true)) {
-
this._x++;
-
}
-
while (_root.punk.hitTest(this._x+this._width/2, this._y, true)) {
-
this._x--;
-
}
-
if (_root.gremat.hitTest(this)) {
-
this._alpha -= 1.5;
-
this._rotation -= 5;
-
this._y -= gravity*2;
-
}
-
if (this._alpha<10) {
-
this.removeMovieClip();
-
score += 50;
-
}
-
if (_root.terrain.conveyer.hitTest(this)) {
-
xspeed3++;
-
}
-
};
-
}
-
// mouse movements//
-
crosshair.onEnterFrame = function() {
-
this._x = _xmouse;
-
this._y = _ymouse;
-
};
-
//movement of the windmachine//
-
tank.onEnterFrame = function() {
-
mousex = _xmouse-this._x;
-
mousey = (_ymouse-this._y)*-1;
-
angle = Math.atan(mousey/mousex)/(Math.PI/180);
-
if (mousex<0) {
-
angle += 180;
-
}
-
if (mousex>=0 && mousey<0) {
-
angle += 360;
-
}
-
firepower = Math.sqrt(mousex*mousex+mousey*mousey);
-
if (firepower>400) {
-
firepower = 400;
-
}
-
this.cannon._rotation = angle*-1;
-
};
-
function onMouseDown() {
-
shot--;
-
if (shot<0) {
-
shot = 0;
-
}
-
angle = tank.cannon._rotation-1;
-
start_ball_x = tank._x+48*Math.cos(angle*Math.PI/180);
-
start_ball_y = tank._y+48*Math.sin(angle*Math.PI/180);
-
cannonball_fired = attachMovie("cannonball", "cannonball_"+_root.getNextHighestDepth(), _root.getNextHighestDepth(), {_x:start_ball_x, _y:start_ball_y});
-
cannonball_fired.dirx = Math.cos(angle*Math.PI/180)*firepower;
-
cannonball_fired.diry = Math.sin(angle*Math.PI/180)*firepower;
-
cannonball_fired.onEnterFrame = function() {
-
this._x += this.dirx/30;
-
this._y += this.diry/30;
-
// interaction between wind and boxes//
-
if (lunk.hitTest(this._x, this._y, true)) {
-
this.removeMovieClip();
-
xspeed3 += firepower/15;
-
lunk._rotation += firepower;
-
}
-
if (junk.hitTest(this._x, this._y, true)) {
-
this.removeMovieClip();
-
xspeed += firepower/15;
-
junk._rotation += firepower;
-
}
-
if (punk.hitTest(this._x, this._y, true)) {
-
this.removeMovieClip();
-
xspeed2 += firepower/15;
-
punk._rotation += firepower;
-
}
-
// a useful reset or respawn function//
-
if (respawn.hitTest(this._x, this._y, true)) {
-
this.removeMovieClip();
-
junk.removeMovieClip();
-
punk.removeMovieClip();
-
lunk.removeMovieClip();
-
score = 0;
-
generate_items();
-
}
-
// scoring//
-
_root.txt.text = "Score: "+score;
-
if (_root.score>149) {
-
_root.gotoAndPlay(3);
-
}
-
};
-
}
-
// a useless reset function. Just a stupid backup//
-
function reset() {
-
junk._x = 200;
-
junk._y = 26;
-
punk._x = 200;
-
punk._y = 0;
-
lunk._x = 200;
-
lunk._y = -50;
-
junk._rotation = 0;
-
punk._rotation = 0;
-
lunk._rotation = 0;
-
junk._height = 50;
-
punk._width = 50;
-
junk._width = 50;
-
punk._height = 50;
-
lunk._width = 50;
-
lunk._height = 50;
-
junk._alpha = 100;
-
punk._alpha = 100;
-
lunk._alpha = 100;
-
}
And Shival is asking for help in this way
Mouse is the only control for this game.
I have the scheme and concept of "STACK!" but due to my rookieness in flash, I cannot code a function. The function is to produce multiple boxes having the same property. But I made it really "unproper".
For instance, if I have 5 boxes, I need 5 movieclip attachments, and 5*5 = 25 collisions.Yes, A game can be made with all this fuss. 10 boxes and managing 10 x 10 = 100 collisions :(
But I know that there is also an easier way of making this game.Also, can you fix the terrain collision code?
I tried my best but nothing better happened.So pls download the attachment "Stack!.fla" ," Stack!.swf"
and pls help me out.I hope you like my idea (a game in future).
Download the source code and give him 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.
10 Responses to “Stack Flash game prototype”
Leave a Reply

Not bad! I rather like the concept. With some fixes (Notably it is rather annoying hitting the reset button when you’re firing at a block that happens to be in that direction, and a bug when a block is hit too fast it flys through the wall), I think it could be a rather enjoyable game. =)
Thanks Emanuele,
I am really honoured.
For everyone who reads this:
^^^^^^^^^^^^^^^^^^^^^^^^^^^
Please help me reduce the code size.
That collisions = (crates)*(crates) formula is really a mess.
hey anyone knows a site for cool background music of low size (not in rar or zip) in mp3 format?
Well, I’ve been looking for that kind of music for a long time, and I think one of the best solutions is to look in Newgrounds Audio portal in the Jazz category, jazz is quite good as background music.Anyway, you can search for:
- Twilight Techno
- Surface
- Chaoz fantasy
- Mazidon’s fury
- A simple jazz
Those aren’t jazz (except of A simple jazz, of course) but are also good.
I hope this helps
shiv1411
I think something you could try would be pretending that the boxes cant get within a certain distance of each other. Then, if they are, move them apart.
Check distance
ydif = junk._y-lunk._y;
xdif = junk._x-lunk._x;
dis = Math.sqrt(ydif*ydif+xdif*xdif);
if(dis
Thanx And Mar,
I fixed that problem. I just subtracted a few pixels from the box to box collision and now it is working absolutely fine. I think I would be able to complete the game till the next sunday.
Thanx RJ
I understand Nothing ! .
good work shiv!
Thanx thomas.
Expect the game at newgrounds on next sunday.