X
xilian7125
Guest
hi there. there are many problems im having with the enemy but this is a big one
when i touch the enemy, both the enemy AND the player get stuck.
code:
PLAYER:
CREATE:
STEP
PLAYERSTATE_FREE
PLAYERSTATE_ATTACK
PLAYERSTATE_HIT
PLAYERHIT
ENEMY
CREATE
STEP
ALARM 0
ENEMYSTATE_FREE
ENEMYSTATE_HIT
ENEMYSTATE_DEAD
ENEMYSTATE_ATTACK
ENEMYHIT
when i touch the enemy, both the enemy AND the player get stuck.
code:
PLAYER:
CREATE:
Code:
hsp = 0;
vsp = 0;
grv = 0.4;
walksp = 8;
hp = 100
state = PLAYERSTATE.FREE
hitbyattack = ds_list_create();
enum PLAYERSTATE
{
FREE,
ATTACK_SLASH,
ATTACK_COMBO,
HIT
}
Code:
//player input (check for correct symbols)
key_left = keyboard_check(vk_left);
key_right = keyboard_check(vk_right);
key_jump = keyboard_check_pressed(vk_up);
key_attack = keyboard_check_pressed(ord("Z"))
switch (state)
{
case PLAYERSTATE.FREE: PlayerState_Free(); break;
case PLAYERSTATE.ATTACK_SLASH: PlayerState_Attack_Slash(); break;
case PLAYERSTATE.ATTACK_COMBO: PlayerState_Attack_Combo(); break;
}
Code:
var move = key_right - key_left;
hsp = move * walksp;
vsp = vsp + grv;
if (place_meeting(x,y+1,grass_obj)) && (key_jump)
{
vsp = -10;
}
//horizontal collision
if (place_meeting(x+hsp,y,grass_obj))
{
while (!place_meeting(x+sign(hsp),y,grass_obj))
{
x = x + sign(hsp);
}
hsp = 0;
}
x = x + hsp;
//vertical collision
if (place_meeting(x,y+vsp,grass_obj))
{
while (!place_meeting(x,y+sign(vsp),grass_obj))
{
y = y + sign(vsp);
}
vsp = 0;
}
y = y + vsp;
//animation
{
if (hsp == 8) and key_right = keyboard_check(vk_right)
{
sprite_index = sPlayerWR;
image_xscale = sign(hsp)
}
if (hsp == -8) and key_left = keyboard_check(vk_left)
{
sprite_index = sPlayerWR;
image_xscale = sign(hsp)
}
if (hsp == 0)
{
sprite_index = sPlayerR
}
}
if (key_attack)
{
state = PLAYERSTATE.ATTACK_SLASH;
}
if hp = 0
then
{
game_restart()
}
Code:
hsp = 0;
vsp = 0;
var move = key_right - key_left;
hsp = move * walksp;
vsp = vsp + grv;
if (place_meeting(x,y+1,grass_obj)) && (key_jump)
{
vsp = -10;
}
//horizontal collision
if (place_meeting(x+hsp,y,grass_obj))
{
while (!place_meeting(x+sign(hsp),y,grass_obj))
{
x = x + sign(hsp);
}
hsp = 0;
}
x = x + hsp;
//vertical collision
if (place_meeting(x,y+vsp,grass_obj))
{
while (!place_meeting(x,y+sign(vsp),grass_obj))
{
y = y + sign(vsp);
}
vsp = 0;
}
y = y + vsp;
//start of the attack
if (sprite_index != sAttack_slash)
{
sprite_index = sAttack_slash;
image_index = 0;
ds_list_clear(hitbyattack);
}
mask_index = sAttack_slashHB;
var hitByAttackNow = ds_list_create();
var hits = instance_place_list(x,y,Enemy,hitByAttackNow,false);
if (hits > 0)
{
for (var i = 0; i < hits; i++)
{
var hitID = hitByAttackNow[| i]
if (ds_list_find_index(hitbyattack,hitID) == -1)
{
ds_list_add(hitbyattack,hitID);
with (hitID)
{
EnemyHit(1);
}
}
}
}
ds_list_destroy(hitByAttackNow);
mask_index = sPlayerR;
if (animation_end())
{
sprite_index = sPlayerR;
state = PLAYERSTATE.FREE;
}
Code:
if place_meeting(x,y,sVantoid_stomperA)
{
hp = hp - 1;
flash = 3;
}
var move = key_right - key_left;
hsp = move * walksp;
vsp = vsp + grv;
if (place_meeting(x,y+1,grass_obj)) && (key_jump)
{
vsp = -10;
}
//horizontal collision
if (place_meeting(x+hsp,y,grass_obj))
{
while (!place_meeting(x+sign(hsp),y,grass_obj))
{
x = x + sign(hsp);
}
hsp = 0;
}
x = x + hsp;
//vertical collision
if (place_meeting(x,y+vsp,grass_obj))
{
while (!place_meeting(x,y+sign(vsp),grass_obj))
{
y = y + sign(vsp);
}
vsp = 0;
}
y = y + vsp;
//animation
{
if (hsp == 8) and key_right = keyboard_check(vk_right)
{
sprite_index = sPlayerWR;
image_xscale = sign(hsp)
}
if (hsp == -8) and key_left = keyboard_check(vk_left)
{
sprite_index = sPlayerWR;
image_xscale = sign(hsp)
}
if (hsp == 0)
{
sprite_index = sPlayerR
}
}
if (key_attack)
{
state = PLAYERSTATE.ATTACK_SLASH;
}
Code:
var _damage = argument0;
hp -= _damage;
if (hp > 0)
{
state = PLAYERSTATE.HIT;
}
else
{
game_restart()
}
var move = key_right - key_left;
hsp = move * walksp;
vsp = vsp + grv;
if (place_meeting(x,y+1,grass_obj)) && (key_jump)
{
vsp = -10;
}
//horizontal collision
if (place_meeting(x+hsp,y,grass_obj))
{
while (!place_meeting(x+sign(hsp),y,grass_obj))
{
x = x + sign(hsp);
}
hsp = 0;
}
x = x + hsp;
//vertical collision
if (place_meeting(x,y+vsp,grass_obj))
{
while (!place_meeting(x,y+sign(vsp),grass_obj))
{
y = y + sign(vsp);
}
vsp = 0;
}
y = y + vsp;
//animation
{
if (hsp == 8) and key_right = keyboard_check(vk_right)
{
sprite_index = sPlayerWR;
image_xscale = sign(hsp)
}
if (hsp == -8) and key_left = keyboard_check(vk_left)
{
sprite_index = sPlayerWR;
image_xscale = sign(hsp)
}
if (hsp == 0)
{
sprite_index = sPlayerR
}
}
if (key_attack)
{
state = PLAYERSTATE.ATTACK_SLASH;
}
CREATE
Code:
hsp = 0;
vsp = 0;
grv = 0.4;
walksp = 2;
hp = 4;
flash = 0;
state = ENEMYSTATE.FREE
hitbyattack = ds_list_create();
can_attack = 0
Code:
vsp+= grv;
switch (state)
{
case ENEMYSTATE.FREE: EnemyState_Free(); break;
case ENEMYSTATE.HIT: EnemyState_Hit(); break;
case ENEMYSTATE.DEAD: EnemyState_Dead(); break;
case ENEMYSTATE.ATTACK: EnemyState_Attack(); break;
}
var dir
if (playerX_obj.x = x) dir = 0
if (playerX_obj.x < x) dir = -1
if (playerX_obj.x > x) dir = 1
if (instance_exists(playerX_obj))
{
if (dir != 0)
{
// add hsp to 1 or -1 x acceleration in direction
hsp += dir* walksp;
hsp = clamp(hsp, -walksp, walksp);
}
}
//Wall and ground collisions
//this comes before to see if it hits a wall or ground
if place_meeting(x+hsp, y, grass_obj)
{
// checks to see if it has contact with the wall, if not move over 1 pixel
// sign : function it used to check is hsp is positive or negative 1 or -1
while !place_meeting(x+sign(hsp), y, grass_obj)
{
x += sign(hsp);
}
hsp = 0;
}
if place_meeting(x+hsp, y, grass_obj)
{
// checks to see if it has contact with the wall, if not move over 1 pixel
// sign : function it used to check is hsp is positive or negative 1 or -1
while !place_meeting(x+sign(hsp), y, grass_obj)
{
x += sign(hsp);
}
hsp = 0;
}
//Adds current horizontal speed to x position to create movement
x += hsp;
if place_meeting(x,y+vsp, grass_obj)
{
while !place_meeting(x, y+sign(vsp), grass_obj)
{
y += sign(vsp);
}
vsp = 0
}
//Adds current vertical speed to y position for jumping and falling
y += vsp;
var dis = (x - playerX_obj.x);
if (dis > 12) dir = -1;
else if (dis < -12) dir = 1;
vsp = vsp + grv;
{
if (hsp == 2)
{
sprite_index = sVantoid_stomperW;
image_xscale = sign(hsp)
}
if (hsp == -2)
{
sprite_index = sVantoid_stomperW;
image_xscale = sign(hsp)
}
if (hsp == 0)
{
sprite_index = sVantoid_stomper
}
}
if place_meeting(x,y, playerX_obj) and can_attack = 0
{
state = ENEMYSTATE.ATTACK
can_attack = 1
alarm[0] = 5*room_speed
}
Code:
can_attack = 0
Code:
vsp = vsp + grv;
//horizontal collision
if (place_meeting(x+hsp,y,grass_obj))
{
while (!place_meeting(x+sign(hsp),y,grass_obj))
{
x = x + sign(hsp);
}
hsp = 0;
}
x = x + hsp;
//vertical collision
if (place_meeting(x,y+vsp,grass_obj))
{
while (!place_meeting(x,y+sign(vsp),grass_obj))
{
y = y + sign(vsp);
}
vsp = 0;
}
y = y + vsp;
if hp = 0
then
{
instance_destroy(Enemy)
}
Code:
if place_meeting(x,y,sAttack_slashHB)
{
hp = hp - 1;
flash = 3;
}
Code:
if hp = 0
{
instance_destroy(other)
}
Code:
//horizontal collision
if (place_meeting(x+hsp,y,grass_obj))
{
while (!place_meeting(x+sign(hsp),y,grass_obj))
{
x = x + sign(hsp);
}
hsp = 0;
}
x = x + hsp;
//vertical collision
if (place_meeting(x,y+vsp,grass_obj))
{
while (!place_meeting(x,y+sign(vsp),grass_obj))
{
y = y + sign(vsp);
}
vsp = 0;
}
y = y + vsp;
//start of the attack
if (sprite_index != sVantoid_stomperBITE)
{
sprite_index = sVantoid_stomperBITE;
image_index = 0;
ds_list_clear(hitbyattack);
}
mask_index = sVantoid_stomperA;
var hitByAttackNow = ds_list_create();
var hits = instance_place_list(x,y,playerX_obj,hitByAttackNow,false);
if (hits > 0)
{
for (var i = 0; i < hits; i++)
{
var hitID = hitByAttackNow[| i]
if (ds_list_find_index(hitbyattack,hitID) == -1)
{
ds_list_add(hitbyattack,hitID);
with (hitID)
{
PlayerHit(1);
}
}
}
}
ds_list_destroy(hitByAttackNow);
mask_index = sVantoid_stomperA;
if (animation_end())
{
sprite_index = sVantoid_stomper;
state = ENEMYSTATE.FREE;
}
Code:
var _damage = argument0;
hp -= _damage;
if (hp > 0)
{
state = ENEMYSTATE.HIT;
}
else
{
state = ENEMYSTATE.DEAD;
}