diff examples/tank/tank_main.c @ 1100:fb79175e6cc3

Add AI for enemy tanks
author Thinker K.F. Li <thinker@codemud.net>
date Sun, 05 Dec 2010 12:23:29 +0800
parents e415c55b4a0d
children dbea3e42bf93
line wrap: on
line diff
--- a/examples/tank/tank_main.c	Sat Dec 04 16:22:11 2010 +0800
+++ b/examples/tank/tank_main.c	Sun Dec 05 12:23:29 2010 +0800
@@ -3,16 +3,13 @@
 #include <string.h>
 #include <mb.h>
 #include <mb_tools.h>
+#include "tank.h"
 #include "svgs.h"
 
 /*! \defgroup tank Example Tank
  * @{
  */
-/*! \brief Tile types in a map. */
-enum { MUD, ROC, BRI, BSH };
-
-/*! \brief Map of the game. */
-static char map[12][16] = {
+char map[12][16] = {
     { MUD, MUD, MUD, MUD, MUD, MUD, MUD, MUD,
       MUD, MUD, MUD, MUD, MUD, MUD, MUD, MUD},
     { MUD, ROC, ROC, ROC, MUD, BSH, BSH, ROC,
@@ -38,78 +35,8 @@
     { MUD, MUD, MUD, MUD, MUD, MUD, BRI, MUD,
       MUD, BRI, MUD, BRI, MUD, MUD, MUD, MUD}
 };
-
-#define MAP_W 16
-#define MAP_H 12
 /* @} */
 
-/*! \defgroup bullet_elf Bullet Elf
- * \ingroup tank
- * @{
- */
-/*! \brief Information about bullet elf
- */
-struct _tank_bullet {
-    redraw_man_t *rdman;
-    coord_t *coord_pos;
-    coord_t *coord_rot;
-    bullet_t *bullet_obj;
-    int start_map_x, start_map_y;
-    int direction;
-    mb_progm_t *progm;
-    mb_timeval_t start_time;
-    observer_t *observer_redraw;
-    int hit_tmr;
-    mb_timer_man_t *timer_man;
-};
-typedef struct _tank_bullet tank_bullet_t;
-/*! \brief The direction a bullet is going.
- */
-enum { BU_UP = 0, BU_RIGHT, BU_DOWN, BU_LEFT };
-/* @} */
-
-/*! \defgroup tank_elf Tank Elf
- * \brief Tank elf module provides control functions of tanks in game.
- * \ingroup tank
- * @{
- */
-/*! \brief Information about a tank elf. */
-struct _tank {
-    coord_t *coord_pos;		/*!< \brief coordinate for position */
-    coord_t *coord_rot;		/*!< \brief coordinate for rotation */
-    coord_t *coord_center;
-    int map_x, map_y;
-    int direction;
-    mb_progm_t *progm;
-    tank_bullet_t *bullet;
-    struct _tank_rt *tank_rt;	/*!< \brief for bullet to check
-				 * hitting on tanks.
-				 */
-};
-typedef struct _tank tank_t;
-enum { TD_UP = 0, TD_RIGHT, TD_DOWN, TD_LEFT };
-
-/* @} */
-
-typedef struct _tank_rt tank_rt_t;
-
-/*! \brief Runtime information for tank, this game/example.
- */
-struct _tank_rt {
-    tank_t *tank1;
-    tank1_t *tank1_o;
-    tank_t *tank2;
-    tank2_t *tank2_o;
-    int n_enemy;
-    tank_t *tank_enemies[10];
-    tank_en_t *tank_enemies_o[10];
-    tank_t *tanks[12];
-    int n_tanks;
-    void *map[12][16];
-    mb_rt_t *mb_rt;
-    observer_t *kb_observer;
-};
-
 /*! \ingroup tank_elf
  * @{
  */
@@ -165,8 +92,8 @@
 
 #define PI 3.1415926
 
-static void tank_move(tank_t *tank, int direction,
-		      tank_rt_t *tank_rt) {
+void
+tank_move(tank_t *tank, int direction, tank_rt_t *tank_rt) {
     mb_rt_t *mb_rt = tank_rt->mb_rt;
     redraw_man_t *rdman;
     mb_timer_man_t *timer_man;
@@ -488,7 +415,8 @@
 }
 
 /*! \brief To fire a bullet for a tank. */
-static void tank_fire_bullet(tank_rt_t *tank_rt, tank_t *tank) {
+void
+tank_fire_bullet(tank_rt_t *tank_rt, tank_t *tank) {
     mb_rt_t *mb_rt;
     redraw_man_t *rdman;
     int map_x, map_y;
@@ -738,6 +666,8 @@
 
     initial_tank(&tank_rt, rt);
     
+    /* init_enemies(&tank_rt); */
+    
     mb_runtime_event_loop(rt);
 
     mb_runtime_free(rt);