aboutsummaryrefslogtreecommitdiffstats
path: root/autoload
diff options
context:
space:
mode:
authorTeddy Wing2015-10-05 23:14:42 -0400
committerTeddy Wing2015-10-05 23:14:42 -0400
commitd0d55b5cba2950bafe42703735c705e56f6d25b4 (patch)
tree4847255208d0a6f7e0a4aa9197c520c26469d048 /autoload
parentf37fb0a02a4fe9185c3e9cbe82b234d12fbb0c72 (diff)
downloadvim-space-vlaze-d0d55b5cba2950bafe42703735c705e56f6d25b4.tar.bz2
Add enemies to board
Add a bunch of enemies to the board. The count will depend on how long you've been playing the game. This currently kind of works in that it adds enemies to the board at random coordinates and adds more as time goes on (too many actually, I'll need to reduce the count or slow down the spawn rate). The trouble is that it looks like it's blocking on the `system` call to `python`. This is a problem because it freezes the board and prevents any player movement while the Python random command is working. Let's try using Vim's built in `:python` to do this to see if that makes any difference. game.vim: Add a `ticks` script variable that tracks clock ticks and increments each time our game loop executes. This will allow us to keep track of time in a consistent way and make it easier for us to pause time when we pause the game. Also, I envision it being easier to deal with smaller numbers starting from 0 instead of a whole Unix timestamp. Got the idea for ticks from Tetris.vim (http://www.vim.org/scripts/script.php?script_id=172) enemy.vim: * Set player character to a spade (like in playing cards) because when it's small it could kind of look like a popcorn kernel * Set a min and max amount of enemies that can be on the board at any given time because we don't want a sparse board and we also don't want to overwhelm the player when they've been playing for a long time and the spawn count increases to an insane amount. * Create a function that will drop an enemy at random coordinates on the board not on the player's coordinates. TODO: we should extend this function to ensure enemies can't spawn within a certain radius of the player so that we don't get random instances of being a dick. TODO: also ensure that we don't place an enemy on top of another enemy or on top of a missile. * Every 5 seconds update the enemies on the board and regenerate them such that the enemy count is withing the min and max enemy counts.
Diffstat (limited to 'autoload')
-rw-r--r--autoload/space_vlaze/enemy.vim52
-rw-r--r--autoload/space_vlaze/game.vim18
2 files changed, 70 insertions, 0 deletions
diff --git a/autoload/space_vlaze/enemy.vim b/autoload/space_vlaze/enemy.vim
new file mode 100644
index 0000000..377c803
--- /dev/null
+++ b/autoload/space_vlaze/enemy.vim
@@ -0,0 +1,52 @@
+function! space_vlaze#enemy#EnemyCharacter()
+ return '♤'
+endfunction
+
+
+if !exists('s:MAX_ENEMIES_ON_BOARD')
+ let s:MAX_ENEMIES_ON_BOARD = 50
+endif
+
+if !exists('s:MIN_ENEMIES_ON_BOARD')
+ let s:MIN_ENEMIES_ON_BOARD = 50
+endif
+
+
+function! space_vlaze#enemy#AddEnemiesToBoard()
+ let ticks = space_vlaze#game#Ticks()
+
+ " At a 50ms refresh rate 100 ticks == 5 seconds
+ if ticks % 100 ==# 1
+ let new_enemy_count = ticks / 20
+
+ if new_enemy_count <# s:MIN_ENEMIES_ON_BOARD
+ let new_enemy_count = s:MIN_ENEMIES_ON_BOARD
+ endif
+
+ if new_enemy_count ># s:MAX_ENEMIES_ON_BOARD
+ let new_enemy_count = s:MAX_ENEMIES_ON_BOARD
+ endif
+
+ let i = 0
+ while i < new_enemy_count
+ call space_vlaze#enemy#DropEnemyAtRandomCoordinates()
+
+ let i += 1
+ endwhile
+ endif
+endfunction
+
+
+function! space_vlaze#enemy#DropEnemyAtRandomCoordinates()
+ let player_y = space_vlaze#player#PlayerY()
+ let player_x = space_vlaze#player#PlayerX()
+ let y = player_y
+ let x = player_x
+
+ while player_y ==# y && player_x ==# x
+ let y = space_vlaze#random#Random(space_vlaze#game#BoardHeight() - 1)
+ let x = space_vlaze#random#Random(space_vlaze#game#BoardWidth() - 1)
+ endwhile
+
+ call space_vlaze#game#SetBoardCell(y, x, space_vlaze#enemy#EnemyCharacter())
+endfunction
diff --git a/autoload/space_vlaze/game.vim b/autoload/space_vlaze/game.vim
index a1e00b3..29ba52b 100644
--- a/autoload/space_vlaze/game.vim
+++ b/autoload/space_vlaze/game.vim
@@ -2,6 +2,7 @@ function! space_vlaze#game#Init()
let s:loop = 1
let s:score = 0
let s:start_time = localtime()
+ let s:ticks = 1
call space_vlaze#game#SetupWindow()
call space_vlaze#colors#Initialize()
call space_vlaze#game#InitializeBoard()
@@ -10,7 +11,9 @@ function! space_vlaze#game#Init()
while s:loop ==# 1
sleep 50ms
call space_vlaze#mappings#Listen()
+ call space_vlaze#enemy#AddEnemiesToBoard()
call space_vlaze#game#RenderBoard()
+ let s:ticks += 1
endwhile
endfunction
@@ -94,6 +97,21 @@ function! space_vlaze#game#IsWithinBoard(y, x)
endfunction
+function! space_vlaze#game#BoardHeight()
+ return s:BOARD_HEIGHT
+endfunction
+
+
+function! space_vlaze#game#BoardWidth()
+ return s:BOARD_WIDTH
+endfunction
+
+
+function! space_vlaze#game#Ticks()
+ return s:ticks
+endfunction
+
+
function! space_vlaze#game#Quit()
let s:loop = -1
endfunction