So I'm sure that I'm probably just over-thinking things, but this problem has taken me longer than usual to figure out a solution to, so I thought I'd ask for some help. I'm not even sure how to phrase what I'm asking, but goes nothing...
I'm working on a game with a fighting system that is a combination of RPG and button-mashing. This code is still in its early stages, and it only works for attacking an enemy, not taking damage (which I haven't tried figuring out yet).
Here's how [what I currently have] works in my head:
Whenever you press the "Z" key on the keyboard, the character throws a punch.
If he's close enough to the enemy, he'll do damage (currently based on a random(10) integer), otherwise a message pops up that says "Not close enough!").
The enemy will run away if their health drops below 50.
When the enemy's health drops below 1, their view changes and they stop moving/attacking.
What I want to do is make it so that anywhere, anytime, you can throw a punch. And if you're close enough to ANY enemy, you can do damage to it. So I'd like to have one script that makes this possible, and have the enemy attacks be defined on a room-by-room basis.
So, the following is the current code in my GlobalScript.asc:
(For reference, "c1984" is a transparent, pixel-sized character that follows the player around the whole game and is used to activate/deactivate various things; in this case, once you enter a room with an enemy for the first time, the enemy starts following c1984, but appears to be going after the player).
Code: AGS
Thank you in advance for your help.
I'm working on a game with a fighting system that is a combination of RPG and button-mashing. This code is still in its early stages, and it only works for attacking an enemy, not taking damage (which I haven't tried figuring out yet).
Here's how [what I currently have] works in my head:
Whenever you press the "Z" key on the keyboard, the character throws a punch.
If he's close enough to the enemy, he'll do damage (currently based on a random(10) integer), otherwise a message pops up that says "Not close enough!").
The enemy will run away if their health drops below 50.
When the enemy's health drops below 1, their view changes and they stop moving/attacking.
What I want to do is make it so that anywhere, anytime, you can throw a punch. And if you're close enough to ANY enemy, you can do damage to it. So I'd like to have one script that makes this possible, and have the enemy attacks be defined on a room-by-room basis.
So, the following is the current code in my GlobalScript.asc:
(For reference, "c1984" is a transparent, pixel-sized character that follows the player around the whole game and is used to activate/deactivate various things; in this case, once you enter a room with an enemy for the first time, the enemy starts following c1984, but appears to be going after the player).
//Setting up distance between character and enemy:
xDiff = cRoy.x - c1984.x;
yDiff = cRoy.y - c1984.y;
enemyDistance = xDiff*xDiff + yDiff*yDiff;
//PUNCH:
if (keycode == eKeyZ){
//currentEnemy = enemyHealth; //<-- My first attempt at making it possible for the punch command to be used against any enemy, rather than just one.
//^^ This didn't work.
if (cRoy.View != 29){
cRoy.ChangeView(29); //<-- Throws the punch!
if (cRoy.View == 29){
if (enemyDistance < 20500){ //<-- Ensures that punching on the other side of the room won't damage the enemy.
damageDone = Random(10);
enemyHealth = enemyHealth - damageDone; //<-- enemyHealth is declared in GlobalScript.ash and should be set when the player first encounters an enemy.
//This next bit's just for me while I'm testing, I plan on having a GUI display this info later:
Display("%d damage inflicted!", damageDone);
Display("%d enemy health left!", enemyHealth);
} else {
Display("Not close enough!");
}
}
Wait(5); //<-- So we have time to enjoy the visual of Roy extending his arm and pulling it back, maybe there's a better way to do this?
cRoy.ChangeView(1);
}
if (enemyHealth < 50){
c1984.Move(588, 100, eNoBlock); //<-- So the enemy runs away when it gets weak... Is there a way to make it do this without inputing specific coordinates, which obviously can't work in every situation...?
c1984.FaceCharacter(cRoy, eNoBlock);
} else if (enemyHealth < 1){
/*"cCurrentEnemy"*/.ChangeView(8); //<-- How do I do something like this? This is what I'm really trying to figure out.
/*"cCurrentEnemy"*/.FollowCharacter(/*"cCurrentEnemy"*/); //<-- Stay put, you're dead!
c1984.FollowCharacter(cRoy); //<-- Since we'll need c1984 later.
}
Thank you in advance for your help.