Help me make Mario like game

I just started making games with flash, could someone tell me how to make mario like game (moving, jumping, collecting coins etc.) :rambo:

Well, I made a mario game not to long ago, so what the heck ;). What do you want to learn first?

Umm how to collect coins… and score.

Well then, let us begin :D. Now, the score keeping is actually quite simple. All you will need to do for this, is create a dynamic text, and give it a variable name of “score” and instance name of “score”. Now select the frame, open the actions panel, and type:

_root.score = 0;

This will make the score start at zero when the game starts. Here is an fla for this part of the lesson:

Now for the coins. First, you will need a coin, so Draw a coin and convert it to a symbol with a name of “coin”. Then open it’s properties, and give it an instance name of “coin”. Now, we will want more then just one coin, right? Of course :)! So now, we open the frame again, and after the score code, we type the following:


numCoin = 2;
//this determines the ammount of coins placed on the screen, 2, being the number we use//
for (i=2; i<=numCoin; i++) {
	 coin.duplicateMovieClip("coin1"+i, i+100);
	 //now, this will duplicate the coin and name it//
	 _root["coin1"+i]._x = //wherever you wish to set his Y position//
	 _root["coin1"+i]._y = //wherever you wish to set his X position//
}
 

Here is the fla source for this part of the lesson:

Wow :), good, clean, tutorial, JoMan! I Understood every thing you said! Have you ever thought of putting a tutorial on Kirupa?

blush Thanks! I like it when my tutorials make sense. I havent really thought of putting any tutorials up… I dont think I’m experienced enough for that.

Hey cool thanks. Now I have made mario and its movements its name is Hero and so now i want when mario hits the coin the coin disappears and scores.

  • ive made the floor and walls platforms :slight_smile:

Good :). Ok, next part commin…

how to make him walk and stuff???:puzzled:

Ok, we have our coin, mario, and the score, right? well now we need mario to obtain the coin. First, we need to edit our coin, so right click the coin and select “edit in place”. Now, create another frame for the coin, and remove the coin picture on the second frame. Now, exit the coin, and open its action panel. Type:


onClipEvent (load) {
	 this.stop();
}
onClipEvent (enterFrame) {
	 if (this.hitTest(_root.mario)) {
		 this.gotoAndStop(2);
		 _root.score +=1;
	 }
}

Please reply when you are ready for the next part.

One minute, post comming…

and also walk on platform…

Yayyy!! Thanks…
If you would be so kind to help me with the enemies too :slight_smile:

Ok, now for mario. First, we draw mario(or import the sprites), then we convert him to a Symbol and name him “mario”, then we give him an instance name of “mario”. Now, we create his moving, jumping, ducking, and dying sequences. Asuming that you know how to do that, we shall move on to the coding. So, we open mario’s action panel, and type:


onClipEvent (load) {
	 vel_y = 0;
//this will be used for his jumping velocoty//
	 started = true;
//this will be required when we make his movement//
	 jumping = false;
//this will be required when we make his jumping//
	 xspeed = 5;
//this is his movement speed//
	 this.stop(); 
//and this commands him to hault on his standing sequence (asuming that you made his standing sequence on his first frame)//
}

Now, we start the moving code. So now type:


onClipEvent (enterFrame) {
	 if (started) {
		 if (move) {
			 if (Key.isDown(Key.LEFT)) {
				 this.gotoAndStop("run");
				 this._xscale = -100;
			 }
			 if (Key.isDown(Key.RIGHT)) {
				 this.gotoAndStop("run");
				 this._xscale = 100;
			 }
			 if (Key.isDown(Key.DOWN)) {
				 this.gotoAndStop("duck");
				 xspeed = 0;
				}
		 }
	 }
} 

