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:

ACTIONSCRIPT:
  1. // HERES THE STACK! PROTOTYPE//
  2. stop();
  3. Mouse.hide();
  4. // loading values//
  5. gravity = 2;
  6. fired = 0;
  7. shot = 10;
  8. xspeed = 0;
  9. yspeed = 0;
  10. xspeed2 = 0;
  11. yspeed2 = 0;
  12. xspeed3 = 0;
  13. yspeed3 = 0;
  14. wind = 0.6;
  15. score = 0;
  16. // generating items//
  17. generate_items();
  18. // attaching mouse//
  19. attachMovie("crosshair", "crosshair", 1);
  20. // telling flash how to generate items//
  21. // and what properties should the generated items have//
  22. function generate_items() {
  23.     //generating boxes//
  24.     junk = _root.attachMovie("rock", "rock"+_root.getNextHighestDepth(), _root.getNextHighestDepth(), {_x:75, _y:25});
  25.     punk = _root.attachMovie("rock", "rock2"+_root.getNextHighestDepth(), _root.getNextHighestDepth(), {_x:75, _y:0});
  26.     lunk = _root.attachMovie("rock", "rock3"+_root.getNextHighestDepth(), _root.getNextHighestDepth(), {_x:75, _y:-25});
  27.     //initializing the colours of the boxes//
  28.     junk.gotoAndStop(1);
  29.     punk.gotoAndStop(2);
  30.     lunk.gotoAndStop(3);
  31.     // inscribing properties//
  32.     junk.onEnterFrame = function() {
  33.         this._y += gravity;
  34.         this._y += yspeed;
  35.         this._x += xspeed;
  36.         this._x += wind;
  37.         xspeed *= 0.8;
  38.         while (_root.terrain.hitTest(this._x, this._y+this._height/2, true)) {
  39.             this._y--;
  40.         }
  41.         while (_root.punk.hitTest(this._x, this._y+this._height/2, true)) {
  42.             this._y--;
  43.         }
  44.         while (_root.punk.hitTest(this._x-this._width/2, this._y, true)) {
  45.             this._x++;
  46.         }
  47.         while (_root.punk.hitTest(this._x+this._width/2, this._y, true)) {
  48.             this._x--;
  49.         }
  50.         while (_root.lunk.hitTest(this._x, this._y+this._height/2, true)) {
  51.             this._y--;
  52.         }
  53.         while (_root.lunk.hitTest(this._x-this._width/2, this._y, true)) {
  54.             this._x++;
  55.         }
  56.         while (_root.lunk.hitTest(this._x+this._width/2, this._y, true)) {
  57.             this._x--;
  58.         }
  59.         if (_root.redmat.hitTest(this)) {
  60.             this._alpha -= 1.5;
  61.             this._rotation -= 5;
  62.             this._y -= gravity*2;
  63.         }
  64.         if (this._alpha<10) {
  65.             this.removeMovieClip();
  66.             score += 50;
  67.         }
  68.         if (_root.terrain.conveyer.hitTest(this)) {
  69.             xspeed++;
  70.         }
  71.     };
  72.     punk.onEnterFrame = function() {
  73.         this._y += gravity*2;
  74.         this._y += yspeed2;
  75.         this._x += xspeed2;
  76.         this._x += wind;
  77.         xspeed2 *= 0.8;
  78.         while (_root.terrain.hitTest(this._x, this._y+this._height/2, true)) {
  79.             this._y--;
  80.         }
  81.         while (_root.junk.hitTest(this._x, this._y+this._height/2, true)) {
  82.             this._y--;
  83.         }
  84.         while (_root.junk.hitTest(this._x-this._width/2, this._y, true)) {
  85.             this._x++;
  86.         }
  87.         while (_root.junk.hitTest(this._x+this._width/2, this._y, true)) {
  88.             this._x--;
  89.         }
  90.         while (_root.lunk.hitTest(this._x, this._y+this._height/2, true)) {
  91.             this._y--;
  92.         }
  93.         while (_root.lunk.hitTest(this._x-this._width/2, this._y, true)) {
  94.             this._x++;
  95.         }
  96.         while (_root.lunk.hitTest(this._x+this._width/2, this._y, true)) {
  97.             this._x--;
  98.         }
  99.         if (_root.blumat.hitTest(this)) {
  100.             this._alpha -= 1.5;
  101.             this._rotation -= 5;
  102.             this._y -= gravity*2;
  103.         }
  104.         if (this._alpha<10) {
  105.             this.removeMovieClip();
  106.             score += 50;
  107.         }
  108.         if (_root.terrain.conveyer.hitTest(this)) {
  109.             xspeed2++;
  110.         }
  111.     };
  112.     lunk.onEnterFrame = function() {
  113.         this._y += gravity*2;
  114.         this._y += yspeed3;
  115.         this._x += xspeed3;
  116.         this._x += wind;
  117.         xspeed3 *= 0.8;
  118.         while (_root.terrain.hitTest(this._x, this._y+this._height/2, true)) {
  119.             this._y--;
  120.         }
  121.         while (_root.junk.hitTest(this._x, this._y+this._height/2, true)) {
  122.             this._y--;
  123.         }
  124.         while (_root.junk.hitTest(this._x-this._width/2, this._y, true)) {
  125.             this._x++;
  126.         }
  127.         while (_root.junk.hitTest(this._x+this._width/2, this._y, true)) {
  128.             this._x--;
  129.         }
  130.         while (_root.punk.hitTest(this._x, this._y+this._height/2, true)) {
  131.             this._y--;
  132.         }
  133.         while (_root.punk.hitTest(this._x-this._width/2, this._y, true)) {
  134.             this._x++;
  135.         }
  136.         while (_root.punk.hitTest(this._x+this._width/2, this._y, true)) {
  137.             this._x--;
  138.         }
  139.         if (_root.gremat.hitTest(this)) {
  140.             this._alpha -= 1.5;
  141.             this._rotation -= 5;
  142.             this._y -= gravity*2;
  143.         }
  144.         if (this._alpha<10) {
  145.             this.removeMovieClip();
  146.             score += 50;
  147.         }
  148.         if (_root.terrain.conveyer.hitTest(this)) {
  149.             xspeed3++;
  150.         }
  151.     };
  152. }
  153. // mouse movements//
  154. crosshair.onEnterFrame = function() {
  155.     this._x = _xmouse;
  156.     this._y = _ymouse;
  157. };
  158. //movement of the windmachine//
  159. tank.onEnterFrame = function() {
  160.     mousex = _xmouse-this._x;
  161.     mousey = (_ymouse-this._y)*-1;
  162.     angle = Math.atan(mousey/mousex)/(Math.PI/180);
  163.     if (mousex<0) {
  164.         angle += 180;
  165.     }
  166.     if (mousex>=0 && mousey<0) {
  167.         angle += 360;
  168.     }
  169.     firepower = Math.sqrt(mousex*mousex+mousey*mousey);
  170.     if (firepower>400) {
  171.         firepower = 400;
  172.     }
  173.     this.cannon._rotation = angle*-1;
  174. };
  175. function onMouseDown() {
  176.     shot--;
  177.     if (shot<0) {
  178.         shot = 0;
  179.     }
  180.     angle = tank.cannon._rotation-1;
  181.     start_ball_x = tank._x+48*Math.cos(angle*Math.PI/180);
  182.     start_ball_y = tank._y+48*Math.sin(angle*Math.PI/180);
  183.     cannonball_fired = attachMovie("cannonball", "cannonball_"+_root.getNextHighestDepth(), _root.getNextHighestDepth(), {_x:start_ball_x, _y:start_ball_y});
  184.     cannonball_fired.dirx = Math.cos(angle*Math.PI/180)*firepower;
  185.     cannonball_fired.diry = Math.sin(angle*Math.PI/180)*firepower;
  186.     cannonball_fired.onEnterFrame = function() {
  187.         this._x += this.dirx/30;
  188.         this._y += this.diry/30;
  189.         // interaction between wind and boxes//
  190.         if (lunk.hitTest(this._x, this._y, true)) {
  191.             this.removeMovieClip();
  192.             xspeed3 += firepower/15;
  193.             lunk._rotation += firepower;
  194.         }
  195.         if (junk.hitTest(this._x, this._y, true)) {
  196.             this.removeMovieClip();
  197.             xspeed += firepower/15;
  198.             junk._rotation += firepower;
  199.         }
  200.         if (punk.hitTest(this._x, this._y, true)) {
  201.             this.removeMovieClip();
  202.             xspeed2 += firepower/15;
  203.             punk._rotation += firepower;
  204.         }
  205.         // a useful reset or respawn function//   
  206.         if (respawn.hitTest(this._x, this._y, true)) {
  207.             this.removeMovieClip();
  208.             junk.removeMovieClip();
  209.             punk.removeMovieClip();
  210.             lunk.removeMovieClip();
  211.             score = 0;
  212.             generate_items();
  213.         }
  214.         // scoring//   
  215.         _root.txt.text = "Score: "+score;
  216.         if (_root.score>149) {
  217.             _root.gotoAndPlay(3);
  218.         }
  219.     };
  220. }
  221. // a useless reset function. Just a stupid backup//
  222. function reset() {
  223.     junk._x = 200;
  224.     junk._y = 26;
  225.     punk._x = 200;
  226.     punk._y = 0;
  227.     lunk._x = 200;
  228.     lunk._y = -50;
  229.     junk._rotation = 0;
  230.     punk._rotation = 0;
  231.     lunk._rotation = 0;
  232.     junk._height = 50;
  233.     punk._width = 50;
  234.     junk._width = 50;
  235.     punk._height = 50;
  236.     lunk._width = 50;
  237.     lunk._height = 50;
  238.     junk._alpha = 100;
  239.     punk._alpha = 100;
  240.     lunk._alpha = 100;
  241. }

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

