Help Needed Coding Enemies

Discussion in 'Programming' started by NovaOzuka, Jun 7, 2018.

  1. NovaOzuka

    NovaOzuka Member

    Joined:
    May 10, 2018
    Posts:
    14
    I wonder how many topics I need to make before I can make a demo of my first platformer. Anyway, I now need help coding two different enemies, and hopefully I can figure the rest out on my own. The first is a Goomba type enemy, and the other is an enemy that can't be hurt by simply jumping on it, but by the side instead. From there I should be able to code the rest of the enemy types I can come up with.

    Obviously, they need to be able to move on their own, but they don't have to follow the player.
     
  2. Xer0botXer0

    Xer0botXer0 Member

    Joined:
    Jun 29, 2016
    Posts:
    665
    What is a goomba type enemy ? Is this a platformer ? The second enemy sounds like you just need to use player position relative to enemy code with key input.
     
  3. TheouAegis

    TheouAegis Member

    Joined:
    Jul 3, 2016
    Posts:
    6,236
    In the collision event for your player with the goomba enemy, check if bbox_bottom-vspeed < other.bbox_top. Replace vspeed with whatever you use for vertical speed. If that expression is true, bounce up and deal damage to the enemy. If it's false, deal damage to the player and apply knockback/immunity.
     
  4. NovaOzuka

    NovaOzuka Member

    Joined:
    May 10, 2018
    Posts:
    14
    I can't seem to figure out how to get knockback working. Or how to code the enemy object deletion.

    I mean, since the player isn't already set to collide with the enemy like it was a moving wall, it would be easy to get hsp right, because even if I got the hsp wrong, it would in theory constantly apply itself until the player completely passes through the enemy.
     
  5. samspade

    samspade Member

    Joined:
    Feb 26, 2017
    Posts:
    1,572
    What does you're current knockback code look like?
     
  6. NovaOzuka

    NovaOzuka Member

    Joined:
    May 10, 2018
    Posts:
    14
    if (other.x > x - 16)
    {
    hsp = -4
    }
    else if (other.x > x + 16)
    {
    hsp = 4
    }
     
  7. samspade

    samspade Member

    Joined:
    Feb 26, 2017
    Posts:
    1,572
    Where is this located? I'll assume this is in the enemy instance somewhere? If so, then the next question is, how is your enemy hsp set? If you're setting enemy hsp every step, you'll just over write this.
     
  8. NovaOzuka

    NovaOzuka Member

    Joined:
    May 10, 2018
    Posts:
    14
    Well I was trying to get knockback applied to the player, so the enemy's hsp shouldn't really matter, which is controlled by a simple state machine, and even if it does, I could always set it up so that the enemy turns away from the player upon bumping into the player.
     
  9. NovaOzuka

    NovaOzuka Member

    Joined:
    May 10, 2018
    Posts:
    14
    So I'm still having trouble with this. Specifically the knockback part.
    From obj_enemy's collision event, we have
    Code:
    if (other.y+16<y and obj_player.vsp>0)
    {other.vsp = -7
    instance_destroy()}
    else
    {obj_HUD.currenthealth =-1
    if (obj_player.hsp < 0)
    {obj_player.knockback = 3}
    if (obj_player.hsp = 0)
    {if (state = "right")
    {obj_player.knockback = 3}}
    if (obj_player.hsp > 0)
    {obj_player.knockback = -3}
    if (obj_player.hsp = 0)
    {if (state = "left")
    {obj_player.knockback = -3}}}
    And from obj_player's Step Event we have
    Code:
    //Knockback
    if (knockback > 0)
    {knockback = knockback - 1
    hsp = 3}
    if (knockback < 0)
    {knockback = knockback + 1
    hsp = -3}
    Now the bounce up and destroy enemy part is working. The knockback? Not so much. Even if it were working incorrectly, it should be at least be pushing the player into the enemy rather than away from it, but it's not doing anything at all, regardless of if the player is moving or not. If the player wasn't moving, then the enemy should be able to push the player away, but not even that is working.
     
  10. TheouAegis

    TheouAegis Member

    Joined:
    Jul 3, 2016
    Posts:
    6,236
    You are probably resetting hsp in the code for each state.
     
  11. NovaOzuka

    NovaOzuka Member

    Joined:
    May 10, 2018
    Posts:
    14
    The thing of it is the code from the player object is from the end of the Step Event code, so it should be resetting to (-)3 for 3 steps. I did use virtually the same piece of code for wall jumping, and that piece of code is still working.
     
  12. TheouAegis

    TheouAegis Member

    Joined:
    Jul 3, 2016
    Posts:
    6,236
    And you verified the knockback variable is getting set and counting to 0?

    And where do you increment x by hsp?

    It should be

    State code that sets hsp
    Knockback read code that sets hsp
    Collision code that might set hsp to 0
    Increase x by hsp.
     

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