From bb54411c76a7765af8a06d15ee748251c2a1dcc4 Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Wed, 7 Oct 2015 04:17:14 -0400 Subject: Add lives * Create life.vim to keep track of lives * Players start with 3 lives * Add increment and decrement functions for lives because they'll be useful in the future (although there's a more immediate need for the decrement function) * Render lives at the bottom of the board * Move the score line down so that it appears just below the life count display --- autoload/space_vlaze/game.vim | 2 ++ autoload/space_vlaze/life.vim | 28 ++++++++++++++++++++++++++++ autoload/space_vlaze/score.vim | 2 +- 3 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 autoload/space_vlaze/life.vim diff --git a/autoload/space_vlaze/game.vim b/autoload/space_vlaze/game.vim index 72594b7..da67c71 100644 --- a/autoload/space_vlaze/game.vim +++ b/autoload/space_vlaze/game.vim @@ -7,6 +7,7 @@ function! space_vlaze#game#Init() call space_vlaze#game#InitializeBoard() call space_vlaze#mappings#Initialize() call space_vlaze#score#Initialize() + call space_vlaze#life#Initialize() while s:loop ==# 1 sleep 50ms @@ -14,6 +15,7 @@ function! space_vlaze#game#Init() call space_vlaze#enemy#AddEnemiesToBoard() call space_vlaze#game#RenderBoard() call space_vlaze#score#RenderScore() + call space_vlaze#life#RenderLives() let s:ticks += 1 endwhile endfunction diff --git a/autoload/space_vlaze/life.vim b/autoload/space_vlaze/life.vim new file mode 100644 index 0000000..1d300bd --- /dev/null +++ b/autoload/space_vlaze/life.vim @@ -0,0 +1,28 @@ +function! space_vlaze#life#Initialize() + let s:lives = 3 +endfunction + + +function! space_vlaze#life#IncrementLives() + let s:lives += 1 +endfunction + + +function! space_vlaze#life#DecrementLives() + let s:lives -= 1 +endfunction + + +function! space_vlaze#life#RenderLives() + let lives_line = space_vlaze#game#BoardHeight() + 1 + let lives_display = '' + + let i = 0 + while i < s:lives + let lives_display .= space_vlaze#player#PlayerCharacter() . ' ' + + let i += 1 + endwhile + + call setline(lives_line, lives_display) +endfunction diff --git a/autoload/space_vlaze/score.vim b/autoload/space_vlaze/score.vim index a6d1684..612f02d 100644 --- a/autoload/space_vlaze/score.vim +++ b/autoload/space_vlaze/score.vim @@ -10,7 +10,7 @@ endfunction function! space_vlaze#score#RenderScore() - let score_line = space_vlaze#game#BoardHeight() + 1 + let score_line = space_vlaze#game#BoardHeight() + 2 call setline(score_line, 'Score: ' . s:score) endfunction -- cgit v1.2.3