Improved buttons. You can create new level-subsets via the leveleditor now. Better...
authorTobias Gläßer <tobi.web@gmx.de>
Tue, 2 Mar 2004 15:42:36 +0000 (15:42 +0000)
committerTobias Gläßer <tobi.web@gmx.de>
Tue, 2 Mar 2004 15:42:36 +0000 (15:42 +0000)
SVN-Revision: 162

src/bitmask.c
src/button.c
src/level.c
src/level.h
src/leveleditor.c
src/player.c
src/texture.c
src/texture.h
src/timer.c
src/type.c

index 3607f01..a0be080 100644 (file)
@@ -23,7 +23,8 @@
  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  */
 
-#include <malloc.h>
+#include <stdlib.h>
+#include <stdio.h>
 #include "bitmask.h"
 
 #define MIN(a,b) ((a) < (b) ? (a) : (b))
index fcd96ce..f0a8e1c 100644 (file)
@@ -85,20 +85,7 @@ void button_free(button_type* pbutton)
 
 void button_event(button_type* pbutton, SDL_Event *event)
 {
-  if(event->type == SDL_KEYDOWN)
-    {
-      SDLKey key = event->key.keysym.sym;
-      if(key == pbutton->shortcut)
-        pbutton->state = BN_CLICKED;
-    }
-  else if(event->type == SDL_MOUSEMOTION)
-    {
-
-      if(pbutton->show_info)
-        {
-          pbutton->show_info = NO;
-        }
-    }
+SDLKey key = event->key.keysym.sym;
 
   if(event->motion.x > pbutton->x && event->motion.x < pbutton->x + pbutton->w &&
       event->motion.y > pbutton->y && event->motion.y < pbutton->y + pbutton->h)
@@ -126,7 +113,7 @@ void button_event(button_type* pbutton, SDL_Event *event)
             }
         }
     }
-  else
+  else if(event->type == SDL_MOUSEBUTTONDOWN || event->type == SDL_MOUSEBUTTONUP)
     {
       pbutton->state = -1;
       if(pbutton->show_info)
@@ -134,6 +121,25 @@ void button_event(button_type* pbutton, SDL_Event *event)
           pbutton->show_info = NO;
         }
     }
+    
+  if(event->type == SDL_KEYDOWN)
+    {
+      if(key == pbutton->shortcut)
+        pbutton->state = BN_PRESSED;
+    }
+  else if(event->type == SDL_KEYUP)
+    {
+      if(pbutton->state == BN_PRESSED && key == pbutton->shortcut)
+        pbutton->state = BN_CLICKED;
+    }
+  else if(event->type == SDL_MOUSEMOTION)
+    {
+
+      if(pbutton->show_info)
+        {
+          pbutton->show_info = NO;
+        }
+    }
 }
 
 int button_get_state(button_type* pbutton)
index 7a84365..ab14055 100644 (file)
@@ -93,7 +93,40 @@ void subset_load(st_subset* st_subset, char *subset)
             break;
         }
     }
-    st_subset->levels = --i;
+  st_subset->levels = --i;
+}
+
+void subset_save(st_subset* st_subset)
+{
+  FILE* fi;
+  char filename[1024];
+
+  /* Save data file: */
+  sprintf(filename, "/levels/%s/", st_subset->name);
+  
+  fcreatedir(filename);
+  snprintf(filename, 1024, "%s/levels/%s/info", st_dir, st_subset->name);
+  if(!fwriteable(filename))
+    snprintf(filename, 1024, "%s/levels/%s/info", DATA_PREFIX, st_subset->name);
+  if(fwriteable(filename))
+    {
+      fi = fopen(filename, "w");
+      if (fi == NULL)
+        {
+          perror(filename);
+        }
+
+      /* Save title info: */
+      fputs(st_subset->title, fi);
+      fputs("\n", fi);
+
+      /* Save the description: */
+
+      fputs(st_subset->description, fi);
+      fputs("\n", fi);
+      fclose(fi);
+
+    }
 }
 
 void subset_free(st_subset* st_subset)
