PDA

View Full Version : [AS2] Platform Game - killing enemy help?


parasitic
09-18-2009, 05:55 PM
Hey,
I'm new to flash but I decided to make a platform game for my ICT media project. I'm quite pleased with it so far (got working pickups, score, hp bar, platforms) as I've been following youtube and other online tutorials but now I am stucks after 2 days of trying to edit my character code so that it would kill the enemy but nothing works so I'm back to point 0. :mad:

I want my character to be a bit like mario, if it hits the enemy the hp bar will go down, until he dies. This is where I am now.
But I need the character to be able to jump on the enemy and kill him, but only when jump option is used not walking...- Makes sense? : )

Even throwing fire balls to the enemy is better than not being able to kill them at all, but I can't make this happen too :[

I want to keep my existing character actionscript as it works on my ground as well... however it is very confusing...

here's the code:

onClipEvent (load) {
grav = 2;
speed = 8;
jumpHeight = 15;
setspeed = speed;
ex = 5;
}
onClipEvent (enterFrame) {
action = true;
grav++;
_y += grav;
while (_root.ground.hitTest(_x, _y, true)) {
_y--;
grav = 0;
}
if (Key.isDown(39)) {
_x += speed;
if (_root.ground.hitTest(_x, _y+3, true)) {
} else {
}
} else if (Key.isDown(37)) {
_x -= speed;
if (_root.ground.hitTest(_x, _y+3, true)) {
} else {
}
} else {
if (_root.ground.hitTest(_x, _y+3, true) && !Key.isDown(79) && !Key.isDown(73)) {
}
}
if (Key.isDown(79) && !Key.isDown(32) && !Key.isDown(37) && !Key.isDown(39) && !Key.isDown(73)) {
}
if (Key.isDown(73) && !Key.isDown(32) && !Key.isDown(37) && !Key.isDown(39) && !Key.isDown(79)) {
}
if (Key.isDown(32) && _root.ground.hitTest(_x, _y+3, true)) {
grav = -jumpHeight;
_y -= 4;
}
if (_root.ground.hitTest(_x+(_width/2)+ex, _y-(_height/2), true) || _root.ground.hitTest(_x+(_width/2)+ex, _y-(_height/6), true) || _root.ground.hitTest(_x+(_width/2)+ex, _y-_height, true)) {
_x -= speed;
}
if (_root.ground.hitTest(_x-(_width/2)-ex, _y-(_height/2), true) || _root.ground.hitTest(_x-(_width/2)-ex, _y-(_height/6), true) || _root.ground.hitTest(_x-(_width/2)-ex, _y-_height, true)) {
_x += speed;
}
if (_root.ground.hitTest(_x, _y-_height-15, true)) {
grav = 1;
}
}


if someone could help me out how to make my character kill enemies I would be very happy and I would give you credit at the end of course.
Any solutions at all, even a new actionscript to go in the character panel that makes everything work... I am really desperate at this stage : {

crosshair
09-18-2009, 07:29 PM
Your not asking for help, your asking people to do it for you and that isnt going to happen on this forum.
Also, you are basically cheating as your not doing your work.

sam.uk.net
09-18-2009, 08:38 PM
Hi...

Getting people to do work for you isn't what these forums are about. I believe helping people with course work and education related things is a bad thing - it encourages people with a lack of knowledge and expertise into the workforce.

Try breaking your problem into several little problems and attempt to tackle them. If your stuck on one of your smaller, broken down problems, show us which bit you are stuck on and we'll help, hint or point you in the direction to the fix for your problem.. We won't do it for you though. :eek:

Good luck!

sam.uk.net

rrh
09-18-2009, 08:39 PM
I think in Mario the distinction is not "has the jump option been used" but it is more based on the relative y position of the hero and villain; whichever is higher wins.

parasitic
09-20-2009, 04:51 PM
Well I'm not asking you to write me the script or anything, besides my project is based on media- graphics and animating, so the coding aspect of it doesn't even get looked at and doesn't gain me marks, a game is simply something I wanted to challenge myself in but also struggling at.

All I want is some help, point me to the right direction, perhaps an example of the code that I could look at and understand. That's how I learn the character and hit test codes by looking at many examples.


rrh> could you please explain the y position further.

Does this mean I have to make a hit test that checks if my character is above the enemy in a certain y position or something? :S

sam.uk.net
09-20-2009, 07:17 PM
if someone could help me out how to make my character kill enemies I would be very happy and I would give you credit at the end of course.

sam.uk.net