Mind you, the “if (move) {” will be confirmed later on his ground touching code, or “collision detection”. More coming…

Sure :P. That is included with marios moving.

Now, we need to make mario’s jumping. Note: the jumping will also be needed to make the “goombas” die. Since this code is a bit big, I am going to post half of it now, and half after words (that way I can explain things about it). So, now we type the following:


onClipEvent (enterFrame) {
	 if (started) {
		 if (Key.isDown(Key.LEFT)) {
			 this._x -= xspeed;
		 }
		 if (Key.isDown(Key.RIGHT)) {
			 this._x += xspeed;
		 }
		 if (Key.isDown(Key.UP) && !jumping) {
			 this.gotoAndStop("jump");
			 move = false;
			 vel_y = 17;
			 jumpSound.start();
			 jumping = true;
		 }
		 if (jumping == true) {
			 vel_y -= 1;
		 if (vel_y<=-17) {
			 vel_y = -17;
		 }
		 this._y -= vel_y;
	 }
//continued...//

Notice, I put “if (started) {” before this, as well as the previous moving code. That is because I use “started” to control the game’s flow of mario’s actions. For example, If I told the game that started = false, mario would stop all of his actions. Also notice, that “vel_y” was used. “vel_y” is to command his actuall jumping, and his jumping speed. Now to continue:


	 if (!_root.ground.hitTest(this._x, this._y+15, true) && !jumping) {
		 fall += 1;
		 move = false;
		 this.gotoAndStop("jump");
	 if (fall>17) {
		 fall = 17;
	 }
	 this._y += fall;
}
if (_root.ground.hitTest(this._x, this._y+15, true)) {
	if (vel_y<=1) {
		fall = 0;
		vel_y = 0;
		jumping = false;
		this.jump.gotoAndStop(2);
		move = true;
	 }
}
//continued...//

ah yes, the mighty ground hitTest… As I have promised, the “move” was confirmed as “true” :party:.


if (_root.goomba.hitTest(this.jump)) {
	 if (vel_y<=1) {
		 _root.goomba.gotoAndPlay("dead");
		 _root.goomba.xspeed = 0;
		 _root.counter.play();
		 vel_y = 10;		 
	 }
}
}
}
//end//

This is what I like to reffer to as “killing”, because this is what kills the goomba. The:

if (_root.goomba.hitTest(this.jump)) {

states that if mario is jumping, and he hits the goomba, he will kill it. By now, I am sure that you have noticed the “_root.counter.play();”, am I right? Well, that will come later. Stay tuned! There is more to come…

posted it :D. It’s in the BIG post :hugegrin:.

By the way, if either of you has a question or you just dont understand, dont hesitate to ask and I will do my best to assist you. Or you can PM me here on Kirupa. Thanks.

If i dont want to make the moving all over again and i still want to kill the goomba. how?
i have these actions in my mario:

 onClipEvent (load) {
gravity = 10;
scale = _xscale;
walkSpeed = 6;
maxjump = 6;
}
onClipEvent (enterFrame) {
if (air == true) {
_y += gravity;
state = 3;
}
if (Key.isDown(Key.LEFT) && !_root.leftbound.hitTest(_x, _y, true)) {
_x -= walkSpeed;
_xscale = -scale;
}
if (Key.isDown(Key.RIGHT) && !_root.rightbound.hitTest(_x, _y, true)) {
_x += walkSpeed;
_xscale = scale;
}
if (_root.platforms.hitTest(_x, _y, true)) {
air = false;
} else {
air = true;
}
if (Key.isDown(Key.SPACE) && jump == true) {
_y -= jumpSpeed;
}
if (air == false) {
jump = true;
jumpcount = 0;
jumpSpeed = 19;
}
if (Key.isDown(Key.SPACE)) {
jumpcount += 1;
}
if (jumpcount> maxjump && jumpSpeed> -2) {
jumpSpeed -= 2;
}
if (air == false && !Key.isDown(Key.LEFT) && !Key.isDown(65) && _currentframe <4 or air == false && !Key.isDown(Key.RIGHT) && !Key.isDown(65) && _currentframe <4) {
state = 1;
}
if (Key.isDown(Key.LEFT) && air == false && !Key.isDown(65) && _currentframe <4 or Key.isDown(Key.RIGHT) && air == false && !Key.isDown(65) && _currentframe <4) {
state = 2;
}
if (!Key.isDown(65)) {
gotoAndStop(state);
}
_root.statetxt = state;
}
onClipEvent (keyUp) {
if (Key.getCode() == 83) {
jump = false;
}
}