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
#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());
}
{
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());
}
{
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<Button*>::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;
}
}
}
-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<Button*>::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<Button*>::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;
}
#ifndef SUPERTUX_BUTTON_H
#define SUPERTUX_BUTTON_H
+#include <vector>
#include "texture.h"
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<Button*> item;
+ };
#endif /*SUPERTUX_BUTTON_H*/
update_time = st_get_ticks();
}
-void activate_bad_guys(void)
+void activate_bad_guys(st_level* plevel)
{
- for (std::vector<BadGuyData>::iterator i = current_level.badguy_data.begin();
- i != current_level.badguy_data.end();
+ for (std::vector<BadGuyData>::iterator i = plevel->badguy_data.begin();
+ i != plevel->badguy_data.end();
++i)
{
add_bad_guy(i->x, i->y, i->kind);
{
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! */
}
arrays_free();
- activate_bad_guys();
+ activate_bad_guys(¤t_level);
activate_particle_systems();
level_free_gfx();
level_load_gfx(¤t_level);
}
level_load_gfx(¤t_level);
- activate_bad_guys();
+ activate_bad_guys(¤t_level);
activate_particle_systems();
level_load_song(¤t_level);
/* 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)
{
{
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
{
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);
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);
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);
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);
/* Display background: */
- texture_draw_bg(&bkgd, UPDATE);
+ texture_draw_bg(&bkgd, 255, UPDATE);
/* Animation: */
++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);
}
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));
}
++scene;
/* Gown notices something... */
- texture_draw(&gown_lookup, 320, 400, UPDATE);
+ texture_draw(&gown_lookup, 320, 400, 255, UPDATE);
}
{
++scene;
/* Gown realizes it's bad! */
-
- texture_draw(&gown_upset, 320, 400, UPDATE);
+
+ texture_draw(&gown_upset, 320, 400, 255, UPDATE);
}
++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);
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;
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));
}
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));
}
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';
}
}
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
transtable['h'] = 98;
transtable['i'] = 99;
transtable['j'] = 100
- ;
+ ;
transtable['#'] = 11;
- transtable['['] = 13;
+ transtable['['] = 13;
transtable['='] = 14;
transtable[']'] = 15;
transtable['$'] = 82;
if (*i == '0' || *i == '1' || *i == '2')
{
plevel->badguy_data.push_back(BadGuyData(static_cast<BadGuyKind>(*i-'0'),
- x*32, y*32));
+ x*32, y*32));
*i = 0;
}
else
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;
+ }
}
}
}
fprintf(fi," %d ", plevel->fg_tiles[y][i]);
}
- fprintf( fi,")");
+ fprintf( fi,")\n");
+ fprintf( fi,"(objects\n");
+
+ for(std::vector<BadGuyData>::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);
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;
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;
static Menu* level_settings_menu;
static Menu* select_tilegroup_menu;
static timer_type select_tilegroup_menu_effect;
-static std::map<std::string, button_panel_type > tilegroups_map;
+static std::map<std::string, ButtonPanel* > 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()
{
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;
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;
return 1;
}
+ ++global_frame_counter;
+
SDL_Delay(25);
now_time = SDL_GetTicks();
if (now_time < last_time + FPS)
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;*/
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();
{
select_tilegroup_menu->additem(MN_ACTION,const_cast<char*>((*it).name.c_str()),0,0);
- button_panel_init(&tilegroups_map[(*it).name], screen->w - 64,98, 64, 318);
- for(std::vector<int>::iterator sit = (*it).tiles.begin(); sit != (*it).tiles.end(); ++sit)
- button_panel_additem(&tilegroups_map[(*it).name],button_create(const_cast<char*>(("images/tilesets/" + TileManager::instance()->get(*sit)->filenames[0]).c_str()), const_cast<char*>((*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<int>::iterator sit = (*it).tiles.begin(); sit != (*it).tiles.end(); ++sit, ++i)
+ tilegroups_map[(*it).name]->additem(new Button(const_cast<char*>(("images/tilesets/" + TileManager::instance()->get(*sit)->filenames[0]).c_str()), const_cast<char*>((*it).name.c_str()),(SDLKey)(i+'a'),0,0,32,32),(*sit));
}
select_tilegroup_menu->additem(MN_HL,"",0,0);
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;
}
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)
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)
{
/* 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);
}
void le_drawlevel()
{
unsigned int y,x,i,s;
+ Uint8 a;
/* Draw the real background */
if(le_current_level->bkgd_image[0] != '\0')
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();
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)
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)
{
}
}
}
- 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);
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<TileMapType>(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;
}
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;
}
arrays_free();
level_load_gfx(le_current_level);
loadshared();
+ activate_bad_guys(le_current_level);
}
void le_showhelp()
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)
Menu* last_menu;
int width();
int height();
-
+
+
public:
timer_type effect;
int arrange_left;
// FIXME: Make the start position configurable via the levelfile
base.x = 100;
base.y = 240;
-
+
base.xm = 0;
base.ym = 0;
old_base = base;
/* --- HANDLE TUX! --- */
- handle_input();
+ if(!dying)
+ handle_input();
/* Move tux: */
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())
}
}
+ else
+ base.ym = physic_get_velocity(&vphysic);
timer_check(&safe_timer);
}
}
}
+ if(dying)
+ text_drawf(&gold_text,"Penguins can fly !:",0,0,A_HMIDDLE,A_VMIDDLE,1);
}
void
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)
{
}
else
{
+ if(size == BIG)
+ duck = true;
+ physic_set_state(&vphysic,PH_VT);
+ physic_set_start_vy(&vphysic,7);
dying = DYING_SQUISHED;
}
}
--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 */
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();
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);
}
}
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);
}
}
}
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;
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;
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);
}
}
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);
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)
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);
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);
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);
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);
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);
glDisable(GL_TEXTURE_2D);
glDisable(GL_BLEND);
+/* Avoid compiler warnings */
+if(update)
+{}
}
#endif
#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;
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)
}
-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;
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;
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)
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
if (strcmp(lisp_symbol(lisp_car(element)), "tile") == 0)
{
+ std::vector<std::string> editor_filenames;
+
Tile* tile = new Tile;
tile->id = -1;
tile->solid = false;
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<std::string>::iterator it = tile->
filenames.begin();
datadir + "images/tilesets/" + (*it),
USE_ALPHA);
}
-
+ for(std::vector<std::string>::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);
#ifndef TILE_H
#define TILE_H
+#include <map>
#include <vector>
#include "texture.h"
#include "globals.h"
int id;
std::vector<texture_type> images;
+ std::vector<texture_type> editor_images;
+
std::vector<std::string> filenames;
/** solid tile that is indestructable by Tux */
break;
}
- texture_draw(&sprite, (int)x, (int)y, NO_UPDATE);
+ texture_draw(&sprite, (int)x, (int)y);
}
void
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();