PDA

View Full Version : Making a mario type platform game! Need Help!



Spiderduckie
August 15th, 2007, 03:32 PM
Hi, I'm working on a mario style platform game, and I used the platform game tutorial from this site, but I'm having problems making another platform for the character to jump on. The only one I have currently is the "ground" platform. Also I'm having trouble with enemies and killing them.

if anyone could help it'd be great thanks.

this is the code I'm using for the main character.

onClipEvent (load) {
jumping = true;
speed = 0;
maxmove = 15;
jump = 0;
}
onClipEvent (enterFrame) {
if (_root.dead) {
this.gotoAndStop("dead");
} else {
speed *= .85;
if (speed>0) {
dir = "right";
} else if (speed<0) {
dir = "left";
}
if (dir == "right" && !_root.leftblock.hitTest(this._x+20, this._y, true)) {
_root.score._x += speed;
this._x += speed;
_root._x -= speed;
}
if (dir == "left" && !_root.rightblock.hitTest(this._x-20, this._y, true)) {
_root.score._x += speed;
this._x += speed;
_root._x -= speed;
}
if (Key.isDown(Key.LEFT)) {
if (speed>-maxmove) {
speed--;
}
this.gotoAndPlay("run");
this._xscale = -100;
} else if (Key.isDown(Key.RIGHT)) {
if (speed<maxmove) {
speed++;
}
this._xscale = 100;
this.gotoAndStop("run");
} else if (speed<1 && speed>-1) {
speed = 0;
this.gotoAndStop("idle");
}
if (Key.isDown(Key.SPACE) && !jumping) {
jumping = true;
}
if (jumping) {
this.gotoAndStop("jump");
this._y -= jump;
jump -= .5;
if (jump<0) {
falling = true;
}
if (jump<-15) {
jump = -15;
}
}
if (_root.ground.hitTest(this._x, this._y, true) && falling) {
jump = 12;
jumping = false;
falling = false;
}
}
}

leetleet
August 15th, 2007, 06:49 PM
Since having two instances named "ground" doesn't work, youll have to rename the instances to something like ground0, ground1, ground2, etc.
Then you can have a for(){ loop to make the hittest with each ground work


onClipEvent (enterFrame) {
i = 0;
j = 5; //lets say if your ground instances only go up to ground5
for (i = 0; i < j; i++) { //executes this statement over and over until i < j is false by increasing i by one
if (_root["ground"+i].hitTest(this._x, this._y, true) && falling) { //ground+i is now grounds 1-5
jump = 12;
jumping = false;
falling = false;
}
}
}

Spiderduckie
August 23rd, 2007, 11:23 AM
Since having two instances named "ground" doesn't work, youll have to rename the instances to something like ground0, ground1, ground2, etc.
Then you can have a for(){ loop to make the hittest with each ground work


onClipEvent (enterFrame) {
i = 0;
j = 5; //lets say if your ground instances only go up to ground5
for (i = 0; i < j; i++) { //executes this statement over and over until i < j is false by increasing i by one
if (_root["ground"+i].hitTest(this._x, this._y, true) && falling) { //ground+i is now grounds 1-5
jump = 12;
jumping = false;
falling = false;
}
}
}




Thanks a LOT! This really helped me. :}

Spiderduckie
August 23rd, 2007, 05:56 PM
Thanks a LOT! This really helped me. :}

unfortunately, I can't get him to fall from platforms!


