Discord
Login
Community
DARK THEME

Player and enemy

the collision between player and enemy is not workingi don't know what the hack, is happen

Link of my game: https://microstudio.io/rianstar/ghosthunt/

thank you for the help

ghost file >>

constructor = function()
.....
    this.shot_cooldown = 0
.....

  draw = function()
    this.auraDraw()
    if keyboard.RIGHT then
      screen.drawSprite("ghost_walking", this.x, this.y, 16, 16)
    elsif keyboard.LEFT then
      screen.drawSprite("ghost_walking", this.x, this.y, 16, 16)
    elsif keyboard.DOWN then
      screen.drawSprite("ghost_going_down", this.x, this.y, 16, 16)
    elsif keyboard.UP then
      screen.drawSprite("ghost_going_up", this.x, this.y, 16, 16)
    else
      screen.drawSprite("ghost_idle", this.x, this.y, 16, 16)
    end
    screen.drawText(this.hp, this.x, this.y + this.height, 10, "rgb(255,85,198)")
  end

main file >>

init = function()
  x = 0
  y = 0
  
  //isso e pra chamar a funcao do player
  //uma tecnica pra nn deixar o codigo mt longo
  ghost = new Ghost()
  touchKeys.arrows = not system.input.keyboard

  touchKeys.keys = ["X"]
  
  menuINIT()
  
  enemies = []
  for i=1 to 20 by 1
    enemies.push( new Enemy())
  end
 
  
  score = 0
  
  level = 1
  pointsThreshold = 10
  points = 0
end

update = function()
  menuUPDATE()
  
  //isso e pra chamar a funcao de update
  ghost.update()
  
  local list = []

  for e in enemies
    for t in list
      if not (e == t) then
        if AABB( e, t ) then
          e.collision += 1
        end
      end
    end
    list.push(e)
    if AABB( e, ghost ) then
      e.hp -= 1
      e.collision += 1
      ghost.hp -= 1    
    end
    if e.hp <= 0 then 
      list.removeElement(e) 
      score += 10
      points += 10
    end
    if e.collision == 0 then 
      e.update(ghost)
    end

    e.collision = 0
  end
  enemies = list

  //maneira tenebrosa q eu fiz o limite do mapa
  //se o codigo de um segundo atras me da medo
  //imagine o de 1hr atras kskskskssk
  ghost.x = clamp(ghost.x, -152, 152)
  ghost.y = clamp(ghost.y, -80, 80)
  
  
  touchKeys.update()

  for i = enemies.length -1 to 0 by -1
    local e = enemies[i]
    for j = ghost.bullets.length -1 to 0 by -1
      local b = ghost.bullets[j]
      if AABB( e, b ) then
        FXSeb_collision()
      //  e.hp -= 1
        ghost.bullets.removeAt( j )
      end
      if e.hp <= 0 then
        score += 10
        points += 10
        enemies.removeElement(e)
        break
      end
    end
  end
  if points > pointsThreshold then
    for i=1 to 4 by 1
      enemies.push( new Enemy() )
      points -= pointsThreshold
    end
  end
end

Post a reply

Progress

Status

Preview
Cancel
Post
Validate your e-mail address to participate in the community