hello everyone
i am coding a mario game and i have my code worked out so i can jump and move and whatnot. but now it comes to the part where i need to hit the blocks and i cannot figure out a hittest that will work.
please help by making a hittest!
the level is in a movieclip (such as the clouds in the background and the blocks i am trying to contact) that movieclip is called "level_mc" and the block movieclip inside the level is called "block1_mc".
ps: i am pretty sure the hittest should be located in that position, if not please specify where it should be.
ActionScript Code:
//variable declarations
onClipEvent(load){
right = true;
left = false;
rduck = false;
lduck = false;
rmoving = false;
lmoving = false;
ducking = true;
jumping = false;
falling = false;
resetpos = false;
jump = 15;
//play themesong
themesong = new Sound(this);
themesong.attachSound("theme.mp3");
themesong.start(0,99);
}
onClipEvent(enterFrame){
//walking config
if(Key.isDown(Key.RIGHT)){
this._xscale = 100;
this._x = 200;
right = true;
left = false;
rmoving = true;
_root.level_mc._x -= 8;
}else{
rmoving = false;
}
if(Key.isDown(Key.LEFT)){
this._xscale = -100;
this._x = 224;
left = true;
right = false;
lmoving = true;
if(_root.level_mc._x <= 200){
_root.level_mc._x += 8;
}
}else{
lmoving = false;
}
if(right && !rmoving||left && !lmoving){
this.gotoAndPlay(1);
}
//duck config
if(Key.isDown(Key.DOWN) && ducking){
this._visible = false;
_root.duck_mc._x = 200;
_root.duck_mc._y = 324;
}else{
this._visible = true;
_root.duck_mc._x = -100;
}
if(right){
_root.duck_mc._xscale = 100;
}
if(left){
_root.duck_mc._xscale = -100;
_root.duck_mc._x += 22;
}
//jump config
if (Key.isDown(Key.UP) && !jumping){
jumping = true;
ducking = false;
jumpsound = new Sound(this);
jumpsound.attachSound("jump.wav");
jumpsound.start(0,1);
}
if (jumping){
this.gotoAndStop(4);
this._y -= jump;
jump -= 1;
if(jump<0){
falling = true;
}
if(jump<-15){
jump = -15;
}
HITTEST SHOULD BE HERE !!!!!!!
}
//ground hit test
if (_root.ground_mc.hitTest(this._x+this._width, this._y+this._height, true) && falling){
jump = 15;
jumping = false;
falling = false;
ducking = true;
resetpos = true;
}
if(resetpos){
this.gotoAndPlay(1);
resetpos = false;
}
}