PDA

View Full Version : mario game



kanu
September 14th, 2006, 09:56 AM
*********************************code written on Player_mc*************************
onClipEvent (load) {
_root.restart();
jumpSpeed = 6;
bounds = this.getBounds(this);
function move(x, y) {
//trace(x);
jump = false;
if (!_root.map.hitTest(_x+x+bounds.xMin, _y+y+bounds.yMin, true)) {
//trace("move1");
if (!_root.map.hitTest(_x+x+bounds.xMax, _y+y+bounds.yMin, true)) {
//trace("move2");
if (!_root.map.hitTest(_x+x+bounds.xMin, _y+y+bounds.yMax, true)) {
//trace("move3");
if (!_root.map.hitTest(_x+x+bounds.xMax, _y+y+bounds.yMax, true)) {
//trace("move4");
_x += x;
_y += y;
jump = true;
//trace(_x);
}
}
}
}
return jump;
}
}
onClipEvent (enterFrame) {
if (_root.playGame) {
_root.falling = move(0, jumpSpeed);
if (Key.isDown(Key.UP) && !_root.falling && !_root.jumping) {
gravity = -12;
_root.jumping = true;
}
if (Key.isDown(Key.LEFT) and _x>_root.left) {
//_x>20) {
//trace("aaaaaaaaa");
move(-jumpSpeed, 0);
this.gotoAndStop("left");
}
if (_root._currentframe != 2) {
if (Key.isDown(Key.LEFT) and _x<=_root.left) {
_root.prevFrame();
this._x = _root.right;
//810;
move(-jumpSpeed, 0);
this.gotoAndStop("left");
}
}
if (Key.isDown(Key.RIGHT)) {
//trace("bbbbbbbbbb");
//_x<615) {
move(jumpSpeed, 0);
this.gotoAndStop("right");
}
if (Key.isDown(Key.RIGHT) and _x>=_root.right) {
//_x>=810){
_root.restart();
_root.nextFrame();
}
if (_root.jumping) {
if (gravity<=12) {
jump = move(0, gravity-jumpSpeed);
if (jump == false && gravity<0) {
gravity *= -1;
}
gravity++;
} else {
_root.jumping = false;
}
}
}
if (this._y>615) {
_root.playGame = false;
_root.hero.gotoAndStop("dead");
}
}
*********************code on root**************************
var right:Number = _root.border._x+_root.border._width;
var left:Number = _root.border._x+10;
var life:Number = 30;
var score:Number = 0;
var playGame:Boolean = true;
function restart() {
hero.gotoAndStop("right");
jumping = false;
playGame = true;
hero._x = map._x+10;
hero._y = 550;
}
function coin(mc:MovieClip) {
if (mc.hitTest(_root.hero)) {
mc.gotoAndStop("end");
_root.score += 1000;
removeMovieClip(mc);
}
}
function hit(mc:MovieClip) {
if (mc.hitTest(_r*********************************cod e written on Player_mc*************************

onClipEvent (load) {
_root.restart();
jumpSpeed = 6;
bounds = this.getBounds(this);
function move(x, y) {
//trace(x);
jump = false;
if (!_root.map.hitTest(_x+x+bounds.xMin, _y+y+bounds.yMin, true)) {
//trace("move1");
if (!_root.map.hitTest(_x+x+bounds.xMax, _y+y+bounds.yMin, true)) {
//trace("move2");
if (!_root.map.hitTest(_x+x+bounds.xMin, _y+y+bounds.yMax, true)) {
//trace("move3");
if (!_root.map.hitTest(_x+x+bounds.xMax, _y+y+bounds.yMax, true)) {
//trace("move4");
_x += x;
_y += y;
jump = true;
//trace(_x);
}
}
}
}
return jump;
}
}
onClipEvent (enterFrame) {
if (_root.playGame) {
_root.falling = move(0, jumpSpeed);
if (Key.isDown(Key.UP) && !_root.falling && !_root.jumping) {
gravity = -12;
_root.jumping = true;
}
if (Key.isDown(Key.LEFT) and _x>_root.left) {
//_x>20) {
//trace("aaaaaaaaa");
move(-jumpSpeed, 0);
this.gotoAndStop("left");
}
if (_root._currentframe != 2) {
if (Key.isDown(Key.LEFT) and _x<=_root.left) {
_root.prevFrame();
this._x = _root.right;
//810;
move(-jumpSpeed, 0);
this.gotoAndStop("left");
}
}
if (Key.isDown(Key.RIGHT)) {
//trace("bbbbbbbbbb");
//_x<615) {
move(jumpSpeed, 0);
this.gotoAndStop("right");
}
if (Key.isDown(Key.RIGHT) and _x>=_root.right) {
//_x>=810){
_root.restart();
_root.nextFrame();
}
if (_root.jumping) {
if (gravity<=12) {
jump = move(0, gravity-jumpSpeed);
if (jump == false && gravity<0) {
gravity *= -1;
}
gravity++;
} else {
_root.jumping = false;
}
}
}
if (this._y>615) {
_root.playGame = false;
_root.hero.gotoAndStop("dead");
}
}
*********************code on root**************************
var right:Number = _root.border._x+_root.border._width;
var left:Number = _root.border._x+10;
var life:Number = 30;
var score:Number = 0;
var playGame:Boolean = true;
function restart() {
hero.gotoAndStop("right");
jumping = false;
playGame = true;
hero._x = map._x+10;
hero._y = 550;
}
function coin(mc:MovieClip) {
if (mc.hitTest(_root.hero)) {
mc.gotoAndStop("end");
_root.score += 1000;
removeMovieClip(mc);
}
}
function hit(mc:MovieClip) {
if (mc.hitTest(_root.hero)) {
_root.playGame = false;
_root.hero.gotoAndStop("dead");
removeMovieClip(mc);
_root.life--;
}
}
**********************************************
is there is anything wrong in this code but still right and left move is not working and jumping is working perfectly fine even with right and left keys.
oot.hero)) {
_root.playGame = false;
_root.hero.gotoAndStop("dead");
removeMovieClip(mc);
_root.life--;
}
}
**********************************************
is there is anything wrong in this code but still right and left move is not working and jumping is working perfectly fine even with right and left keys.

LittleFenris
September 14th, 2006, 03:49 PM
I'm curious why you have the code written on the player movieclip instead of having all the code on the root timeline? I would get used to programming everything on the timeline as it makes it much easier to change things later on so you don't have to hunt around on your movieclips to find the code.

nathan99
September 14th, 2006, 07:01 PM
I'm curious why you have the code written on the player movieclip instead of having all the code on the root timeline? I would get used to programming everything on the timeline as it makes it much easier to change things later on so you don't have to hunt around on your movieclips to find the code.

Why would you be curious?. People start learning their own ways and as the improve they can figure out and conform to the best programming practises. There is no rule that says you have to program on the timelines.

However, it is a good idea to lean how to code one timelines ASAP, as it is a lot more flexible, and in Flash 9, you actually cannot do that any more.