diff options
| author | Teddy Wing | 2015-10-04 14:31:34 -0400 | 
|---|---|---|
| committer | Teddy Wing | 2015-10-04 14:31:34 -0400 | 
| commit | 97a6dd3d97d3061351d732a3e3561b8e1e5eb76e (patch) | |
| tree | 50f9642f11ca4b8b848829cb5e1e841ce9de3fae /autoload/space_vlaze | |
| parent | 69587e1338a2c54596b0c3bbeb414479368c6b7a (diff) | |
| download | vim-space-vlaze-97a6dd3d97d3061351d732a3e3561b8e1e5eb76e.tar.bz2 | |
Make player movement work
* Store player coordinates in `player.vim` instead of `game.vim` because
  they belong to a player instead of the game/board so it makes more
  sense to store them there.
* Remove old player functions from `game.vim`
* Update movement functions to ensure that they update the player
  coordinates in addition to updating the board array
Diffstat (limited to 'autoload/space_vlaze')
| -rw-r--r-- | autoload/space_vlaze/game.vim | 16 | ||||
| -rw-r--r-- | autoload/space_vlaze/player.vim | 34 | 
2 files changed, 32 insertions, 18 deletions
| diff --git a/autoload/space_vlaze/game.vim b/autoload/space_vlaze/game.vim index 0f822d1..587b7d0 100644 --- a/autoload/space_vlaze/game.vim +++ b/autoload/space_vlaze/game.vim @@ -31,8 +31,8 @@ function! space_vlaze#game#SetupBoard()  	let s:board = []  	let s:BOARD_HEIGHT = 20  	let s:BOARD_WIDTH = 80 -	let s:PLAYER_X = s:BOARD_WIDTH / 2 - 1 -	let s:PLAYER_Y = s:BOARD_HEIGHT / 2 +	call space_vlaze#player#SetPlayerX(s:BOARD_WIDTH / 2 - 1) +	call space_vlaze#player#SetPlayerY(s:BOARD_HEIGHT / 2)  	" Create 20-row by 80-column board initialised with spaces  	let i = 0 @@ -50,7 +50,7 @@ function! space_vlaze#game#SetupBoard()  	endwhile  	" Initialise player to the middle of the board -	let s:board[s:PLAYER_Y][s:PLAYER_X] = space_vlaze#player#PlayerCharacter() +	let s:board[space_vlaze#player#PlayerY()][space_vlaze#player#PlayerX()] = space_vlaze#player#PlayerCharacter()  endfunction @@ -74,16 +74,6 @@ function! space_vlaze#game#SetBoardCell(y, x, value)  endfunction -function! space_vlaze#game#PlayerY() -	return s:PLAYER_Y -endfunction - -function! space_vlaze#game#PlayerX() -	return s:PLAYER_X -endfunction - - -  function! space_vlaze#game#Quit()  	let s:loop = -1  endfunction diff --git a/autoload/space_vlaze/player.vim b/autoload/space_vlaze/player.vim index f3340db..e03cc24 100644 --- a/autoload/space_vlaze/player.vim +++ b/autoload/space_vlaze/player.vim @@ -3,32 +3,56 @@ function! space_vlaze#player#PlayerCharacter()  endfunction +function! space_vlaze#player#PlayerX() +	return s:PLAYER_X +endfunction + + +function! space_vlaze#player#SetPlayerX(player_x) +	let s:PLAYER_X = a:player_x +endfunction + + +function! space_vlaze#player#PlayerY() +	return s:PLAYER_Y +endfunction + + +function! space_vlaze#player#SetPlayerY(player_y) +	let s:PLAYER_Y = a:player_y +endfunction + +  function! space_vlaze#player#ClearPlayerCell() -	call space_vlaze#game#SetBoardCell(space_vlaze#game#PlayerY(), space_vlaze#game#PlayerX(), ' ') +	call space_vlaze#game#SetBoardCell(space_vlaze#player#PlayerY(), space_vlaze#player#PlayerX(), ' ')  endfunction  function! space_vlaze#player#MoveLeft()  	call space_vlaze#player#ClearPlayerCell() -	call space_vlaze#game#SetBoardCell(space_vlaze#game#PlayerY(), space_vlaze#game#PlayerX() - 1, space_vlaze#player#PlayerCharacter()) +	call space_vlaze#player#SetPlayerX(space_vlaze#player#PlayerX() - 1) +	call space_vlaze#game#SetBoardCell(space_vlaze#player#PlayerY(), space_vlaze#player#PlayerX(), space_vlaze#player#PlayerCharacter())  endfunction  function! space_vlaze#player#MoveDown()  	call space_vlaze#player#ClearPlayerCell() -	call space_vlaze#game#SetBoardCell(space_vlaze#game#PlayerY() + 1, space_vlaze#game#PlayerX(), space_vlaze#player#PlayerCharacter()) +	call space_vlaze#player#SetPlayerY(space_vlaze#player#PlayerY() + 1) +	call space_vlaze#game#SetBoardCell(space_vlaze#player#PlayerY(), space_vlaze#player#PlayerX(), space_vlaze#player#PlayerCharacter())  endfunction  function! space_vlaze#player#MoveUp()  	call space_vlaze#player#ClearPlayerCell() -	call space_vlaze#game#SetBoardCell(space_vlaze#game#PlayerY() - 1, space_vlaze#game#PlayerX(), space_vlaze#player#PlayerCharacter()) +	call space_vlaze#player#SetPlayerY(space_vlaze#player#PlayerY() - 1) +	call space_vlaze#game#SetBoardCell(space_vlaze#player#PlayerY(), space_vlaze#player#PlayerX(), space_vlaze#player#PlayerCharacter())  endfunction  function! space_vlaze#player#MoveRight()  	call space_vlaze#player#ClearPlayerCell() -	call space_vlaze#game#SetBoardCell(space_vlaze#game#PlayerY(), space_vlaze#game#PlayerX() + 1, space_vlaze#player#PlayerCharacter()) +	call space_vlaze#player#SetPlayerX(space_vlaze#player#PlayerX() + 1) +	call space_vlaze#game#SetBoardCell(space_vlaze#player#PlayerY(), space_vlaze#player#PlayerX(), space_vlaze#player#PlayerCharacter())  endfunction | 
