Shutter effect Springy throwing thing tutorial
May 17

Hello, this is the second part for the jetpack game tutorial things. In this tutorial I will show how to make some platforms and walls and that. Easy as pie :)

Part 1 here!

Remember that this is actionscript 2!

When you’ve followed the last tutorial right, you should have a single mc on the stage called “fly” or something. That’s good. Then we have atleast something there. But, now, you should draw the ground. It should look something like this:



Your Ad Here

Select the ground, right click it and click “Convert to symbol…”. Name it whatever you want. Press Ok. Now, make the instance name of it ground. To give it a instance name, select the movie clip and bring up the properties menu for it. It looks like this:

Now it has a name, and you probably now know where to find the instance name. Good. And thats the only thing necessary to make platforms, but you need the code. Click the main timeline frame, and those who don’t know what that is, its this:

So, you can either right click it and select “Actions” or just click it and press F9. A window pops up. Paste this code into there:

?View Code ACTIONSCRIPT
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
yspeed = 0;
xspeed = 0;
gravity = 0.2;
rotationspeed = 0;
power = 1.1;
friction = 0.9;
fly.onEnterFrame = function() {
	while (ground.hitTest(fly._x, fly._y, true)) {
		fly._y--;
	}
	while (ground.hitTest(fly._x-25, fly._y-25, true)) {
		fly._x++;
		xspeed = 0;
	}
	while (ground.hitTest(fly._x+25, fly._y-25, true)) {
		fly._x--;
		xspeed = 0;
	}
	while (ground.hitTest(fly._x, fly._y-fly._width, true)) {
		fly._y++;
		yspeed = 0;
	}
	if ((_root.ground.hitTest(fly._x, fly._y+1, true))) {
		yspeed = 0;
	}
	xspeed *= friction;
	this._x += xspeed;
	rotationspeed *= friction;
	this._rotation = 0+rotationspeed/2;
	this._y += yspeed;
 
	if (Key.isDown(37)) {
		xspeed -= power;
		rotationspeed += power*xspeed/2;
	} else if (Key.isDown(39)) {
		xspeed += power;
		rotationspeed += power*xspeed/2;
	}
	if (Key.isDown(38)) {
		yspeed -= power;
		fly._y -= 0.2;
	}
	if (yspeed<0) {
		yspeed *= friction;
	}
	yspeed += gravity;
};

Now you can try the game or what you want to call it. You only have to press ctrl+return. it flies around nicely and hits the walls and stuff pretty good. It looks like this if youve done right:

There’s not much new things to explain here. As you see in the code, I’ve removed the if thing that checks if the jetpack guys _y is more than 340, and some other things.

The new stuff in the code are the while loops. They check if the fly guy hits the ground in different positions, and then resets y- or xspeed. And does fly._x–; and the others. A while loop is a super fast loop that runs as many times it can while a condition is true. But, if you use it in wrong places or in wrong ways it can easily crash your flash player.

Yup, its that easy to make a beginning to a “jet pack game”. Cheers to you all!


Your Ad Here

But, if you’re smart enough to not understand this, or cant get it to work, here’s the source.

Share this:
  • Digg
  • del.icio.us
  • Facebook
  • Mixx
  • Google
  • BarraPunto
  • co.mments
  • Fleck
  • Furl
  • feedmelinks
  • Live
  • Spurl
  • StumbleUpon

written by torskmunken \\ tags: , , , , , ,

19 Responses to “Jetpack game - part 2”

  1. Jetpack game - part 1 | Aksel Kornesjö Says:

    [...] Jetpack game - part 2 [...]

  2. steve Says:

    nice, im making a similar sort of game except the wall is moving around the player and i cant get it to work properly if your willing to help answer

  3. Bill Says:

    Great tutorial, but I have one question: the collisions act like the platforms are a couple pixels lower than they are. Anyone know whats wrong?

  4. guy with problems! Says:

    So I did everything you said, but My fly guy goes partially into walls when colliding from the top and doesn’t go close at all when colliding from the bottom. It’s not a box shaped guy and the walls aren’t flatt. is that a problem? Can somebody help!? Please, and thanks

  5. cuac10 Says:

    cmon, its a great tutoial, plz continue this tutorial U ROCK!

  6. CarlinRawks:] Says:

    Sooo good thank you

  7. ??????????????? Says:

    umm is there a way for part 3 where u can make landing spots and levels and gas and health and gas powerups and health power ups. lol a mouthful so if u can plz do

  8. manuel Says:

    tnx for the tutorial i folow the steps and i do this http://amsterdam1.plunder.com/142927/jet%20pack%20adventure%20stick.swf

    please do a 3 tutorial

  9. ? Says:

    You must makesure that the registraction point is at the bottom of you character(jetpack in this case).

  10. Jetpack game - Part 3 | Aksel Kornesjö Says:

    [...] Part 2 [...]

  11. kenny Says:

    it has problems on mx4 when the guy comes back down and hits the floor he can’t move then you half to restart the swf help me please

  12. megha Says:

    very good

  13. Reaper Says:

    very good, but registration
    point MUST BE DOWN or it doesnt work. NICE WORK

  14. DannoDan Says:

    yeah….the flyin works but the collidin dosent…..it says ive got 7 errors in my actionscript….i copied and pasted the code…so its not typed wrong..any help?anyone?

  15. Deelon9 Says:

    is this for Macromedia flash 8 cause the walls are doing anything, do u draw the walls in a new layer or in a new frame. And my thing for naming the instance is not the same? someone help plz?

  16. Deelon9 Says:

    ok so now im colliding but i cant hit the cieling, it wont let it get close? someone plz help, does it matter what shape the fly thing is???

  17. Mike Says:

    There’s a problem with the code for the platform. It doesn’t seem to work.

    Any help?

  18. chris Says:

    Nice thx man :) coooooooooooooooooool

  19. Corey Says:

    When u move it out of the screen it disapears cn u make it scroll so the guy is always in the middle

Leave a Reply