diff options
| author | Teddy Wing | 2015-10-07 02:56:34 -0400 |
|---|---|---|
| committer | Teddy Wing | 2015-10-07 02:56:34 -0400 |
| commit | 2223ed7b3a6f347457ba63eef378d071eb9e57e6 (patch) | |
| tree | 1f842d93ce9e1a184d0f46696b4a1332a1761026 | |
| parent | dd70d247ec64d68188ba28a2a25ee02de82f8d8c (diff) | |
| download | vim-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.vim | 27 |
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 |