@@ -168,11 +201,11 @@ int level_load(st_level* plevel, char *subset, int level)
   /* (Level width) */
   fgets(str, 10, fi);
   plevel->width = atoi(str);
-  
+
   /* (Level gravity) */
   fgets(str, 10, fi);
   plevel->gravity = atof(str);
-  
+
   /* Set the global gravity to the latest loaded level's gravity */
   gravity = plevel->gravity;
 
@@ -250,7 +283,7 @@ void level_save(st_level* plevel, char * subset, int level)
   fputs(str, fi);
   sprintf(str, "%2.1f\n", plevel->gravity);    /* level gravity */
   fputs(str, fi);
-  
+
   for(y = 0; y < 15; ++y)
     {
       fputs((const char*)plevel->tiles[y], fi);
index 27c94a7..d2fbf82 100644 (file)
@@ -28,6 +28,7 @@ typedef struct st_subset
 
 void subset_init(st_subset* st_subset);
 void subset_load(st_subset* st_subset, char *subset);
+void subset_save(st_subset* st_subset);
 void subset_free(st_subset* st_subset);
   
 #define LEVEL_NAME_MAX 20
index 2ed158d..6d74395 100644 (file)
@@ -1,3 +1,4 @@
+
 /***************************************************************************
  *                                                                         *
  *   This program is free software; you can redistribute it and/or modify  *
@@ -70,6 +71,7 @@ void le_testlevel();
 void le_showhelp();
 void le_set_defaults(void);
 void le_activate_bad_guys(void);
+void le_new_subset(char *subset_name);
 
 void le_highlight_selection();
 void apply_level_settings_menu();
@@ -225,6 +227,8 @@ int leveleditor(int levelnb)
                     {
                       subset_load(&le_level_subset,level_subsets[i-2]);
                       leveleditor_menu.item[3].kind = MN_GOTO;
+                     menu_item_change_input(&subset_settings_menu.item[2],le_level_subset.title);
+                     menu_item_change_input(&subset_settings_menu.item[3],le_level_subset.description);
                       le_level = 1;
                       arrays_init();
                       loadshared();
@@ -247,33 +251,16 @@ int leveleditor(int levelnb)
               if(subset_new_menu.item[2].input[0] == '\0')
                 subset_new_menu.item[3].kind = MN_DEACTIVE;
               else
+             {
                 subset_new_menu.item[3].kind = MN_ACTION;
 
-              /*switch (i = menu_check(&subset_load_menu))
+              switch (i = menu_check(&subset_new_menu))
                 {
-                case 0:
-                  break;
-                default:
-                  if(i != -1)
-                    {
-                      subset_load(&le_level_subset,level_subsets[i-2]);
-                      leveleditor_menu.item[3].kind = MN_GOTO;
-                      le_level = 1;
-                      arrays_init();
-                      loadshared();
-              le_current_level = (st_level*) malloc(sizeof(st_level));
-                      if(level_load(le_current_level, le_level_subset.name, le_level) != 0)
-                        {
-                          le_quit();
-                          return 1;
-                        }
-                      le_set_defaults();
-                      level_load_gfx(le_current_level);
-                      le_activate_bad_guys();
-                      show_menu = YES;
-                    }
+                case 3:
+                   le_new_subset(subset_new_menu.item[2].input);
                   break;
-                }*/
+                }
+               }
             }
         }
 
@@ -300,6 +287,45 @@ int leveleditor(int levelnb)
   return done;
 }
 
