diff options
| author | Teddy Wing | 2015-10-04 14:16:14 -0400 | 
|---|---|---|
| committer | Teddy Wing | 2015-10-04 14:16:14 -0400 | 
| commit | 69587e1338a2c54596b0c3bbeb414479368c6b7a (patch) | |
| tree | c009d2cb324ef8289118a2d8b634d0b540ce9fd5 | |
| parent | 9b09b6d8bacdc48858e82ce072fe8e33db8558a9 (diff) | |
| download | vim-space-vlaze-69587e1338a2c54596b0c3bbeb414479368c6b7a.tar.bz2 | |
Add player movement (WIP)
Kind of add player movement.
TODO: Update player coordinates when moving
* Add a main game loop to `space_vlaze#game#Init`
* Fill in player directional movement functions
* game.vim: Add functions to access and set `s:` variables so these can
  be accessed from player.vim
* Add new mappings based on
  https://github.com/mattn/invader-vim/blob/f04e7f5e8ac42ae87db6050e64449055206c4054/plugin/invader.vim#L44-L60
  because it turns out that the mappings we previously defined don't
  work when out main loop is running.
| -rw-r--r-- | autoload/space_vlaze/game.vim | 29 | ||||
| -rw-r--r-- | autoload/space_vlaze/mappings.vim | 21 | ||||
| -rw-r--r-- | autoload/space_vlaze/player.vim | 14 | 
3 files changed, 63 insertions, 1 deletions
| diff --git a/autoload/space_vlaze/game.vim b/autoload/space_vlaze/game.vim index e975bd6..0f822d1 100644 --- a/autoload/space_vlaze/game.vim +++ b/autoload/space_vlaze/game.vim @@ -1,10 +1,18 @@  function! space_vlaze#game#Init() +	let s:loop = 1  	let s:score = 0  	let s:start_time = localtime()  	call space_vlaze#game#SetupWindow()  	call space_vlaze#colors#Initialize()  	call space_vlaze#game#InitializeBoard()  	call space_vlaze#mappings#Initialize() +	 +	while s:loop ==# 1 +		sleep 50ms +		call space_vlaze#mappings#Listen() +		call space_vlaze#game#RenderBoard() +		redraw! +	endwhile  endfunction @@ -56,7 +64,28 @@ function! space_vlaze#game#RenderBoard()  endfunction +function! space_vlaze#game#Board() +	return s:board +endfunction + + +function! space_vlaze#game#SetBoardCell(y, x, value) +	let s:board[a:y][a:x] = a: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/mappings.vim b/autoload/space_vlaze/mappings.vim index 65cfe6e..9194eb0 100644 --- a/autoload/space_vlaze/mappings.vim +++ b/autoload/space_vlaze/mappings.vim @@ -7,3 +7,24 @@ function! space_vlaze#mappings#Initialize()  	nnoremap <silent><buffer> l       :call space_vlaze#player#MoveRight()<cr>  	nnoremap <silent><buffer> <space> :call space_vlaze#player#FireBlasters()<cr>  endfunction + + +function! space_vlaze#mappings#Listen() +	let c = nr2char(getchar(0)) +	 +	if c ==# 'q' +		call space_vlaze#game#Quit() +	elseif c ==# 'p' +		call space_vlaze#game#Pause() +	elseif c ==# 'h' +		call space_vlaze#player#MoveLeft() +	elseif c ==# 'j' +		call space_vlaze#player#MoveDown() +	elseif c ==# 'k' +		call space_vlaze#player#MoveUp() +	elseif c ==# 'l' +		call space_vlaze#player#MoveRight() +	elseif c ==# '\<space>' +		call space_vlaze#player#FireBlasters() +	endif +endfunction diff --git a/autoload/space_vlaze/player.vim b/autoload/space_vlaze/player.vim index 17b0178..f3340db 100644 --- a/autoload/space_vlaze/player.vim +++ b/autoload/space_vlaze/player.vim @@ -3,20 +3,32 @@ function! space_vlaze#player#PlayerCharacter()  endfunction +function! space_vlaze#player#ClearPlayerCell() +	call space_vlaze#game#SetBoardCell(space_vlaze#game#PlayerY(), space_vlaze#game#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())  endfunction  function! space_vlaze#player#MoveDown() -	echom 'booya' +	call space_vlaze#player#ClearPlayerCell() +	call space_vlaze#game#SetBoardCell(space_vlaze#game#PlayerY() + 1, space_vlaze#game#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())  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())  endfunction | 
