Skip to content

Commit

Permalink
cleanned units and moved away some units
Browse files Browse the repository at this point in the history
  • Loading branch information
pierre.gueth@gmail.com committed Dec 15, 2008
1 parent dcfee3c commit c7456ed
Show file tree
Hide file tree
Showing 42 changed files with 202 additions and 224 deletions.
2 changes: 1 addition & 1 deletion Doxyfile
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ INPUT = /home/pierre/git/freesiege
INPUT_ENCODING = UTF-8
FILE_PATTERNS = *.h *.cpp *.tpp
RECURSIVE = YES
EXCLUDE = build CVS .git
EXCLUDE = build CVS .git units_unused
EXCLUDE_SYMLINKS = NO
EXCLUDE_PATTERNS = CMake*
EXCLUDE_SYMBOLS =
Expand Down
2 changes: 0 additions & 2 deletions combi.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,4 @@ ram:......WWWS../........WWWS/WWWS......../..WWWS....../
marion:MM....MM..../..MM....MM../....MM....MM/
plant:MM....WW..../..MM....WW../....MM....WW/
dragon:FFFFFFFMMMMF/
archer:SW....SW..../..SW....SW../....SW....SW/
veteran:SW....WS..../..SW....WS../....SW....WS/
catapult:WWWWWWWSFFSW/
6 changes: 4 additions & 2 deletions common/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//
#ifndef __PLATEFORMSDL_H
#define __PLATEFORMSDL_H
#ifndef __CONFIG_H__
#define __CONFIG_H__

#include <vector>
#include <list>
Expand All @@ -29,6 +29,8 @@
#include <stack>
#include <sstream>
#include <cassert>
#include <algorithm>
#include <set>

#ifdef WIN32
#include <windows.h>
Expand Down
14 changes: 0 additions & 14 deletions common/param.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,16 +71,6 @@ typedef enum {PLAYER_1=1,PLAYER_2=2,PLAYER_NEUTRAL} PLAYER;
#define NONE 'x'
#define USED 'x'

//BATTLEFIELD parameters
#define FIELD_CASTLE_W 80
#define FIELD_CASTLE_H 180
#define FIELD_BASE_Y SCREEN_H-FIELD_CASTLE_H+155

//BACKGROUND parameters
#define N_CLOUD 10
#define MIN_CLOUD_SPEED 4
#define MAX_CLOUD_ALTITUDE 300

//LIFEBAR parameters
#define LIFE_Y 320
#define LIFE_INNER_BORDER 3
Expand All @@ -90,8 +80,4 @@ typedef enum {PLAYER_1=1,PLAYER_2=2,PLAYER_NEUTRAL} PLAYER;
#define LIFE_FACTOR 60
#define LIFE_DECREASE 0.002

//FINALSCREEN parameters
#define FONT_COLOR { 0x77, 0xd1, 0x00, 0 }
typedef enum {SOLDIER,DRUID,BALL,EXPLOSION,KNIGHT,GOLEM,PLANT,DRAGON,FLAME,FLOWER,ARCHER,ARROW,VETERAN,CATAPULT,STONE} UNIT_ID;

#endif
3 changes: 0 additions & 3 deletions engine/collisionmatrix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@
#include "collisionmatrix.h"

#include "unit.h"
#include <algorithm>
#include <vector>
#include <cassert>

typedef std::pair<float,int> CoordPair;// fst: coord, scd: unit index

Expand Down
12 changes: 0 additions & 12 deletions fight.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,24 +130,12 @@ int main(int argc, char* argv[]) {
case SDLK_j:
battlefield.spawn(FLOWER,PLAYER_1);
break;
case SDLK_i:
battlefield.spawn(ARCHER,PLAYER_2);
break;
case SDLK_k:
battlefield.spawn(ARCHER,PLAYER_1);
break;
case SDLK_o:
battlefield.spawn(VETERAN,PLAYER_2);
break;
case SDLK_l:
battlefield.spawn(VETERAN,PLAYER_1);
break;
case SDLK_p:
battlefield.spawn(CATAPULT,PLAYER_2);
break;
case SDLK_m:
battlefield.spawn(CATAPULT,PLAYER_1);
break;
default:
break;
}
Expand Down
8 changes: 5 additions & 3 deletions gui/background.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@
//
#include "background.h"

#include <string>
#include "param.h"
#include "utils.h"
#include "utils.h" //for factor

#define N_CLOUD 10
#define MIN_CLOUD_SPEED 4
#define MAX_CLOUD_ALTITUDE 300

