From 1cf03f7192b1840362da1a9eebcf3d68d7a4e8f6 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Tobias=20Gl=C3=A4=C3=9Fer?= Date: Sat, 3 Apr 2004 13:31:14 +0000 Subject: [PATCH] lots of improvements all over the code. Leveleditor improvements. Changed Tux's dying sequence. Intros can be skipped with any device now. Converted button_type and button_panel_type to C++ classes. SVN-Revision: 428 --- src/button.cpp | 250 +++++++++++++++++----------------- src/button.h | 80 ++++++----- src/gameloop.cpp | 22 +-- src/gameloop.h | 3 +- src/high_scores.cpp | 2 +- src/intro.cpp | 26 ++-- src/level.cpp | 37 ++++-- src/leveleditor.cpp | 377 ++++++++++++++++++++++++---------------------------- src/lispreader.cpp | 8 +- src/menu.h | 3 +- src/player.cpp | 40 ++++-- src/player.h | 1 + src/special.cpp | 17 +-- src/text.cpp | 14 +- src/texture.cpp | 48 +++++-- src/texture.h | 18 +-- src/tile.cpp | 15 ++- src/tile.h | 3 + src/worldmap.cpp | 6 +- 19 files changed, 498 insertions(+), 472 deletions(-) diff --git a/src/button.cpp b/src/button.cpp index a80f8cf0f..f6541d90a 100644 --- a/src/button.cpp +++ b/src/button.cpp @@ -17,13 +17,13 @@ #include "globals.h" #include "button.h" -void button_load(button_type* pbutton,char* icon_file, char* info, SDLKey shortcut, int x, int y) +Button::Button(std::string icon_file, std::string ninfo, SDLKey nshortcut, int x, int y, int mw, int mh) { char filename[1024]; - if(icon_file != NULL) + if(!icon_file.empty()) { - snprintf(filename, 1024, "%s/%s", datadir.c_str(), icon_file); + snprintf(filename, 1024, "%s/%s", datadir.c_str(), icon_file.c_str()); if(!faccessible(filename)) snprintf(filename, 1024, "%s/images/icons/default-icon.png", datadir.c_str()); } @@ -31,37 +31,46 @@ void button_load(button_type* pbutton,char* icon_file, char* info, SDLKey shortc { snprintf(filename, 1024, "%s/images/icons/default-icon.png", datadir.c_str()); } - texture_load(&pbutton->icon,filename,USE_ALPHA); - if(info == NULL) + if(mw != -1 || mh != -1) { - pbutton->info = NULL; + texture_load(&icon,filename,USE_ALPHA); + if(mw != -1) + icon.w = mw; + if(mh != -1) + icon.h = mh; + + SDL_Rect dest; + dest.x = 0; + dest.y = 0; + dest.w = icon.w; + dest.h = icon.h; + SDL_SoftStretch(icon.sdl_surface, NULL, icon.sdl_surface, &dest); } else - { - pbutton->info = (char*) malloc(sizeof(char)*(strlen(info) + 1)); - strcpy(pbutton->info,info); - } + texture_load(&icon,filename,USE_ALPHA); - pbutton->shortcut = shortcut; + info = ninfo; - pbutton->x = x; - pbutton->y = y; - pbutton->w = pbutton->icon.w; - pbutton->h = pbutton->icon.h; - pbutton->tag = -1; - pbutton->state = BUTTON_NONE; - pbutton->show_info = false; - pbutton->bkgd = NULL; + shortcut = nshortcut; + + rect.x = x; + rect.y = y; + rect.w = icon.w; + rect.h = icon.h; + tag = -1; + state = BUTTON_NONE; + show_info = false; + bkgd = NULL; } -void button_change_icon(button_type* pbutton,char* icon_file) +void Button::change_icon(std::string icon_file, int mw, int mh) { char filename[1024]; - if(icon_file != NULL) + if(!icon_file.empty()) { - snprintf(filename, 1024, "%s/%s", datadir.c_str(), icon_file); + snprintf(filename, 1024, "%s/%s", datadir.c_str(), icon_file.c_str()); if(!faccessible(filename)) snprintf(filename, 1024, "%s/images/icons/default-icon.png", datadir.c_str()); } @@ -69,153 +78,144 @@ void button_change_icon(button_type* pbutton,char* icon_file) { snprintf(filename, 1024, "%s/images/icons/default-icon.png", datadir.c_str()); } - - texture_free(&pbutton->icon); - texture_load(&pbutton->icon,filename,USE_ALPHA); -} -button_type* button_create(char* icon_file, char* info, SDLKey shortcut, int x, int y) -{ - button_type* pnew_button = (button_type*) malloc(sizeof(button_type)); - button_load(pnew_button,icon_file, info, shortcut, x, y); - return pnew_button; + texture_free(&icon); + texture_load(&icon,filename,USE_ALPHA); } -void button_draw(button_type* pbutton) +void Button::draw() { - fillrect(pbutton->x,pbutton->y,pbutton->w,pbutton->h,75,75,75,200); - fillrect(pbutton->x+1,pbutton->y+1,pbutton->w-2,pbutton->h-2,175,175,175,200); - if(pbutton->bkgd != NULL) - { - texture_draw(pbutton->bkgd,pbutton->x,pbutton->y); - } - texture_draw(&pbutton->icon,pbutton->x,pbutton->y); - if(pbutton->show_info) + fillrect(rect.x,rect.y,rect.w,rect.h,75,75,75,200); + fillrect(rect.x+1,rect.y+1,rect.w-2,rect.h-2,175,175,175,200); + if(bkgd != NULL) + { + texture_draw(bkgd,rect.x,rect.y); + } + texture_draw(&icon,rect.x,rect.y); + if(show_info) { char str[80]; int i = -32; - if(0 > pbutton->x - (int)strlen(pbutton->info) * white_small_text.w) - i = pbutton->w + strlen(pbutton->info) * white_small_text.w; + if(0 > rect.x - (int)strlen(info.c_str()) * white_small_text.w) + i = rect.w + strlen(info.c_str()) * white_small_text.w; - if(pbutton->info) - text_draw(&white_small_text, pbutton->info, i + pbutton->x - strlen(pbutton->info) * white_small_text.w, pbutton->y, 1); - sprintf(str,"(%s)", SDL_GetKeyName(pbutton->shortcut)); - text_draw(&white_small_text, str, i + pbutton->x - strlen(str) * white_small_text.w, pbutton->y + white_small_text.h+2, 1); + if(!info.empty()) + text_draw(&white_small_text, info.c_str(), i + rect.x - strlen(info.c_str()) * white_small_text.w, rect.y, 1); + sprintf(str,"(%s)", SDL_GetKeyName(shortcut)); + text_draw(&white_small_text, str, i + rect.x - strlen(str) * white_small_text.w, rect.y + white_small_text.h+2, 1); } - if(pbutton->state == BUTTON_PRESSED) - fillrect(pbutton->x,pbutton->y,pbutton->w,pbutton->h,75,75,75,200); - else if(pbutton->state == BUTTON_HOVER) - fillrect(pbutton->x,pbutton->y,pbutton->w,pbutton->h,150,150,150,128); + if(state == BUTTON_PRESSED) + fillrect(rect.x,rect.y,rect.w,rect.h,75,75,75,200); + else if(state == BUTTON_HOVER) + fillrect(rect.x,rect.y,rect.w,rect.h,150,150,150,128); } -void button_free(button_type* pbutton) +Button::~Button() { - free(pbutton->info); - texture_free(&pbutton->icon); + texture_free(&icon); } -void button_event(button_type* pbutton, SDL_Event *event) +void Button::event(SDL_Event &event) { - SDLKey key = event->key.keysym.sym; + 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) + if(event.motion.x > rect.x && event.motion.x < rect.x + rect.w && + event.motion.y > rect.y && event.motion.y < rect.y + rect.h) { - if(event->type == SDL_MOUSEBUTTONDOWN) + if(event.type == SDL_MOUSEBUTTONDOWN) { - if(event->button.button == SDL_BUTTON_LEFT) + if(event.button.button == SDL_BUTTON_LEFT) { - pbutton->state = BUTTON_PRESSED; + state = BUTTON_PRESSED; } else { - pbutton->show_info = true; + show_info = true; } } - else if(event->type == SDL_MOUSEBUTTONUP) + else if(event.type == SDL_MOUSEBUTTONUP) { - if(event->button.button == SDL_BUTTON_LEFT && pbutton->state == BUTTON_PRESSED) + if(event.button.button == SDL_BUTTON_LEFT && state == BUTTON_PRESSED) { - pbutton->state = BUTTON_CLICKED; + state = BUTTON_CLICKED; } - else if(event->button.button != SDL_BUTTON_LEFT && pbutton->state != BUTTON_PRESSED) + else if(event.button.button != SDL_BUTTON_LEFT && state != BUTTON_PRESSED) { - pbutton->show_info = true; + show_info = true; } } - if(pbutton->state != BUTTON_PRESSED && pbutton->state != BUTTON_CLICKED) + if(state != BUTTON_PRESSED && state != BUTTON_CLICKED) { - pbutton->state = BUTTON_HOVER; - mouse_cursor->set_state(MC_LINK); + state = BUTTON_HOVER; + mouse_cursor->set_state(MC_LINK); } } - else if(event->type != SDL_KEYDOWN && event->type != SDL_KEYUP) + else if(event.type != SDL_KEYDOWN && event.type != SDL_KEYUP) { - pbutton->state = BUTTON_NONE; - if(pbutton->show_info) + state = BUTTON_NONE; + if(show_info) { - pbutton->show_info = false; + show_info = false; } } - if(event->type == SDL_KEYDOWN) + if(event.type == SDL_KEYDOWN) { - if(key == pbutton->shortcut) - pbutton->state = BUTTON_PRESSED; + if(key == shortcut) + state = BUTTON_PRESSED; } - else if(event->type == SDL_KEYUP) + else if(event.type == SDL_KEYUP) { - if(pbutton->state == BUTTON_PRESSED && key == pbutton->shortcut) - pbutton->state = BUTTON_CLICKED; + if(state == BUTTON_PRESSED && key == shortcut) + state = BUTTON_CLICKED; } - else if(event->type == SDL_MOUSEMOTION) + else if(event.type == SDL_MOUSEMOTION) { - if(pbutton->show_info) + if(show_info) { - pbutton->show_info = false; + show_info = false; } } } -int button_get_state(button_type* pbutton) +int Button::get_state() { - int state; - if(pbutton->state == BUTTON_CLICKED) + int rstate; + if(state == BUTTON_CLICKED) { - state = pbutton->state; - pbutton->state = BUTTON_NONE; - return state; + rstate = state; + state = BUTTON_NONE; + return rstate; } else { - return pbutton->state; + return state; } } -void button_panel_init(button_panel_type* pbutton_panel, int x, int y, int w, int h) -{ - pbutton_panel->num_items = 0; - pbutton_panel->item = NULL; - pbutton_panel->x = x; - pbutton_panel->y = y; - pbutton_panel->w = w; - pbutton_panel->h = h; - pbutton_panel->hidden = false; +ButtonPanel::ButtonPanel(int x, int y, int w, int h) +{ + bw = 32; + bh = 32; + rect.x = x; + rect.y = y; + rect.w = w; + rect.h = h; + hidden = false; } -button_type* button_panel_event(button_panel_type* pbutton_panel, SDL_Event* event) +Button* ButtonPanel::event(SDL_Event& event) { - if(pbutton_panel->hidden == false) + if(!hidden) { - int i; - for(i = 0; i < pbutton_panel->num_items; ++i) + for(std::vector::iterator it = item.begin(); it != item.end(); ++it) { - button_event(&pbutton_panel->item[i],event); - if(pbutton_panel->item[i].state != -1) - return &pbutton_panel->item[i]; + (*it)->event(event); + if((*it)->state != -1) + return (*it); } return NULL; } @@ -225,49 +225,43 @@ button_type* button_panel_event(button_panel_type* pbutton_panel, SDL_Event* eve } } -void button_panel_free(button_panel_type* pbutton_panel) +ButtonPanel::~ButtonPanel() { - int i; - for(i = 0; i < pbutton_panel->num_items; ++i) + for(std::vector::iterator it = item.begin(); it != item.end(); ++it) { - button_free(&pbutton_panel->item[i]); + delete (*it); } - if(pbutton_panel->num_items) - free(pbutton_panel->item); + item.clear(); } -void button_panel_draw(button_panel_type* pbutton_panel) +void ButtonPanel::draw() { - if(pbutton_panel->hidden == false) + if(hidden == false) { - int i; - fillrect(pbutton_panel->x,pbutton_panel->y,pbutton_panel->w,pbutton_panel->h,100,100,100,200); - for(i = 0; i < pbutton_panel->num_items; ++i) + fillrect(rect.x,rect.y,rect.w,rect.h,100,100,100,200); + for(std::vector::iterator it = item.begin(); it != item.end(); ++it) { - button_draw(&pbutton_panel->item[i]); + (*it)->draw(); } } } -void button_panel_additem(button_panel_type* pbutton_panel, button_type* pbutton, int tag) +void ButtonPanel::additem(Button* pbutton, int tag) { int max_cols, row, col; - ++pbutton_panel->num_items; - pbutton_panel->item = (button_type*) realloc(pbutton_panel->item, sizeof(button_type) * pbutton_panel->num_items); - memcpy(&pbutton_panel->item[pbutton_panel->num_items-1],pbutton,sizeof(button_type)); - free(pbutton); + item.push_back(pbutton); /* A button_panel takes control of the buttons it contains and arranges them */ - max_cols = pbutton_panel->w / 32; + max_cols = rect.w / bw; - row = (pbutton_panel->num_items-1) / max_cols; - col = (pbutton_panel->num_items-1) % max_cols; + row = (item.size()-1) / max_cols; + col = (item.size()-1) % max_cols; - pbutton_panel->item[pbutton_panel->num_items-1].x = pbutton_panel->x + col * 32; - pbutton_panel->item[pbutton_panel->num_items-1].y = pbutton_panel->y + row * 32; - pbutton_panel->item[pbutton_panel->num_items-1].tag = tag; + item[item.size()-1]->rect.x = rect.x + col * bw; + item[item.size()-1]->rect.y = rect.y + row * bh; + item[item.size()-1]->tag = tag; } diff --git a/src/button.h b/src/button.h index 5af5d35e2..d80e823d4 100644 --- a/src/button.h +++ b/src/button.h @@ -13,6 +13,7 @@ #ifndef SUPERTUX_BUTTON_H #define SUPERTUX_BUTTON_H +#include #include "texture.h" enum ButtonState { @@ -22,42 +23,51 @@ enum ButtonState { BUTTON_HOVER }; -struct button_type -{ - texture_type icon; - texture_type* bkgd; - char *info; - SDLKey shortcut; - int x; - int y; - int w; - int h; - bool show_info; - ButtonState state; - int tag; -}; +class ButtonPanel; -void button_load(button_type* pbutton,char* icon_file, char* info, SDLKey shortcut, int x, int y); -button_type* button_create(char* icon_file, char* info, SDLKey shortcut, int x, int y); -void button_change_icon(button_type* pbutton,char* icon_file); -void button_draw(button_type* pbutton); -void button_free(button_type* pbutton); -void button_event(button_type* pbutton, SDL_Event* event); -int button_get_state(button_type* pbutton); - -struct button_panel_type -{ - int num_items; - int hidden; - int x,y; - int w,h; - button_type* item; -}; +class Button + { + friend class ButtonPanel; + + public: + Button(std::string icon_file, std::string info, SDLKey shortcut, int x, int y, int mw = -1, int h = -1); + ~Button(); + void event(SDL_Event& event); + void draw(); + int get_state(); + void change_icon(std::string icon_file, int mw, int mh); + int get_tag() + { + return tag; + } + + private: + texture_type icon; + texture_type* bkgd; + std::string info; + SDLKey shortcut; + SDL_Rect rect; + bool show_info; + ButtonState state; + int tag; + }; + +class ButtonPanel + { + public: + ButtonPanel(int x, int y, int w, int h); + ~ButtonPanel(); + void draw(); + Button* event(SDL_Event &event); + void additem(Button* pbutton, int tag); + Button* button_panel_event(SDL_Event& event); + void set_button_size(int w, int h) { bw = w; bh = h; } -void button_panel_init(button_panel_type* pbutton_panel, int x, int y, int w, int h); -void button_panel_free(button_panel_type* pbutton_panel); -void button_panel_draw(button_panel_type* pbutton_panel); -void button_panel_additem(button_panel_type* pbutton_panel, button_type* pbutton, int tag); -button_type* button_panel_event(button_panel_type* pbutton_panel, SDL_Event* event); + private: + int bw, bh; + bool hidden; + SDL_Rect rect; + std::vector item; + }; #endif /*SUPERTUX_BUTTON_H*/ diff --git a/src/gameloop.cpp b/src/gameloop.cpp index 751261021..3dac681fe 100644 --- a/src/gameloop.cpp +++ b/src/gameloop.cpp @@ -99,10 +99,10 @@ void start_timers(void) update_time = st_get_ticks(); } -void activate_bad_guys(void) +void activate_bad_guys(st_level* plevel) { - for (std::vector::iterator i = current_level.badguy_data.begin(); - i != current_level.badguy_data.end(); + for (std::vector::iterator i = plevel->badguy_data.begin(); + i != plevel->badguy_data.end(); ++i) { add_bad_guy(i->x, i->y, i->kind); @@ -300,8 +300,8 @@ int game_action(void) { unsigned int i; - /* (tux_dying || next_level) */ - if (tux.dying || next_level) + /* (tux.is_dead() || next_level) */ + if (tux.is_dead() || next_level) { /* Tux either died, or reached the end of a level! */ @@ -371,7 +371,7 @@ int game_action(void) } arrays_free(); - activate_bad_guys(); + activate_bad_guys(¤t_level); activate_particle_systems(); level_free_gfx(); level_load_gfx(¤t_level); @@ -611,7 +611,7 @@ int gameloop(const char * subset, int levelnb, int mode) } level_load_gfx(¤t_level); - activate_bad_guys(); + activate_bad_guys(¤t_level); activate_particle_systems(); level_load_song(¤t_level); @@ -1156,7 +1156,7 @@ void unloadshared(void) /* Draw a tile on the screen: */ -void drawshape(float x, float y, unsigned int c) +void drawshape(float x, float y, unsigned int c, Uint8 alpha) { if (c != 0) { @@ -1165,11 +1165,11 @@ void drawshape(float x, float y, unsigned int c) { if(ptile->images.size() > 1) { - texture_draw(&ptile->images[( ((global_frame_counter*25) / ptile->anim_speed) % (ptile->images.size()))],x,y); + texture_draw(&ptile->images[( ((global_frame_counter*25) / ptile->anim_speed) % (ptile->images.size()))],x,y, alpha); } else if (ptile->images.size() == 1) { - texture_draw(&ptile->images[0],x,y); + texture_draw(&ptile->images[0],x,y, alpha); } else { @@ -1638,7 +1638,7 @@ void loadgame(int slot) if(level_load(¤t_level,level_subset,level) != 0) exit(1); arrays_free(); - activate_bad_guys(); + activate_bad_guys(¤t_level); activate_particle_systems(); level_free_gfx(); level_load_gfx(¤t_level); diff --git a/src/gameloop.h b/src/gameloop.h index 27a6d1629..2f3721543 100644 --- a/src/gameloop.h +++ b/src/gameloop.h @@ -31,6 +31,7 @@ extern st_level current_level; class Tile; Tile* gettile(float x, float y); +void activate_bad_guys(st_level* plevel); int gameloop(const char * subset, int levelnb, int mode); void savegame(int slot); void loadgame(int slot); @@ -40,7 +41,7 @@ bool isbrick(float x, float y); bool isice(float x, float y); bool isfullbox(float x, float y); bool rectcollision(base_type* one, base_type* two); -void drawshape(float x, float y, unsigned int c); +void drawshape(float x, float y, unsigned int c, Uint8 alpha = 255); unsigned int shape(float x, float y); void bumpbrick(float x, float y); diff --git a/src/high_scores.cpp b/src/high_scores.cpp index c435ad112..09bec1bc4 100644 --- a/src/high_scores.cpp +++ b/src/high_scores.cpp @@ -103,7 +103,7 @@ void save_hs(int score) show_menu = 1; while(show_menu) { - texture_draw_bg(&bkgd, NO_UPDATE); + texture_draw_bg(&bkgd); text_drawf(&blue_text, "Congratulations", 0, 130, A_HMIDDLE, A_TOP, 2, NO_UPDATE); text_draw(&blue_text, "Your score:", 150, 180, 1, NO_UPDATE); diff --git a/src/intro.cpp b/src/intro.cpp index ae532fba5..d005e47f0 100644 --- a/src/intro.cpp +++ b/src/intro.cpp @@ -80,7 +80,7 @@ int intro(void) /* Display background: */ - texture_draw_bg(&bkgd, UPDATE); + texture_draw_bg(&bkgd, 255, UPDATE); /* Animation: */ @@ -113,8 +113,8 @@ int intro(void) ++scene; /* Gown and tux sitting: */ - texture_draw(&tux_sit, 270, 400, UPDATE); - texture_draw(&gown_sit, 320, 400, UPDATE); + texture_draw(&tux_sit, 270, 400, 255, UPDATE); + texture_draw(&gown_sit, 320, 400, 255, UPDATE); text_drawf(&white_text, intro_text[0], 0, -8, A_HMIDDLE, A_BOTTOM, 0); } @@ -136,8 +136,7 @@ int intro(void) texture_draw_part(&bkgd,0,32, 0, 32, screen->w, (copter[0].h)); texture_draw(&copter[i % 2], - (float)(timer_get_gone(&timer) - 2000) / 5 - (copter[0].w), 32, - NO_UPDATE); + (float)(timer_get_gone(&timer) - 2000) / 5 - (copter[0].w), 32); update_rect(screen, 0, 32, screen->w, (copter[0].h)); } @@ -148,7 +147,7 @@ int intro(void) ++scene; /* Gown notices something... */ - texture_draw(&gown_lookup, 320, 400, UPDATE); + texture_draw(&gown_lookup, 320, 400, 255, UPDATE); } @@ -156,8 +155,8 @@ int intro(void) { ++scene; /* Gown realizes it's bad! */ - - texture_draw(&gown_upset, 320, 400, UPDATE); + + texture_draw(&gown_upset, 320, 400, 255, UPDATE); } @@ -176,7 +175,7 @@ int intro(void) ++scene; /* Tux realizes something's happening: */ - texture_draw(&tux_upset, 270, 400, UPDATE); + texture_draw(&tux_upset, 270, 400, 255, UPDATE); erasecenteredtext(&white_text, intro_text[1], 454, &bkgd, UPDATE, 1); @@ -197,8 +196,7 @@ int intro(void) for (j = 0; j < (gown_upset.sdl_surface -> w); j++) { - texture_draw(&beam, 320 + j - ((beam.w) / 2), height[j], - NO_UPDATE); + texture_draw(&beam, 320 + j - ((beam.w) / 2), height[j]); src.x = j; src.y = 0; @@ -250,8 +248,7 @@ int intro(void) texture_draw_part(&bkgd, 0, 32, 0, 32, screen->w, (copter_squish.h)); texture_draw(&copter_squish, - 400 - (copter[0].w), 32, - NO_UPDATE); + 400 - (copter[0].w), 32); update_rect(screen, 0, 32, screen->w, (copter_squish.h)); } @@ -265,8 +262,7 @@ int intro(void) texture_draw(&copter_stretch, (timer_get_gone(&timer) - 8250) /*(i - (8250 / FPS)) * 30*/ + 400 - (copter[0].w), - 32, - NO_UPDATE); + 32); update_rect(screen, 0, 32, screen->w, (copter_stretch.h)); } diff --git a/src/level.cpp b/src/level.cpp index d4935863c..bb218d436 100644 --- a/src/level.cpp +++ b/src/level.cpp @@ -210,19 +210,19 @@ void level_default(st_level* plevel) plevel->ia_tiles[i] = (unsigned int*) malloc((plevel->width+1)*sizeof(unsigned int)); plevel->ia_tiles[i][plevel->width] = (unsigned int) '\0'; for(y = 0; y < plevel->width; ++y) - plevel->ia_tiles[i][y] = (unsigned int) '.'; + plevel->ia_tiles[i][y] = 0; plevel->ia_tiles[i][plevel->width] = (unsigned int) '\0'; plevel->bg_tiles[i] = (unsigned int*) malloc((plevel->width+1)*sizeof(unsigned int)); plevel->bg_tiles[i][plevel->width] = (unsigned int) '\0'; for(y = 0; y < plevel->width; ++y) - plevel->bg_tiles[i][y] = (unsigned int) '.'; + plevel->bg_tiles[i][y] = 0; plevel->bg_tiles[i][plevel->width] = (unsigned int) '\0'; plevel->fg_tiles[i] = (unsigned int*) malloc((plevel->width+1)*sizeof(unsigned int)); plevel->fg_tiles[i][plevel->width] = (unsigned int) '\0'; for(y = 0; y < plevel->width; ++y) - plevel->fg_tiles[i][y] = (unsigned int) '.'; + plevel->fg_tiles[i][y] = 0; plevel->fg_tiles[i][plevel->width] = (unsigned int) '\0'; } } @@ -305,10 +305,10 @@ int level_load(st_level* plevel, const char* filename) reader.read_int("y", &bg_data.y); plevel->badguy_data.push_back(bg_data); - + cur = lisp_cdr(cur); } - } + } } // Convert old levels to the new tile numbers @@ -342,9 +342,9 @@ int level_load(st_level* plevel, const char* filename) transtable['h'] = 98; transtable['i'] = 99; transtable['j'] = 100 - ; + ; transtable['#'] = 11; - transtable['['] = 13; + transtable['['] = 13; transtable['='] = 14; transtable[']'] = 15; transtable['$'] = 82; @@ -361,7 +361,7 @@ int level_load(st_level* plevel, const char* filename) if (*i == '0' || *i == '1' || *i == '2') { plevel->badguy_data.push_back(BadGuyData(static_cast(*i-'0'), - x*32, y*32)); + x*32, y*32)); *i = 0; } else @@ -373,10 +373,11 @@ int level_load(st_level* plevel, const char* filename) printf("Error: conversion will fail, unsupported char: '%c' (%d)\n", *i, *i); } ++x; - if (x >= plevel->width) { - x = 0; - ++y; - } + if (x >= plevel->width) + { + x = 0; + ++y; + } } } } @@ -503,7 +504,17 @@ void level_save(st_level* plevel,const char * subset, int level) fprintf(fi," %d ", plevel->fg_tiles[y][i]); } - fprintf( fi,")"); + fprintf( fi,")\n"); + fprintf( fi,"(objects\n"); + + for(std::vector::iterator it = plevel-> + badguy_data.begin(); + it != plevel->badguy_data.end(); + ++it) + fprintf( fi,"(%s (x %d) (y %d))\n",badguykind_to_string((*it).kind).c_str(),(*it).x,(*it).y); + + fprintf( fi,")\n"); + fprintf( fi,")\n"); fclose(fi); diff --git a/src/leveleditor.cpp b/src/leveleditor.cpp index 12a1ff416..b0598be1c 100644 --- a/src/leveleditor.cpp +++ b/src/leveleditor.cpp @@ -80,7 +80,6 @@ void le_highlight_selection(); void apply_level_settings_menu(); void update_subset_settings_menu(); void save_subset_settings_menu(); -void le_update_buttons(const char*); /* leveleditor internals */ static string_list_type level_subsets; @@ -95,17 +94,19 @@ static texture_type le_selection; static int done; static unsigned int le_current_tile; static bool le_mouse_pressed[2]; -static button_type le_save_level_bt; -static button_type le_test_level_bt; -static button_type le_next_level_bt; -static button_type le_previous_level_bt; -static button_type le_move_right_bt; -static button_type le_move_left_bt; -static button_type le_rubber_bt; -static button_type le_select_mode_one_bt; -static button_type le_select_mode_two_bt; -static button_type le_settings_bt; -static button_type le_tilegroup_bt; +static Button* le_save_level_bt; +static Button* le_exit_bt; +static Button* le_test_level_bt; +static Button* le_next_level_bt; +static Button* le_previous_level_bt; +static Button* le_move_right_bt; +static Button* le_move_left_bt; +static Button* le_rubber_bt; +static Button* le_select_mode_one_bt; +static Button* le_select_mode_two_bt; +static Button* le_settings_bt; +static Button* le_tilegroup_bt; +static ButtonPanel* le_tilemap_panel; static Menu* leveleditor_menu; static Menu* subset_load_menu; static Menu* subset_new_menu; @@ -113,12 +114,13 @@ static Menu* subset_settings_menu; static Menu* level_settings_menu; static Menu* select_tilegroup_menu; static timer_type select_tilegroup_menu_effect; -static std::map tilegroups_map; +static std::map tilegroups_map; static std::string cur_tilegroup; static square selection; static int le_selection_mode; static SDL_Event event; +TileMapType active_tm; void le_set_defaults() { @@ -248,9 +250,9 @@ int leveleditor(int levelnb) le_quit(); return 1; } - le_update_buttons(le_current_level->theme.c_str()); le_set_defaults(); level_load_gfx(le_current_level); + activate_bad_guys(le_current_level); show_menu = true; } break; @@ -279,9 +281,9 @@ int leveleditor(int levelnb) le_quit(); return 1; } - le_update_buttons(le_current_level->theme.c_str()); le_set_defaults(); level_load_gfx(le_current_level); + activate_bad_guys(le_current_level); menu_item_change_input(&subset_new_menu->item[2],""); show_menu = true; break; @@ -319,6 +321,8 @@ int leveleditor(int levelnb) return 1; } + ++global_frame_counter; + SDL_Delay(25); now_time = SDL_GetTicks(); if (now_time < last_time + FPS) @@ -330,59 +334,13 @@ int leveleditor(int levelnb) return done; } - -void le_update_buttons(const char *theme) -{ - /*int i; - char filename[1024]; - char pathname[1024]; - SDLKey key; - string_list_type bkgd_files; - string_list_type fgd_files; - - sprintf(pathname,"images/themes/%s",theme); - bkgd_files = dfiles(pathname,"bkgd-", NULL); - string_list_sort(&bkgd_files); - - le_bkgd_panel.hidden = true; - key = SDLK_a; - for(i = 0; i < bkgd_files.num_items; ++i) - { - sprintf(filename,"%s/%s",pathname,bkgd_files.item[i]); - button_change_icon(&le_bkgd_panel.item[i],filename); - } - - sprintf(pathname,"images/themes/%s",theme); - fgd_files = dfiles(pathname,"solid", NULL); - string_list_sort(&fgd_files); - key = SDLK_a; - for(i = 0; i < fgd_files.num_items; ++i) - { - sprintf(filename,"%s/%s",pathname,fgd_files.item[i]); - button_change_icon(&le_fgd_panel.item[i],filename); - } - - string_list_free(&fgd_files); - fgd_files = dfiles(pathname,"brick", NULL); - string_list_sort(&fgd_files); - - for(i = 0; i < fgd_files.num_items; ++i) - { - sprintf(filename,"%s/%s",pathname,fgd_files.item[i]); - button_change_icon(&le_fgd_panel.item[i+14],filename); - }*/ -} - int le_init() { int i; - char filename[1024]; - SDLKey key; - string_list_type fgd_files; - string_list_type bkgd_files; - string_list_type bad_files; level_subsets = dsubdirs("/levels", "info"); + active_tm = TM_IA; + le_show_grid = true; /* level_changed = NO;*/ @@ -401,18 +359,25 @@ int le_init() timer_init(&select_tilegroup_menu_effect,false); /* Load buttons */ - button_load(&le_save_level_bt,"/images/icons/save.png","Save level", SDLK_F6,screen->w-64,32); - 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-32,48); - button_load(&le_select_mode_one_bt,"/images/icons/select-mode1.png","Select single tile",SDLK_F3,screen->w-64,48); - button_load(&le_select_mode_two_bt,"/images/icons/select-mode2.png","Select multiple tiles",SDLK_F3,screen->w-64,64); - 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,0,0); - button_load(&le_move_right_bt,"/images/icons/right.png","Move right",SDLK_RIGHT,screen->w-80,0); - button_load(&le_tilegroup_bt,"/images/icons/tilegroup.png","Select Tilegroup", SDLK_F7,screen->w-64,82); - + le_save_level_bt = new Button("/images/icons/save.png","Save level", SDLK_F6,screen->w-64,32); + le_exit_bt = new Button("/images/icons/exit.png","Exit", SDLK_F6,screen->w-32,32); + le_next_level_bt = new Button("/images/icons/up.png","Next level", SDLK_PAGEUP,screen->w-64,0); + le_previous_level_bt = new Button("/images/icons/down.png","Previous level",SDLK_PAGEDOWN,screen->w-32,0); + le_rubber_bt = new Button("/images/icons/rubber.png","Rubber",SDLK_DELETE,screen->w-32,48); + le_select_mode_one_bt = new Button ("/images/icons/select-mode1.png","Select single tile",SDLK_F3,screen->w-64,48); + le_select_mode_two_bt = new Button("/images/icons/select-mode2.png","Select multiple tiles",SDLK_F3,screen->w-64,64); + le_test_level_bt = new Button("/images/icons/test-level.png","Test level",SDLK_F4,screen->w-64,screen->h - 64); + le_settings_bt = new Button("/images/icons/settings.png","Level settings",SDLK_F5,screen->w-32,screen->h - 64); + le_move_left_bt = new Button("/images/icons/left.png","Move left",SDLK_LEFT,0,0); + le_move_right_bt = new Button("/images/icons/right.png","Move right",SDLK_RIGHT,screen->w-80,0); + le_tilegroup_bt = new Button("/images/icons/tilegroup.png","Select Tilegroup", SDLK_F7,screen->w-64,80); + + le_tilemap_panel = new ButtonPanel(screen->w-64,screen->h-32,32,32); + le_tilemap_panel->set_button_size(32,10); + le_tilemap_panel->additem(new Button("/images/icons/bkgrd.png","Background",SDLK_F4,0,0),TM_BG); + le_tilemap_panel->additem(new Button("/images/icons/intact.png","Interactive",SDLK_F4,0,0),TM_IA); + le_tilemap_panel->additem(new Button("/images/icons/frgrd.png","Foreground",SDLK_F4,0,0),TM_FG); + leveleditor_menu = new Menu(); subset_load_menu = new Menu(); subset_new_menu = new Menu(); @@ -483,9 +448,10 @@ int le_init() { select_tilegroup_menu->additem(MN_ACTION,const_cast((*it).name.c_str()),0,0); - button_panel_init(&tilegroups_map[(*it).name], screen->w - 64,98, 64, 318); - for(std::vector::iterator sit = (*it).tiles.begin(); sit != (*it).tiles.end(); ++sit) - button_panel_additem(&tilegroups_map[(*it).name],button_create(const_cast(("images/tilesets/" + TileManager::instance()->get(*sit)->filenames[0]).c_str()), const_cast((*it).name.c_str()),(SDLKey)((int)key),0,0),(*sit)); + tilegroups_map[(*it).name] = new ButtonPanel(screen->w - 64,96, 64, 318); + i = 0; + for(std::vector::iterator sit = (*it).tiles.begin(); sit != (*it).tiles.end(); ++sit, ++i) + tilegroups_map[(*it).name]->additem(new Button(const_cast(("images/tilesets/" + TileManager::instance()->get(*sit)->filenames[0]).c_str()), const_cast((*it).name.c_str()),(SDLKey)(i+'a'),0,0,32,32),(*sit)); } select_tilegroup_menu->additem(MN_HL,"",0,0); @@ -548,7 +514,6 @@ void apply_level_settings_menu() if(le_current_level->theme.compare(string_list_active(level_settings_menu->item[3].list)) != 0) { le_current_level->theme = string_list_active(level_settings_menu->item[3].list); - le_update_buttons(le_current_level->theme.c_str()); i = true; } @@ -591,10 +556,10 @@ void le_goto_level(int levelnb) le_set_defaults(); - le_update_buttons(le_current_level->theme.c_str()); level_free_gfx(); level_load_gfx(le_current_level); + activate_bad_guys(le_current_level); } void le_quit(void) @@ -612,17 +577,19 @@ void le_quit(void) delete subset_settings_menu; delete level_settings_menu; delete select_tilegroup_menu; - button_free(&le_save_level_bt); - button_free(&le_test_level_bt); - button_free(&le_next_level_bt); - button_free(&le_previous_level_bt); - button_free(&le_move_right_bt); - button_free(&le_move_left_bt); - button_free(&le_rubber_bt); - button_free(&le_select_mode_one_bt); - button_free(&le_select_mode_two_bt); - button_free(&le_settings_bt); - button_free(&le_tilegroup_bt); + delete le_save_level_bt; + delete le_exit_bt; + delete le_test_level_bt; + delete le_next_level_bt; + delete le_previous_level_bt; + delete le_move_right_bt; + delete le_move_left_bt; + delete le_rubber_bt; + delete le_select_mode_one_bt; + delete le_select_mode_two_bt; + delete le_settings_bt; + delete le_tilegroup_bt; + delete le_tilemap_panel; if(le_current_level != NULL) { @@ -669,49 +636,30 @@ void le_drawinterface() /* draw button bar */ fillrect(screen->w - 64, 0, 64, screen->h, 50, 50, 50,255); drawshape(19 * 32, 14 * 32, le_current_tile); - switch(le_current_tile) - { - case 'B': - texture_draw(&img_mints, 19 * 32, 14 * 32); - break; - case '!': - texture_draw(&img_golden_herring,19 * 32, 14 * 32); - break; - case 'x': - case 'y': - case 'A': - texture_draw(&img_distro[(le_frame / 5) % 4], 19 * 32, 14 * 32); - break; - case '0': - texture_draw(&img_bsod_left[(le_frame / 5) % 4],19 * 32, 14 * 32); - break; - case '1': - texture_draw(&img_laptop_left[(le_frame / 5) % 3],19 * 32, 14 * 32); - break; - case '2': - texture_draw(&img_money_left[0],19 * 32, 14 * 32); - break; - default: - break; - } + + if(TileManager::instance()->get(le_current_tile)->editor_images.size() > 0) + texture_draw(&TileManager::instance()->get(le_current_tile)->editor_images[0], 19 * 32, 14 * 32); if(le_current_level != NULL) { - button_draw(&le_save_level_bt); - button_draw(&le_test_level_bt); - button_draw(&le_next_level_bt); - button_draw(&le_previous_level_bt); - button_draw(&le_rubber_bt); - button_draw(&le_select_mode_one_bt); - button_draw(&le_select_mode_two_bt); - button_draw(&le_settings_bt); - button_draw(&le_move_right_bt); - button_draw(&le_move_left_bt); - button_draw(&le_tilegroup_bt); - button_panel_draw(&tilegroups_map[cur_tilegroup]); + le_save_level_bt->draw(); + le_exit_bt->draw(); + le_test_level_bt->draw(); + le_next_level_bt->draw(); + le_previous_level_bt->draw(); + le_rubber_bt->draw(); + le_select_mode_one_bt->draw(); + le_select_mode_two_bt->draw(); + le_settings_bt->draw(); + le_move_right_bt->draw(); + le_move_left_bt->draw(); + le_tilegroup_bt->draw(); + if(!cur_tilegroup.empty()) + tilegroups_map[cur_tilegroup]->draw(); + le_tilemap_panel->draw(); sprintf(str, "%d/%d", le_level,le_level_subset.levels); - text_drawf(&white_text, str, -8, 16, A_RIGHT, A_TOP, 1); + text_drawf(&white_text, str, -10, 16, A_RIGHT, A_TOP, 0); text_draw(&white_small_text, "F1 for Help", 10, 430, 1); } @@ -728,6 +676,7 @@ void le_drawinterface() void le_drawlevel() { unsigned int y,x,i,s; + Uint8 a; /* Draw the real background */ if(le_current_level->bkgd_image[0] != '\0') @@ -746,51 +695,55 @@ void le_drawlevel() for (y = 0; y < 15; ++y) for (x = 0; x < 20; ++x) { - drawshape(32*x - fmodf(pos_x, 32), y * 32, le_current_level->ia_tiles[y][x + (int)(pos_x / 32)]); - + + if(active_tm == TM_BG) + a = 255; + else + a = 128; + + drawshape(32*x - fmodf(pos_x, 32), y * 32, le_current_level->bg_tiles[y][x + (int)(pos_x / 32)],a); + + if(active_tm == TM_IA) + a = 255; + else + a = 128; + + drawshape(32*x - fmodf(pos_x, 32), y * 32, le_current_level->ia_tiles[y][x + (int)(pos_x / 32)],a); + + if(active_tm == TM_FG) + a = 255; + else + a = 128; + + drawshape(32*x - fmodf(pos_x, 32), y * 32, le_current_level->fg_tiles[y][x + (int)(pos_x / 32)],a); + /* draw whats inside stuff when cursor is selecting those */ /* (draw them all the time - is this the right behaviour?) */ - switch(le_current_level->ia_tiles[y][x + (int)(pos_x/32)]) - { - case 'B': - texture_draw(&img_mints, x * 32 - ((int)pos_x % 32), y*32); - break; - case '!': - texture_draw(&img_golden_herring, x * 32 - ((int)pos_x % 32), y*32); - break; - case 'x': - case 'y': - case 'A': - texture_draw(&img_distro[(global_frame_counter / 5) % 4], x * 32 - ((int)pos_x % 32), y*32); - break; - default: - break; - } + if(TileManager::instance()->get(le_current_level->ia_tiles[y][x + (int)(pos_x / 32)])->editor_images.size() > 0) + texture_draw(&TileManager::instance()->get(le_current_level->ia_tiles[y][x + (int)(pos_x / 32)])->editor_images[0], x * 32 - ((int)pos_x % 32), y*32); + } /* Draw the Bad guys: */ for (i = 0; i < bad_guys.size(); ++i) { /* to support frames: img_bsod_left[(frame / 5) % 4] */ - if(bad_guys[i].kind == BAD_BSOD) - texture_draw(&img_bsod_left[(le_frame / 5) % 4], bad_guys[i].base.x - pos_x, bad_guys[i].base.y); - else if(bad_guys[i].kind == BAD_LAPTOP) - texture_draw(&img_laptop_left[(le_frame / 5) % 3], bad_guys[i].base.x - pos_x, bad_guys[i].base.y); - else if (bad_guys[i].kind == BAD_MONEY) - texture_draw(&img_money_left[(le_frame / 5) % 2], bad_guys[i].base.x - pos_x, bad_guys[i].base.y); + + scroll_x = pos_x; + bad_guys[i].draw(); } /* Draw the player: */ - /* for now, the position is fixed at (0, 240) */ - texture_draw(&tux_right[(global_frame_counter / 5) % 3], 0 - pos_x, 240); + /* for now, the position is fixed at (100, 240) */ + texture_draw(&tux_right[(global_frame_counter / 5) % 3], 100 - pos_x, 240); } void le_checkevents() { SDLKey key; SDLMod keymod; - button_type* pbutton; + Button* pbutton; int x,y; keymod = SDL_GetModState(); @@ -907,7 +860,23 @@ void le_checkevents() selection.y2 = event.motion.y; } else if(event.button.button == SDL_BUTTON_RIGHT) + { + switch(active_tm) + { + case TM_BG: + active_tm = TM_IA; + break; + case TM_IA: + active_tm = TM_FG; + break; + case TM_FG: + active_tm = TM_BG; + break; + default: + break; + } le_mouse_pressed[RIGHT] = true; + } break; case SDL_MOUSEBUTTONUP: if(event.button.button == SDL_BUTTON_LEFT) @@ -955,14 +924,20 @@ void le_checkevents() if(show_menu == false) { /* Check for button events */ - button_event(&le_test_level_bt,&event); - if(button_get_state(&le_test_level_bt) == BUTTON_CLICKED) + le_test_level_bt->event(event); + if(le_test_level_bt->get_state() == BUTTON_CLICKED) le_testlevel(); - button_event(&le_save_level_bt,&event); - if(button_get_state(&le_save_level_bt) == BUTTON_CLICKED) + le_save_level_bt->event(event); + if(le_save_level_bt->get_state() == BUTTON_CLICKED) level_save(le_current_level,le_level_subset.name.c_str(),le_level); - button_event(&le_next_level_bt,&event); - if(button_get_state(&le_next_level_bt) == BUTTON_CLICKED) + le_exit_bt->event(event); + if(le_exit_bt->get_state() == BUTTON_CLICKED) + { + Menu::set_current(leveleditor_menu); + show_menu = true; + } + le_next_level_bt->event(event); + if(le_next_level_bt->get_state() == BUTTON_CLICKED) { if(le_level < le_level_subset.levels) { @@ -1007,24 +982,24 @@ void le_checkevents() } } } - button_event(&le_previous_level_bt,&event); - if(button_get_state(&le_previous_level_bt) == BUTTON_CLICKED) + le_previous_level_bt->event(event); + if(le_previous_level_bt->get_state() == BUTTON_CLICKED) { if(le_level > 1) le_goto_level(--le_level); } - button_event(&le_rubber_bt,&event); - if(button_get_state(&le_rubber_bt) == BUTTON_CLICKED) + le_rubber_bt->event(event); + if(le_rubber_bt->get_state() == BUTTON_CLICKED) le_current_tile = 0; - button_event(&le_select_mode_one_bt,&event); - if(button_get_state(&le_select_mode_one_bt) == BUTTON_CLICKED) + le_select_mode_one_bt->event(event); + if(le_select_mode_one_bt->get_state() == BUTTON_CLICKED) le_selection_mode = CURSOR; - button_event(&le_select_mode_two_bt,&event); - if(button_get_state(&le_select_mode_two_bt) == BUTTON_CLICKED) + le_select_mode_two_bt->event(event); + if(le_select_mode_two_bt->get_state() == BUTTON_CLICKED) le_selection_mode = SQUARE; - button_event(&le_tilegroup_bt,&event); - if(button_get_state(&le_tilegroup_bt) == BUTTON_CLICKED) + le_tilegroup_bt->event(event); + if(le_tilegroup_bt->get_state() == BUTTON_CLICKED) { Menu::set_current(select_tilegroup_menu); timer_start(&select_tilegroup_menu_effect,200); @@ -1032,48 +1007,39 @@ void le_checkevents() show_menu = true; } - button_event(&le_settings_bt,&event); - if(button_get_state(&le_settings_bt) == BUTTON_CLICKED) + le_settings_bt->event(event); + if(le_settings_bt->get_state() == BUTTON_CLICKED) { update_level_settings_menu(); Menu::set_current(level_settings_menu); show_menu = true; } - if((pbutton = button_panel_event(&tilegroups_map[cur_tilegroup],&event)) != NULL) + if(!cur_tilegroup.empty()) + if((pbutton = tilegroups_map[cur_tilegroup]->event(event)) != NULL) { - if(button_get_state(pbutton) == BUTTON_CLICKED) + if(pbutton->get_state() == BUTTON_CLICKED) { - le_current_tile = pbutton->tag; + le_current_tile = pbutton->get_tag(); + } + } + if((pbutton = le_tilemap_panel->event(event)) != NULL) + { + if(pbutton->get_state() == BUTTON_CLICKED) + { + active_tm = static_cast(pbutton->get_tag()); } } - /*if((pbutton = button_panel_event(&le_bkgd_panel,&event)) != NULL) - { - if(button_get_state(pbutton) == BUTTON_CLICKED) - { - char c = '\0'; - if(pbutton->tag >= 0 && pbutton->tag <= 3) - c = 'G' + pbutton->tag; - else if(pbutton->tag >= 4 && pbutton->tag <= 7) - c = 'g' + pbutton->tag - 4; - else if(pbutton->tag >= 8 && pbutton->tag <= 11) - c = 'C' + pbutton->tag - 8; - else if(pbutton->tag >= 12 && pbutton->tag <= 15) - c = 'c' + pbutton->tag - 12; - if(c != '\0') - le_current_tile = c; - } - }*/ } else { - button_event(&le_settings_bt,&event); - if(button_get_state(&le_settings_bt) == BUTTON_CLICKED) + le_settings_bt->event(event); + if(le_settings_bt->get_state() == BUTTON_CLICKED) { Menu::set_current(leveleditor_menu); show_menu = false; } - button_event(&le_tilegroup_bt,&event); - if(button_get_state(&le_tilegroup_bt) == BUTTON_CLICKED) + le_tilegroup_bt->event(event); + if(le_tilegroup_bt->get_state() == BUTTON_CLICKED) { Menu::set_current(leveleditor_menu); show_menu = false; @@ -1082,32 +1048,32 @@ void le_checkevents() } if(show_menu == false) { - button_event(&le_move_left_bt,&event); - button_event(&le_move_right_bt,&event); + le_move_left_bt->event(event); + le_move_right_bt->event(event); if(le_mouse_pressed[LEFT]) { - le_change(cursor_x, cursor_y, TM_IA, le_current_tile); + le_change(cursor_x, cursor_y, active_tm, le_current_tile); } } } } if(show_menu == false) { - if(button_get_state(&le_move_left_bt) == BUTTON_PRESSED) + if(le_move_left_bt->get_state() == BUTTON_PRESSED) { pos_x -= 192; } - else if(button_get_state(&le_move_left_bt) == BUTTON_HOVER) + else if(le_move_left_bt->get_state() == BUTTON_HOVER) { pos_x -= 96; } - if(button_get_state(&le_move_right_bt) == BUTTON_PRESSED) + if(le_move_right_bt->get_state() == BUTTON_PRESSED) { pos_x += 192; } - else if(button_get_state(&le_move_right_bt) == BUTTON_HOVER) + else if(le_move_right_bt->get_state() == BUTTON_HOVER) { pos_x += 96; } @@ -1239,6 +1205,7 @@ void le_testlevel() arrays_free(); level_load_gfx(le_current_level); loadshared(); + activate_bad_guys(le_current_level); } void le_showhelp() diff --git a/src/lispreader.cpp b/src/lispreader.cpp index df34a9e91..0ece43d83 100644 --- a/src/lispreader.cpp +++ b/src/lispreader.cpp @@ -48,10 +48,10 @@ static char token_string[MAX_TOKEN_LENGTH + 1] = ""; static int token_length = 0; -static lisp_object_t end_marker = { LISP_TYPE_EOF }; -static lisp_object_t error_object = { LISP_TYPE_PARSE_ERROR }; -static lisp_object_t close_paren_marker = { LISP_TYPE_PARSE_ERROR }; -static lisp_object_t dot_marker = { LISP_TYPE_PARSE_ERROR }; +static lisp_object_t end_marker = { LISP_TYPE_EOF , {0,0} }; +static lisp_object_t error_object = { LISP_TYPE_PARSE_ERROR , {0,0} }; +static lisp_object_t close_paren_marker = { LISP_TYPE_PARSE_ERROR , {0,0} }; +static lisp_object_t dot_marker = { LISP_TYPE_PARSE_ERROR , {0,0} }; static void _token_clear (void) diff --git a/src/menu.h b/src/menu.h index 0d26c1656..fc1c02766 100644 --- a/src/menu.h +++ b/src/menu.h @@ -63,7 +63,8 @@ private: Menu* last_menu; int width(); int height(); - + + public: timer_type effect; int arrange_left; diff --git a/src/player.cpp b/src/player.cpp index dd7e3b1c5..9b40c0174 100644 --- a/src/player.cpp +++ b/src/player.cpp @@ -66,7 +66,7 @@ Player::init() // FIXME: Make the start position configurable via the levelfile base.x = 100; base.y = 240; - + base.xm = 0; base.ym = 0; old_base = base; @@ -156,7 +156,8 @@ Player::action() /* --- HANDLE TUX! --- */ - handle_input(); + if(!dying) + handle_input(); /* Move tux: */ @@ -164,15 +165,17 @@ Player::action() base.x += base.xm * frame_ratio; base.y += base.ym * frame_ratio; - - collision_swept_object_map(&old_base,&base); - - keep_in_bounds(); - /* Land: */ if (!dying) { + + collision_swept_object_map(&old_base,&base); + keep_in_bounds(); + + /* Land: */ + + if( !on_ground()) { if(under_solid()) @@ -250,6 +253,8 @@ Player::action() } } + else + base.ym = physic_get_velocity(&vphysic); timer_check(&safe_timer); @@ -770,6 +775,8 @@ Player::draw() } } } + if(dying) + text_drawf(&gold_text,"Penguins can fly !:",0,0,A_HMIDDLE,A_VMIDDLE,1); } void @@ -873,14 +880,10 @@ Player::collision(void* p_c_object, int c_object) void Player::kill(int mode) { - base.ym = -5; play_sound(sounds[SND_HURT], SOUND_CENTER_SPEAKER); - if (dir == RIGHT) - base.xm = -8; - else if (dir == LEFT) - base.xm = 8; + base.xm = 0; if (mode == SHRINK && size == BIG) { @@ -894,6 +897,10 @@ Player::kill(int mode) } else { + if(size == BIG) + duck = true; + physic_set_state(&vphysic,PH_VT); + physic_set_start_vy(&vphysic,7); dying = DYING_SQUISHED; } } @@ -908,9 +915,14 @@ Player::is_dying() --lives; remove_powerups(); dying = DYING_NOT; - - level_begin(); +} +bool Player::is_dead() +{ + if(base.y > screen->h) + return true; + else + return false; } /* Remove Tux's power ups */ diff --git a/src/player.h b/src/player.h index 51592f158..f22257907 100644 --- a/src/player.h +++ b/src/player.h @@ -121,6 +121,7 @@ class Player void collision(void* p_c_object, int c_object); void kill(int mode); void is_dying(); + bool is_dead(); void player_remove_powerups(); void keep_in_bounds(); bool on_ground(); diff --git a/src/special.cpp b/src/special.cpp index 92abb31be..53b372fb6 100644 --- a/src/special.cpp +++ b/src/special.cpp @@ -82,7 +82,7 @@ void bullet_draw(bullet_type* pbullet) if (pbullet->base.x >= scroll_x - pbullet->base.width && pbullet->base.x <= scroll_x + screen->w) { - texture_draw(&img_bullet, pbullet->base.x - scroll_x, pbullet->base.y, + texture_draw(&img_bullet, pbullet->base.x - scroll_x, pbullet->base.y, 255, NO_UPDATE); } } @@ -195,31 +195,28 @@ void upgrade_draw(upgrade_type* pupgrade) dest.h = (int)pupgrade->base.height; if (pupgrade->kind == UPGRADE_MINTS) - texture_draw_part(&img_mints,0,0,dest.x,dest.y,dest.w,dest.h,NO_UPDATE); + texture_draw_part(&img_mints,0,0,dest.x,dest.y,dest.w,dest.h); else if (pupgrade->kind == UPGRADE_COFFEE) - texture_draw_part(&img_coffee,0,0,dest.x,dest.y,dest.w,dest.h,NO_UPDATE); + texture_draw_part(&img_coffee,0,0,dest.x,dest.y,dest.w,dest.h); else if (pupgrade->kind == UPGRADE_HERRING) - texture_draw_part(&img_golden_herring,0,0,dest.x,dest.y,dest.w,dest.h,NO_UPDATE); + texture_draw_part(&img_golden_herring,0,0,dest.x,dest.y,dest.w,dest.h); } else { if (pupgrade->kind == UPGRADE_MINTS) { texture_draw(&img_mints, - pupgrade->base.x - scroll_x, pupgrade->base.y, - NO_UPDATE); + pupgrade->base.x - scroll_x, pupgrade->base.y); } else if (pupgrade->kind == UPGRADE_COFFEE) { texture_draw(&img_coffee, - pupgrade->base.x - scroll_x, pupgrade->base.y, - NO_UPDATE); + pupgrade->base.x - scroll_x, pupgrade->base.y); } else if (pupgrade->kind == UPGRADE_HERRING) { texture_draw(&img_golden_herring, - pupgrade->base.x - scroll_x, pupgrade->base.y, - NO_UPDATE); + pupgrade->base.x - scroll_x, pupgrade->base.y); } } } diff --git a/src/text.cpp b/src/text.cpp index 58a91b691..8258b746e 100644 --- a/src/text.cpp +++ b/src/text.cpp @@ -86,13 +86,13 @@ void text_draw_chars(text_type* ptext, texture_type* pchars,const char* text, i for( i = 0, j = 0; i < len; ++i,++j) { if( text[i] >= 'A' && text[i] <= 'Z') - texture_draw_part(pchars, (int)(text[i] - 'A')*w, 0, x+(j*w), y, ptext->w, ptext->h, update); + texture_draw_part(pchars, (int)(text[i] - 'A')*w, 0, x+(j*w), y, ptext->w, ptext->h, 255, update); else if( text[i] >= 'a' && text[i] <= 'z') - texture_draw_part(pchars, (int)(text[i] - 'a')*w, h, x+(j*w), y, ptext->w, ptext->h, update); + texture_draw_part(pchars, (int)(text[i] - 'a')*w, h, x+(j*w), y, ptext->w, ptext->h, 255, update); else if ( text[i] >= '!' && text[i] <= '9') - texture_draw_part(pchars, (int)(text[i] - '!')*w, h*2, x+(j*w), y, ptext->w, ptext->h, update); + texture_draw_part(pchars, (int)(text[i] - '!')*w, h*2, x+(j*w), y, ptext->w, ptext->h, 255, update); else if ( text[i] == '?') - texture_draw_part(pchars, 25*w, h*2, x+(j*w), y, ptext->w, ptext->h, update); + texture_draw_part(pchars, 25*w, h*2, x+(j*w), y, ptext->w, ptext->h, 255, update); else if ( text[i] == '\n') { y += ptext->h + 2; @@ -105,7 +105,7 @@ void text_draw_chars(text_type* ptext, texture_type* pchars,const char* text, i for( i = 0, j = 0; i < len; ++i, ++j) { if ( text[i] >= '0' && text[i] <= '9') - texture_draw_part(pchars, (int)(text[i] - '0')*w, 0, x+(j*w), y, w, h, update); + texture_draw_part(pchars, (int)(text[i] - '0')*w, 0, x+(j*w), y, w, h, 255, update); else if ( text[i] == '\n') { y += ptext->h + 2; @@ -165,7 +165,7 @@ void text_drawf(text_type* ptext,const char* text, int x, int y, TextHAlign hal else if(valign == A_VMIDDLE) y += screen->h/2 - ptext->h/2; - text_draw(ptext,text,x,y,shadowsize,update); + text_draw(ptext,text,x,y,shadowsize, update); } } @@ -192,7 +192,7 @@ void erasetext(text_type* ptext,const char * text, int x, int y, texture_type * if (dest.w > screen->w) dest.w = screen->w; - texture_draw_part(ptexture,dest.x,dest.y,dest.x,dest.y,dest.w,dest.h,update); + texture_draw_part(ptexture,dest.x,dest.y,dest.x,dest.y,dest.w,dest.h, 255, update); if (update == UPDATE) update_rect(screen, dest.x, dest.y, dest.w, dest.h); diff --git a/src/texture.cpp b/src/texture.cpp index febda9761..ef22a3e77 100644 --- a/src/texture.cpp +++ b/src/texture.cpp @@ -20,9 +20,9 @@ void (*texture_load) (texture_type* ptexture, const std::string& file, int use_alpha); void (*texture_load_part)(texture_type* ptexture, const std::string& file, int x, int y, int w, int h, int use_alpha); void (*texture_free) (texture_type* ptexture); -void (*texture_draw) (texture_type* ptexture, float x, float y, bool update); -void (*texture_draw_bg) (texture_type* ptexture, bool update); -void (*texture_draw_part)(texture_type* ptexture, float sx, float sy, float x, float y, float w, float h, bool update); +void (*texture_draw) (texture_type* ptexture, float x, float y, Uint8 alpha, bool update); +void (*texture_draw_bg) (texture_type* ptexture, Uint8 alpha, bool update); +void (*texture_draw_part)(texture_type* ptexture, float sx, float sy, float x, float y, float w, float h, Uint8 alpha, bool update); void texture_setup(void) @@ -135,7 +135,7 @@ void texture_free_gl(texture_type* ptexture) glDeleteTextures(1, &ptexture->gl_texture); } -void texture_draw_gl(texture_type* ptexture, float x, float y, bool update) +void texture_draw_gl(texture_type* ptexture, float x, float y, Uint8 alpha, bool update) { float pw = power_of_two(ptexture->w); float ph = power_of_two(ptexture->h); @@ -144,7 +144,7 @@ float ph = power_of_two(ptexture->h); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - glColor4ub(255, 255, 255,255); + glColor4ub(alpha, alpha, alpha, alpha); glBindTexture(GL_TEXTURE_2D, ptexture->gl_texture); @@ -160,14 +160,18 @@ float ph = power_of_two(ptexture->h); glDisable(GL_TEXTURE_2D); glDisable(GL_BLEND); + +/* Avoid compiler warnings */ +if(update) +{} } -void texture_draw_bg_gl(texture_type* ptexture, bool update) +void texture_draw_bg_gl(texture_type* ptexture, Uint8 alpha, bool update) { float pw = power_of_two(ptexture->w); float ph = power_of_two(ptexture->h); - glColor3ub(255, 255, 255); + glColor3ub(alpha, alpha, alpha); glEnable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D, ptexture->gl_texture); @@ -184,9 +188,13 @@ float ph = power_of_two(ptexture->h); glEnd(); glDisable(GL_TEXTURE_2D); + +/* Avoid compiler warnings */ +if(update) +{} } -void texture_draw_part_gl(texture_type* ptexture,float sx, float sy, float x, float y, float w, float h, bool update) +void texture_draw_part_gl(texture_type* ptexture,float sx, float sy, float x, float y, float w, float h, Uint8 alpha, bool update) { float pw = power_of_two(ptexture->w); float ph = power_of_two(ptexture->h); @@ -196,7 +204,7 @@ float ph = power_of_two(ptexture->h); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - glColor4ub(255, 255, 255,255); + glColor4ub(alpha, alpha, alpha, alpha); glEnable(GL_TEXTURE_2D); @@ -215,6 +223,9 @@ float ph = power_of_two(ptexture->h); glDisable(GL_TEXTURE_2D); glDisable(GL_BLEND); +/* Avoid compiler warnings */ +if(update) +{} } #endif @@ -342,7 +353,7 @@ void texture_from_sdl_surface(texture_type* ptexture, SDL_Surface* sdl_surf, int #endif } -void texture_draw_sdl(texture_type* ptexture, float x, float y, bool update) +void texture_draw_sdl(texture_type* ptexture, float x, float y, Uint8 alpha, bool update) { SDL_Rect dest; @@ -350,6 +361,11 @@ void texture_draw_sdl(texture_type* ptexture, float x, float y, bool update) dest.y = (int)y; dest.w = ptexture->w; dest.h = ptexture->h; + + if(alpha != 255) /* SDL isn't capable of this kind of alpha :( therefore we'll leave now. */ + return; + + SDL_SetAlpha(ptexture->sdl_surface ,SDL_SRCALPHA,alpha); SDL_BlitSurface(ptexture->sdl_surface, NULL, screen, &dest); if (update == UPDATE) @@ -357,7 +373,7 @@ void texture_draw_sdl(texture_type* ptexture, float x, float y, bool update) } -void texture_draw_bg_sdl(texture_type* ptexture, bool update) +void texture_draw_bg_sdl(texture_type* ptexture, Uint8 alpha, bool update) { SDL_Rect dest; @@ -365,14 +381,16 @@ void texture_draw_bg_sdl(texture_type* ptexture, bool update) dest.y = 0; dest.w = screen->w; dest.h = screen->h; - + + if(alpha != 255) + SDL_SetAlpha(ptexture->sdl_surface ,SDL_SRCALPHA,alpha); SDL_SoftStretch(ptexture->sdl_surface, NULL, screen, &dest); if (update == UPDATE) SDL_UpdateRect(screen, dest.x, dest.y, dest.w, dest.h); } -void texture_draw_part_sdl(texture_type* ptexture, float sx, float sy, float x, float y, float w, float h, bool update) +void texture_draw_part_sdl(texture_type* ptexture, float sx, float sy, float x, float y, float w, float h, Uint8 alpha, bool update) { SDL_Rect src, dest; @@ -386,7 +404,9 @@ void texture_draw_part_sdl(texture_type* ptexture, float sx, float sy, float x, dest.w = (int)w; dest.h = (int)h; - + if(alpha != 255) + SDL_SetAlpha(ptexture->sdl_surface ,SDL_SRCALPHA,alpha); + SDL_BlitSurface(ptexture->sdl_surface, &src, screen, &dest); if (update == UPDATE) diff --git a/src/texture.h b/src/texture.h index 06bc1ddb4..1efd6e598 100644 --- a/src/texture.h +++ b/src/texture.h @@ -34,23 +34,23 @@ void texture_setup(void); extern void (*texture_load) (texture_type* ptexture, const std::string& file, int use_alpha); extern void (*texture_load_part) (texture_type* ptexture, const std::string& file, int x, int y, int w, int h, int use_alpha); extern void (*texture_free) (texture_type* ptexture); -extern void (*texture_draw) (texture_type* ptexture, float x, float y, bool update = false); -extern void (*texture_draw_bg) (texture_type* ptexture, bool update = false); -extern void (*texture_draw_part) (texture_type* ptexture, float sx, float sy, float x, float y, float w, float h, bool update = false); +extern void (*texture_draw) (texture_type* ptexture, float x, float y, Uint8 alpha = 255, bool update = false); +extern void (*texture_draw_bg) (texture_type* ptexture, Uint8 alpha = 255, bool update = false); +extern void (*texture_draw_part) (texture_type* ptexture, float sx, float sy, float x, float y, float w, float h, Uint8 alpha = 255, bool update = false); void texture_load_sdl(texture_type* ptexture, const std::string&, int use_alpha); void texture_load_part_sdl(texture_type* ptexture, const std::string& file, int x, int y, int w, int h, int use_alpha); void texture_free_sdl(texture_type* ptexture); -void texture_draw_sdl(texture_type* ptexture, float x, float y, bool update); -void texture_draw_bg_sdl(texture_type* ptexture, bool update); -void texture_draw_part_sdl(texture_type* ptexture,float sx, float sy, float x, float y, float w, float h, bool update); +void texture_draw_sdl(texture_type* ptexture, float x, float y, Uint8 alpha, bool update); +void texture_draw_bg_sdl(texture_type* ptexture, Uint8 alpha, bool update); +void texture_draw_part_sdl(texture_type* ptexture,float sx, float sy, float x, float y, float w, float h, Uint8 alpha, bool update); void texture_from_sdl_surface(texture_type* ptexture, SDL_Surface * sdl_surf, int use_alpha); #ifndef NOOPENGL void texture_load_gl(texture_type* ptexture, const std::string& file, int use_alpha); void texture_load_part_gl(texture_type* ptexture, const std::string& file, int x, int y, int w, int h, int use_alpha); void texture_free_gl(texture_type* ptexture); -void texture_draw_gl(texture_type* ptexture, float x, float y, bool update); -void texture_draw_bg_gl(texture_type* ptexture, bool update); -void texture_draw_part_gl(texture_type* ptexture, float sx, float sy, float x, float y, float w, float h, bool update); +void texture_draw_gl(texture_type* ptexture, float x, float y, Uint8 alpha, bool update); +void texture_draw_bg_gl(texture_type* ptexture, Uint8 alpha, bool update); +void texture_draw_part_gl(texture_type* ptexture, float sx, float sy, float x, float y, float w, float h, Uint8 alpha, bool update); void texture_create_gl(SDL_Surface * surf, GLuint * tex); #endif diff --git a/src/tile.cpp b/src/tile.cpp index 429bd1656..efe97776a 100644 --- a/src/tile.cpp +++ b/src/tile.cpp @@ -39,6 +39,8 @@ void TileManager::load_tileset(std::string filename) if (strcmp(lisp_symbol(lisp_car(element)), "tile") == 0) { + std::vector editor_filenames; + Tile* tile = new Tile; tile->id = -1; tile->solid = false; @@ -61,6 +63,7 @@ void TileManager::load_tileset(std::string filename) reader.read_int("anim-speed", &tile->anim_speed); reader.read_int("next-tile", &tile->next_tile); reader.read_string_vector("images", &tile->filenames); + reader.read_string_vector("editor-images", &editor_filenames); for(std::vector::iterator it = tile-> filenames.begin(); @@ -73,7 +76,17 @@ void TileManager::load_tileset(std::string filename) datadir + "images/tilesets/" + (*it), USE_ALPHA); } - + for(std::vector::iterator it = editor_filenames.begin(); + it != editor_filenames.end(); + ++it) + { + texture_type cur_image; + tile->editor_images.push_back(cur_image); + texture_load(&tile->editor_images[tile->editor_images.size()-1], + datadir + "images/tilesets/" + (*it), + USE_ALPHA); + } + if (tile->id + tileset_id >= int(tiles.size()) ) tiles.resize(tile->id + tileset_id+1); diff --git a/src/tile.h b/src/tile.h index 0fd809c43..721b010b9 100644 --- a/src/tile.h +++ b/src/tile.h @@ -12,6 +12,7 @@ #ifndef TILE_H #define TILE_H +#include #include #include "texture.h" #include "globals.h" @@ -26,6 +27,8 @@ struct Tile int id; std::vector images; + std::vector editor_images; + std::vector filenames; /** solid tile that is indestructable by Tux */ diff --git a/src/worldmap.cpp b/src/worldmap.cpp index 86249cc91..f873c9604 100644 --- a/src/worldmap.cpp +++ b/src/worldmap.cpp @@ -135,7 +135,7 @@ Tux::draw() break; } - texture_draw(&sprite, (int)x, (int)y, NO_UPDATE); + texture_draw(&sprite, (int)x, (int)y); } void @@ -450,12 +450,12 @@ WorldMap::draw() for(int x = 0; x < width; ++x) { Tile* tile = at(Point(x, y)); - texture_draw(&tile->sprite, x*32, y*32, NO_UPDATE); + texture_draw(&tile->sprite, x*32, y*32); } for(Levels::iterator i = levels.begin(); i != levels.end(); ++i) { - texture_draw(&level_sprite, i->x*32, i->y*32, NO_UPDATE); + texture_draw(&level_sprite, i->x*32, i->y*32); } tux->draw(); -- 2.11.0