Improve the blog rating this post
Tell me what do you think about this post. I'll write better and better entries.
1 Star2 Stars3 Stars4 Stars5 Stars (1 votes, average: 5 out of 5)
Loading ... Loading ...

» Flash Templates provided by Template Monster are pre-made web design products developed using Flash technology.
They can be easily customized to meet the unique requirements of your project.

10 Responses to “Stack Flash game prototype”

  1. Michael on December 12th, 2007 5:23 am

    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. =)

  2. shiv1411 on December 12th, 2007 10:58 am

    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.

  3. shiv1411 on December 12th, 2007 1:34 pm

    hey anyone knows a site for cool background music of low size (not in rar or zip) in mp3 format?

  4. RJ on December 12th, 2007 6:04 pm

    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

  5. And Mar on December 12th, 2007 10:02 pm

    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

  6. shiv1411 on December 13th, 2007 12:13 pm

    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.

  7. shiv1411 on December 13th, 2007 12:27 pm

    Thanx RJ

  8. ööö on December 13th, 2007 7:40 pm

    I understand Nothing ! .

  9. Thomas on December 14th, 2007 11:23 pm

    good work shiv!

  10. shiv1411 on December 15th, 2007 11:57 am

    Thanx thomas.

    Expect the game at newgrounds on next sunday.

Leave a Reply