Stack Flash game prototype
- December 11, 2007 by Emanuele Feronato
- Filed under Flash, Game design, Users contributions | 10 Comments
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:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 | // 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
They can be easily customized to meet the unique requirements of your project.
10 Responses
Leave a Reply
TUTORIAL SERIES:
- Una guida completa al gioco del poker online e una selezione dei migliori casino online.
- casino online
- migliori casino online
- BlackJack online
- casinò online



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.