diff --git a/include/AnimSprite.h b/include/AnimSprite.h index 93a04ee..9c637de 100644 --- a/include/AnimSprite.h +++ b/include/AnimSprite.h @@ -1,55 +1,55 @@ -/* - * - * AnimSprite - By CrociDB - * http://crocidb.wordpress.com/ - * - * Obrigado por usar ^^ - * - */ - -#include - -#include -#include - -#include - -class AnimSprite -{ -private: - std::vector frames; - int frame_atual; - int delay; - - int time; - - std::vector states; - int curr_state; - - int x, y; -public: - AnimSprite(); - - void run(BITMAP* bmp); - - void SetDelay(int sdelay); - int GetDelay() const; - - void SetX(int sx); - void SetY(int sy); - void SetPosition(int sx, int sy); - - int GetX() const; - int GetY() const; - - void AddFrame(const char* file); - void AddFrame(BITMAP* bmp); - - int GetNumFrames() const; - - void AddState(State* st); - void FitStates(); - - void SetCurrentState(int st); - int GetCurrentState() const; -}; +/* + * + * AnimSprite - By CrociDB + * http://crocidb.wordpress.com/ + * + * Obrigado por usar ^^ + * + */ + +#include + +#include +#include + +#include + +class AnimSprite +{ +private: + std::vector frames; + int frame_atual; + int delay; + + int time; + + std::vector states; + int curr_state; + + int x, y; +public: + AnimSprite(); + + void run(BITMAP* bmp); + + void SetDelay(int sdelay); + int GetDelay() const; + + void SetX(int sx); + void SetY(int sy); + void SetPosition(int sx, int sy); + + int GetX() const; + int GetY() const; + + void AddFrame(const char* file); + void AddFrame(BITMAP* bmp); + + int GetNumFrames() const; + + void AddState(State* st); + void FitStates(); + + void SetCurrentState(int st); + int GetCurrentState() const; +}; diff --git a/include/CApp.h b/include/CApp.h index 0980a3a..2458c02 100644 --- a/include/CApp.h +++ b/include/CApp.h @@ -1,62 +1,62 @@ -/* - * Game developed by CrociDB on SpeedHack 2009 - * http://speedhack.allegro.cc/ - * - * CrociDBlog - http://crocidb.wordpress.com/ - * - * The App Control class. - * - */ - -#include - -class CApp -{ -private: - /* Variaveis que guardam a resolucao */ - int w, h; - /* Tamanho para programacao */ - int tw, th; - /* Buffer */ - BITMAP *buffer; - /* Wide */ - int wide; - /* Bitmap do mouse */ - BITMAP *bmpMouse; -public: - /* Funcao de Inicializacao */ - void Init(int sw, int sh, char *title); - /* Funcao de Inicializacao (carrega info do arquivo) */ - void Init(char *title); - /* Funcao de Desiniciacao */ - void deInit(); - /* Funcao que muda entre Fullscreen e Windowed */ - void SwitchMode(); - /* Funcao que muda entre Widescreen e normal */ - void SwitchWide(); - /* Limpa o Buffer */ - void ClearBuffer(); - void ClearBuffer(int col); - /* Funcao que atualiza o buffer */ - void Refresh(); - /* Mostra o cursor */ - void ShowMouse(); - - /* Está em Widescreen? */ - int isWide(); - - /* Seta o Buffer */ - void SetBuffer(BITMAP *dbuffer); - /* Pega o Buffer */ - BITMAP *GetBuffer(); - /* Cria um Buffer */ - void CreateBuffer(); - - /* Fade In */ - void fade_in(BITMAP *bmp_orig, int speed); - void fadeInToColor(BITMAP *bmp_orig, int speed, int color); - /* Fade Out */ - void fade_out(int speed); - void fadeOutToColor(int speed, int color); - -}; +/* + * Game developed by CrociDB on SpeedHack 2009 + * http://speedhack.allegro.cc/ + * + * CrociDBlog - http://crocidb.wordpress.com/ + * + * The App Control class. + * + */ + +#include + +class CApp +{ +private: + /* Variaveis que guardam a resolucao */ + int w, h; + /* Tamanho para programacao */ + int tw, th; + /* Buffer */ + BITMAP *buffer; + /* Wide */ + int wide; + /* Bitmap do mouse */ + BITMAP *bmpMouse; +public: + /* Funcao de Inicializacao */ + void Init(int sw, int sh, char *title); + /* Funcao de Inicializacao (carrega info do arquivo) */ + void Init(char *title); + /* Funcao de Desiniciacao */ + void deInit(); + /* Funcao que muda entre Fullscreen e Windowed */ + void SwitchMode(); + /* Funcao que muda entre Widescreen e normal */ + void SwitchWide(); + /* Limpa o Buffer */ + void ClearBuffer(); + void ClearBuffer(int col); + /* Funcao que atualiza o buffer */ + void Refresh(); + /* Mostra o cursor */ + void ShowMouse(); + + /* Está em Widescreen? */ + int isWide(); + + /* Seta o Buffer */ + void SetBuffer(BITMAP *dbuffer); + /* Pega o Buffer */ + BITMAP *GetBuffer(); + /* Cria um Buffer */ + void CreateBuffer(); + + /* Fade In */ + void fade_in(BITMAP *bmp_orig, int speed); + void fadeInToColor(BITMAP *bmp_orig, int speed, int color); + /* Fade Out */ + void fade_out(int speed); + void fadeOutToColor(int speed, int color); + +}; diff --git a/include/CArm.h b/include/CArm.h index 3ce9d96..d229ead 100644 --- a/include/CArm.h +++ b/include/CArm.h @@ -1,67 +1,67 @@ -/** - * GameJam 2009 - GamePlay - * - * The Arm class file. - */ - - #ifndef _CARM_H_ - #define _CARM_H_ - - #define DEFAULT_X 800 - #define DEFAULT_Y 0 - - #include - - #include "CMap.h" - #include "AnimSprite.h" - - enum EArmState - { - EAS_NULL, - EAS_MOVE_GO, - EAS_MOVE_BA, - EAS_SET - }; - - class CArm - { - private: - int x, y; - int dx, dy; - int rx, ry; - - int vel; - - int curr; - - CMap *map; - - int type; - - BITMAP *sprite[2]; - - EArmState state; - - public: - CArm(); - - void getMap(CMap *map); - - // Setters - void setX(int px); - void setY(int py); - - // Getters - int getX(); - int getY(); - - void armAction(); - - void show(BITMAP *buffer); - void update(); - }; - - - - #endif - +/** + * GameJam 2009 - GamePlay + * + * The Arm class file. + */ + + #ifndef _CARM_H_ + #define _CARM_H_ + + #define DEFAULT_X 800 + #define DEFAULT_Y 0 + + #include + + #include "CMap.h" + #include "AnimSprite.h" + + enum EArmState + { + EAS_NULL, + EAS_MOVE_GO, + EAS_MOVE_BA, + EAS_SET + }; + + class CArm + { + private: + int x, y; + int dx, dy; + int rx, ry; + + int vel; + + int curr; + + CMap *map; + + int type; + + BITMAP *sprite[2]; + + EArmState state; + + public: + CArm(); + + void getMap(CMap *map); + + // Setters + void setX(int px); + void setY(int py); + + // Getters + int getX(); + int getY(); + + void armAction(); + + void show(BITMAP *buffer); + void update(); + }; + + + + #endif + diff --git a/include/CButton.h b/include/CButton.h index 83c6a90..838c3d9 100644 --- a/include/CButton.h +++ b/include/CButton.h @@ -1,61 +1,61 @@ -/* - * Game developed by CrociDB on SpeedHack 2007 - * http://speedhack.allegro.cc/ - * - * CrociDBlog - http://crocidb.wordpress.com/ - * - * The App Control class. - * - */ - -#include -#include - -#define CENTER 1 -#define LEFT 0 - -/* - * Valores para TYPE: - * 0 - Texto normal - * 1 - Texto com fundo do botão - */ - -class CButton -{ -private: - char *text; - char *desc; - int type; - - int x, y; - int w, h; - - int ncolor, ucolor; - int color; - - BITMAP *buf; - FONT *fonte; - - int up; - int align; -public: - int id; - - CButton(char *txt, int tp, int cx, int cy, int cw, int ch, BITMAP *buffer); - - void setDesc(char *txt); - void setText(char *txt); - - void setFont(FONT * fnt); - void setAlign(int al); - - void setPosition(int cx, int cy); - - void setColors(int a, int b); - - void runButton(); - int isPressed(); - - ~CButton(); -}; - +/* + * Game developed by CrociDB on SpeedHack 2007 + * http://speedhack.allegro.cc/ + * + * CrociDBlog - http://crocidb.wordpress.com/ + * + * The App Control class. + * + */ + +#include +#include + +#define CENTER 1 +#define LEFT 0 + +/* + * Valores para TYPE: + * 0 - Texto normal + * 1 - Texto com fundo do botão + */ + +class CButton +{ +private: + char *text; + char *desc; + int type; + + int x, y; + int w, h; + + int ncolor, ucolor; + int color; + + BITMAP *buf; + FONT *fonte; + + int up; + int align; +public: + int id; + + CButton(char *txt, int tp, int cx, int cy, int cw, int ch, BITMAP *buffer); + + void setDesc(char *txt); + void setText(char *txt); + + void setFont(FONT * fnt); + void setAlign(int al); + + void setPosition(int cx, int cy); + + void setColors(int a, int b); + + void runButton(); + int isPressed(); + + ~CButton(); +}; + diff --git a/include/CGame.h b/include/CGame.h index d9dc989..9c330ac 100644 --- a/include/CGame.h +++ b/include/CGame.h @@ -1,77 +1,88 @@ -/** - * GameJam 2009 - GamePlay - * - * The main Game Class - */ - - #ifndef _CGAME_H_ - #define _CGAME_H_ - - #include - - #include "CApp.h" - #include "CMap.h" - #include "CArm.h" - #include "CTimer.h" - - #define FADE_TIME 5 - - // This enum stores all the stats of the machine - enum GameStatus - { - GAME_OPEN, - GAME_MENU, - GAME_GAME, - GAME_OVER - }; - - class CGame - { - private: - - // Our game status - GameStatus game_status; - - // App Manager - CApp *App; - - // Boolean - bool flow; - - // Buffer for double buffering - BITMAP *buffer; - - // Maps test - CMap *Map; - - CArm *Arm; - - // Images =D - BITMAP *bmpOpen; - BITMAP *bmpBackGame; - BITMAP *bmpGameOver; - - // Timer - CTimer *timer; - - public: - - CGame(); - - // Runs the game - void run(); - - // One method for each game state - void game_open(); - void game_menu(); - void game_game(); - void game_over(); - - void loadImages(); - - }; - - - #endif - - +/** + * GameJam 2009 - GamePlay + * + * The main Game Class + */ + + #ifndef _CGAME_H_ + #define _CGAME_H_ + + #include + + #include "CApp.h" + #include "CMap.h" + #include "CArm.h" + #include "CTimer.h" + + #define FADE_TIME 5 + + // This enum stores all the stats of the machine + enum GameStatus + { + GAME_OPEN, + GAME_MENU, + GAME_GAME, + GAME_OVER, + GAME_FAIL + }; + + class CGame + { + private: + + // Our game status + GameStatus game_status; + + // App Manager + CApp *App; + + // Boolean + bool flow; + + // Buffer for double buffering + BITMAP *buffer; + + // Maps test + CMap *Map; + + CArm *Arm; + + // Images =D + BITMAP *bmpOpen; + BITMAP *bmpBackGame; + BITMAP *bmpGameOver; + BITMAP *bmpBackMenu; + BITMAP *arrow; + + // A - Arrow ;) + int ax, ay; + int op; + + // Music + MIDI *midi_menu; + MIDI *midi_game; + + // Timer + CTimer *timer; + + public: + + CGame(); + + // Runs the game + void run(); + + // One method for each game state + void game_open(); + void game_menu(); + void game_game(); + void game_over(); + + void loadMedia(); + + }; + + + #endif + + diff --git a/include/CInput.h b/include/CInput.h index ef547b8..5b02dee 100644 --- a/include/CInput.h +++ b/include/CInput.h @@ -1,28 +1,28 @@ -/** - * GameJam 2009 - GamePlay - * - * The main Input Class - */ - - #ifndef _CINPUT_H_ - #define _CINPUT_H_ - - #include - - class CInput - { - private: - // Mouse flag - bool fMouseLeft; - bool fMouseRight; - - public: - CInput(); - - bool isMouseLeftClick(); - bool isMouseRightClick(); - - void update(); - }; - +/** + * GameJam 2009 - GamePlay + * + * The main Input Class + */ + + #ifndef _CINPUT_H_ + #define _CINPUT_H_ + + #include + + class CInput + { + private: + // Mouse flag + bool fMouseLeft; + bool fMouseRight; + + public: + CInput(); + + bool isMouseLeftClick(); + bool isMouseRightClick(); + + void update(); + }; + #endif \ No newline at end of file diff --git a/include/CMap.h b/include/CMap.h index 43cd60d..c9e7bf2 100644 --- a/include/CMap.h +++ b/include/CMap.h @@ -1,99 +1,101 @@ -/** - * GameJam 2009 - GamePlay - * - * The map class file. - */ - -#ifndef _CMAP_H_ -#define _CMAP_H_ - -#include - -#include "CInput.h" - -#define RADIUS 15 - -#define GET_I (i*(RADIUS * 1.3)*2) + RADIUS -#define GET_J (j*(RADIUS * 1.3)*2) + RADIUS - -#define MAX_ITEMS 2 - -enum EItem -{ - EITEM_NULL, - EITEM_A, - EITEM_B -}; - -class CMap -{ - private: - CInput Input; - - EItem **items; - - int width, height; - - int x, y; - - bool full; - - // Images - BITMAP *elevation; - BITMAP *box; - BITMAP *box2; - BITMAP *box_select; - - // Did the player clicked once? - bool clicked; - - // These are for highlighting the current selected - int sel_x, sel_y; - - public: - CMap(); - - void initMatrix(); - - // Setters - void setWidth(int w); - void setHeight(int h); - - void setX(int px); - void setY(int py); - - void setFull(bool op); - - // Getters - int getWidth(); - int getHeight(); - - int getX(); - int getY(); - - // Is the map already full? - bool getFull(); - - // Place the map in the center of the screen - void center(); - - // Swap the values - void swap(int a, int b, int c, int d); - - bool isClicked(int i, int j, int cx, int cy); - - void increaseMap(); - - EItem **getMap(); - - void loadImages(); - - void show(BITMAP *buffer); - - void update(); -}; - - - -#endif - +/** + * GameJam 2009 - GamePlay + * + * The map class file. + */ + +#ifndef _CMAP_H_ +#define _CMAP_H_ + +#include + +#include "CInput.h" + +#define RADIUS 15 + +#define GET_I (i*(RADIUS * 1.3)*2) + RADIUS +#define GET_J (j*(RADIUS * 1.3)*2) + RADIUS + +#define MAX_ITEMS 2 + +enum EItem +{ + EITEM_NULL, + EITEM_A, + EITEM_B +}; + +class CMap +{ + private: + CInput Input; + + EItem **items; + + int width, height; + + int x, y; + + bool full; + + // Images + BITMAP *elevation; + BITMAP *box; + BITMAP *box2; + BITMAP *box_select; + + // Did the player clicked once? + bool clicked; + + // These are for highlighting the current selected + int sel_x, sel_y; + + public: + CMap(); + + void initMatrix(); + + // Setters + void setWidth(int w); + void setHeight(int h); + + void setX(int px); + void setY(int py); + + void setFull(bool op); + + // Getters + int getWidth(); + int getHeight(); + + int getX(); + int getY(); + + // Is the map already full? + bool getFull(); + + // Place the map in the center of the screen + void center(); + + // Swap the values + void swap(int a, int b, int c, int d); + + bool isClicked(int i, int j, int cx, int cy); + + void increaseMap(); + + EItem **getMap(); + + void drawBoxesOnHand(BITMAP *buffer, int x, int y, int i); + + void loadImages(); + + void show(BITMAP *buffer); + + void update(); +}; + + + +#endif + diff --git a/include/State.h b/include/State.h index 91c692b..c23e201 100644 --- a/include/State.h +++ b/include/State.h @@ -1,25 +1,25 @@ -/* - * - * AnimSprite - By CrociDB - * http://crocidb.wordpress.com/ - * - * Obrigado por usar ^^ - * - */ - -class State -{ -private: - int first; - int last; -public: - State(int f, int l); - - void SetFirstFrame(int f); - void SetLastFrame(int l); - - int GetFirstFrame() const; - int GetLastFrame() const; - - int GetNumFrames() const; -}; +/* + * + * AnimSprite - By CrociDB + * http://crocidb.wordpress.com/ + * + * Obrigado por usar ^^ + * + */ + +class State +{ +private: + int first; + int last; +public: + State(int f, int l); + + void SetFirstFrame(int f); + void SetLastFrame(int l); + + int GetFirstFrame() const; + int GetLastFrame() const; + + int GetNumFrames() const; +}; diff --git a/media/arrow.bmp b/media/arrow.bmp new file mode 100644 index 0000000..952ccf2 Binary files /dev/null and b/media/arrow.bmp differ diff --git a/media/back_menu.bmp b/media/back_menu.bmp new file mode 100644 index 0000000..cb4ef36 Binary files /dev/null and b/media/back_menu.bmp differ diff --git a/media/btJogar.bmp b/media/btJogar.bmp new file mode 100644 index 0000000..7b4e4a8 Binary files /dev/null and b/media/btJogar.bmp differ diff --git a/media/harestwav.mid b/media/harestwav.mid new file mode 100644 index 0000000..a6552c6 Binary files /dev/null and b/media/harestwav.mid differ diff --git a/media/unbal.mid b/media/unbal.mid new file mode 100644 index 0000000..0bd3b3d Binary files /dev/null and b/media/unbal.mid differ diff --git a/media_source/box-elevation.svg b/media_source/box-elevation.svg index f6f7892..b1b807e 100644 --- a/media_source/box-elevation.svg +++ b/media_source/box-elevation.svg @@ -1,115 +1,115 @@ - - - - - - - - - - - image/svg+xml - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + diff --git a/media_source/box.svg b/media_source/box.svg index 5c0a31b..3bf9f41 100644 --- a/media_source/box.svg +++ b/media_source/box.svg @@ -1,93 +1,93 @@ - - - - - - - - - - - image/svg+xml - - - - - - - - - - - - - - - + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + diff --git a/media_source/drawing.svg b/media_source/drawing.svg index e631455..bf59b21 100644 --- a/media_source/drawing.svg +++ b/media_source/drawing.svg @@ -1,745 +1,745 @@ - - - - - - - - - - - image/svg+xml - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/media_source/elevation.svg b/media_source/elevation.svg index 372f957..e6f05bc 100644 --- a/media_source/elevation.svg +++ b/media_source/elevation.svg @@ -1,80 +1,80 @@ - - - - - - - - - - - image/svg+xml - - - - - - - - - - - + + + + + + + + + + + image/svg+xml + + + + + + + + + + + diff --git a/media_source/main_menu_robot2.xcf b/media_source/main_menu_robot2.xcf new file mode 100644 index 0000000..a3999db Binary files /dev/null and b/media_source/main_menu_robot2.xcf differ diff --git a/src/AnimSprite.cpp b/src/AnimSprite.cpp index 6d476b2..77450ef 100644 --- a/src/AnimSprite.cpp +++ b/src/AnimSprite.cpp @@ -1,134 +1,134 @@ -/* - * - * AnimSprite - By CrociDB - * http://crocidb.wordpress.com/ - * - * Obrigado por usar ^^ - * - */ - -#include - -/* Construtor */ - -AnimSprite::AnimSprite() -{ - SetPosition(0, 0); - SetDelay(10); - - time = 0; - frame_atual = 0; - curr_state = 0; -} - - -/* Métodos de Delay da Animação */ - -void AnimSprite::SetDelay(int sdelay) -{ - this->delay = sdelay; -} - -int AnimSprite::GetDelay() const -{ - return this->delay; -} - - -/* Método de Execução */ - -void AnimSprite::run(BITMAP* bmp) -{ - time++; - if (frames.size() > 0) - { - draw_trans_sprite(bmp, frames[frame_atual], GetX(), GetY()); - if ((time-delay) > 0) - { - time = 0; - if (states[curr_state]->GetNumFrames() > 1) - { - if (frame_atual++ == states[curr_state]->GetLastFrame()) - { - frame_atual = states[curr_state]->GetFirstFrame(); - } - } - else - { - frame_atual = states[curr_state]->GetFirstFrame(); - } - } - } -} - - -/* Métodos de Coordenadas do Sprite */ - -void AnimSprite::SetX(int sx) -{ - this->x = sx; -} - -void AnimSprite::SetY(int sy) -{ - this->y = sy; -} - -void AnimSprite::SetPosition(int sx, int sy) -{ - this->x = sx; - this->y = sy; -} - -int AnimSprite::GetX() const -{ - return this->x; -} - -int AnimSprite::GetY() const -{ - return this->y; -} - - -/* Métodos do Vetor de Bitmaps */ - -void AnimSprite::AddFrame(const char* file) -{ - frames.push_back(load_bitmap(file, NULL)); -} - -void AnimSprite::AddFrame(BITMAP* bmp) -{ - frames.push_back(bmp); -} - -int AnimSprite::GetNumFrames() const -{ - return frames.size(); -} - - -/* Métodos para controle dos States */ - -void AnimSprite::AddState(State* st) -{ - states.push_back(st); -} - -void AnimSprite::FitStates() -{ - states.push_back(new State(0, frames.size()-1)); -} - -void AnimSprite::SetCurrentState(int st) -{ - this->curr_state = st; - this->time = this->delay; - frame_atual = states[curr_state]->GetFirstFrame(); -} - -int AnimSprite::GetCurrentState() const -{ - return this->curr_state; -} +/* + * + * AnimSprite - By CrociDB + * http://crocidb.wordpress.com/ + * + * Obrigado por usar ^^ + * + */ + +#include + +/* Construtor */ + +AnimSprite::AnimSprite() +{ + SetPosition(0, 0); + SetDelay(10); + + time = 0; + frame_atual = 0; + curr_state = 0; +} + + +/* Métodos de Delay da Animação */ + +void AnimSprite::SetDelay(int sdelay) +{ + this->delay = sdelay; +} + +int AnimSprite::GetDelay() const +{ + return this->delay; +} + + +/* Método de Execução */ + +void AnimSprite::run(BITMAP* bmp) +{ + time++; + if (frames.size() > 0) + { + draw_trans_sprite(bmp, frames[frame_atual], GetX(), GetY()); + if ((time-delay) > 0) + { + time = 0; + if (states[curr_state]->GetNumFrames() > 1) + { + if (frame_atual++ == states[curr_state]->GetLastFrame()) + { + frame_atual = states[curr_state]->GetFirstFrame(); + } + } + else + { + frame_atual = states[curr_state]->GetFirstFrame(); + } + } + } +} + + +/* Métodos de Coordenadas do Sprite */ + +void AnimSprite::SetX(int sx) +{ + this->x = sx; +} + +void AnimSprite::SetY(int sy) +{ + this->y = sy; +} + +void AnimSprite::SetPosition(int sx, int sy) +{ + this->x = sx; + this->y = sy; +} + +int AnimSprite::GetX() const +{ + return this->x; +} + +int AnimSprite::GetY() const +{ + return this->y; +} + + +/* Métodos do Vetor de Bitmaps */ + +void AnimSprite::AddFrame(const char* file) +{ + frames.push_back(load_bitmap(file, NULL)); +} + +void AnimSprite::AddFrame(BITMAP* bmp) +{ + frames.push_back(bmp); +} + +int AnimSprite::GetNumFrames() const +{ + return frames.size(); +} + + +/* Métodos para controle dos States */ + +void AnimSprite::AddState(State* st) +{ + states.push_back(st); +} + +void AnimSprite::FitStates() +{ + states.push_back(new State(0, frames.size()-1)); +} + +void AnimSprite::SetCurrentState(int st) +{ + this->curr_state = st; + this->time = this->delay; + frame_atual = states[curr_state]->GetFirstFrame(); +} + +int AnimSprite::GetCurrentState() const +{ + return this->curr_state; +} diff --git a/src/CApp.cpp b/src/CApp.cpp index 76aec9b..58029a9 100644 --- a/src/CApp.cpp +++ b/src/CApp.cpp @@ -1,279 +1,279 @@ -/* - * Game developed by CrociDB on SpeedHack 2009 - * http://speedhack.allegro.cc/ - * - * CrociDBlog - http://crocidb.wordpress.com/ - * - * The App Control class. - * - */ - -#include - -void sair() -{ - // ESC! ;) - key[KEY_ESC] = true; -}END_OF_FUNCTION(sair) - -void CApp::Init(int sw, int sh, char *title) -{ - this->w = sw; - this->h = sh; - - int depth, res; - allegro_init(); - - set_config_file("../config.dbc"); - - depth = desktop_color_depth(); - if (depth == 0) depth = 32; - set_color_depth(depth); - - int i = get_config_int("gfx", "mode", -1); - if (i == 0) - res = set_gfx_mode(GFX_AUTODETECT_WINDOWED, sw, sh, 0, 0); - else if (i == 1) - res = set_gfx_mode(GFX_AUTODETECT_FULLSCREEN, sw, sh, 0, 0); - else - { - res = set_gfx_mode(GFX_AUTODETECT_WINDOWED, sw, sh, 0, 0); - } - - if (res != 0) { - allegro_message(allegro_error); - exit(-1); - } - - install_timer(); - install_keyboard(); - install_mouse(); - - install_sound(DIGI_AUTODETECT, MIDI_AUTODETECT, NULL); - - // Seta o titulo da janela - set_window_title(title); - - // Para que os sorteios acontecam realmente - srand(time(NULL)); - - CreateBuffer(); - - LOCK_FUNCTION(sair); - set_close_button_callback(sair); - - bmpMouse = load_bitmap("../media/mouse.bmp", NULL); -} - -void CApp::Init(char *title) -{ - allegro_init(); - - set_config_file("config.dbc"); - - this->tw = 640; - this->th = 480; -} - -void CApp::deInit() -{ - clear_keybuf(); - allegro_exit(); // Finaliza o Allegro -} - -void CApp::SwitchWide() -{ - set_config_file("config.dbc"); - - if (this->wide == 0) - { - w = 640; - h = 400; - if (set_gfx_mode(GFX_AUTODETECT_WINDOWED, this->w, this->h, 0, 0)) - { - allegro_message("Your monitor doesn't support this resolution."); - exit(-1); - } - set_config_int("gfx", "wide", 1); - this->wide = 1; - } - else - { - w = 640; - h = 480; - set_gfx_mode(GFX_AUTODETECT_WINDOWED, this->w, this->h, 0, 0); - set_config_int("gfx", "wide", 0); - this->wide = 0; - } - //this->CreateBuffer(); - set_config_int("gfx", "mode", 0); -} - -void CApp::SwitchMode() -{ - set_config_file("config.dbc"); - - if (is_windowed_mode()) - { - if (set_gfx_mode(GFX_AUTODETECT_FULLSCREEN, this->w, this->h, 0, 0)) - { - allegro_message("Your monitor doesn't support this resolution."); - exit(-1); - } - else - { - set_config_int("gfx", "mode", 1); - } - } - else - { - set_gfx_mode(GFX_AUTODETECT_WINDOWED, this->w, this->h, 0, 0); - set_config_int("gfx", "mode", 0); - } -} - -void CApp::ClearBuffer() -{ - clear(this->buffer); -} - -void CApp::ClearBuffer(int col) -{ - clear_to_color(buffer, col); -} - -void CApp::Refresh() -{ - //stretch_blit(this->buffer, screen, 0, 0, tw, th, 0, 0, this->w, this->h); - blit(this->buffer, screen, 0, 0, 0, 0, this->w, this->h); -} - -void CApp::ShowMouse() -{ - draw_sprite(this->buffer, bmpMouse, mouse_x, mouse_y); -} - -void CApp::fade_in(BITMAP *bmp_orig, int speed) -{ - BITMAP *bmp_buff; - - if ((bmp_buff = create_bitmap(SCREEN_W, SCREEN_H))) - { - int a; - if (speed <= 0) speed = 16; - - for (a = 0; a < 256; a+=speed) - { - clear(bmp_buff); - set_trans_blender(0,0,0,a); - draw_trans_sprite(bmp_buff, bmp_orig, 0, 0); - vsync(); - blit(bmp_buff, screen, 0,0, 0,0, SCREEN_W, SCREEN_H); - } - destroy_bitmap(bmp_buff); - } - - blit(bmp_orig, screen, 0,0, 0,0, SCREEN_W, SCREEN_H); -} - -void CApp::fadeInToColor(BITMAP *bmp_orig, int speed, int color) -{ - BITMAP *bmp_buff; - - if ((bmp_buff = create_bitmap(SCREEN_W, SCREEN_H))) - { - clear_to_color(bmp_buff, color); - int a; - if (speed <= 0) speed = 16; - - for (a = 0; a < 256; a+=speed) - { - clear_to_color(bmp_buff, color); - set_trans_blender(0,0,0,a); - draw_trans_sprite(bmp_buff, bmp_orig, 0, 0); - vsync(); - blit(bmp_buff, screen, 0,0, 0,0, SCREEN_W, SCREEN_H); - } - destroy_bitmap(bmp_buff); - } - - blit(bmp_orig, screen, 0,0, 0,0, SCREEN_W, SCREEN_H); -} - -void CApp::fade_out(int speed) -{ - BITMAP *bmp_orig, *bmp_buff; - - if ((bmp_orig = create_bitmap(SCREEN_W, SCREEN_H))) - { - if ((bmp_buff = create_bitmap(SCREEN_W, SCREEN_H))) - { - int a; - blit(screen, bmp_orig, 0,0, 0,0, SCREEN_W, SCREEN_H); - if (speed <= 0) speed = 16; - - for (a = 255-speed; a > 0; a-=speed) - { - clear(bmp_buff); - set_trans_blender(0,0,0,a); - draw_trans_sprite(bmp_buff, bmp_orig, 0, 0); - vsync(); - blit(bmp_buff, screen, 0,0, 0,0, SCREEN_W, SCREEN_H); - } - destroy_bitmap(bmp_buff); - } - destroy_bitmap(bmp_orig); - } - - rectfill(screen, 0,0, SCREEN_W,SCREEN_H, makecol(0,0,0)); -} - -void CApp::fadeOutToColor(int speed, int color) -{ - BITMAP *bmp_orig, *bmp_buff; - - if ((bmp_orig = create_bitmap(SCREEN_W, SCREEN_H))) - { - if ((bmp_buff = create_bitmap(SCREEN_W, SCREEN_H))) - { - clear_to_color(bmp_buff, color); - int a; - blit(screen, bmp_orig, 0,0, 0,0, SCREEN_W, SCREEN_H); - if (speed <= 0) speed = 16; - - for (a = 255-speed; a > 0; a-=speed) - { - clear_to_color(bmp_buff, color); - set_trans_blender(0,0,0,a); - draw_trans_sprite(bmp_buff, bmp_orig, 0, 0); - vsync(); - blit(bmp_buff, screen, 0,0, 0,0, SCREEN_W, SCREEN_H); - } - destroy_bitmap(bmp_buff); - } - destroy_bitmap(bmp_orig); - } - - rectfill(screen, 0,0, SCREEN_W,SCREEN_H, makecol(0,0,0)); -} - -void CApp::SetBuffer(BITMAP *dbuffer) -{ - this->buffer = dbuffer; -} - -BITMAP* CApp::GetBuffer() -{ - return this->buffer; -} - -void CApp::CreateBuffer() -{ - this->buffer = create_bitmap(tw, th); -} - -int CApp::isWide() -{ - return wide; -} - +/* + * Game developed by CrociDB on SpeedHack 2009 + * http://speedhack.allegro.cc/ + * + * CrociDBlog - http://crocidb.wordpress.com/ + * + * The App Control class. + * + */ + +#include + +void sair() +{ + // ESC! ;) + key[KEY_ESC] = true; +}END_OF_FUNCTION(sair) + +void CApp::Init(int sw, int sh, char *title) +{ + this->w = sw; + this->h = sh; + + int depth, res; + allegro_init(); + + set_config_file("../config.dbc"); + + depth = desktop_color_depth(); + if (depth == 0) depth = 32; + set_color_depth(depth); + + int i = get_config_int("gfx", "mode", -1); + if (i == 0) + res = set_gfx_mode(GFX_AUTODETECT_WINDOWED, sw, sh, 0, 0); + else if (i == 1) + res = set_gfx_mode(GFX_AUTODETECT_FULLSCREEN, sw, sh, 0, 0); + else + { + res = set_gfx_mode(GFX_AUTODETECT_WINDOWED, sw, sh, 0, 0); + } + + if (res != 0) { + allegro_message(allegro_error); + exit(-1); + } + + install_timer(); + install_keyboard(); + install_mouse(); + + install_sound(DIGI_AUTODETECT, MIDI_AUTODETECT, NULL); + + // Seta o titulo da janela + set_window_title(title); + + // Para que os sorteios acontecam realmente + srand(time(NULL)); + + CreateBuffer(); + + LOCK_FUNCTION(sair); + set_close_button_callback(sair); + + bmpMouse = load_bitmap("../media/mouse.bmp", NULL); +} + +void CApp::Init(char *title) +{ + allegro_init(); + + set_config_file("config.dbc"); + + this->tw = 640; + this->th = 480; +} + +void CApp::deInit() +{ + clear_keybuf(); + allegro_exit(); // Finaliza o Allegro +} + +void CApp::SwitchWide() +{ + set_config_file("config.dbc"); + + if (this->wide == 0) + { + w = 640; + h = 400; + if (set_gfx_mode(GFX_AUTODETECT_WINDOWED, this->w, this->h, 0, 0)) + { + allegro_message("Your monitor doesn't support this resolution."); + exit(-1); + } + set_config_int("gfx", "wide", 1); + this->wide = 1; + } + else + { + w = 640; + h = 480; + set_gfx_mode(GFX_AUTODETECT_WINDOWED, this->w, this->h, 0, 0); + set_config_int("gfx", "wide", 0); + this->wide = 0; + } + //this->CreateBuffer(); + set_config_int("gfx", "mode", 0); +} + +void CApp::SwitchMode() +{ + set_config_file("config.dbc"); + + if (is_windowed_mode()) + { + if (set_gfx_mode(GFX_AUTODETECT_FULLSCREEN, this->w, this->h, 0, 0)) + { + allegro_message("Your monitor doesn't support this resolution."); + exit(-1); + } + else + { + set_config_int("gfx", "mode", 1); + } + } + else + { + set_gfx_mode(GFX_AUTODETECT_WINDOWED, this->w, this->h, 0, 0); + set_config_int("gfx", "mode", 0); + } +} + +void CApp::ClearBuffer() +{ + clear(this->buffer); +} + +void CApp::ClearBuffer(int col) +{ + clear_to_color(buffer, col); +} + +void CApp::Refresh() +{ + //stretch_blit(this->buffer, screen, 0, 0, tw, th, 0, 0, this->w, this->h); + blit(this->buffer, screen, 0, 0, 0, 0, this->w, this->h); +} + +void CApp::ShowMouse() +{ + draw_sprite(this->buffer, bmpMouse, mouse_x, mouse_y); +} + +void CApp::fade_in(BITMAP *bmp_orig, int speed) +{ + BITMAP *bmp_buff; + + if ((bmp_buff = create_bitmap(SCREEN_W, SCREEN_H))) + { + int a; + if (speed <= 0) speed = 16; + + for (a = 0; a < 256; a+=speed) + { + clear(bmp_buff); + set_trans_blender(0,0,0,a); + draw_trans_sprite(bmp_buff, bmp_orig, 0, 0); + vsync(); + blit(bmp_buff, screen, 0,0, 0,0, SCREEN_W, SCREEN_H); + } + destroy_bitmap(bmp_buff); + } + + blit(bmp_orig, screen, 0,0, 0,0, SCREEN_W, SCREEN_H); +} + +void CApp::fadeInToColor(BITMAP *bmp_orig, int speed, int color) +{ + BITMAP *bmp_buff; + + if ((bmp_buff = create_bitmap(SCREEN_W, SCREEN_H))) + { + clear_to_color(bmp_buff, color); + int a; + if (speed <= 0) speed = 16; + + for (a = 0; a < 256; a+=speed) + { + clear_to_color(bmp_buff, color); + set_trans_blender(0,0,0,a); + draw_trans_sprite(bmp_buff, bmp_orig, 0, 0); + vsync(); + blit(bmp_buff, screen, 0,0, 0,0, SCREEN_W, SCREEN_H); + } + destroy_bitmap(bmp_buff); + } + + blit(bmp_orig, screen, 0,0, 0,0, SCREEN_W, SCREEN_H); +} + +void CApp::fade_out(int speed) +{ + BITMAP *bmp_orig, *bmp_buff; + + if ((bmp_orig = create_bitmap(SCREEN_W, SCREEN_H))) + { + if ((bmp_buff = create_bitmap(SCREEN_W, SCREEN_H))) + { + int a; + blit(screen, bmp_orig, 0,0, 0,0, SCREEN_W, SCREEN_H); + if (speed <= 0) speed = 16; + + for (a = 255-speed; a > 0; a-=speed) + { + clear(bmp_buff); + set_trans_blender(0,0,0,a); + draw_trans_sprite(bmp_buff, bmp_orig, 0, 0); + vsync(); + blit(bmp_buff, screen, 0,0, 0,0, SCREEN_W, SCREEN_H); + } + destroy_bitmap(bmp_buff); + } + destroy_bitmap(bmp_orig); + } + + rectfill(screen, 0,0, SCREEN_W,SCREEN_H, makecol(0,0,0)); +} + +void CApp::fadeOutToColor(int speed, int color) +{ + BITMAP *bmp_orig, *bmp_buff; + + if ((bmp_orig = create_bitmap(SCREEN_W, SCREEN_H))) + { + if ((bmp_buff = create_bitmap(SCREEN_W, SCREEN_H))) + { + clear_to_color(bmp_buff, color); + int a; + blit(screen, bmp_orig, 0,0, 0,0, SCREEN_W, SCREEN_H); + if (speed <= 0) speed = 16; + + for (a = 255-speed; a > 0; a-=speed) + { + clear_to_color(bmp_buff, color); + set_trans_blender(0,0,0,a); + draw_trans_sprite(bmp_buff, bmp_orig, 0, 0); + vsync(); + blit(bmp_buff, screen, 0,0, 0,0, SCREEN_W, SCREEN_H); + } + destroy_bitmap(bmp_buff); + } + destroy_bitmap(bmp_orig); + } + + rectfill(screen, 0,0, SCREEN_W,SCREEN_H, makecol(0,0,0)); +} + +void CApp::SetBuffer(BITMAP *dbuffer) +{ + this->buffer = dbuffer; +} + +BITMAP* CApp::GetBuffer() +{ + return this->buffer; +} + +void CApp::CreateBuffer() +{ + this->buffer = create_bitmap(tw, th); +} + +int CApp::isWide() +{ + return wide; +} + diff --git a/src/CArm.cpp b/src/CArm.cpp index 6269318..48a20d5 100644 --- a/src/CArm.cpp +++ b/src/CArm.cpp @@ -1,139 +1,145 @@ -/** - * GameJam 2009 - GamePlay - * - * The robot arm class file. - */ - -#include "CArm.h" - -CArm::CArm(){ - setX(DEFAULT_X); - setY(DEFAULT_Y); - - state = EAS_NULL; - - // Loading Arm sprite - sprite[0] = load_bitmap("../media/arm.bmp", NULL); - sprite[1] = load_bitmap("../media/arm2.bmp", NULL); - - vel = 6; - - curr = 0; -} - -void CArm::getMap(CMap *map) -{ - this->map = map; -} - -void CArm::armAction(){ - if (state == EAS_NULL) - { - state = EAS_MOVE_GO; - - if (map->getFull() == false) - { - EItem** b; - do{ - rx = rand() % map->getWidth(); - ry = rand() % map->getHeight(); - b = map->getMap(); - }while(b[rx][ry] != EITEM_NULL); - - int i = rx; - int j = ry; - - dx = (map->getX() + GET_I) - 50; - dy = (map->getY() + GET_J) - 20; - - type = (rand() % MAX_ITEMS) + 1; - curr = 0; - } - } -} - -//Setters -void CArm::setX(int px){ - x = px; -} - -void CArm::setY(int py){ - y = py; -} - -//Getters -int CArm::getX(){ - return x; -} - -int CArm::getY(){ - return y; -} - -void CArm::show(BITMAP *buffer) -{ - draw_sprite(buffer, sprite[curr], x, y); -} - -void CArm::update() -{ - vel = map->getWidth() * 2; - - switch(state) - { - case EAS_NULL: - { - armAction(); - break; - } - - case EAS_MOVE_GO: - { - if (x > dx) - { - x -= vel; - } - - if (y < dy) - { - y += vel; - } - - if (x <= dx && y >= dy) - { - state = EAS_SET; - } - - break; - } - - case EAS_MOVE_BA: - { - if (x < DEFAULT_X) - { - x += vel; - } - - if (y > DEFAULT_Y) - { - y -= vel; - } - - if (x >= DEFAULT_X && y <= DEFAULT_Y) - { - state = EAS_NULL; - } - - break; - } - - case EAS_SET: - { - EItem** b= map->getMap(); - b[rx][ry] = (EItem)type; - state = EAS_MOVE_BA; - curr = 1; - break; - } - } -} +/** + * GameJam 2009 - GamePlay + * + * The robot arm class file. + */ + +#include "CArm.h" + +CArm::CArm(){ + setX(DEFAULT_X); + setY(DEFAULT_Y); + + state = EAS_NULL; + + // Loading Arm sprite + sprite[0] = load_bitmap("../media/arm.bmp", NULL); + sprite[1] = load_bitmap("../media/arm2.bmp", NULL); + + vel = 6; + + curr = 0; +} + +void CArm::getMap(CMap *map) +{ + this->map = map; +} + +void CArm::armAction(){ + if (state == EAS_NULL) + { + state = EAS_MOVE_GO; + + if (map->getFull() == false) + { + EItem** b; + do{ + rx = rand() % map->getWidth(); + ry = rand() % map->getHeight(); + b = map->getMap(); + }while(b[rx][ry] != EITEM_NULL); + + int i = rx; + int j = ry; + + dx = (map->getX() + GET_I) - 50; + dy = (map->getY() + GET_J) - 20; + + type = (rand() % MAX_ITEMS) + 1; + curr = 0; + } + } +} + +//Setters +void CArm::setX(int px){ + x = px; +} + +void CArm::setY(int py){ + y = py; +} + +//Getters +int CArm::getX(){ + return x; +} + +int CArm::getY(){ + return y; +} + +void CArm::show(BITMAP *buffer) +{ + if (state == EAS_MOVE_GO) + { + + map->drawBoxesOnHand(buffer, x+25, y+14, type); + } + + draw_sprite(buffer, sprite[curr], x, y); +} + +void CArm::update() +{ + vel = map->getWidth() * 2; + + switch(state) + { + case EAS_NULL: + { + armAction(); + break; + } + + case EAS_MOVE_GO: + { + if (x > dx) + { + x -= vel; + } + + if (y < dy) + { + y += vel; + } + + if (x <= dx && y >= dy) + { + state = EAS_SET; + } + + break; + } + + case EAS_MOVE_BA: + { + if (x < DEFAULT_X) + { + x += vel; + } + + if (y > DEFAULT_Y) + { + y -= vel; + } + + if (x >= DEFAULT_X && y <= DEFAULT_Y) + { + state = EAS_NULL; + } + + break; + } + + case EAS_SET: + { + EItem** b= map->getMap(); + b[rx][ry] = (EItem)type; + state = EAS_MOVE_BA; + curr = 1; + break; + } + } +} diff --git a/src/CButton.cpp b/src/CButton.cpp index 7d0c928..f539622 100644 --- a/src/CButton.cpp +++ b/src/CButton.cpp @@ -1,123 +1,123 @@ -/* - * Game developed by CrociDB on SpeedHack 2007 - * http://speedhack.allegro.cc/ - * - * CrociDBlog - http://crocidb.wordpress.com/ - * - * The App Control class. - * - */ - -#include - -CButton::CButton(char *txt, int tp, int cx, int cy, int cw, int ch, BITMAP *buffer) -{ - this->text = new char[50]; - strcpy(this->text, txt); - - this->type = tp; - - this->x = cx; - this->y = cy; - this->w = cw; - this->h = ch; - - this->buf = buffer; - - this->align = LEFT; - - this->up = 0; - - if (this->type == 1) - { - - } -} - -void CButton::setDesc(char *txt) -{ - this->desc = new char[100]; - strcpy(this->desc, txt); -} - -void CButton::setText(char *txt) -{ - this->text = new char[100]; - strcpy(this->text, txt); -} - -void CButton::setFont(FONT *fnt) -{ - this->fonte = fnt; -} - -void CButton::setAlign(int al) -{ - this->align = al; -} - -void CButton::setPosition(int cx, int cy) -{ - this->x = cx; - this->y = cy; -} - -void CButton::setColors(int a, int b) -{ - this->ncolor = a; - this->ucolor = b; - - this->color = ncolor; -} - -void CButton::runButton() -{ - if (this->type == 0) - { - if (this->align == LEFT) - { - textprintf_ex(this->buf, fonte, this->x, this->y, color, -1, "%s", this->text); - - if ((mouse_x > this->x) && (mouse_x < this->x + this->w) && (mouse_y > this->y) && (mouse_y < this->y + this->h)) - { - this->color = this->ucolor; - this->up = 1; - } - else - { - this->color = this->ncolor; - this->up = 0; - } - } - else - { - textprintf_centre_ex(this->buf, fonte, this->x, this->y, color, -1, "%s", this->text); - - if ((mouse_y > this->y) && (mouse_y < this->y + this->h)) - { - this->color = this->ucolor; - this->up = 1; - } - else - { - this->color = this->ncolor; - this->up = 0; - } - } - - } -} - -int CButton::isPressed() -{ - if (this->up == 1) - { - if (mouse_b & 1) - { - return 1; - } - } - return 0; -} - - +/* + * Game developed by CrociDB on SpeedHack 2007 + * http://speedhack.allegro.cc/ + * + * CrociDBlog - http://crocidb.wordpress.com/ + * + * The App Control class. + * + */ + +#include + +CButton::CButton(char *txt, int tp, int cx, int cy, int cw, int ch, BITMAP *buffer) +{ + this->text = new char[50]; + strcpy(this->text, txt); + + this->type = tp; + + this->x = cx; + this->y = cy; + this->w = cw; + this->h = ch; + + this->buf = buffer; + + this->align = LEFT; + + this->up = 0; + + if (this->type == 1) + { + + } +} + +void CButton::setDesc(char *txt) +{ + this->desc = new char[100]; + strcpy(this->desc, txt); +} + +void CButton::setText(char *txt) +{ + this->text = new char[100]; + strcpy(this->text, txt); +} + +void CButton::setFont(FONT *fnt) +{ + this->fonte = fnt; +} + +void CButton::setAlign(int al) +{ + this->align = al; +} + +void CButton::setPosition(int cx, int cy) +{ + this->x = cx; + this->y = cy; +} + +void CButton::setColors(int a, int b) +{ + this->ncolor = a; + this->ucolor = b; + + this->color = ncolor; +} + +void CButton::runButton() +{ + if (this->type == 0) + { + if (this->align == LEFT) + { + textprintf_ex(this->buf, fonte, this->x, this->y, color, -1, "%s", this->text); + + if ((mouse_x > this->x) && (mouse_x < this->x + this->w) && (mouse_y > this->y) && (mouse_y < this->y + this->h)) + { + this->color = this->ucolor; + this->up = 1; + } + else + { + this->color = this->ncolor; + this->up = 0; + } + } + else + { + textprintf_centre_ex(this->buf, fonte, this->x, this->y, color, -1, "%s", this->text); + + if ((mouse_y > this->y) && (mouse_y < this->y + this->h)) + { + this->color = this->ucolor; + this->up = 1; + } + else + { + this->color = this->ncolor; + this->up = 0; + } + } + + } +} + +int CButton::isPressed() +{ + if (this->up == 1) + { + if (mouse_b & 1) + { + return 1; + } + } + return 0; +} + + diff --git a/src/CGame.cpp b/src/CGame.cpp index 20f25a8..f6c4cce 100644 --- a/src/CGame.cpp +++ b/src/CGame.cpp @@ -1,141 +1,192 @@ -/** - * GameJam 2009 - GamePlay - * - * The main Game Class - */ - -#include "CGame.h" - -CGame::CGame() -{ - // Initializes the game here... - - App = new CApp(); - App->Init(800, 600, "GameJam 2009 - GamePlay"); - - Map = new CMap(); - - this->buffer = create_bitmap(800, 600); - - App->SetBuffer(buffer); - - game_status = GAME_GAME; - - // Maps test - Arm = new CArm(); - - flow = true; - - // Load all bitmaps of the game =D - loadImages(); - - Arm->getMap(Map); - - // Initializing the timer - timer = new CTimer(16); -} - -void CGame::run() -{ - // Ok... Main Looping - - timer->Start(); - - while (flow) - { - if (timer->getCount() > 0) - { - - App->ClearBuffer(0xFFFFFF); - - switch(game_status) - { - case GAME_OPEN: - { - game_open(); - break; - } - case GAME_MENU: - { - game_menu(); - break; - } - case GAME_GAME: - { - game_game(); - break; - } - case GAME_OVER: - { - game_over(); - break; - } - } - - App->Refresh(); - timer->desc(); - } - } - - exit(-1); - -} - -void CGame::game_open() -{ - clear_to_color(screen, 0xFFFFFF); - App->fadeInToColor(bmpOpen, FADE_TIME, 0xFFFFFF); - rest(3000); - App->fadeOutToColor(FADE_TIME, 0xFFFFFF); - game_status = GAME_GAME; - -} - -void CGame::game_menu() -{ - // Nada -} - -void CGame::game_game() -{ - blit(bmpBackGame, App->GetBuffer(), 0, 0, 0, 0, 800, 600); - - if (key[KEY_ESC]) - { - flow = false; - } - - if (key[KEY_A]) - { - Map->increaseMap(); - } - - Map->show(App->GetBuffer()); - Map->update(); - - if (Map->getFull()) - { - game_status = GAME_OVER; - } - - Arm->show(App->GetBuffer()); - Arm->update(); - - App->ShowMouse(); -} - -void CGame::game_over() -{ - App->fadeOutToColor(FADE_TIME, 0xFFFFFF); - App->fadeInToColor(bmpGameOver, FADE_TIME, 0xFFFFFF); - rest(2000); - exit(-1); -} - -void CGame::loadImages() -{ - bmpOpen = load_bitmap("../media/open.bmp", NULL); - bmpBackGame = load_bitmap("../media/back_game.bmp", NULL); - bmpGameOver = load_bitmap("../media/game_over.bmp", NULL); -} - +/** + * GameJam 2009 - GamePlay + * + * The main Game Class + */ + +#include "CGame.h" + +CGame::CGame() +{ + // Initializes the game here... + + App = new CApp(); + App->Init(800, 600, "GameJam 2009 - GamePlay"); + + Map = new CMap(); + + this->buffer = create_bitmap(800, 600); + + App->SetBuffer(buffer); + + game_status = GAME_OPEN; + + // Maps test + Arm = new CArm(); + + flow = true; + + // Load all bitmaps of the game =D + loadMedia(); + + Arm->getMap(Map); + + // Initializing the timer + timer = new CTimer(16); + + op = 0; +} + +void CGame::run() +{ + // Ok... Main Looping + + timer->Start(); + + while (flow) + { + if (timer->getCount() > 0) + { + + App->ClearBuffer(0xFFFFFF); + + switch(game_status) + { + case GAME_OPEN: + { + game_open(); + break; + } + case GAME_MENU: + { + game_menu(); + break; + } + case GAME_GAME: + { + game_game(); + break; + } + case GAME_OVER: + { + game_over(); + break; + } + default: + { + flow = false; + break; + } + } + + App->Refresh(); + timer->desc(); + } + } + + exit(-1); + +} + +void CGame::game_open() +{ + clear_to_color(screen, 0xFFFFFF); + App->fadeInToColor(bmpOpen, FADE_TIME, 0xFFFFFF); + rest(3000); + App->fadeOutToColor(FADE_TIME, 0xFFFFFF); + game_status = GAME_MENU; + timer->Reset(); + play_midi(midi_menu, 1); + +} + +void CGame::game_menu() +{ + blit(bmpBackMenu, App->GetBuffer(), 0, 0, 0, 0, 800, 600); + + if (key[KEY_ESC] || (mouse_b & 1 && op == 1 && mouse_y < 445)) + { + game_status = GAME_FAIL; + } + + if (op == 0) + { + ax = 390; + ay = 303; + } + else if (op == 1) + { + ax = 390; + ay = 388; + } + + if (mouse_y < 375) + { + op = 0; + } + else + { + op = 1; + } + + if (mouse_b & 1 && mouse_y > 300) + { + if (op == 0) + { + App->fadeOutToColor(FADE_TIME, 0xFFFFFF); + App->ClearBuffer(0x000000); + game_status = GAME_GAME; + timer->Reset(); + play_midi(midi_game, 1); + } + } + + draw_sprite(App->GetBuffer(), arrow, ax, ay); + + App->ShowMouse(); +} + +void CGame::game_game() +{ + blit(bmpBackGame, App->GetBuffer(), 0, 0, 0, 0, 800, 600); + + if (key[KEY_ESC]) + { + flow = false; + } + + Map->show(App->GetBuffer()); + Map->update(); + + if (Map->getFull()) + { + game_status = GAME_OVER; + } + + Arm->show(App->GetBuffer()); + Arm->update(); + + App->ShowMouse(); +} + +void CGame::game_over() +{ + App->fadeOutToColor(FADE_TIME, 0xFFFFFF); + App->fadeInToColor(bmpGameOver, FADE_TIME, 0xFFFFFF); + rest(2000); + exit(-1); +} + +void CGame::loadMedia() +{ + bmpOpen = load_bitmap("../media/open.bmp", NULL); + bmpBackGame = load_bitmap("../media/back_game.bmp", NULL); + bmpBackMenu = load_bitmap("../media/back_menu.bmp", NULL); + bmpGameOver = load_bitmap("../media/game_over.bmp", NULL); + + arrow = load_bitmap("../media/arrow.bmp", NULL); + + midi_game = load_midi("../media/unbal.mid"); + midi_menu = load_midi("../media/harestwav.mid"); +} + diff --git a/src/CInput.cpp b/src/CInput.cpp index 8a19371..c120019 100644 --- a/src/CInput.cpp +++ b/src/CInput.cpp @@ -1,55 +1,55 @@ -/** - * GameJam 2009 - GamePlay - * - * The main Input Class - */ - -#include "CInput.h" - -CInput::CInput() -{ - fMouseLeft = false; - fMouseRight = false; -} - -bool CInput::isMouseLeftClick() -{ - if (mouse_b & 1) - { - if (!fMouseLeft) - { - fMouseLeft = true; - return true; - } - } - else - { - fMouseLeft = false; - } - - return false; -} - -bool CInput::isMouseRightClick() -{ - if (mouse_b & 2) - { - if (!fMouseRight) - { - fMouseRight = true; - return true; - } - } - else - { - fMouseRight = false; - } - - return false; -} - -void CInput::update() -{ - -} +/** + * GameJam 2009 - GamePlay + * + * The main Input Class + */ + +#include "CInput.h" + +CInput::CInput() +{ + fMouseLeft = false; + fMouseRight = false; +} + +bool CInput::isMouseLeftClick() +{ + if (mouse_b & 1) + { + if (!fMouseLeft) + { + fMouseLeft = true; + return true; + } + } + else + { + fMouseLeft = false; + } + + return false; +} + +bool CInput::isMouseRightClick() +{ + if (mouse_b & 2) + { + if (!fMouseRight) + { + fMouseRight = true; + return true; + } + } + else + { + fMouseRight = false; + } + + return false; +} + +void CInput::update() +{ + +} \ No newline at end of file diff --git a/src/CMap.cpp b/src/CMap.cpp index 0b81e73..3ef9dbc 100644 --- a/src/CMap.cpp +++ b/src/CMap.cpp @@ -1,263 +1,273 @@ -/** - * GameJam 2009 - GamePlay - * - * The map class file. - */ - -#include "CMap.h" - -CMap::CMap(){ - full = false; - - setWidth(4); - setHeight(4); - - setX(0); - setY(0); - - clicked = false; - - loadImages(); - - center(); - initMatrix(); -} - -void CMap::show(BITMAP *buffer){ - int i = width; - int j = height; - rectfill(buffer, x-RADIUS-5, y-RADIUS-5, x+GET_I-3, y+GET_J-10, 0xAAAAAA); - rectfill(buffer, x-RADIUS-5, y-RADIUS-5, x+GET_I-3, y-10, 0x444444); - rectfill(buffer, x-RADIUS-5, y-RADIUS-5, x-10, y+GET_J-10, 0x444444); - - for(int i=0; i < width; i++){ - for(int j=0; j< height; j++){ - //circlefill(buffer, x+GET_I, y+GET_J, RADIUS, 0xFF0000); - draw_sprite(buffer, elevation, x+GET_I-RADIUS, y+GET_J-RADIUS); - - if (items[i][j] == EITEM_A) { - //circlefill(buffer, x + GET_I, y + GET_J, 6, 0xCC00AA); - draw_sprite(buffer, box2, x + GET_I - 12, y + GET_J - 12); - } else if (items[i][j] == EITEM_B) { - //circlefill(buffer, x + GET_I, y + GET_J, 6, 0xAAFFAA); - draw_sprite(buffer, box, x + GET_I - 12, y + GET_J - 12); - } - - } - } - - if (clicked && items[sel_x][sel_y] != EITEM_NULL) - { - int i = sel_x; - int j = sel_y; - //circle(buffer, x + GET_I, y + GET_J, RADIUS, 0); - draw_sprite(buffer, box_select, x + GET_I - 12, y + GET_J - 12); - } - -} - -void CMap::initMatrix(){ - items = new EItem*[width]; - for(int i=0; i < width; i++){ - items[i] = new EItem[height]; - for(int j=0; j < height; j++){ - items[i][j] = EITEM_NULL; - } - } -} - -void CMap::center(){ - x = (800 - (width * RADIUS * 2 * 1.3)) / 2; - y = (600 - (height * RADIUS * 2 * 1.3)) / 2; -} - -EItem** CMap::getMap(){ - return items; -} - -//Setters -void CMap::setWidth(int w){ - width = w; } - -void CMap::setHeight(int h){ - height = h; -} - -void CMap::setX(int px){ - x = px; -} - -void CMap::setY(int py){ - y = py; -} - -void CMap::setFull(bool op) { - full = op; -} - -//Getters -int CMap::getWidth(){ - return width; -} - -int CMap::getHeight(){ - return height; -} - -int CMap::getX(){ - return x; -} - -int CMap::getY(){ - return y; -} - -bool CMap::getFull(){ - return full; -} - -void CMap::update() { - int empty = 0; - - int clicked_x = -1, clicked_y = -1; - bool c = false; - - if (Input.isMouseLeftClick()) - { - clicked_x = mouse_x; - clicked_y = mouse_y; - c = true; - } - else - { - c = false; - } - - int a = 0; - - for (int i = 0; i < width; i++) - { - int zz = 0; - int za = 0; - - for (int j = 0; j < height; j++) - { - // - if (j != 0 && items[i][j] == items[i][j-1] && items[i][j] != EITEM_NULL) - { - zz++; - } - - if (j != 0 && items[j][i] == items[j-1][i] && items[j][i] != EITEM_NULL) - { - za++; - } - - // Clicked? - if (isClicked(i, j, clicked_x, clicked_y) && c == true) - { - if (!clicked) - { - clicked = true; - sel_x = i; - sel_y = j; - } - else - { - if (clicked_x != -1 && clicked_y != -1) - { - swap(sel_x, sel_y, i, j); - clicked_x = -1; - clicked_y = -1; - } - - clicked = false; - } - a++; - } - - // Is it empty? - if (items[i][j] != EITEM_NULL) - { - empty++; - } - } - - if (zz == width-1 || za == height-1) - { - increaseMap(); - } - - } - - - if (a == 0 && clicked == true && c == true) - { - clicked == false; - } - - if (empty == width * height) - { - setFull(true); - } -} - -bool CMap::isClicked(int i, int j, int cx, int cy) -{ - int px = x + GET_I; - int py = y + GET_J; - - if ((((px - cx) * (px - cx)) + ((py - cy) * (py - cy))) < ((2 * RADIUS) * (2 * RADIUS))) - { - // Clicked... =D - return true; - } - - return false; -} - -void CMap::swap(int a, int b, int c, int d) -{ - if (items[a][b] == EITEM_NULL || items[c][d] == EITEM_NULL) - { - return; - } - - if (a == c) - { - int dis = ((d-b)<0?-(d-b):(d-b)); - if (dis == 1) - { - EItem tmp = items[a][b]; - items[a][b] = items[c][d]; - items[c][d] = tmp; - } - } - else if(b == d) - { - int dis = ((a-c)<0?-(a-c):(a-c)); - if (dis == 1) - { - EItem tmp = items[a][b]; - items[a][b] = items[c][d]; - items[c][d] = tmp; - } - } -} - -void CMap::increaseMap() -{ - width++; - height++; - - center(); - initMatrix(); -} - -void CMap::loadImages() -{ - elevation = load_bitmap("../media/elevation.bmp", NULL); - box = load_bitmap("../media/box.bmp", NULL); - box2 = load_bitmap("../media/box2.bmp", NULL); - box_select = load_bitmap("../media/box_select.bmp", NULL); -} +/** + * GameJam 2009 - GamePlay + * + * The map class file. + */ + +#include "CMap.h" + +CMap::CMap(){ + full = false; + + setWidth(4); + setHeight(4); + + setX(0); + setY(0); + + clicked = false; + + loadImages(); + + center(); + initMatrix(); +} + +void CMap::show(BITMAP *buffer){ + textprintf_ex(buffer, font, 10, 10, 1, -1, "Level: %d", (width - 3)); + + int i = width; + int j = height; + rectfill(buffer, x-RADIUS-5, y-RADIUS-5, x+GET_I-3, y+GET_J-10, 0xAAAAAA); + rectfill(buffer, x-RADIUS-5, y-RADIUS-5, x+GET_I-3, y-10, 0x444444); + rectfill(buffer, x-RADIUS-5, y-RADIUS-5, x-10, y+GET_J-10, 0x444444); + + for(int i=0; i < width; i++){ + for(int j=0; j< height; j++){ + //circlefill(buffer, x+GET_I, y+GET_J, RADIUS, 0xFF0000); + draw_sprite(buffer, elevation, x+GET_I-RADIUS, y+GET_J-RADIUS); + + if (items[i][j] == EITEM_A) { + //circlefill(buffer, x + GET_I, y + GET_J, 6, 0xCC00AA); + draw_sprite(buffer, box2, x + GET_I - 12, y + GET_J - 12); + } else if (items[i][j] == EITEM_B) { + //circlefill(buffer, x + GET_I, y + GET_J, 6, 0xAAFFAA); + draw_sprite(buffer, box, x + GET_I - 12, y + GET_J - 12); + } + + } + } + + if (clicked && items[sel_x][sel_y] != EITEM_NULL) + { + int i = sel_x; + int j = sel_y; + //circle(buffer, x + GET_I, y + GET_J, RADIUS, 0); + draw_sprite(buffer, box_select, x + GET_I - 12, y + GET_J - 12); + } + +} + +void CMap::initMatrix(){ + items = new EItem*[width]; + for(int i=0; i < width; i++){ + items[i] = new EItem[height]; + for(int j=0; j < height; j++){ + items[i][j] = EITEM_NULL; + } + } +} + +void CMap::center(){ + x = (800 - (width * RADIUS * 2 * 1.3)) / 2; + y = (600 - (height * RADIUS * 2 * 1.3)) / 2; +} + +EItem** CMap::getMap(){ + return items; +} + +//Setters +void CMap::setWidth(int w){ + width = w; } + +void CMap::setHeight(int h){ + height = h; +} + +void CMap::setX(int px){ + x = px; +} + +void CMap::setY(int py){ + y = py; +} + +void CMap::setFull(bool op) { + full = op; +} + +//Getters +int CMap::getWidth(){ + return width; +} + +int CMap::getHeight(){ + return height; +} + +int CMap::getX(){ + return x; +} + +int CMap::getY(){ + return y; +} + +bool CMap::getFull(){ + return full; +} + +void CMap::update() { + int empty = 0; + + int clicked_x = -1, clicked_y = -1; + bool c = false; + + if (Input.isMouseLeftClick()) + { + clicked_x = mouse_x; + clicked_y = mouse_y; + c = true; + } + else + { + c = false; + } + + int a = 0; + + for (int i = 0; i < width; i++) + { + int zz = 0; + int za = 0; + + for (int j = 0; j < height; j++) + { + // + if (j != 0 && items[i][j] == items[i][j-1] && items[i][j] != EITEM_NULL) + { + zz++; + } + + if (j != 0 && items[j][i] == items[j-1][i] && items[j][i] != EITEM_NULL) + { + za++; + } + + // Clicked? + if (isClicked(i, j, clicked_x, clicked_y) && c == true) + { + if (!clicked) + { + clicked = true; + sel_x = i; + sel_y = j; + } + else + { + if (clicked_x != -1 && clicked_y != -1) + { + swap(sel_x, sel_y, i, j); + clicked_x = -1; + clicked_y = -1; + } + + clicked = false; + } + a++; + } + + // Is it empty? + if (items[i][j] != EITEM_NULL) + { + empty++; + } + } + + if (zz == width-1 || za == height-1) + { + increaseMap(); + } + + } + + + if (a == 0 && clicked == true && c == true) + { + clicked == false; + } + + if (empty == width * height) + { + setFull(true); + } +} + +bool CMap::isClicked(int i, int j, int cx, int cy) +{ + int px = x + GET_I; + int py = y + GET_J; + + if ((((px - cx) * (px - cx)) + ((py - cy) * (py - cy))) < ((2 * RADIUS) * (2 * RADIUS))) + { + // Clicked... =D + return true; + } + + return false; +} + +void CMap::swap(int a, int b, int c, int d) +{ + if (items[a][b] == EITEM_NULL || items[c][d] == EITEM_NULL) + { + return; + } + + if (a == c) + { + int dis = ((d-b)<0?-(d-b):(d-b)); + if (dis == 1) + { + EItem tmp = items[a][b]; + items[a][b] = items[c][d]; + items[c][d] = tmp; + } + } + else if(b == d) + { + int dis = ((a-c)<0?-(a-c):(a-c)); + if (dis == 1) + { + EItem tmp = items[a][b]; + items[a][b] = items[c][d]; + items[c][d] = tmp; + } + } +} + +void CMap::increaseMap() +{ + width++; + height++; + + center(); + initMatrix(); +} + +void CMap::loadImages() +{ + elevation = load_bitmap("../media/elevation.bmp", NULL); + box = load_bitmap("../media/box.bmp", NULL); + box2 = load_bitmap("../media/box2.bmp", NULL); + box_select = load_bitmap("../media/box_select.bmp", NULL); +} + +void CMap::drawBoxesOnHand(BITMAP *buffer, int x, int y, int i) +{ + if (i == EITEM_B) + draw_sprite(buffer, box, x, y); + else + draw_sprite(buffer, box2, x, y); +} diff --git a/src/State.cpp b/src/State.cpp index 444f6ee..039cf0d 100644 --- a/src/State.cpp +++ b/src/State.cpp @@ -1,45 +1,45 @@ -/* - * - * AnimSprite - By CrociDB - * http://crocidb.wordpress.com/ - * - * Obrigado por usar ^^ - * - */ - -#include - -State::State(int f, int l) -{ - SetFirstFrame(f); - SetLastFrame(l); -} - - -void State::SetFirstFrame(int f) -{ - this->first = f; -} - -void State::SetLastFrame(int l) -{ - this->last = l; -} - - -int State::GetFirstFrame() const -{ - return this->first; -} - -int State::GetLastFrame() const -{ - return this->last; -} - -int State::GetNumFrames() const -{ - return (GetLastFrame()-GetFirstFrame()) + 1; -} - - +/* + * + * AnimSprite - By CrociDB + * http://crocidb.wordpress.com/ + * + * Obrigado por usar ^^ + * + */ + +#include + +State::State(int f, int l) +{ + SetFirstFrame(f); + SetLastFrame(l); +} + + +void State::SetFirstFrame(int f) +{ + this->first = f; +} + +void State::SetLastFrame(int l) +{ + this->last = l; +} + + +int State::GetFirstFrame() const +{ + return this->first; +} + +int State::GetLastFrame() const +{ + return this->last; +} + +int State::GetNumFrames() const +{ + return (GetLastFrame()-GetFirstFrame()) + 1; +} + + diff --git a/src/main.cpp b/src/main.cpp index db38d40..bb599c7 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,20 +1,20 @@ -/** - * GameJam 2009 - GamePlay - * - * Here is the magic. With a few lines, our game OWNS yours! ;) - */ - -#include -#include "CGame.h" - -int main() -{ - CGame Game; - - // No fear, go ahead, son! - Game.run(); - - // Ok... Thanks for playing. ^^ - return 0; - -}END_OF_MAIN() +/** + * GameJam 2009 - GamePlay + * + * Here is the magic. With a few lines, our game OWNS yours! ;) + */ + +#include +#include "CGame.h" + +int main() +{ + CGame Game; + + // No fear, go ahead, son! + Game.run(); + + // Ok... Thanks for playing. ^^ + return 0; + +}END_OF_MAIN()