Prototype of a Flash game like GearTaker
Do you know Tony Pa‘s GearTaker game?
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?
|
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 |
// constant to convert degrees to radians degrees_to_radians = 0.0174532925; // constant to convert radians to degrees radians_to_degrees = 57.2957795; // arrays storing cogs information: x position, y position and diameter cog_x_position = Array(100, 400); cog_y_position = Array(200, 200); cog_diameter = Array(100, 100); // diameter of the hero hero_diameter = 24; // speed of the hero, when he'll fly hero_speed = 5; // flag to determine if the hero has to rotate attached to the cog (true) or not (false) rotate = true; // cog where the hero will rotate. The starting one cog_to_rotate = 0; // offset to align the hero to the top of the inner circle of the cog angle_offset = -Math.PI/2; // cycle scanning through all cogs for (x=0; x<cog_x_position.length; x++) { // attaching the cog 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]}); // setting a random rotation speed for the cogs wheel.speed = Math.random()*20-10; wheel.onEnterFrame = function() { // update cog rotation according to its speed this._rotation += this.speed; }; } // placing the hero on the screen _root.attachMovie("hero", "hero", _root.getNextHighestDepth()); // function the hero will execute every frame hero.onEnterFrame = function() { // if the hero is supposed to rotate sticked to the cog... if (rotate) { // determining hero's angle angle = (_root["cog_"+cog_to_rotate]._rotation)*degrees_to_radians+angle_offset; x = _root["cog_"+cog_to_rotate]._x; y = _root["cog_"+cog_to_rotate]._y; // no!!! this wont work //radius = (_root["cog_0"]._width+hero_diameter)/2; // yes !! radius = (cog_diameter[0]+hero_diameter)/2; // updating hero position this._x = x+Math.cos(angle)*radius; this._y = y+Math.sin(angle)*radius; // if the hero is flying } else { // updating hero's x and y position this._x += hero_speed*Math.cos(shooting_angle); this._y += hero_speed*Math.sin(shooting_angle); // scanning all cogs for (x=0; x<cog_x_position.length; x++) { // if it's not the cog the hero just left... if (x != cog_to_rotate) { // checking the distance bewteen the hero and the cog dist_x = _root["cog_"+x]._x-this._x; dist_y = _root["cog_"+x]._y-this._y; distance = Math.sqrt(dist_x*dist_x+dist_y*dist_y); // if the hero hits a cog if (distance<(cog_diameter[x]+hero_diameter)/2) { // time to calculate a new angle offset if you want // stick the hero to the cog cog_to_rotate = x; // make the hero rotate around the cog rotate = true; } } } } }; // if the player presses the mouse onMouseDown = function () { // checking hero's angle dist_x = hero._x-_root["cog_"+cog_to_rotate]._x; dist_y = hero._y-_root["cog_"+cog_to_rotate]._y; shooting_angle = Math.atan2(dist_y, dist_x); // dont' make the hero rotate sticked to the cog anymore rotate = false; }; |
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…
They can be easily customized to meet the unique requirements of your project.







(5 votes, average: 3.60 out of 5)






This post has 10 comments
JDog
Its good, can’t wait to see what you are going to do with this !
Jack Hopkisn
I forsee an awesome game coming out of this :D
Galaxian
I’ve seen an awesome game like this. Miniclip’s Wheels of Salvation.
Andre
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.
Emanuele Feronato
Wrong!
you’re mixing degrees with radians…
JDog
Don’t you just correct it using radians ? the code could stil have some use….I imagine ?
Xavi
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.
Emanuele Feronato
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;
*************************
Fernando
explain the actions please i want know more about the codes and u dont explain
DutchBoy
lol ! Fernando is that your name or “his” name? xO
This is soooo old and other scripts too, but I use them :)