onClipEvent (load) {
jumping = true;
speed = 0;
maxmove = 15;
jump = 0;
}
onClipEvent (enterFrame) {
if (_root.dead) {
this.gotoAndStop("dead");
} else {
speed *= .85;
if (speed>0) {
dir = "right";
} else if (speed<0) {
dir = "left";
}
if (dir == "right" && !_root.leftblock.hitTest(this._x+20, this._y, true)) {
_root.score._x += speed;
this._x += speed;
_root._x -= speed;
}
if (dir == "left" && !_root.rightblock.hitTest(this._x-20, this._y, true)) {
_root.score._x += speed;
this._x += speed;
_root._x -= speed;
}
if (Key.isDown(Key.LEFT)) {
if (speed>-maxmove) {
speed--;
}
this.gotoAndPlay("run");
this._xscale = -85;
} else if (Key.isDown(Key.RIGHT)) {
if (speed<maxmove) {
speed++;
}
this._xscale = 85;
this.gotoAndStop("run");
} else if (speed<1 && speed>-1) {
speed = 0;
this.gotoAndStop("idle");
}
if (Key.isDown(Key.SPACE) && !jumping) {
jumping = true;
}
if (jumping) {
this.gotoAndStop("jump");
this._y -= jump;
jump -= .5;
if (jump<0) {
falling = true;
}
if (jump<-15) {
jump = -15;
}
}
if (_root.ground.hitTest(this._x, this._y, true) && falling) {
jump = 12;
jumping = false;
falling = false;
}
}
}
onClipEvent (enterFrame) {
i = 0;
j = 20; //lets say if your ground instances only go up to ground5
for (i = 0; i < j; i++) { //executes this statement over and over until i < j is false by increasing i by one
if (_root["ground"+i].hitTest(this._x, this._y, true) && falling) { //ground+i is now grounds 1-5
jump = 12;
jumping = false;
falling = false;
}
}
}

zellers
August 23rd, 2007, 11:41 PM
:cowboy: well, wouldn't it just work to have one instance of the ground, and place all of your platforms there? I believe it would considering that when i used that tutorial as a case study(over a year ago) on movieclip actions, I know that one "ground" instance is only needed for as many platforms as you need.

Spiderduckie
August 24th, 2007, 01:57 AM
:cowboy: well, wouldn't it just work to have one instance of the ground, and place all of your platforms there? I believe it would considering that when i used that tutorial as a case study(over a year ago) on movieclip actions, I know that one "ground" instance is only needed for as many platforms as you need.

Well the reason I need them separate is because, some of the objects have to contain different actions for hit tests, such as jumping and hitting the bottom of the coin dispenser and adding a point.

Spiderduckie
August 24th, 2007, 02:16 AM
unfortunately, I can't get him to fall from platforms!


onClipEvent (load) {
jumping = true;
speed = 0;
maxmove = 15;
jump = 0;
}
onClipEvent (enterFrame) {
if (_root.dead) {
this.gotoAndStop("dead");
} else {
speed *= .85;
if (speed>0) {
dir = "right";
} else if (speed<0) {
dir = "left";
}
if (dir == "right" && !_root.leftblock.hitTest(this._x+20, this._y, true)) {
_root.score._x += speed;
this._x += speed;
_root._x -= speed;
}
if (dir == "left" && !_root.rightblock.hitTest(this._x-20, this._y, true)) {
_root.score._x += speed;
this._x += speed;
_root._x -= speed;
}
if (Key.isDown(Key.LEFT)) {
if (speed>-maxmove) {
speed--;
}
this.gotoAndPlay("run");
this._xscale = -85;
} else if (Key.isDown(Key.RIGHT)) {
if (speed<maxmove) {
speed++;
}
this._xscale = 85;
this.gotoAndStop("run");
} else if (speed<1 && speed>-1) {
speed = 0;
this.gotoAndStop("idle");
}
if (Key.isDown(Key.SPACE) && !jumping) {
jumping = true;
}
if (jumping) {
this.gotoAndStop("jump");
this._y -= jump;
jump -= .5;
if (jump<0) {
falling = true;
}
if (jump<-15) {
jump = -15;
}
}
if (_root.ground.hitTest(this._x, this._y, true) && falling) {
jump = 12;
jumping = false;
falling = false;
}
}
}
onClipEvent (enterFrame) {
i = 0;
j = 20; //lets say if your ground instances only go up to ground5
for (i = 0; i < j; i++) { //executes this statement over and over until i < j is false by increasing i by one
if (_root["ground"+i].hitTest(this._x, this._y, true) && falling) { //ground+i is now grounds 1-5
jump = 12;
jumping = false;
falling = false;
}
}
}

Still having Trouble with this...