Prototype of a Flash game like GearTaker

Do you know Tony Pa's GearTaker game?

GearTaker

You have a buddy jumping around rotating gears. As most Tony Pa's games, it's easier to play than to explain, and it's hard to link... from this page select "GearTaker" and play.

I made a Flash prototype using two objects, the cog and the hero

The prototype has the following features:

1) Commented code
2) (virtually) unlimited fully customizable gears
3) Player starting gear and offset

Do you want more?

The only feature I am not showing you at the moment is how to determine the angle offset when the hero jumps from a cog to another. In my prototype, the hero always places himself at the top of the gear.

Also, if the hero files out of the stage, you'll have to reload the page.

Can you improve the prototype?

ACTIONSCRIPT:
  1. // constant to convert degrees to radians
  2. degrees_to_radians = 0.0174532925;
  3. // constant to convert radians to degrees
  4. radians_to_degrees = 57.2957795;
  5. // arrays storing cogs information: x position, y position and diameter
  6. cog_x_position = Array(100, 400);
  7. cog_y_position = Array(200, 200);
  8. cog_diameter = Array(100, 100);
  9. // diameter of the hero
  10. hero_diameter = 24;
  11. // speed of the hero, when he'll fly
  12. hero_speed = 5;
  13. // flag to determine if the hero has to rotate attached to the cog (true) or not (false)
  14. rotate = true;
  15. // cog where the hero will rotate. The starting one
  16. cog_to_rotate = 0;
  17. // offset to align the hero to the top of the inner circle of the cog
  18. angle_offset = -Math.PI/2;
  19. // cycle scanning through all cogs
  20. for (x=0; x<cog_x_position.length; x++) {
  21.     // attaching the cog
  22.     wheel = _root.attachMovie("cog", "cog_"+x, x, {_x:cog_x_position[x], _y:cog_y_position[x], _width:cog_diameter[x], _height:cog_diameter[x]});
  23.     // setting a random rotation speed for the cogs
  24.     wheel.speed = Math.random()*20-10;
  25.     wheel.onEnterFrame = function() {
  26.         // update cog rotation according to its speed
  27.         this._rotation += this.speed;
  28.     };
  29. }
  30. // placing the hero on the screen
  31. _root.attachMovie("hero", "hero", _root.getNextHighestDepth());
  32. // function the hero will execute every frame
  33. hero.onEnterFrame = function() {
  34.     // if the hero is supposed to rotate sticked to the cog...
  35.     if (rotate) {
  36.         // determining hero's angle
  37.         angle = (_root["cog_"+cog_to_rotate]._rotation)*degrees_to_radians+angle_offset;
  38.         x = _root["cog_"+cog_to_rotate]._x;
  39.         y = _root["cog_"+cog_to_rotate]._y;
  40.         // no!!! this wont work
  41.         //radius = (_root["cog_0"]._width+hero_diameter)/2;
  42.         // yes !!
  43.         radius = (cog_diameter[0]+hero_diameter)/2;
  44.         // updating hero position
  45.         this._x = x+Math.cos(angle)*radius;
  46.         this._y = y+Math.sin(angle)*radius;
  47.         // if the hero is flying
  48.     } else {
  49.         // updating hero's x and y position
  50.         this._x += hero_speed*Math.cos(shooting_angle);
  51.         this._y += hero_speed*Math.sin(shooting_angle);
  52.         // scanning all cogs
  53.         for (x=0; x<cog_x_position.length; x++) {
  54.             // if it's not the cog the hero just left...
  55.             if (x != cog_to_rotate) {
  56.                 // checking the distance bewteen the hero and the cog
  57.                 dist_x = _root["cog_"+x]._x-this._x;
  58.                 dist_y = _root["cog_"+x]._y-this._y;
  59.                 distance = Math.sqrt(dist_x*dist_x+dist_y*dist_y);
  60.                 // if the hero hits a cog
  61.                 if (distance<(cog_diameter[x]+hero_diameter)/2) {
  62.                     // time to calculate a new angle offset if you want
  63.                     // stick the hero to the cog
  64.                     cog_to_rotate = x;
  65.                     // make the hero rotate around the cog
  66.                     rotate = true;
  67.                 }
  68.             }
  69.         }
  70.     }
  71. };
  72. // if the player presses the mouse
  73. onMouseDown = function () {
  74.     // checking hero's angle
  75.     dist_x = hero._x-_root["cog_"+cog_to_rotate]._x;
  76.     dist_y = hero._y-_root["cog_"+cog_to_rotate]._y;
  77.     shooting_angle = Math.atan2(dist_y, dist_x);
  78.     // dont' make the hero rotate sticked to the cog anymore
  79.     rotate = false;
  80. };

Mouse button to play. Happy jumping. Yes, this is a one-button game, and I have a next-to-be-published incredible game based upon this prototype.

Prototypes are the most interesting ways to make a game, remember what I was able to make from this to this...

And this is the source code, just in case you need it...

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 (No Ratings Yet)
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.

9 Responses to “Prototype of a Flash game like GearTaker”

  1. JDog on May 6th, 2008 8:43 pm

    Its good, can’t wait to see what you are going to do with this !

  2. Jack Hopkisn on May 6th, 2008 9:38 pm

    I forsee an awesome game coming out of this :D

  3. Galaxian on May 6th, 2008 9:47 pm

    I’ve seen an awesome game like this. Miniclip’s Wheels of Salvation.

  4. Andre on May 6th, 2008 9:48 pm

    In between lines 62-63 add…

    *************************************************
    angle = Math.atan2(dist_y, dist_x);
    angle_offset = angle - _root["cog_"+x]._rotation;
    *************************************************

    This will make the hero stick to the place where it hit the cog.

  5. Emanuele Feronato on May 7th, 2008 11:51 am

    Wrong!

    you’re mixing degrees with radians…

  6. JDog on May 7th, 2008 5:42 pm

    Don’t you just correct it using radians ? the code could stil have some use….I imagine ?

  7. Xavi on May 7th, 2008 5:48 pm

    ya, I played wheels of salvatin too.
    What’s different though is that the guy doesn’t automatically go to a predefined point.
    it just continues from the point where it hit the wheel/gear.

  8. Emanuele Feronato on May 7th, 2008 5:52 pm

    No, it would attach at the opposite side of the wheel

    the correct angle_offset is determined by

    *************************
    angle_offset = angle-_root["cog_"+x]._rotation*degrees_to_radians+Math.PI;
    *************************

  9. Fernando on August 2nd, 2008 5:14 pm

    explain the actions please i want know more about the codes and u dont explain

Leave a Reply