aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTeddy Wing2015-10-07 02:56:34 -0400
committerTeddy Wing2015-10-07 02:56:34 -0400
commit2223ed7b3a6f347457ba63eef378d071eb9e57e6 (patch)
tree1f842d93ce9e1a184d0f46696b4a1332a1761026
parentdd70d247ec64d68188ba28a2a25ee02de82f8d8c (diff)
downloadvim-space-vlaze-2223ed7b3a6f347457ba63eef378d071eb9e57e6.tar.bz2
missile.vim: Stop missile when it hits an enemy
Instead of traversing the whole board and continuing to hit enemies along the way, ensure that missiles stop when they hit their first enemy. This restructures the loop such that each missile acts independently of the other three.
-rw-r--r--autoload/space_vlaze/missile.vim27
1 files changed, 19 insertions, 8 deletions
diff --git a/autoload/space_vlaze/missile.vim b/autoload/space_vlaze/missile.vim
index 95f4e94..f2facbf 100644
--- a/autoload/space_vlaze/missile.vim
+++ b/autoload/space_vlaze/missile.vim
@@ -1,15 +1,26 @@
" Fires all (4) missiles around an origin corrdinate (should be the player)
function! space_vlaze#missile#FireAll(y, x)
- let missiles_firing = 1
+ let left = 1
+ let bottom = 1
+ let top = 1
+ let right = 1
+
let i = 1
- while missiles_firing
- let left = space_vlaze#missile#Move(a:y, a:x - i, 'left')
- let bottom = space_vlaze#missile#Move(a:y + i, a:x, 'bottom')
- let top = space_vlaze#missile#Move(a:y - i, a:x, 'top')
- let right = space_vlaze#missile#Move(a:y, a:x + i, 'right')
+ while left || bottom || top || right
+ if left
+ let left = space_vlaze#missile#Move(a:y, a:x - i, 'left')
+ endif
+
+ if bottom
+ let bottom = space_vlaze#missile#Move(a:y + i, a:x, 'bottom')
+ endif
+
+ if top
+ let top = space_vlaze#missile#Move(a:y - i, a:x, 'top')
+ endif
- if !(left || bottom || top || right)
- let missiles_firing = 0
+ if right
+ let right = space_vlaze#missile#Move(a:y, a:x + i, 'right')
endif
sleep 20ms