Create a Flash game like Metro Siberia Underground – Part 3

Multipart tutorial: available parts 1, 2, 3, 4 ,5

In the 3rd part I’ll leave the tunnel for a future use and I will introduce some “asteroids”, some “fuel tanks” and the distance traveled so far.

I suggest to read part 1 and 2 before reading this one

It’s not a line-by-line commented tutorial, I am just sharing the source code at the moment, a full explication will come soon

* edit: full explication available

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
import flash.filters.GlowFilter;
var ship_filter:GlowFilter = new GlowFilter(0x00ff00, 0.8, 4, 4, 2, 3, false, false);
var smoke_filter:GlowFilter = new GlowFilter(0xff0000, 0.8, 4, 4, 2, 3, false, false);
var tunnel_filter:GlowFilter = new GlowFilter(0xffff00, 0.8, 4, 4, 2, 3, false, false);
var fuel_filter:GlowFilter = new GlowFilter(0x00ffff, 0.8, 4, 4, 2, 3, false, false);
var rock_filter:GlowFilter = new GlowFilter(0xffffff, 0.8, 4, 4, 2, 3, false, false);
var score_filter:GlowFilter = new GlowFilter(0xff00ff, 0.8, 2, 4, 2, 3, false, false);
gravity = 0.1;
thrust = 0.25;
yspeed = 0;
xspeed = 5;
distance = 0;
smoke_interval = 10000;
frames_passed = 0;
tunnel_height = 150;
fuel_freq = 10;
gasoline = 500;
rock_freq = 50;
engines = false;
_root.attachMovie("ship", "ship", _root.getNextHighestDepth(), {_x:150, _y:200});
_root.createEmptyMovieClip("fuel_movie", _root.getNextHighestDepth());
_root.createEmptyMovieClip("deadly_movie", _root.getNextHighestDepth());
_root.attachMovie("score", "score", _root.getNextHighestDepth());
ship.filters = new Array(ship_filter);
score.filters = new Array(score_filter);
ship.onEnterFrame = function() {
	score.sc.text = "Distance: "+distance+" - "+"Fuel: "+gasoline;
	if ((gasoline>0)and(engines)) {
		yspeed -= thrust;
		smoke_interval -= 0.25;
		gasoline -= 1;
	}
	if (Math.random()*1000<fuel_freq) {
		fuel = fuel_movie.attachMovie("fuel", "fuel"+fuel_movie.getNextHighestDepth(), fuel_movie.getNextHighestDepth(), {_x:510, _y:Math.random()*400+50});
		fuel.filters = new Array(fuel_filter);
		fuel.onEnterFrame = function() {
			this._x -= (xspeed*1.2);
			dist_x = ship._x+28*Math.cos(angle)-this._x;
			dist_y = ship._y+28*Math.sin(angle)-this._y;
			dist = Math.sqrt(dist_x*dist_x+dist_y*dist_y);
			if (dist<10) {
				gasoline += 100;
				this.removeMovieClip();
			}
			if (this._x<-10) {
				this.removeMovieClip();
			}
		};
	}
	if (Math.random()*1000<rock_freq) {
		rock = deadly_movie.attachMovie("rock", "rock"+deadly_movie.getNextHighestDepth(), deadly_movie.getNextHighestDepth(), {_x:510, _y:Math.random()*400+50, _rotation:Math.random()*360});
		rock.filters = new Array(rock_filter);
		rock.onEnterFrame = function() {
			this._x -= xspeed;
			if (this._x<-10) {
				this.removeMovieClip();
			}
		};
	}
	yspeed += gravity;
	this._y += yspeed;
	angle = Math.atan2(yspeed, xspeed);
	this._rotation = angle*180/Math.PI;
	frames_passed++;
	distance += xspeed;
	if (frames_passed>=smoke_interval) {
		sm = _root.attachMovie("smoke", "smoke"+_root.getNextHighestDepth(), _root.getNextHighestDepth(), {_x:this._x-2, _y:this._y});
		sm.filters = new Array(smoke_filter);
		sm.onEnterFrame = function() {
			this._x -= xspeed;
			this._width += 0.2;
			this._height += 0.2;
			this._alpha -= 2;
			if (this._alpha<=0) {
				this.removeMovieClip();
			}
		};
		frames_passed = 0;
	}
	if ((this._y>400) or (this._y<0) or deadly_movie.hitTest(this._x+28*Math.cos(angle), this._y+28*Math.sin(angle), true) or deadly_movie.hitTest(this._x+8*Math.cos(angle+Math.PI/2), this._y+8*Math.sin(angle+Math.PI/2), true) or deadly_movie.hitTest(this._x+8*Math.cos(angle-Math.PI/2), this._y+8*Math.sin(angle-Math.PI/2), true)) {
		yspeed = 0;
		this._y = 200;
		gasoline = 500;
		distance = 0;
		deadly_movie.removeMovieClip();
		fuel_movie.removeMovieClip();
		_root.createEmptyMovieClip("fuel_movie", _root.getNextHighestDepth());
		_root.createEmptyMovieClip("deadly_movie", _root.getNextHighestDepth());
	}
};
_root.onMouseDown = function() {
	engines = true;
	smoke_interval = 10;
};
_root.onMouseUp = function() {
	engines = false;
	smoke_interval = 100000;
};

