Hi, I am having a major issue with this file. It was given to me to use specifically to convert it to my own game assets as an assignment. I can use another but I do not have one and do not have time to code a game from scratch. The problem I cannot seem to figure out is where the main character/stage is getting moved to a certain position on the stage when I click the start button. I can see that when I click it goes to the moveme function but no matter what I change within that function the character jumps from wherever I place him to the top left of the stage. I need my character to be in around the middle of the screen but slightly to the left. The link to the file is here
http://www.mediafire.com/?d8cwz9h2nb5m5bh
Sorry for not attaching but the file was too large and I didn’t want to modify it due to a chance of messing something up. If anyone else has a sidescroller game that they would like to let me use their source i’d be more than happy with that, especially if it was AS2.0 (3.0 is fine but i really dont know it yet) My character is going to be flying though so I dont need the typical gravity code, just a basic hovering movement. Thanks a ton for looking and helping!
Here is the code just in case it’s that easy of a solution, all of the “this.” code boggles my mind though, i do not know what this. means or how it chooses what “this” is.
moveLayer.hero.gotoAndStop(1);
// Hide the level complete dialog.
levelcomplete._visible = false;
var onground = false;
jumpsetup = false;
// This is the main character movement code
moveme = function () {
// This is our very first iteration through the code, store some variables.
if (this.x == undefined) {
this.startx = this.x=this._x;
this.starty = this.y=this._y;
}
this.dy += 0.5;
// Fall down. This variable, dy, is going to be added to the player's y position each frame
var nexty = Math.ceil(this.y+this.dy);
// My next y position
var nextx = this.x+this.dx;
// My next x position
onground = false;
// Am I falling down?
if (this.dy>=0) {
// Have I hit a solid platform?
if (moveLayer.platforms.hitTest(this.x+moveLayer._x, nexty+moveLayer._y, true) && !jumpsetup) {
onground = true;
jumping = false;
var cnt = 0;
var ty = Math.floor(nexty);
// I may have my next position being 'through' the ground, so
// Count backwards from my 'next position' to see where the real ground is
while (moveLayer.platforms.hitTest(this.x+moveLayer._x, ty+moveLayer._y, true)) {
cnt++;
ty -= 2;
}
if (cnt<10) {
// correct my y position
this.y = ty;
this.dy = 0;
} else {
// I've hit a wall
this.x -= this.dx;
this.dx = 0;
}
} else if (this.dy>5 && !shooting) {
// Falling
this.gotoAndStop(3);
this.mc.gotoAndStop(11);
}
} else if (this.dy<0) {
// Hit my head on the ceiling
if (moveLayer.platforms.hitTest(this.x+moveLayer._x, nexty+moveLayer._y-40, true)) {
this.dy = 1;
}
}
// Have I hit the exit?
if (moveLayer.exit.hitTest(this.x+moveLayer._x, this.y+moveLayer._y-40, true)) {
// Play the exit door animation. At the end of this animation is code to
// hide the player, and show the "level complete" screen.
moveLayer.exit.play();
}
if (this.dy>9) {
this.dy = 9;
}
// Terminal falling velocity
if (!jumpsetup) {
// If not in the process of starting the jump animation, then move the character
// along his motion path. Add dy to y and dx to x, moving the player.
this.x += this.dx;
this.y += this.dy;
}
if (Key.isDown(Key.RIGHT) && !shooting) {
// Pressing RIGHT button, set my x speed (dx)
if (jumping) {
this.dx += .4;
} else {
this.dx += 1;
}
// Set the direction the movieclip is facing.
this._xscale = 80;
} else if (Key.isDown(Key.LEFT) && !shooting) {
// Pressing LEFT button, set my x speed (dx)
if (jumping) {
this.dx -= .4;
} else {
this.dx -= 1;
}
// Set the direction the movieclip is facing.
this._xscale = -80;
} else {
this.dx *= 0.7;
}
// Slide to a stop because I'm not pressing left/right.
// Cap my max speeds left or right
if (this.dx>7) {
this.dx = 7;
}
if (this.dx<-7) {
this.dx = -7;
}
if (!jumpsetup && !jumping && !shooting && onground) {
// Animation control - show me standing still, or moving depending on my speed.
if (Math.abs(this.dx)<0.5) {
this.dx = 0;
this.gotoAndStop(1);
} else {
this.gotoAndStop(2);
}
}
// Jumping initiated.
if (Key.isDown(Key.UP) && this.dy>=0 && this.dy<1 && !jumping) {
onground = false;
shooting = false;
jumping = true;
jumpsetup = true;
// Play the jump animation.
this.gotoAndStop(3);
}
lasty = this._y;
// Move the background relative to myself. Since the character doesn't move from
// dead center of screen, the background must instead move relative to the character.
moveLayer._x = Math.round(160-this.x);
moveLayer._y = Math.round(150-this.y);
// Do not scroll the background more than -1268 - this way the character will fall off
// the bottom of the screen to his death.
if (moveLayer._y<-1268) {
moveLayer._y = -1268;
}
// Move the far background (the stars / planets) at a ratio relative to the level map.
// This creates 'parallax' scrolling.
bg._x = (moveLayer._x/2)-160;
bg._y = (moveLayer._y/2)-120;
// Fire the gun.
if (Key.isDown(Key.SPACE) && !shooting) {
shooting = true;
jumping = false;
jumpsetup = false;
this.gotoAndStop(4);
}
// I have fallen off the bottom of the level and am dead. Restart.
if (this.y>1580) {
this.x = this.startx;
this.y = this.starty;
intro._visible = true;
}
// Set my actual _x and _y properties to a rounded version of the x and y
// I've been using to compute my collision and position. Eliminates errors
// and a bad flickering effect.
this._x = Math.floor(this.x);
this._y = Math.floor(this.y);
};
// This function is used by the bullet when fired.
moveBullet = function () {
// Move along by my dx speed.
this._x += this.dx;
// If I'm out of visual range of the hero, then remove me.
if (this._x<moveLayer.hero._x-170 || this._x>moveLayer.hero._x+170) {
this.removeMovieClip();
}
};
// Call this function to create a bullet.
createBullet = function () {
var dir = moveLayer.hero._xscale/80;
// compute bullet's direction based on player's direction
nm = "bul0";
moveLayer.attachMovie("bullet", nm, 100);
moveLayer[nm]._x = moveLayer.hero._x+(35*dir);
moveLayer[nm]._y = moveLayer.hero._y-25;
moveLayer[nm]._xscale = dir*100;
moveLayer[nm].dx = 20*dir;
moveLayer[nm].onEnterFrame = moveBullet;
};
// 'splat' is the enemy's bullet. This function moves it and computes collisino with
// the player.
moveSplat = function () {
this._x += this.dx;
// Splat is far off screen, kill it.
if (this._x<moveLayer.hero._x-300 || this._x>moveLayer.hero._x+300) {
this.removeMovieClip();
}
// Did I hit the player?
if (this.hitTest(moveLayer.hero)) {
// Bash the player into the air.
moveLayer.hero.dx = this.dx*5;
moveLayer.hero.dy = -10;
this.removeMovieClip();
}
};
// Creates a splat.
numsplats = 0;
createSplat = function () {
var dir = this._xscale/80;
nm = "splat" add numsplats;
moveLayer.attachMovie("splatBullet", nm, numsplats+200);
moveLayer[nm]._x = this._x+(35*dir);
moveLayer[nm]._y = this._y-25;
moveLayer[nm]._xscale = dir*100;
moveLayer[nm].dx = 10*dir;
moveLayer[nm].onEnterFrame = moveSplat;
numsplats++;
numsplats %= 20;
};
// This is attached to the onEnterFrame of each monster. The onEnterFrame attach code
// is in the monster movie clips themselves.
simpleMove = function () {
if (this.x == undefined) {
this.x = this._x;
this.y = this._y;
}
this.x += this.dx;
this.y += this.dy;
// x1 and x2 are defined in the component parameters of the monsters. The monsters
// are components.
if (this.x<this.x1) {
this.x = this.x1;
this.dx *= -1;
} else if (this.x>this.x2) {
this.x = this.x2;
this.dx *= -1;
}
if (this.dx>0) {
this._xscale = 80;
} else if (this.dx<0) {
this._xscale = -80;
}
this._x = Math.floor(this.x);
this._y = Math.floor(this.y);
// I'm shot by the player!
if (this.hitTest(moveLayer.bul0)) {
this.gotoAndStop(2);
this.onEnterFrame = null;
}
// Randomly fire every 100 frames or so.
if (random(100) == 0) {
this.gotoAndStop(3);
}
};
// Start the game.
intro.playButton.onRelease = function() {
intro._visible = false;
moveLayer.hero.onEnterFrame = moveme;
};