Index: apps/plugins/spacerocks.c
===================================================================
RCS file: /cvsroot/rockbox/apps/plugins/spacerocks.c,v
retrieving revision 1.9
diff -u -r1.9 spacerocks.c
--- apps/plugins/spacerocks.c	3 Aug 2006 20:17:18 -0000	1.9
+++ apps/plugins/spacerocks.c	4 Oct 2006 11:29:55 -0000
@@ -121,21 +121,13 @@
 
 #endif
 
-#define SHOW_COL 0
-#define HISCORE_FILE PLUGIN_DIR "/astrorocks.hs"
-#define POINT_SIZE 2
-#define MAX_NUM_ASTEROIDS 25
-#define MAX_NUM_MISSILES 6
 #define ABS(x) ((x)>0?(x):-(x))
 
-#define SCALE 5000
-#define MISSILE_SCALE 5000
-#define WRAP_GAP                12
-#define EXPLOSION_LENGTH        35
-
 #if CONFIG_KEYPAD == RECORDER_PAD || CONFIG_KEYPAD == ONDIO_PAD
   #define ENEMY_MISSILE_SURVIVAL_LENGTH 65
   #define MISSILE_SURVIVAL_LENGTH 40
+  #define ASTEROID_SPEED 5
+  #define LARGE_LCD 0
 #elif (CONFIG_KEYPAD == IRIVER_H100_PAD) || \
       (CONFIG_KEYPAD == IRIVER_H300_PAD) || \
       (CONFIG_KEYPAD == IAUDIO_X5_PAD) || \
@@ -143,10 +135,27 @@
       (CONFIG_KEYPAD == IPOD_4G_PAD) || \
       (CONFIG_KEYPAD == GIGABEAT_PAD)|| \
       (CONFIG_KEYPAD == IRIVER_H10_PAD)
-  #define ENEMY_MISSILE_SURVIVAL_LENGTH 120
-  #define MISSILE_SURVIVAL_LENGTH 80
+  #define ENEMY_MISSILE_SURVIVAL_LENGTH 140
+  #define MISSILE_SURVIVAL_LENGTH 40
+  #define ASTEROID_SPEED 15
+  #define LARGE_LCD 1
 #endif
-      
+
+#define EXTRA_LIFE 250
+#define SCALE 5000
+#define MISSILE_SCALE 5000
+#define WRAP_GAP                12
+#define EXPLOSION_LENGTH        20
+#define SHOW_COL 0
+#define HISCORE_FILE PLUGIN_DIR "/astrorocks.hs"
+#define POINT_SIZE 2
+#define MAX_NUM_ASTEROIDS 25
+#define MAX_NUM_MISSILES 6
+#define ENEMY_BIG_PROBABILITY_START 10
+#define ENEMY_APPEAR_PROBABILITY_START 35
+#define ENEMY_APPEAR_TIMING_START 1800
+#define LITTLE_SHIP 2
+#define BIG_SHIP 1
 #define SHOW_GAME_OVER_TIME     100
 #define SHOW_LEVEL_TIME         50
 #define START_LIVES             3
@@ -161,13 +170,10 @@
 #define SIZE_ENEMY_COLLISION    5*SCALE
 #define ATTRACT_FLIP_TIME       100
 #define NUM_STARS               50
+#define NUM_TRAIL_POINTS	70
 #define NUM_ROTATIONS           16
 
 #define SIN_COS_SCALE           10000
-#define SHIP_ROT_CW_SIN         3827
-#define SHIP_ROT_CW_COS         9239
-#define SHIP_ROT_ACW_SIN        -3827 
-#define SHIP_ROT_ACW_COS        9239 
 
 #define FAST_ROT_CW_SIN         873
 #define FAST_ROT_CW_COS         9963
@@ -184,18 +190,49 @@
 #define SLOW_ROT_ACW_SIN -      350
 #define SLOW_ROT_ACW_COS        9994
 
