PDA

View Full Version : Hello! gotta question :)


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:

rrh
12-19-2007, 09:41 PM
First glance:
enemy.hitTest(tr._x, tr._y)-20
You are using enemy instead of ob. (Shouldn't cause a problem since you have only one enemy, but kind of undermines the point of passing a parameter.)

More important, hitTest returns a boolean, not a number, so there's no point subtracting from it. Maybe you meant:
enemy.hitTest(tr._x, tr._y-20)

scarce
12-19-2007, 10:19 PM
First glance:
enemy.hitTest(tr._x, tr._y)-20
You are using enemy instead of ob. (Shouldn't cause a problem since you have only one enemy, but kind of undermines the point of passing a parameter.)

More important, hitTest returns a boolean, not a number, so there's no point subtracting from it. Maybe you meant:
enemy.hitTest(tr._x, tr._y-20)

hmm, ok, yeah thats true. Alright lemme try that and I'll see if that works

thanks :)

scarce
12-19-2007, 10:24 PM
First glance:
enemy.hitTest(tr._x, tr._y)-20
You are using enemy instead of ob. (Shouldn't cause a problem since you have only one enemy, but kind of undermines the point of passing a parameter.)

More important, hitTest returns a boolean, not a number, so there's no point subtracting from it. Maybe you meant:
enemy.hitTest(tr._x, tr._y-20)

I just had a thought about it, my hitTest for the enemy to attack me works fine, but I'll probibly change it to ob for when I am using more enemies. That'll be a different thing, I tried it once and had probs. But first thjings first, lol.

The jumping portion has it saying ob instead of enemy, and I tried enemy before.

scarce
12-20-2007, 07:02 PM
Are my issues stated confusingly? If so just ask and I can elaborate more.

rrh
12-20-2007, 09:07 PM
What about the -20 thing? What's the deal with that?

scarce
12-20-2007, 09:34 PM
What about the -20 thing? What's the deal with that?

the point of it is so when the enemy is so far away, he'll start attacking...without it you have to wait until the enemy is all up on you which makes NO difficulty at all because you can stand away and attack and the enemy never attacks...that part is working just fine.

rrh
12-23-2007, 01:56 AM
Well, it shouldn't work just fine:

if (false-20)
trace("false-20 evaluates as true " + hitTest(-100,-100));

This is your jumping code?
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");
}
}
I don't understand the for loop; I think the same could be accomplished with:
enemy.vy += enemy.jump*10;
enemy._y += enemy.jump*10;

From context, it will only jump when it's within 60 pixels of you. You didn't say if that was the desired behaviour.

scarce
12-30-2007, 03:12 PM
Well, it shouldn't work just fine:

if (false-20)
trace("false-20 evaluates as true " + hitTest(-100,-100));

This is your jumping code?
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");
}
}
I don't understand the for loop; I think the same could be accomplished with:
enemy.vy += enemy.jump*10;
enemy._y += enemy.jump*10;

From context, it will only jump when it's within 60 pixels of you. You didn't say if that was the desired behaviour.

i tried just that and it didn't work...the for loop is to constantly check if he's touching a wall...

rrh
12-31-2007, 06:55 AM
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");
}
}
The for loop is inside of the if statement, not the other way around. This for loop does not contain any code that checks if it's touching a wall. The for loop continues as long as (i<=10) is true. Maybe what you want instead is a while loop:
while (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))) {
trace("eureka");
enemy.vy += enemy.jump;
enemy._y += enemy.jump;
enemy.jumping = true;
enemy.gotoAndStop("jump");
}

Being able to keep your loops and conditionals straight is pretty fundamental to programming. You need to really pay attention to this.

scarce
12-31-2007, 04:16 PM
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");
}
}
The for loop is inside of the if statement, not the other way around. This for loop does not contain any code that checks if it's touching a wall. The for loop continues as long as (i<=10) is true. Maybe what you want instead is a while loop:
while (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))) {
trace("eureka");
enemy.vy += enemy.jump;
enemy._y += enemy.jump;
enemy.jumping = true;
enemy.gotoAndStop("jump");
}

Being able to keep your loops and conditionals straight is pretty fundamental to programming. You need to really pay attention to this.


hey now, no need to be mean, this is my first game. I don't know everything which is why I came here, I'mma try that out now.


update: i tried it, and it worked...I think...I added another platform and wall (wall2 and platform2) but they weren't working like the other platform. The wall I switched the numbers (wall1 became wall2 and vice versa) then the wall worked...but the second platform moves with the screen...bah...until I can fix that I won't be sure if the enemy works precisely...he did jump and played the animation, but didn't move forward...but thats cause I fell through the top of the wall cause the platform wasn't the to support me, lol.

rrh
01-02-2008, 05:01 AM
I didn't intend to be mean. I just meant to emphasize the importance of this skill. In programming classes, they'll often give you some sample code and you will need to predict the execution order, based on the conditionals and loops.

My first game was a text-based choose-your-own-adventure story, that used only nested if statements.

In my first game with graphics, you controlled a circle which had to hit the blue square without getting shot by the green square.

On my first platformer game, the screen moved sideways at a constant speed, because that was the simplest way to handle it. Both my character and the enemies bounced constantly, so I wouldn't have to deal with jumping. The enemies were completely oblivious to my presence.

If this is your first game, you can allow yourself the occasional shortcut to simplify the coding. You can always do it the hard way on your second game.

scarce
01-02-2008, 03:30 PM
I didn't intend to be mean. I just meant to emphasize the importance of this skill. In programming classes, they'll often give you some sample code and you will need to predict the execution order, based on the conditionals and loops.

My first game was a text-based choose-your-own-adventure story, that used only nested if statements.

In my first game with graphics, you controlled a circle which had to hit the blue square without getting shot by the green square.

On my first platformer game, the screen moved sideways at a constant speed, because that was the simplest way to handle it. Both my character and the enemies bounced constantly, so I wouldn't have to deal with jumping. The enemies were completely oblivious to my presence.

If this is your first game, you can allow yourself the occasional shortcut to simplify the coding. You can always do it the hard way on your second game.


yeah i gotcha, it's cool...funny you say about the simple ways of things...cause I'm right now in the process of translating it over to oop in as3. lol...I love doing thing harder then I need to because I learn so much more. It may take longer but I have no timeframe for this game, it's just a personal game, so I have all the time in the world, ya know?