diff options
| -rw-r--r-- | autoload/space_vlaze/game.vim | 21 | ||||
| -rw-r--r-- | autoload/space_vlaze/missile.vim | 71 | ||||
| -rw-r--r-- | autoload/space_vlaze/player.vim | 6 | 
3 files changed, 97 insertions, 1 deletions
| diff --git a/autoload/space_vlaze/game.vim b/autoload/space_vlaze/game.vim index b5567f8..a1e00b3 100644 --- a/autoload/space_vlaze/game.vim +++ b/autoload/space_vlaze/game.vim @@ -70,8 +70,27 @@ function! space_vlaze#game#Board()  endfunction +function! space_vlaze#game#BoardCell(y, x) +	return s:board[a:y][a:x] +endfunction + +  function! space_vlaze#game#SetBoardCell(y, x, value) -	let s:board[a:y][a:x] = a:value +	if space_vlaze#game#IsWithinBoard(a:y, a:x) +		let s:board[a:y][a:x] = a:value +	endif +endfunction + + +function! space_vlaze#game#IsBoardCellEmpty(y, x) +	if space_vlaze#game#IsWithinBoard(a:y, a:x) +		return s:board[a:y][a:x] ==# ' ' +	endif +endfunction + + +function! space_vlaze#game#IsWithinBoard(y, x) +	return a:y >=# 0 && a:y <# s:BOARD_HEIGHT && a:x >=# 0 && a:x <# s:BOARD_WIDTH  endfunction diff --git a/autoload/space_vlaze/missile.vim b/autoload/space_vlaze/missile.vim new file mode 100644 index 0000000..68c4e24 --- /dev/null +++ b/autoload/space_vlaze/missile.vim @@ -0,0 +1,71 @@ +" Fires all (4) missiles around an origin corrdinate (should be the player) +function! space_vlaze#missile#FireAll(y, x) +	let missiles_firing = 1 +	let i = 1 +	while missiles_firing +		let missiles_firing = space_vlaze#missile#Move(a:y, a:x + i, 'right') +		 +		sleep 20ms +		 +		let i += 1 +	endwhile +endfunction + + +" Move a missile starting from a set of coordinates in a specified direction. +" Clears the missile's previous location. +"  +" y: Previous Y coordinate of missile +" x: Previous X coordinate of missile +" direction: 'left', 'right', 'bottom', or 'top' +" returns: 1 if the missile was able to move, 0 if it hit a wall or object +function! space_vlaze#missile#Move(y, x, direction) +	let y = a:y +	let x = a:x +	 +	if a:direction ==# 'left' +		let x -= 1 +	elseif a:direction ==# 'right' +		let x += 1 +	elseif a:direction ==# 'bottom' +		let y += 1 +	elseif a:direction ==# 'top' +		let y -= 1 +	endif +	 +	if space_vlaze#game#IsBoardCellEmpty(y, x) +		call space_vlaze#missile#ClearMissile(a:y, a:x) +		 +		call space_vlaze#game#SetBoardCell( +			\ y, +			\ x, +			\ space_vlaze#missile#MissileCharacter(a:direction)) +		 +		call space_vlaze#game#RenderBoard() +		 +		return 1 +	endif +	 +	return 0 +endfunction + + +function! space_vlaze#missile#ClearMissile(y, x) +	call space_vlaze#game#SetBoardCell(a:y, a:x, ' ') +endfunction + + +function! space_vlaze#missile#MissileCharacter(direction) +	let horizontal = '—' +	let vertical = '|' +	 +	if a:direction ==# 'left' +		return horizontal +	elseif a:direction ==# 'right' +		return horizontal +	elseif a:direction ==# 'bottom' +		return vertical +	elseif a:direction ==# 'top' +		return vertical +	endif +endfunction diff --git a/autoload/space_vlaze/player.vim b/autoload/space_vlaze/player.vim index e03cc24..51b38bb 100644 --- a/autoload/space_vlaze/player.vim +++ b/autoload/space_vlaze/player.vim @@ -57,4 +57,10 @@ endfunction  function! space_vlaze#player#FireBlasters() +	" Fire top, right, bottom, left blasters +	" A single missile fires in each direction +	" The missile moves outward from the player to the edge of the board +	" The missile stops when it hits an enemy or the edge of the board +	 +	call space_vlaze#missile#FireAll(s:PLAYER_Y, s:PLAYER_X)  endfunction | 