Background::Background(const SpriteCollection *spr_coll) {
bit_back=spr_coll->get_sprite("background_back");
Expand Down
7 changes: 2 additions & 5 deletions gui/battlefield.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,7 @@
//
#include "battlefield.h"

#include <string>
#include <algorithm>
#include "param.h"
#include "utils.h"
#include "collisionmatrix.h"

#include "unit.h"
Expand Down Expand Up @@ -122,6 +119,6 @@ void BattleField::draw() {
for (Units::const_iterator iter=units.begin(); iter!=units.end(); iter++) (*iter)->draw();

//draw castles
bit_castle->draw(0,SCREEN_H-FIELD_CASTLE_H);
bit_castle->draw_flip_h(SCREEN_W-bit_castle->w,SCREEN_H-FIELD_CASTLE_H);
bit_castle->draw(0,SCREEN_H-CastleH);
bit_castle->draw_flip_h(SCREEN_W-bit_castle->w,SCREEN_H-CastleH);
}
5 changes: 5 additions & 0 deletions gui/battlefield.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#define __BATTLEFIELD_H

#include "message.h"
#include "unit.h"
#include "lifebar.h"
#include "foreground.h"

Expand All @@ -29,6 +30,10 @@ class BattleField {

void draw();
void spawn(UNIT_ID name,PLAYER player,float x=0);

static const float CastleW=80;
static const float CastleH=180;
static const float BaseY=SCREEN_H-180+155;
private:
typedef std::list<Unit*> Units;
Units units;
Expand Down
7 changes: 4 additions & 3 deletions gui/board.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -170,9 +170,10 @@ void Board::validate() {
else if (*name=="dragon") field->spawn(DRAGON,player);
else if (*name=="marion") field->spawn(FLOWER,player);
else if (*name=="veteran") field->spawn(VETERAN,player);
else if (*name=="archer") field->spawn(ARCHER,player);
else if (*name=="catapult") field->spawn(CATAPULT,player);
else field->spawn(SOLDIER,player);
else {
std::cout<<"WARNING default spawing..."<<std::endl;
field->spawn(SOLDIER,player);
}
iter++;
}
//std::cout<<std::endl;
Expand Down
2 changes: 2 additions & 0 deletions gui/gamescreen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
#include "lifebar.h"
#include "foreground.h"

#define FONT_COLOR { 0x77, 0xd1, 0x00, 0 }

GameScreen::GameScreen(const SpriteCollection *spr_coll,const CombinaisonCollection *cmb_coll,const std::string &ttf_path,TextureIds ids,Background *background) {
font=TTF_OpenFont(ttf_path.c_str(),80);
font_huge=TTF_OpenFont(ttf_path.c_str(),120);
Expand Down
4 changes: 0 additions & 4 deletions units/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,4 @@ SET(FS_UNITS_SRCS
units/flame.cpp
units/soldier.cpp
units/veteran.cpp
units/archer.cpp
units/arrow.cpp
units/catapult.cpp
units/stone.cpp
)
33 changes: 17 additions & 16 deletions units/ball.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,28 +16,29 @@
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//
#include "ball.h"
#include "battlefield.h"

#define BALL_X 14
#define BALL_Y 84
#define BALL_DX 7
#define BALL_DY 5
#define BALL_AY 0.12
#define BALL_DAMAGE 80
float Ball::X=14;
float Ball::Y=84;
float Ball::DX=7;
float Ball::DY=5;
float Ball::AY=0.12;
float Ball::Damage=80;

Ball::Ball(const SpriteCollection *spr_coll,PLAYER player) : Unit(player) {
bit_ball=spr_coll->get_sprite("ball_unit");

w=bit_ball->w;
h=bit_ball->h;

if (player==PLAYER_1) x=BALL_X;
else x=SCREEN_W-BALL_X-w;
if (player==PLAYER_1) x=X;
else x=SCREEN_W-X-w;

float factor=0.5+0.5*rand()/RAND_MAX;
y=FIELD_BASE_Y-BALL_Y;
dy=-BALL_DY*factor;
if (player==PLAYER_1) dx=BALL_DX*factor;
else dx=-BALL_DX*factor;
y=BattleField::BaseY-Y;
dy=-DY*factor;
if (player==PLAYER_1) dx=DX*factor;
else dx=-DX*factor;
this->player=PLAYER_NEUTRAL;

collide=true;
Expand All @@ -49,9 +50,9 @@ Ball::~Ball() {}
void Ball::post_message(MessageQueue *mess_queue) {
x+=dx;
y+=dy;
dy+=BALL_AY;
if (y>=FIELD_BASE_Y-h) {
y=FIELD_BASE_Y-h;
dy+=AY;
if (y>=BattleField::BaseY-h) {
y=BattleField::BaseY-h;
mess_queue->push(Message(Message::EVENT_SPAWN,this,this,NO_DELAY,Message::PRIORITY_NORMAL,EXPLOSION,x));
dead=true;
}
Expand All @@ -62,7 +63,7 @@ void Ball::handle_message(const Message &mess,MessageQueue *mess_queue) {
switch (mess.event) {
case Message::EVENT_COLLISION:
if (mess.sender->get_player()!=PLAYER_NEUTRAL) {
mess_queue->push(Message(Message::EVENT_ATTACK,mess.sender,this,NO_DELAY,Message::PRIORITY_NORMAL,BALL_DAMAGE));
mess_queue->push(Message(Message::EVENT_ATTACK,mess.sender,this,NO_DELAY,Message::PRIORITY_NORMAL,Damage));
dead=true;
}
break;
Expand Down
7 changes: 7 additions & 0 deletions units/ball.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,13 @@ class Ball: public Unit {
virtual void post_message(MessageQueue *mess_queue);
virtual void handle_message(const Message &mess,MessageQueue *mess_queue);
virtual void draw();

static float X;
static float Y;
static float DX;
static float DY;
static float AY;
static float Damage;
private:
float dx,dy;
const Sprite *bit_ball;
Expand Down
24 changes: 9 additions & 15 deletions units/dragon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,35 +17,29 @@
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//
#include "dragon.h"

#define DRAGON_LIFE 200
#define DRAGON_PLAYER_DAMAGE 6
#define DRAGON_Y 180
#define DRAGON_W 174
#define DRAGON_H 58
#define DRAGON_DX 1
#include "battlefield.h"

Dragon::Dragon(const SpriteCollection *spr_coll,PLAYER player): Unit(player) {
w=DRAGON_W;
h=DRAGON_H;
w=W;
h=H;

float f=factor(0.8);
if (player==PLAYER_1) {
x=-w;
dx=f*DRAGON_DX;
dx=f*DX;
} else {
x=SCREEN_W;
dx=-f*DRAGON_DX;
dx=-f*DX;
}
y=FIELD_BASE_Y-DRAGON_Y;
y=BattleField::BaseY-Y;

anim_dragon_fly=spr_coll->get_anim_cycle_iterator("dragon_fly",0.175);
bit_dragon_dead=spr_coll->get_sprite("dragon_cadaver");

state=FLY;

this->name="dragon";
this->life=DRAGON_LIFE;
this->life=Life;
this->collide=true;
this->init=true;
this->player = player;
Expand All @@ -56,7 +50,7 @@ Dragon::~Dragon() {}
void Dragon::post_message(MessageQueue *mess_queue) {
switch (state) {
case FLY:
if ((player==PLAYER_1 && x>SCREEN_W-FIELD_CASTLE_W) || (player==PLAYER_2 && x<FIELD_CASTLE_W-w)) mess_queue->push(Message(Message::EVENT_DAMAGE_PLAYER,this,this,NO_DELAY,Message::PRIORITY_NORMAL,DRAGON_PLAYER_DAMAGE));
if ((player==PLAYER_1 && x>SCREEN_W-BattleField::CastleW) || (player==PLAYER_2 && x<BattleField::CastleW-w)) mess_queue->push(Message(Message::EVENT_DAMAGE_PLAYER,this,this,NO_DELAY,Message::PRIORITY_NORMAL,PlayerDamage));
else x=x+dx;

if (init) {
Expand All @@ -66,7 +60,7 @@ void Dragon::post_message(MessageQueue *mess_queue) {

break;
case CADAVER:
if (y<FIELD_BASE_Y-DRAGON_H) { y+=5; x+=dx; }
if (y<BattleField::BaseY-H) { y+=5; x+=dx; }
break;
}
}
Expand Down
7 changes: 7 additions & 0 deletions units/dragon.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,13 @@ class Dragon: public Unit {
virtual void post_message(MessageQueue *mess_queue);
virtual void handle_message(const Message &mess,MessageQueue *mess_queue);
virtual void draw();

static const float Life=200;
static const float PlayerDamage=6;
static const float Y=180;
static const float W=174;
static const float H=58;
static const float DX=1;
private:
typedef enum {FLY,CADAVER} State;

Expand Down
12 changes: 4 additions & 8 deletions units/druid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,16 @@
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//
#include "druid.h"

#include "param.h"

#define DRUID_X 2
#define DRUID_Y 90
#include "battlefield.h"

Druid::Druid(const SpriteCollection *spr_coll,PLAYER player) : Unit(player) {
bit_druid=spr_coll->get_sprite("druid_unit");
if (player==PLAYER_1) {
x=DRUID_X;
x=X;
} else {
x=SCREEN_W-DRUID_X-bit_druid->w;
x=SCREEN_W-X-bit_druid->w;
}
y=FIELD_BASE_Y-DRUID_Y;
y=BattleField::BaseY-Y;
w=bit_druid->w;
h=bit_druid->h;

Expand Down
4 changes: 3 additions & 1 deletion units/druid.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
#define __DRUID_H

#include "unit.h"
#include <set>

class Druid: public Unit {
public:
Expand All @@ -28,6 +27,9 @@ class Druid: public Unit {
virtual void post_message(MessageQueue *mess_queue);
virtual void handle_message(const Message &mess,MessageQueue *mess_queue);
virtual void draw();

static const float X=2;
static const float Y=90;
private:
typedef enum {INIT,WAIT,SHOOTED} State;
State state;
Expand Down
Loading

0 comments on commit c7456ed

Please sign in to comment.