+#ifdef HAVE_LCD_COLOR
+#define SHIP_ROT_CW_SIN         2419
+#define SHIP_ROT_CW_COS         9702
+#define SHIP_ROT_ACW_SIN        -2419 
+#define SHIP_ROT_ACW_COS        9702
+#else
+#define SHIP_ROT_CW_SIN         3827
+#define SHIP_ROT_CW_COS         9239
+#define SHIP_ROT_ACW_SIN        -3827 
+#define SHIP_ROT_ACW_COS        9239 
+#endif
+
+
 #define SCALED_WIDTH (LCD_WIDTH*SCALE)
 #define SCALED_HEIGHT (LCD_HEIGHT*SCALE)
 #define CENTER_LCD_X (LCD_WIDTH/2)
 #define CENTER_LCD_Y (LCD_HEIGHT/2)
 
+#define SHIP_EXPLOSION_COLOUR     1
+#define ASTEROID_EXPLOSION_COLOUR 2
+#define ENEMY_EXPLOSION_COLOUR    3
+#define THRUST_COLOUR             4
+
+#define ASTEROID_R 230
+#define ASTEROID_G 200
+#define ASTEROID_B 100
+#define SHIP_R 255
+#define SHIP_G 255
+#define SHIP_B 255
+#define ENEMY_R 50
+#define ENEMY_G 220
+#define ENEMY_B 50
+#define THRUST_R 200
+#define THRUST_G 200
+#define THRUST_B 0
+
 #ifdef HAVE_LCD_COLOR
 #define COL_MISSILE  LCD_RGBPACK(200,0,0)
 #define COL_PLAYER   LCD_RGBPACK(200,200,200)
 #define COL_STARS    LCD_WHITE
-#define COL_ASTEROID LCD_RGBPACK(150,95,0)
+#define COL_ASTEROID LCD_RGBPACK(ASTEROID_R,ASTEROID_G,ASTEROID_B)
 #define COL_TEXT     LCD_RGBPACK(200,200,255)
-#define COL_ENEMY    LCD_RGBPACK(50,220,50)
+#define COL_ENEMY    LCD_RGBPACK(ENEMY_R,ENEMY_G,ENEMY_B)
 #define SET_FG       rb->lcd_set_foreground
 #define SET_BG       rb->lcd_set_background
 #else
@@ -203,11 +240,100 @@
 #define SET_BG(x)
 #endif
 
+/* The array of points that make up an asteroid */
+static const short asteroid_one[NUM_ASTEROID_VERTICES*2] =
+{ 
+    -2, -12, 
+    4, -8, 
+    8, -14, 
+    16, -5, 
+    14, 0,   
+    20,  2,  
+    12,  14, 
+    -4,  14, 
+    -10,  6,  
+    -10, -8    
+};
+
+/* The array of points that make up an asteroid */
+static const short asteroid_two[NUM_ASTEROID_VERTICES*2] =
+{ 
+    -2, -12, 
+    4, -16,
+    6, -14,
+    16, -8,
+    14, 0,
+    20,  2,
+    12,  14,
+    -4,  14,
+    -10,  6,
+    -10, -8
+};
+
+/* The array of points that make up an asteroid */
+static const short asteroid_three[NUM_ASTEROID_VERTICES*2] =
+{ 
+    -2, -12, 
+    4, -16,
+    6, -14,
+    2, -8,
+    14, 0,
+    20,  2,
+    12,  14,
+    -4,  14,
+    -16,  6,
+    -10, -8
+};
+
+/* The array od points the make up the ship */
+static const short ship_vertices[NUM_SHIP_VERTICES*2] =
+{ 
+    #if(LARGE_LCD)
+    0,-6, 
+    4, 6,
+    0, 2,
+    -4, 6
+    #else
+    0,-4, 
+    3, 4,
+    0, 1,
+    -3, 4
+    #endif
+};
+
+/* The array of points the make up the bad spaceship */
+static const short enemy_vertices[NUM_ENEMY_VERTICES*2] =
+{ 
+    #if(LARGE_LCD)
+    -8,  0, 
+    -4,  4,
+    4,  4,
+    8,  0,
+    4, -4,
+    -4, -4
+    #else
+    -5,  0, 
+    -2,  2,
+    2,  2,
+    5,  0,
+    2, -2,
+    -2, -2
+    #endif
+    
+};
+
 enum asteroid_type
 {
+    #if(LARGE_LCD)
+    SMALL =  2,
+    MEDIUM = 4,
+    LARGE =  6,
+    #else
     SMALL =  1,
     MEDIUM = 2,
     LARGE =  3,
+    #endif
+
 };
 
 enum game_state
@@ -227,6 +353,16 @@
     int dy;
 };
 
+struct TrailPoint
+{
+  int alive;
+  struct Point position;
+  short r;
+  short g;
+  short b;
+  short dec;
+};
+
 /* Asteroid structure, contains an array of points */
 struct Asteroid
 {
@@ -253,6 +389,10 @@
     struct Point vertices[NUM_ENEMY_VERTICES];
     struct Point position;
     int explode_countdown;
+    long last_time_appeared;
+    short size_probability;
+    short appear_probability; 
+    short appear_timing;
 };
 
 struct Missile
@@ -267,13 +407,14 @@
 static int next_missile_count;
 static int next_thrust_count;
 static int num_lives;
+static int extra_life;
 static int show_level_timeout;
 static int attract_flip_timeout;
 static int show_game_over;
 static int current_level;
 static int current_score;
 static int high_score;
-static int space_check_size = 20*SCALE;
+static int space_check_size = 30*SCALE;
 
 static bool enemy_on_screen;
 static char phscore[30];
@@ -284,6 +425,7 @@
 static struct Missile enemy_missile;
 static struct Enemy enemy;
 static struct Point lives_points[NUM_SHIP_VERTICES];
+static struct TrailPoint trailPoints[NUM_TRAIL_POINTS];
 
 void draw_and_move_asteroids(void);
 void initialise_game(int nStartNum);
@@ -318,70 +460,7 @@
 void drawstars(void);
 bool is_ship_within_asteroid(struct Asteroid* asteroid);
 
-/* The array of points that make up an asteroid */
-static const short asteroid_one[NUM_ASTEROID_VERTICES*2] =
-{ 
-    -1, -6, 
-    2, -4, 
-    4, -7, 
-    8, -4, 
-    7, 0,   
-    10,  1,  
-    6,  7, 
-    -2,  7, 
-    -5,  3,  
-    -5, -4    
-};
-
-/* The array of points that make up an asteroid */
-static const short asteroid_two[NUM_ASTEROID_VERTICES*2] =
-{ 
-    -1, -6, 
-    2, -8,
-    3, -7,
-    8, -4,
-    7, 0,
-    10,  1,
-    6,  7,
-    -2,  7,
-    -5,  3,
-    -5, -4
-};
-
-/* The array of points that make up an asteroid */
-static const short asteroid_three[NUM_ASTEROID_VERTICES*2] =
-{ 
-    -1, -6, 
-    2, -8,
-    3, -7,
-    1, -4,
-    7, 0,
-    10,  1,
-    6,  7,
-    -2,  7,
-    -8,  3,
-    -5, -4
-};
 
-/* The array od points the make up the ship */
-static const short ship_vertices[NUM_SHIP_VERTICES*2] =
-{ 
-    0,-4, 
-    3, 4,
-    0, 1,
-    -3, 4
-};
-
-/* The array of points the make up the bad spaceship */
-static const short enemy_vertices[NUM_ENEMY_VERTICES*2] =
-{ 
-    -5,  0, 
-    -2,  2,
-    2,  2,
-    5,  0,
-    2, -2,
-    -2, -2
-};
 
 /*Hi-Score reading and writing to file - this needs moving to the hi-score plugin lib as
 a 3rd function */
@@ -458,6 +537,131 @@
         point->y = SCALED_HEIGHT; 
 }
 
+void create_trail(struct TrailPoint* tpoint)
+{
+  tpoint->position.dx = -( ship.vertices[0].x - ship.vertices[2].x )/10;
+  tpoint->position.dy = -( ship.vertices[0].y - ship.vertices[2].y )/10; 
+}
+
+void create_explosion_trail(struct TrailPoint* tpoint)
+{
+  tpoint->position.dx = (rb->rand()%5050)-2500;
+  tpoint->position.dy = (rb->rand()%5050)-2500; 
+}
+
+void create_trail_blaze(int colour, struct Point* position)
+{
+  int numtoadd; 
+  struct TrailPoint* tpoint;
+  int n;
+  int xadd,yadd;
+  if(colour != SHIP_EXPLOSION_COLOUR)
+  {
+    numtoadd = NUM_TRAIL_POINTS/5;
+    xadd = position->x;
+    yadd = position->y;
+  }
+  else
+  {
+    numtoadd = NUM_TRAIL_POINTS/8;
+    xadd = ship.position.x;
+    yadd = ship.position.y;
+  }
+
+  //give the point a random countdown timer, so they dissapears at different times
+  tpoint = trailPoints;
+  n = NUM_TRAIL_POINTS;
+  while(--n)
+  {
+    if(tpoint->alive <= 0 && numtoadd)
+    {
+      numtoadd--;
+      //take a random x point anywhere between
+      //bottom two points of ship.
+      tpoint->position.x = (ship.vertices[2].x + (rb->rand()%18000)-9000) + position->x; //ship.position.x;
+      tpoint->position.y = (ship.vertices[2].y + (rb->rand()%18000)-9000) + position->y;
+
+      switch(colour)
+      {
+        case SHIP_EXPLOSION_COLOUR:
+         tpoint->r = 255;
+         tpoint->g = 255;
+         tpoint->b = 255;
+         create_explosion_trail(tpoint);
+         tpoint->alive = 510;
+         tpoint->dec = 2;
+        break;
+        case ASTEROID_EXPLOSION_COLOUR:
+         tpoint->r = ASTEROID_R;
+         tpoint->g = ASTEROID_G;
+         tpoint->b = ASTEROID_B;
+         create_explosion_trail(tpoint);
+         tpoint->alive = 510;
+         tpoint->dec = 2;
+        break;
+        case ENEMY_EXPLOSION_COLOUR:
+         tpoint->r = ENEMY_R;
+         tpoint->g = ENEMY_G;
+         tpoint->b = ENEMY_B;
+         create_explosion_trail(tpoint);
+         tpoint->alive = 510;
+         tpoint->dec = 2;
+        break;
+        case THRUST_COLOUR:
+         tpoint->r = THRUST_R;
+         tpoint->g = THRUST_G;
+         tpoint->b = THRUST_B;
+         create_trail(tpoint);
+         tpoint->alive = 175;
+         tpoint->dec = 4;
+        break;
+      }
+      //add a proportional bit to the x and y based on dx and dy
+  
+      //give the points a speed based on direction of travel - i.e. opposite
+      tpoint->position.dx += position->dx;
+      tpoint->position.dy += position->dy;
+
+      
+    }
+    tpoint++;
+  }
+  //find a space in the array of trail_points that is NULL or DEAD or whatever.
+  //and place this one here.
+  
+}
+
+void draw_trail_blaze(void)
+{
+  struct TrailPoint* tpoint;
+  //loop through, if alive then move and draw.
+  //when drawn, countdown it's timer.
+  //if zero kill it!
+  tpoint = trailPoints;
+  int n = NUM_TRAIL_POINTS;
+
+  while(--n)
+  {
+    if(tpoint->alive)
+    {
+      if(game_state != PAUSE_MODE) 
+      {
+        tpoint->alive-=10;
+        move_point(&(tpoint->position));
+      }
+      #ifdef HAVE_LCD_COLOR
+      //intensity = tpoint->alive/2;
+      if(tpoint->r>0)tpoint->r-=tpoint->dec;
+      if(tpoint->g>0)tpoint->g-=tpoint->dec;
+      if(tpoint->b>0)tpoint->b-=tpoint->dec;
+      SET_FG(LCD_RGBPACK(tpoint->r, tpoint->g, tpoint->b));
+      #endif
+      rb->lcd_drawpixel(tpoint->position.x/SCALE , tpoint->position.y/SCALE);
+    }
+    tpoint++;
+  }
+}
+
 /*Check if point is within a rectangle*/
 bool is_point_within_rectangle(struct Point* rect, struct Point* p, int size)
 {
@@ -548,18 +752,33 @@
 {
     struct Point* point;
     int n;
+    int size;
+
+    if(rb->rand()%100 > enemy.size_probability)
+    {
+      size = BIG_SHIP;
+      enemy.size_probability++;
+      if(enemy.size_probability < 90)
+      {
+         enemy.size_probability = ENEMY_BIG_PROBABILITY_START;
+      }
+    }
+    else
+    {
+      size = LITTLE_SHIP;
+    } 
     
     enemy_missile.survived = 0;
     enemy_on_screen = true;
     enemy.explode_countdown = 0;
-    
+    enemy.last_time_appeared = *rb->current_tick;
     point = enemy.vertices;
     for(n = 0; n < NUM_ENEMY_VERTICES+NUM_ENEMY_VERTICES; n+=2)
     {
         point->x  = enemy_vertices[n];
         point->y  = enemy_vertices[n+1];
-        point->x *= SCALE;
-        point->y *= SCALE;
+        point->x *= SCALE/size;
+        point->y *= SCALE/size;
         point++;
     }
     
@@ -606,7 +825,7 @@
             draw_polygon(enemy.vertices, enemy_x, enemy_y, NUM_ENEMY_VERTICES);
             rb->lcd_drawline(enemy.vertices[0].x/SCALE + enemy_x,
                              enemy.vertices[0].y/SCALE + enemy_y, 
-                             enemy.vertices[3].x/SCALE  + enemy_x,
+                             enemy.vertices[3].x/SCALE + enemy_x,
                              enemy.vertices[3].y/SCALE + enemy_y);
 
             if(game_state != PAUSE_MODE)
@@ -629,8 +848,8 @@
         else
         {
             
-            animate_and_draw_explosion(enemy.vertices, NUM_ENEMY_VERTICES,
-                                       enemy_x, enemy.position.y/SCALE);
+            //animate_and_draw_explosion(enemy.vertices, NUM_ENEMY_VERTICES,
+            //                           enemy_x, enemy.position.y/SCALE);
             if(game_state != PAUSE_MODE)
             {
                 enemy.explode_countdown--;
@@ -641,8 +860,8 @@
     }
     else
     {
-        if( (rb->rand()%1000) < 2 )
-            initialise_enemy();
+        if( (*rb->current_tick - enemy.last_time_appeared) > enemy.appear_timing)
+            if(rb->rand()%100 > enemy.appear_probability) initialise_enemy();
     }
     
     if(!enemy_missile.survived && game_state != GAME_OVER)
@@ -719,7 +938,7 @@
         { 
         case(SMALL):
             asteroid->explode_countdown = EXPLOSION_LENGTH; 
-            initialise_explosion(asteroid->vertices, NUM_ASTEROID_VERTICES); 
+            create_trail_blaze(ASTEROID_EXPLOSION_COLOUR, &asteroid->position);
             break;
             
         case(LARGE):
@@ -736,6 +955,11 @@
         }
         
         current_score++;
+        if(current_score > extra_life)
+        {
+          num_lives++;
+          extra_life = current_score+EXTRA_LIFE;
+        }
         asteroid_count--;
         asteroid->exists = false;
         return true;
@@ -746,12 +970,13 @@
 
 bool is_point_within_enemy(struct Point* point)
 {
-    if( is_point_within_rectangle(&enemy.position, point, 5*SCALE) )
+    if( is_point_within_rectangle(&enemy.position, point, 7*SCALE) )
     {
         current_score += 5;
         /*enemy_missile.survived = 0;*/
         enemy.explode_countdown = EXPLOSION_LENGTH;
-        initialise_explosion(enemy.vertices, NUM_ENEMY_VERTICES);
+       // initialise_explosion(enemy.vertices, NUM_ENEMY_VERTICES);
+        create_trail_blaze(ENEMY_EXPLOSION_COLOUR, &enemy.position);
         return true;
     }
     else
@@ -795,6 +1020,7 @@
         point->dy = point->y;
         point++;
     }
+    
 }
 
 /* Check for collsions between the missiles and the asteroids and the ship */
@@ -831,41 +1057,37 @@
                 }
                 missile++;
             }
-        } 
         
-        /*If it exists now, check ship collision:*/
-        if(asteroid->exists)
-        {
             /*now check collision with ship:*/
-            if(!ship.waiting_for_space && !ship.explode_countdown)
+            if(asteroid->exists && !ship.waiting_for_space && !ship.explode_countdown)
             {
                 if(is_ship_within_asteroid(asteroid))
                 {
                     /*blow up ship*/
                     ship.explode_countdown = EXPLOSION_LENGTH;
-                    initialise_explosion(ship.vertices, NUM_SHIP_VERTICES);
+                   // initialise_explosion(ship.vertices, NUM_SHIP_VERTICES);
+                    create_trail_blaze(SHIP_EXPLOSION_COLOUR, &ship.position);
                 }
-            }
-        }  
-        
-        /*has the enemy missile blown something up?*/
-        if(asteroid->exists && enemy_missile.survived)
-        {
-            if(is_point_within_asteroid(asteroid, &enemy_missile.position))
-            {
-