B
Brian Le
Guest
Hi guys!
Last step of my game!
I am making a 2-player game in which they can punch each other. I have coded 2 objects, each stand for a player, named obj_player and obj_player2. They are the same except for the input keys. The problem is when player 1 attacks player 2, he receives the damage, but when player 2 attacks player 1, nothing happens. I will just add the 'receive damage' part of my code:
obj_player
obj_player2 (similar):
par_hitbox Create Event Code:
par_hitbox Animation End Event Code:
obj_hitbox1, obj_hitbox2: Created when the player 1 is punching - no action.
obj_hitbox1_2, obj_hitbox2_2: Created when the player2 is puching - Create Event:
The question is very difficult for me, but may be simple for you guys.
Another question is about jumping: How can you check the player jumps from a certain height? i.e: about 50px from the ground.
Thanks in advanced!!!
Last step of my game!
I am making a 2-player game in which they can punch each other. I have coded 2 objects, each stand for a player, named obj_player and obj_player2. They are the same except for the input keys. The problem is when player 1 attacks player 2, he receives the damage, but when player 2 attacks player 1, nothing happens. I will just add the 'receive damage' part of my code:
obj_player
Code:
var damage_place = instance_place(x,y,par_hitbox);
if (damage_place != noone) { //Check if the hitbox is collided with the player or not
if (damage_place.type == 2) { //Check if the hitbox belongs to the second player
damaged = true;
damage_plus ++; //Count the number of damage for personal use (Just don't care much about it)
if (damage_plus > 2) {
damage_plus = 1; //If the number of damage is larger than 2 then it will be 1 (at most 2)
}
damage_delay = 0;
}
}
if (damage_plus != 0) { //Check if the player is receiving the damage
damage_delay ++;
if (damage_delay >= 11) {
damage_plus = 0;
damaged = false;
} //Check after about 11 frames all the damage will be remove.
}
if (damaged) {
image_xscale = -obj_player2.image_xscale; //Flip the player 1 according to player 2
ladder = false;
sprite_index = spr_player_damaged; //Change //sprite
if (damage_plus == 1) image_index = 0; //Check if the player receive the first damage, then the image_index is 1
if (damage_plus == 2) image_index = 1;
if (damage_plus == 1 && obj_player2.melee_counter == 3) {
damage_last = true; //Just a custom variable
vsp = -10; //Throw the player upwards
}
}
Code:
var damage_place = instance_place(x,y,par_hitbox);
if (damage_place != noone) {
if (damage_place.type == 1) {
damaged = true;
damage_plus ++;
if (damage_plus > 2) {
damage_plus = 1;
}
damage_delay = 0;
}
}
if (damage_plus != 0) {
damage_delay ++;
if (damage_delay >= 11) {
damage_plus = 0;
damaged = false;
}
}
if (damaged) {
image_xscale = -obj_player.image_xscale;
ladder = false;
sprite_index = spr_player_damaged;
if (damage_plus == 1) image_index = 0;
if (damage_plus == 2) image_index = 1;
if (damage_plus == 1 && obj_player.melee_counter == 3) {
damage_last = true;
vsp = -10;
}
}
Code:
type = 1;
Code:
instance_destroy();
obj_hitbox1_2, obj_hitbox2_2: Created when the player2 is puching - Create Event:
Code:
type = 2;
Another question is about jumping: How can you check the player jumps from a certain height? i.e: about 50px from the ground.
Thanks in advanced!!!