V
Vincent
Guest
So I'm making a platformer, and I want to collide with and enemy, and when that happens, make the character jump, change sprite and decrease the hp, and I don't know how to do that.
This is the code
Player's "create" (variables)
Player's "step"
And that's the movement. How should I do it? Thanks!
(sorry if the code is very big, I'm a begginer in this xD)
This is the code
Player's "create" (variables)
Code:
gravedad = 1
vel_horizontal = 0
vel_vertical = 0
vel_salto = 16
vel_movimiento = 6
global.hp = 12
Code:
//Variables
derecha = keyboard_check (ord("D"))
izquierda = -keyboard_check (ord("A"))
salto = keyboard_check_pressed (ord("W"))
//Movimiento
movimiento = derecha + izquierda
vel_horizontal = movimiento * vel_movimiento
if (vel_vertical < 10)
{
vel_vertical += gravedad
}
//Colisiones
//Vertical
if (place_meeting (x, y+1, obj_cesped))
{
vel_vertical = salto * -vel_salto
}
if (place_meeting (x, y+vel_vertical, obj_barrier))
{
while (!place_meeting (x, y+sign(vel_vertical), obj_cesped))
{
y += sign (vel_vertical)
}
vel_vertical = 0
}
//Horizontal
if (place_meeting (x+vel_horizontal, y, obj_barrier))
{
while (!place_meeting (x+sign(vel_horizontal), y, obj_barrier))
{
x += sign (vel_horizontal)
}
vel_horizontal = 0
}
x += vel_horizontal
y += vel_vertical
(sorry if the code is very big, I'm a begginer in this xD)