scarce
12-19-2007, 08:15 PM
:) Well, I just signed up here. I'm having a couple issues with a platform game I am working on.
When the screen pans with the character...I'm trying to get it like Alien Hominid style. When the level starts, you can't pan left, but when you hit the center of the screen it starts panning, but if you walk left, the "camera" stops panning. I can't figure it out.
Also the longest lasting problem, my enemy won't jump up onto a platform if he hits it and I'm on it. Torwards the bottom under the brain() function.
stop();
var player:Object = new Object();
Key.addListener(player);
_global.duck = false;
_global.death = false;
_global.hurt = false;
_global.attack = false;
_global.eattack = false;
_global.ehurt = false;
_global.edeath = false;
var g:Number = .3;
var f:Number = .5;
miscar._x = 120;
miscar.vx = 0;
miscar.vy = 0;
miscar.power = 5;
miscar.jump = -8;
miscar.jumping = false;
miscar.health = 50;
enemy.health = 10;
enemy.vx = 0;
enemy.vy = 0;
enemy.power = .05;
enemy.jump = -8;
enemy.jumping = false;
//for (i=1; i<=10; i++) {
//_root["wall"+i]._visible = false;
//_root["platform"+i]._visible = false;
//}
this.onEnterFrame = function() {
brain(enemy,miscar);
miscar.vx *= f;
miscar.vy += g;
miscar._y += miscar.vy;
healthbar.gotoAndStop(miscar.health);
if (miscar.health<=0) {
_global.hurt = false;
_global.death = true;
miscar.gotoAndStop("death");
cleanup();
}
if (miscar._x>=(Stage.width)/2) {
for (i=1; i<=10; i++) {
_root["wall"+i]._x -= miscar.vx;
_root["platform"+i]._x -= miscar.vx;
}
stage1.road._x -= miscar.vx;
if (stage1.road._x<=-1912) {
stage1.road._x = -560;
}
stage1.mhouse._x -= miscar.vx;
stage1.foreground._x -= miscar.vx/2;
if (stage1.foreground._x<=-1908) {
stage1.foreground._x = -560;
}
stage1.backscene._x -= miscar.vx/3;
if (stage1.backscene._x<=-1908) {
stage1.backscene._x = -555;
}
stage1.mountains._x -= miscar.vx/4;
if (stage1.mountains._x<=-1907) {
stage1.mountains._x = -555;
}
enemy._x -= miscar.vx;
} else {
miscar._x += miscar.vx;
}
updater(enemy);
for (i=1; i<=10; i++) {
if (_global.death == false) {
if (_global.duck == false) {
if (_global.attack == false) {
if (_global.hurt == false) {
if (miscar.jumping == false) {
if (Key.isDown(Key.LEFT) && !_root["platform"+i].hitTest(miscar._x-(miscar._width/2)-3, miscar._y, true)) {
_root.miscar._xscale = -100;
miscar.vx -= miscar.power;
miscar.gotoAndStop("walk");
} else if (Key.isDown(Key.RIGHT) && !_root["platform"+i].hitTest(miscar._x+(miscar._width/2)+3, miscar._y, true)) {
miscar.vx += miscar.power;
_root.miscar._xscale = +100;
miscar.gotoAndStop("walk");
} else {
miscar.gotoAndStop("stand");
}
}
if (miscar.jumping == true) {
if (Key.isDown(Key.LEFT) && !_root["platform"+i].hitTest(miscar._x-(miscar._width/2)-3, miscar._y, true)) {
miscar._xscale = -100;
miscar.vx -= miscar.power;
} else if (Key.isDown(Key.RIGHT) && !_root["platform"+i].hitTest(miscar._x+(miscar._width/2)+3, miscar._y, true)) {
miscar.vx += miscar.power;
miscar._xscale = 100;
}
miscar.gotoAndStop("jump");
}
if (Key.isDown(65) && !miscar.jumping) {
miscar.vy += miscar.jump;
miscar._y += miscar.jump;
miscar.jumping = true;
miscar.gotoAndStop("jump");
}
if (Key.isDown(Key.DOWN) && !miscar.jumping) {
_global.duck = miscar.gotoAndStop("duck");
_global.duck = true;
if (_global.duck == true) {
_global.hurt = false;
miscar.jump = -10;
f = 0;
}
} else {
f = .5;
}
}
}
if (Key.isDown(83) && !miscar.jumping) {
_global.attack = miscar.gotoAndStop("attack");
_global.attack = true;
if (enemy.health>0) {
if (_root.miscar.attack.weapon.hitTest(enemy)) {
enemy.gotoAndStop("hurt");
enemy.health--;
_global.ehurt = true;
trace(enemy.health);
}
if (_global.attack == true) {
f = 0;
}
}
} else {
f = .5;
}
}
}
collisions(miscar);
collisions(enemy);
}
player = miscar;
};
player.onKeyUp = function() {
if (Key.isDown(65)) {
miscar.jump = -10;
} else {
miscar.jump = -8;
}
f = .5;
_global.duck = false;
};
function updater(ob) {
ob.vx *= f;
ob.vy += g;
ob._x += ob.vx;
ob._y += ob.vy;
}
function collisions(ob) {
for (i=1; i<=10; i++) {
while (_root["platform"+i].hitTest(ob._x, ob._y-(ob._height/2), true)) {
ob._y += .1;
ob.vy = 0;
}
while (_root["platform"+i].hitTest(ob._x+(ob._width)/3, ob._y+(ob._height/18), true)) {
ob._y -= .1;
ob.vy = 0;
ob.jumping = false;
}
while (_root["platform"+i].hitTest(ob._x+(ob._width/2), ob._y-(ob._height/2), true)) {
ob._x -= .1;
ob.vx = 0;
}
while (_root["platform"+i].hitTest(ob._x-(ob._width/2), ob._y-(ob._height/2), true)) {
ob._x += .1;
ob.vx = 0;
}
while (_root["wall"+i].hitTest(ob._x, ob._y-(ob._height/2), true)) {
ob._y += .1;
ob.vy = 0;
}
while (_root["wall"+i].hitTest(ob._x+(ob._width)/3, ob._y+(ob._height/18), true)) {
ob._y -= .1;
ob.vy = 0;
ob.jumping = false;
}
while (_root["wall"+i].hitTest(ob._x+(ob._width/2), ob._y-(ob._height/2), true)) {
ob._x -= .1;
ob.vx = 0;
}
while (_root["wall"+i].hitTest(ob._x-(ob._width/2), ob._y-(ob._height/2), true)) {
ob._x += .1;
ob.vx = 0;
}
}
}
function brain(ob, tr) {
if (_global.edeath == false) {
if (_global.ehurt == false) {
if (ob.jumping == false) {
if (enemy._x<tr._x-60) {
enemy._x++;
enemy._xscale = 100;
enemy.vx -= enemy.power;
enemy.gotoAndStop("walk");
} else if (enemy._x>tr._x+60) {
enemy._x--;
enemy._xscale = -100;
enemy.vx += ob.power;
enemy.gotoAndStop("walk");
} else if (enemy.hitTest(tr._x, tr._y)-20) {
enemy.gotoAndStop("attack");
if (_global.attack == false) {
if (_global.duck == false) {
if (enemy.attack.eweapon.hitTest(tr)) {
tr.health -= 1;
_global.hurt = true;
_global.hurt = tr.gotoAndStop("hurt");
}
}
}
}
if (ob._y<tr._y && !ob.jumping && (_root["wall"+i].hitTest(ob._x+(ob._width/2)+3, ob._y, true) || _root["wall"+i].hitTest(ob._x-(ob._width/2)-3, ob._y, true))) {
for (i=1; i<=10; i++) {
trace("eureka");
enemy.vy += enemy.jump;
enemy._y += enemy.jump;
enemy.jumping = true;
enemy.gotoAndStop("jump");
}
}
}
}
}
if (enemy.health<=0) {
_global.edeath = true;
enemy.gotoAndStop("death");
}
}
function cleanup() {
delete this.onEnterFrame;
gotoAndPlay(2);
}
Here's the code, can anyone help?:) :confused:
When the screen pans with the character...I'm trying to get it like Alien Hominid style. When the level starts, you can't pan left, but when you hit the center of the screen it starts panning, but if you walk left, the "camera" stops panning. I can't figure it out.
Also the longest lasting problem, my enemy won't jump up onto a platform if he hits it and I'm on it. Torwards the bottom under the brain() function.
stop();
var player:Object = new Object();
Key.addListener(player);
_global.duck = false;
_global.death = false;
_global.hurt = false;
_global.attack = false;
_global.eattack = false;
_global.ehurt = false;
_global.edeath = false;
var g:Number = .3;
var f:Number = .5;
miscar._x = 120;
miscar.vx = 0;
miscar.vy = 0;
miscar.power = 5;
miscar.jump = -8;
miscar.jumping = false;
miscar.health = 50;
enemy.health = 10;
enemy.vx = 0;
enemy.vy = 0;
enemy.power = .05;
enemy.jump = -8;
enemy.jumping = false;
//for (i=1; i<=10; i++) {
//_root["wall"+i]._visible = false;
//_root["platform"+i]._visible = false;
//}
this.onEnterFrame = function() {
brain(enemy,miscar);
miscar.vx *= f;
miscar.vy += g;
miscar._y += miscar.vy;
healthbar.gotoAndStop(miscar.health);
if (miscar.health<=0) {
_global.hurt = false;
_global.death = true;
miscar.gotoAndStop("death");
cleanup();
}
if (miscar._x>=(Stage.width)/2) {
for (i=1; i<=10; i++) {
_root["wall"+i]._x -= miscar.vx;
_root["platform"+i]._x -= miscar.vx;
}
stage1.road._x -= miscar.vx;
if (stage1.road._x<=-1912) {
stage1.road._x = -560;
}
stage1.mhouse._x -= miscar.vx;
stage1.foreground._x -= miscar.vx/2;
if (stage1.foreground._x<=-1908) {
stage1.foreground._x = -560;
}
stage1.backscene._x -= miscar.vx/3;
if (stage1.backscene._x<=-1908) {
stage1.backscene._x = -555;
}
stage1.mountains._x -= miscar.vx/4;
if (stage1.mountains._x<=-1907) {
stage1.mountains._x = -555;
}
enemy._x -= miscar.vx;
} else {
miscar._x += miscar.vx;
}
updater(enemy);
for (i=1; i<=10; i++) {
if (_global.death == false) {
if (_global.duck == false) {
if (_global.attack == false) {
if (_global.hurt == false) {
if (miscar.jumping == false) {
if (Key.isDown(Key.LEFT) && !_root["platform"+i].hitTest(miscar._x-(miscar._width/2)-3, miscar._y, true)) {
_root.miscar._xscale = -100;
miscar.vx -= miscar.power;
miscar.gotoAndStop("walk");
} else if (Key.isDown(Key.RIGHT) && !_root["platform"+i].hitTest(miscar._x+(miscar._width/2)+3, miscar._y, true)) {
miscar.vx += miscar.power;
_root.miscar._xscale = +100;
miscar.gotoAndStop("walk");
} else {
miscar.gotoAndStop("stand");
}
}
if (miscar.jumping == true) {
if (Key.isDown(Key.LEFT) && !_root["platform"+i].hitTest(miscar._x-(miscar._width/2)-3, miscar._y, true)) {
miscar._xscale = -100;
miscar.vx -= miscar.power;
} else if (Key.isDown(Key.RIGHT) && !_root["platform"+i].hitTest(miscar._x+(miscar._width/2)+3, miscar._y, true)) {
miscar.vx += miscar.power;
miscar._xscale = 100;
}
miscar.gotoAndStop("jump");
}
if (Key.isDown(65) && !miscar.jumping) {
miscar.vy += miscar.jump;
miscar._y += miscar.jump;
miscar.jumping = true;
miscar.gotoAndStop("jump");
}
if (Key.isDown(Key.DOWN) && !miscar.jumping) {
_global.duck = miscar.gotoAndStop("duck");
_global.duck = true;
if (_global.duck == true) {
_global.hurt = false;
miscar.jump = -10;
f = 0;
}
} else {
f = .5;
}
}
}
if (Key.isDown(83) && !miscar.jumping) {
_global.attack = miscar.gotoAndStop("attack");
_global.attack = true;
if (enemy.health>0) {
if (_root.miscar.attack.weapon.hitTest(enemy)) {
enemy.gotoAndStop("hurt");
enemy.health--;
_global.ehurt = true;
trace(enemy.health);
}
if (_global.attack == true) {
f = 0;
}
}
} else {
f = .5;
}
}
}
collisions(miscar);
collisions(enemy);
}
player = miscar;
};
player.onKeyUp = function() {
if (Key.isDown(65)) {
miscar.jump = -10;
} else {
miscar.jump = -8;
}
f = .5;
_global.duck = false;
};
function updater(ob) {
ob.vx *= f;
ob.vy += g;
ob._x += ob.vx;
ob._y += ob.vy;
}
function collisions(ob) {
for (i=1; i<=10; i++) {
while (_root["platform"+i].hitTest(ob._x, ob._y-(ob._height/2), true)) {
ob._y += .1;
ob.vy = 0;
}
while (_root["platform"+i].hitTest(ob._x+(ob._width)/3, ob._y+(ob._height/18), true)) {
ob._y -= .1;
ob.vy = 0;
ob.jumping = false;
}
while (_root["platform"+i].hitTest(ob._x+(ob._width/2), ob._y-(ob._height/2), true)) {
ob._x -= .1;
ob.vx = 0;
}
while (_root["platform"+i].hitTest(ob._x-(ob._width/2), ob._y-(ob._height/2), true)) {
ob._x += .1;
ob.vx = 0;
}
while (_root["wall"+i].hitTest(ob._x, ob._y-(ob._height/2), true)) {
ob._y += .1;
ob.vy = 0;
}
while (_root["wall"+i].hitTest(ob._x+(ob._width)/3, ob._y+(ob._height/18), true)) {
ob._y -= .1;
ob.vy = 0;
ob.jumping = false;
}
while (_root["wall"+i].hitTest(ob._x+(ob._width/2), ob._y-(ob._height/2), true)) {
ob._x -= .1;
ob.vx = 0;
}
while (_root["wall"+i].hitTest(ob._x-(ob._width/2), ob._y-(ob._height/2), true)) {
ob._x += .1;
ob.vx = 0;
}
}
}
function brain(ob, tr) {
if (_global.edeath == false) {
if (_global.ehurt == false) {
if (ob.jumping == false) {
if (enemy._x<tr._x-60) {
enemy._x++;
enemy._xscale = 100;
enemy.vx -= enemy.power;
enemy.gotoAndStop("walk");
} else if (enemy._x>tr._x+60) {
enemy._x--;
enemy._xscale = -100;
enemy.vx += ob.power;
enemy.gotoAndStop("walk");
} else if (enemy.hitTest(tr._x, tr._y)-20) {
enemy.gotoAndStop("attack");
if (_global.attack == false) {
if (_global.duck == false) {
if (enemy.attack.eweapon.hitTest(tr)) {
tr.health -= 1;
_global.hurt = true;
_global.hurt = tr.gotoAndStop("hurt");
}
}
}
}
if (ob._y<tr._y && !ob.jumping && (_root["wall"+i].hitTest(ob._x+(ob._width/2)+3, ob._y, true) || _root["wall"+i].hitTest(ob._x-(ob._width/2)-3, ob._y, true))) {
for (i=1; i<=10; i++) {
trace("eureka");
enemy.vy += enemy.jump;
enemy._y += enemy.jump;
enemy.jumping = true;
enemy.gotoAndStop("jump");
}
}
}
}
}
if (enemy.health<=0) {
_global.edeath = true;
enemy.gotoAndStop("death");
}
}
function cleanup() {
delete this.onEnterFrame;
gotoAndPlay(2);
}
Here's the code, can anyone help?:) :confused: