From dd70d247ec64d68188ba28a2a25ee02de82f8d8c Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Wed, 7 Oct 2015 02:45:32 -0400 Subject: Hitting enemies with missiles makes enemies disappear When a missile hits an enemy, the enemy now disappears. TODO: * Add scoring * Currently missiles don't stop when they hit an enemy so they'll just keep on killing enemies until they get to the edge of the board. --- autoload/space_vlaze/enemy.vim | 13 +++++++++++++ autoload/space_vlaze/missile.vim | 2 ++ 2 files changed, 15 insertions(+) diff --git a/autoload/space_vlaze/enemy.vim b/autoload/space_vlaze/enemy.vim index 51bf14d..1fefbf5 100644 --- a/autoload/space_vlaze/enemy.vim +++ b/autoload/space_vlaze/enemy.vim @@ -51,3 +51,16 @@ function! space_vlaze#enemy#DropEnemyAtRandomCoordinates() call space_vlaze#game#SetBoardCell(y, x, space_vlaze#enemy#EnemyCharacter()) endfunction + + +" Calling this function tells us that coordinates y, x were hit by a missile. +" If an enemy lives at y, x, it needs to disappear and update the score. +function! space_vlaze#enemy#HandleEnemyHitAt(y, x) + if space_vlaze#game#IsWithinBoard(a:y, a:x) + if space_vlaze#game#BoardCell(a:y, a:x) ==# space_vlaze#enemy#EnemyCharacter() + call space_vlaze#game#ClearBoardCell(a:y, a:x) + + return 1 + endif + endif +endfunction diff --git a/autoload/space_vlaze/missile.vim b/autoload/space_vlaze/missile.vim index aa9da39..95f4e94 100644 --- a/autoload/space_vlaze/missile.vim +++ b/autoload/space_vlaze/missile.vim @@ -51,6 +51,8 @@ function! space_vlaze#missile#Move(y, x, direction) call space_vlaze#game#RenderBoard() return 1 + else + call space_vlaze#enemy#HandleEnemyHitAt(y, x) endif return 0 -- cgit v1.2.3