1. Hey! Guest! The 34th GMC Jam will take place between August 22nd, 12:00 UTC (Thursday noon) and August 26th, 12:00 UTC (Monday noon). Why not join in! Click here to find out more!
    Dismiss Notice

GMS 2 enemy stops moving (again)

Discussion in 'Programming' started by xilian7125, Jul 3, 2019.

Tags:
  1. xilian7125

    xilian7125 Member

    Joined:
    Jul 24, 2018
    Posts:
    15
    when i walk over the enemy, they stop moving. everything else is functional
    code:

    vantoid_stomper step
    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;
        
    }
    
    if place_meeting(x+hsp, y, playerX_obj)
    {
        while !place_meeting(x+sign(hsp), y, playerX_obj)
            {
                x += sign(hsp);
                state = ENEMYSTATE.ATTACK
            }
            hsp = 0
        state = ENEMYSTATE.ATTACK
    }
    else
    {
        state = ENEMYSTATE.FREE
    }
    
    
    //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
        }
        
    }
    
    
    enemystate_attack
    Code:
    hsp = 0;
    vsp = 0;
    
    var move = 1;
    
    hsp = move * walksp;
    
    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;
    
    
    //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_stomper;
    if (animation_end())
    {
        sprite_index = sVantoid_stomper;
        state = ENEMYSTATE.FREE;
    
    }
    
    these are the only two that seem to change anything
     
  2. zATARA_0

    zATARA_0 Member

    Joined:
    Apr 10, 2019
    Posts:
    43
    My guess is that the enemy is constantly being put into attack state. Maybe its triggering switch to attack state every frame in the vantoid_stomper step
     
  3. xilian7125

    xilian7125 Member

    Joined:
    Jul 24, 2018
    Posts:
    15
    i tested some things and found it was specifically this breaking it:
    Code:
    var move = 1
    deleting it crashes the game, some testing with other variables (ex: hsp, walksp) showed big changes but it was still broken.
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice