File moon-lander-expanded.patch of Package moon-lander
--- moon_lander.c_org 2011-06-20 16:59:10.000000000 +0200
+++ moon_lander.c 2012-02-24 18:05:22.217000008 +0100
@@ -22,6 +22,8 @@
*
* 18/06/2011 - bugs fixed about background-pics / game-parameters and code cleaned by Uli
*
+* 23/02/2012 - background pic´s algorithm overworked; fuel initialized in startscreen;
+* flight director can´t draw outside screen; ship can changed in option menu
*/
@@ -54,6 +56,7 @@
#define NEWGAME 4
#define AIGAME 5
#define BONUS_SHIP 6
+#define FUEL_FULL 700
/************************************************/
@@ -110,7 +113,9 @@ typedef struct {
int back_no;
SDL_Surface *screen;
Sprite explosion[25];
- Sprite ship;
+ Sprite ship; // used in game for drawing
+ Sprite shipA; // the orginal ship
+ Sprite shipB; // the new ship
Sprite background;
Sprite thrust;
Sprite thrustb;
@@ -120,7 +125,9 @@ typedef struct {
Sprite crosshairsb;
Sprite beacon;
Sprite beaconb;
- Sprite miniship;
+ Sprite miniship; // used in game for drawing
+ Sprite minishipA; // the orginal mini ship
+ Sprite minishipB; // the new mini ship
Sprite logo;
Sprite gameover_screen;
Sprite magigames;
@@ -131,6 +138,7 @@ typedef struct {
int opt_num_lives;
int opt_fancy_terrain;
int opt_frame_period;
+ int opt_ship;
AI ai;
#ifndef NOSOUND
Mix_Chunk *engine;
@@ -192,6 +200,7 @@ void get_new_background(Game *game) {
struct dirent *files[100];
int done = 0;
int count = 0;
+ int PicNr = 0;
/* read images/backgrounds dir and choose a random image from there.
put it's filename in image_file */
@@ -207,7 +216,8 @@ void get_new_background(Game *game) {
while (!done){
if ( (files[count] = readdir(dir)) ){
//printf("I see - %d %s\n", count, files[count]->d_name);
- if ((strchr(files[count]->d_name, '.') - files[count]->d_name) > 0) { // filtering the "." ".." and ".Directory"
+ if (files[count]->d_name[0] != '.') { // skip entries that begin with .
+// if ((strchr(files[count]->d_name, '.') - files[count]->d_name) > 0) { // filtering the "." ".." and ".Directory"
count++; // if first char of filename is NOT a "." use it as a picture
}
}
@@ -223,12 +233,13 @@ void get_new_background(Game *game) {
closedir(dir);
- if (!count){
+ if (count < 2){
printf("I got no images for backgrounds - ERROR\n");
exit(0);
}
- // randomize backgroundpics
+ PicNr = game->back_no; // randomize backgroundpics
+ do { // always new Pictures // randomize backgroundpics
#ifndef WIN32_BUILD
game->back_no = 0 + ( random() % (count)); // a + ( rand() % ( b - a + 1)) a=0, b=count-1
#endif
@@ -236,15 +247,7 @@ void get_new_background(Game *game) {
#ifdef WIN32_BUILD
game->back_no = 0 + ( rand() % (count)); // a + ( rand() % ( b - a + 1)) a=0, b=count-1
#endif
-
-//game->back_no++;
-// if (game->back_no < 0){ // game->back_no is not used because of random
-// game->back_no = 0;
-// }
-
-// if (game->back_no >= count){
-// game->back_no = 0;
-// }
+ } while (PicNr == game->back_no);
if (game->background.image != NULL){
//printf("about to free background\n");
@@ -291,9 +294,9 @@ void save_game(Game *game){
if ( (file = fopen(filename, "w")) != NULL) {
- fprintf(file,"%d %d %d %d %d %d", game->opt_num_lives,
+ fprintf(file,"%d %d %d %d %d %d %d", game->opt_num_lives,
game->opt_lp_bonus,game->opt_lp_warn,game->opt_prog_grav,
- game->opt_fancy_terrain,game->opt_frame_period);
+ game->opt_fancy_terrain,game->opt_frame_period,game->opt_ship);
}
else{
@@ -331,9 +334,9 @@ void load_game(Game *game){
if ( (file = fopen(filename, "r")) != NULL) {
- fscanf(file,"%d %d %d %d %d %d", &game->opt_num_lives,
+ fscanf(file,"%d %d %d %d %d %d %d", &game->opt_num_lives,
&game->opt_lp_bonus, &game->opt_lp_warn, &game->opt_prog_grav,
- &game->opt_fancy_terrain, &game->opt_frame_period);
+ &game->opt_fancy_terrain, &game->opt_frame_period, &game->opt_ship);
}
else{
printf("cannot open file for reading: %s - loading defaults\n", filename);
@@ -345,6 +348,7 @@ void load_game(Game *game){
game->opt_prog_grav = 1;
game->opt_fancy_terrain = 1;
game->opt_frame_period = 2;
+ game->opt_ship = 0;
return;
}
@@ -359,11 +363,11 @@ void options (Game *game) {
int done = 0;
int *selected;
int position = 0;
- char options[6][100];
+ char options[7][100];
char display_string[150];
char selected_text[3];
int count;
- int value[6];
+ int value[7];
Uint8 *key_table;
SDL_Event event;
@@ -373,7 +377,7 @@ void options (Game *game) {
sprintf(options[3],"%s", "Variable Speed Landing Pads");
sprintf(options[4],"%s", "Number Of Ships");
sprintf(options[5],"%s", "Frame Period (x10ms)");
-
+ sprintf(options[6],"%s", "Rocket(0) or Eagle(1)");
/* clear event buffer */
while (SDL_PollEvent(&event)){};
@@ -399,13 +403,13 @@ void options (Game *game) {
if (key_table[SDLK_UP]){
position--;
if (position < 0){
- position = 5;
+ position = 6;
}
}
if (key_table[SDLK_DOWN]){
position++;
- if (position >5){
+ if (position > 6){
position = 0;
}
}
@@ -468,13 +472,16 @@ void options (Game *game) {
else if (position == 5){
selected = &(game->opt_frame_period);
}
-
+ else if (position == 6){
+ selected = &(game->opt_ship);
+ }
value[0] = game->opt_fancy_terrain;
value[1] = game->opt_prog_grav;
value[2] = game->opt_lp_warn;
value[3] = game->opt_lp_bonus;
value[4] = game->opt_num_lives;
value[5] = game->opt_frame_period;
+ value[6] = game->opt_ship;
/* draw the options */
@@ -491,7 +498,7 @@ void options (Game *game) {
DT_DrawText("ENTER / Arrow Keys changes value", game->screen, game->small_font, 260, 90);
DT_DrawText("ESC back to game", game->screen, game->small_font, 260, 105);
- for (count = 0; count < 6; count ++) {
+ for (count = 0; count < 7; count ++) {
if (position == count) {
sprintf(selected_text,"%s","**");
@@ -501,7 +508,7 @@ void options (Game *game) {
}
sprintf(display_string, "%s %s - %d", selected_text, options[count], value[count] );
- DT_DrawText(display_string, game->screen, game->big_font, 50, 150 + (count * 50) );
+ DT_DrawText(display_string, game->screen, game->big_font, 50, 150 + (count * 45) );
}
@@ -512,6 +519,15 @@ void options (Game *game) {
save_game(game);
+ if (game->opt_ship == 1) {
+ game->ship = game->shipB;
+ game->miniship = game->minishipB;
+ }
+ if (game->opt_ship == 0) {
+ game->ship = game->shipA;
+ game->miniship = game->minishipA;
+ }
+
/* clear event buffer */
delay(15); // if somebody press ESC to long
while (SDL_PollEvent(&event)){}; // should kill al the wrong ESC key-pressed
@@ -813,7 +829,7 @@ void random_level(Game *game) {
new_sprite_surface(&(game->current_level.sprite), game->current_level.sprite.image, 0, TERRAIN_YSIZE, 1);
- game->current_level.fuel = (700 - (game->difficulty * 25));
+ game->current_level.fuel = (FUEL_FULL - (game->difficulty * 25));
if (game->current_level.fuel < 300){
game->current_level.fuel = 300;
@@ -1725,7 +1741,7 @@ void gameloop(Game *game){
key_table = SDL_GetKeyState(NULL);
- if (key_table[SDLK_ESCAPE]){
+ if (key_table[SDLK_ESCAPE] && ( !pause)){
options(game);
}
@@ -1947,8 +1963,12 @@ void gameloop(Game *game){
int cx = game->crosshairs.x+4;
int cy = game->crosshairs.y+4;
for( xy = 1; xy < 15; xy++ ){
- x = xy * (hi/scale) * 2, y = xy * (vi/scale) * 2;
- DrawPixel(game->screen, 0, 255, 0, cx-x, cy-y);
+ x = xy * (hi/scale) * 2;
+ y = xy * (vi/scale) * 2;
+ if (cy > YSIZE) { cy = YSIZE; } // do NOT draw outside the screen
+ if (cx < 0) { cx = 0; }
+ if (cx > XSIZE) { cx = XSIZE; }
+ DrawPixel(game->screen, 0, 255, 0, cx-x, cy-y);
}
}
@@ -2083,7 +2103,6 @@ int main(int argc, char **argv) {
char filename[100];
Game game;
-
#ifndef NOSOUND
printf( "Sound active\n" );
#endif
@@ -2103,6 +2122,7 @@ int main(int argc, char **argv) {
game.demo_mode = 0;
game.autopilot = 0;
+ game.fuel = FUEL_FULL;
game.opt_num_lives = 3; // initialising the game-parameter,
game.opt_lp_bonus = 1; //if config-file is defect or false (older one)
@@ -2110,9 +2130,10 @@ int main(int argc, char **argv) {
game.opt_prog_grav = 1;
game.opt_fancy_terrain = 1;
game.opt_frame_period = 2;
-
- load_game(&game);
-
+ game.opt_ship = 0;
+
+ load_game(&game); // read game-parameter from file
+
game.score = 0;
game.difficulty = 0;
game.ships_remaining = (game.opt_num_lives - 1);
@@ -2122,7 +2143,6 @@ int main(int argc, char **argv) {
game.current_level.sprite.x = -1;
game.background.image = NULL;
game.background.x = -1;
-//game.back_no = 0; //not longer used, because random backgrounds
@@ -2135,10 +2155,16 @@ int main(int argc, char **argv) {
/* initialize sprites */
sprintf(filename, "%simages/miniship2.bmp", DATAPATH);
- new_sprite(&(game.miniship), filename, 0, 0, 1, 0 );
+ new_sprite(&(game.minishipA), filename, 0, 0, 1, 0 );
+
+ sprintf(filename, "%simages/minieagle.bmp", DATAPATH);
+ new_sprite(&(game.minishipB), filename, 0, 0, 1, 0 );
sprintf(filename, "%simages/newship.png", DATAPATH);
- new_sprite(&(game.ship), filename, XSIZE / 2, 1, 1, 0);
+ new_sprite(&(game.shipA), filename, XSIZE / 2, 1, 1, 0);
+
+ sprintf(filename, "%simages/neweagle.png", DATAPATH);
+ new_sprite(&(game.shipB), filename, XSIZE / 2, 1, 1, 0);
sprintf(filename, "%simages/thrust1.png", DATAPATH);
new_sprite(&(game.thrust), filename, 0, 0, 1, 0);
@@ -2235,9 +2261,16 @@ int main(int argc, char **argv) {
}
game.state = FRESHRUN;
-
-
-
+
+ if (game.opt_ship == 0) {
+ game.ship = game.shipA;
+ game.miniship = game.minishipA;
+ }
+ else {
+ game.ship = game.shipB;
+ game.miniship = game.minishipB;
+ }
+
/* everything is now loaded up */