changeset 157:5cd12609a5c7

Make sure bullet is fired with positive shift length.
author Thinker K.F. Li <thinker@branda.to>
date Wed, 01 Oct 2008 16:30:05 +0800
parents 2aad042b30a4
children c1cdd3fcd28f
files examples/tank/tank_main.c
diffstat 1 files changed, 7 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/examples/tank/tank_main.c	Wed Oct 01 14:58:27 2008 +0800
+++ b/examples/tank/tank_main.c	Wed Oct 01 16:30:05 2008 +0800
@@ -424,10 +424,6 @@
     dir = tank->direction;
     map_x = tank->map_x + map_xy_adj[dir][0];
     map_y = tank->map_y + map_xy_adj[dir][1];
-    tank->bullet = tank_bullet_new(rdman, map_x, map_y, dir);
-    bullet = tank->bullet;
-    bullet->tman = tman;
-
     switch(dir) {
     case TD_UP:
 	shift_len = map_y + 1;
@@ -451,6 +447,13 @@
 	break;
     }
 
+    if(shift_len <= 0)
+	return;
+
+    tank->bullet = tank_bullet_new(rdman, map_x, map_y, dir);
+    bullet = tank->bullet;
+    bullet->tman = tman;
+
     progm = mb_progm_new(2, rdman);
     MB_TIMEVAL_SET(&start, 0, 0);
     MB_TIMEVAL_SET(&playing, shift_len / 4, (shift_len % 4) * 250000);