+void le_default_level(st_level* plevel)
+{
+  int i,y;
+  strcpy(plevel->name,"UnNamed");
+  strcpy(plevel->theme,"antarctica");
+  strcpy(plevel->song_title,"Mortimers_chipdisko.mod");
+  strcpy(plevel->bkgd_image,"arctis.png");
+  plevel->width = 21;
+  plevel->time_left = 100;
+  plevel->gravity = 10.;
+  plevel->bkgd_red = 0;
+  plevel->bkgd_green = 0;
+  plevel->bkgd_blue = 0;
+
+  for(i = 0; i < 15; ++i)
+    {
+      plevel->tiles[i] = (unsigned char*) malloc((plevel->width+1)*sizeof(unsigned char));
+      plevel->tiles[i][plevel->width] = (unsigned char) '\0';
+      for(y = 0; y < plevel->width; ++y)
+        plevel->tiles[i][y] = (unsigned char) '.';
+      plevel->tiles[i][plevel->width] = (unsigned char) '\0';
+    }
+}
+
+void le_new_subset(char *subset_name)
+{
+  st_level new_lev;
+  st_subset new_subset;
+  new_subset.name = (char*) malloc((strlen(subset_name)+1)*sizeof(char));
+  strcpy(new_subset.name,subset_name);
+  new_subset.title = (char*) malloc((strlen("Unknown Title")+1)*sizeof(char));
+  strcpy(new_subset.title,"Unknown Title");
+  new_subset.description = (char*) malloc((strlen("No description so far.")+1)*sizeof(char));
+  strcpy(new_subset.description,"No description so far.");
+  subset_save(&new_subset);
+  le_default_level(&new_lev);
+  level_save(&new_lev,subset_name,1);
+}
+
 int le_init()
 {
   int i;
@@ -341,15 +367,15 @@ int le_init()
   texture_load(&le_selection,DATA_PREFIX "/images/leveleditor/select.png", USE_ALPHA);
 
   /* Load buttons */
-  button_load(&le_next_level_bt,"/images/icons/up.png","Test Level", SDLK_PAGEUP,screen->w-64,0);
-  button_load(&le_previous_level_bt,"/images/icons/down.png","Test Level",SDLK_PAGEDOWN,screen->w-32,0);
+  button_load(&le_next_level_bt,"/images/icons/up.png","Next level", SDLK_PAGEUP,screen->w-64,0);
+  button_load(&le_previous_level_bt,"/images/icons/down.png","Previous level",SDLK_PAGEDOWN,screen->w-32,0);
   button_load(&le_rubber_bt,"/images/icons/rubber.png","Rubber",SDLK_DELETE,screen->w-64,32);
-  button_load(&le_select_mode_one_bt,"/images/icons/select-mode1.png","Select Tile",SDLK_F3,screen->w-64,16);
-  button_load(&le_select_mode_two_bt,"/images/icons/select-mode2.png","Select Tiles",SDLK_F3,screen->w-32,16);
-  button_load(&le_test_level_bt,"/images/icons/test-level.png","Test Level",SDLK_F4,screen->w-64,screen->h - 64);
-  button_load(&le_settings_bt,"/images/icons/settings.png","Level settings",SDLK_0,screen->w-32,screen->h - 64);
-  button_load(&le_move_left_bt,"/images/icons/left.png","Test Level",SDLK_F4,screen->w-64,screen->h - 32);
-  button_load(&le_move_right_bt,"/images/icons/right.png","Level settings",SDLK_0,screen->w-48,screen->h - 32);
+  button_load(&le_select_mode_one_bt,"/images/icons/select-mode1.png","Select single tile",SDLK_F3,screen->w-64,16);
+  button_load(&le_select_mode_two_bt,"/images/icons/select-mode2.png","Select multiple tiles",SDLK_F3,screen->w-32,16);
+  button_load(&le_test_level_bt,"/images/icons/test-level.png","Test level",SDLK_F4,screen->w-64,screen->h - 64);
+  button_load(&le_settings_bt,"/images/icons/settings.png","Level settings",SDLK_F5,screen->w-32,screen->h - 64);
+  button_load(&le_move_left_bt,"/images/icons/left.png","Move left",SDLK_LEFT,screen->w-64,screen->h - 32);
+  button_load(&le_move_right_bt,"/images/icons/right.png","Move right",SDLK_RIGHT,screen->w-48,screen->h - 32);
   button_panel_init(&le_bt_panel, screen->w - 64,64, 64, 380);
 
   menu_init(&leveleditor_menu);
@@ -387,6 +413,11 @@ int le_init()
   menu_init(&subset_settings_menu);
   menu_additem(&subset_settings_menu,menu_item_create(MN_LABEL,"Level Subset Settings",0,0));
   menu_additem(&subset_settings_menu,menu_item_create(MN_HL,"",0,0));
+  menu_additem(&subset_settings_menu,menu_item_create(MN_TEXTFIELD,"Title",0,0));
+  menu_additem(&subset_settings_menu,menu_item_create(MN_TEXTFIELD,"Description",0,0));
+  menu_additem(&subset_settings_menu,menu_item_create(MN_HL,"",0,0));
+  menu_additem(&subset_settings_menu,menu_item_create(MN_ACTION,"Apply Changes",0,0));
+  menu_additem(&subset_settings_menu,menu_item_create(MN_HL,"",0,0));
   menu_additem(&subset_settings_menu,menu_item_create(MN_BACK,"Back",0,0));
 
   menu_init(&level_settings_menu);
@@ -927,7 +958,7 @@ void le_checkevents()
 
   if(le_current_level != NULL)
     {
-      if(event.type == SDL_KEYDOWN || ((event.type == SDL_MOUSEBUTTONDOWN || SDL_MOUSEMOTION) && (event.motion.x > screen->w-64 && event.motion.x < screen->w &&
+      if(event.type == SDL_KEYDOWN || event.type == SDL_KEYUP || ((event.type == SDL_MOUSEBUTTONDOWN || SDL_MOUSEMOTION) && (event.motion.x > screen->w-64 && event.motion.x < screen->w &&
                                        event.motion.y > 0 && event.motion.y < screen->h)))
         {
           /* Check for button events */
index 9423b10..8b567cb 100644 (file)
@@ -124,6 +124,9 @@ void player_level_begin(player_type* pplayer)
   timer_init(&pplayer->invincible_timer,YES);
   timer_init(&pplayer->skidding_timer,YES);
   timer_init(&pplayer->safe_timer,YES);
+  timer_init(&pplayer->frame_timer,YES);
+  physic_init(&pplayer->hphysic);
+  physic_init(&pplayer->vphysic);
 }
 
 void player_action(player_type* pplayer)
index 2284786..05c3d34 100644 (file)
@@ -10,8 +10,8 @@
 //
 //
 
-#include <SDL/SDL.h>
-#include <SDL/SDL_image.h>
+#include "SDL.h"
+#include "SDL_image.h"
 #include "globals.h"
 #include "screen.h"
 #include "setup.h"
index 9904b29..3c3d803 100644 (file)
@@ -13,9 +13,9 @@
 #ifndef SUPERTUX_TEXTURE_H
 #define SUPERTUX_TEXTURE_H
 
-#include <SDL/SDL.h>
+#include "SDL.h"
 #ifndef NOOPENGL
-#include <SDL/SDL_opengl.h>
+#include "SDL_opengl.h"
 #endif
 
 /* Texture type */
@@ -25,8 +25,7 @@ typedef struct texture_type
    GLuint gl_texture;
    int w;
    int h;
-  }  
-texture_type;
+  } texture_type;
 
 void texture_setup(void);
 extern void (*texture_load) (texture_type* ptexture, char * file, int use_alpha);  
index eb9cccd..2e5b458 100644 (file)
@@ -10,7 +10,7 @@
 //
 //
 
-#include <SDL/SDL.h>
+#include "SDL.h"
 #include "defines.h"
 #include "timer.h"
 
index d6f9347..69c61f3 100644 (file)
@@ -10,7 +10,7 @@
 //
 //
 
-#include <SDL/SDL_image.h>
+#include "SDL_image.h"
 #include "setup.h"
 #include "globals.h"
 #include "screen.h"