And this is the result. White blocks are deadly while blue circles raise your fuel.

Download the source code and tell me what do you think about it.

Multipart tutorial: available parts 1, 2, 3, 4 ,5

Rate this post: 1 Star2 Stars3 Stars4 Stars5 Stars (2 votes, average: 3.00 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.
Be my fan on Facebook and follow me on Twitter! Exclusive content for my Facebook fans and Twitter followers

This post has 11 comments

  1. Jerry

    on February 1, 2008 at 10:53 pm

    Awesome. I was trying to do it but wasn’t getting it to work. Keep up the great work!

  2. Michael

    on February 2, 2008 at 4:45 am

    Cool.
    I got to about 14k distance before I ran out of fuel and couldn’t grab any more. =\

  3. Bill

    on February 2, 2008 at 8:12 am

    doode!

    I’ve been trying to submit my game to you like it recommends in the support this blog section but i cant find how. anyway, if you didnt see a comment i made earlier, I’ve used these tutorials to make this game here

    http://galacticflashgames.com/games/bumblebee.php

    and would love to get some feedback on it. I actually did it before part 3 came out, and i sort of invented my own ‘fuel’ system, but in the case of this game, pollen is your fuel

  4. Orava

    on February 2, 2008 at 1:37 pm

    the distancemeter <3

  5. Create a Flash game like Metro Siberia Underground - Part 4 : Emanuele Feronato - italian geek and PROgrammer

    on February 5, 2008 at 5:14 pm

    [...] this 4th part I’ll cover the code written in 3rd part. You should read parts 1 and 2 too, because I will comment only the new code. For a better [...]

  6. Goinginsane

    on February 5, 2008 at 9:05 pm

    No offense Emanuele. Most of your tutorials have helped me immensly. But this one doesnt seem to meet the par. It is more suited for those of more expeience with flash. What about us? The noobs. What happened to the step by step instructions that helped me out so much on other tutorials. I am sorry if that seemed a bit harsh….I have been working on this game with no avail for several weaks.

  7. David

    on February 6, 2008 at 10:56 pm

    15k. i beat you all!!! MWHAHAHAHAHA

  8. Create a Flash game like Metro Siberia Underground - Part 5 : Emanuele Feronato - italian geek and PROgrammer

    on February 13, 2008 at 6:54 pm

    [...] tutorial: available parts 1, 2, 3, 4 [...]

  9. Create a Flash game like Metro Siberia Underground - Part 2 : Emanuele Feronato - italian geek and PROgrammer

    on February 13, 2008 at 6:56 pm

    [...] tutorial: available parts 1, 2, 3, 4 [...]

  10. Create a Flash game like Metro Siberia Underground : Emanuele Feronato - italian geek and PROgrammer

    on February 13, 2008 at 6:57 pm

    [...] tutorial: available parts 1, 2, 3, 4 [...]

  11. william

    on May 10, 2009 at 7:15 pm

    5/5. but can you make a shooter tutorial, where you have to shoot something and then it reappears somewhere else. ty anyway.