Log In  


Cart #36644 | 2017-01-25 | Code ▽ | Embed ▽ | No License



Neat homage! The art is cute.

Right now, if a player loses all HP, the notification only stays up for a frame each time the character with 0 HP is hit, and then the game keeps going. This is because game_over() is called in the collision logic.

To get your game_over logic to work properly, you'll want to have the check in "move_spell" set a flag instead of calling game_over():

if(collide) then  
    spell.dead = true 	  
    if(spell.playerhit) then  
      spell.playerhit.cpthit = 10  
      spell.playerhit.health -= spell.power  
      if (spell.playerhit.health <= 0) then  
        spell.playerhit.health =0  
        spell.playerhit.dead = true  
        state='gameover
      end
    end		
  end

Then, you'll probably want to update your update function to disallow input:

function _update()
  if state != 'gameover' then
    foreach(actors,control_player)
    foreach(spells,control_spell)
    foreach(spells,move_spell)
    foreach(actors,move_actor)

    timer +=1
  else  --If the game's over, let them press the unused button to reset everything
    if (btnp(5)) then
      actors = {}
      spells = {}
      state='playing'
      _init()
    end
  end

And finally, you'll want to put your print in the _draw function to make sure it shows up properly. The way you have it set up, you can just call your game_over() function there, since it's already checking for the appropriate values / printing the message. You may want to rename that function, so it better reflects what it's actually doing, but it's up to you:

function _draw()
  cls()
  local x = timer 
  local y = timer 
  x = x % 128
  y = y % 128
  map(0, 0, -x,-y, 64, 32)

  --print("x "..p1.x,0,120,7)
  --print("y "..p1.y,85,120,7)

  foreach(spells,draw_actor)
  foreach(actors,draw_actor)
  removedeadspell()
  print_health()

  game_over()

end

In addition to that, you could implement a score counter so players know who's won the most matches.



[Please log in to post a comment]