Skip to content
This repository has been archived by the owner on Feb 19, 2018. It is now read-only.

Commit

Permalink
Merge pull request #133 from demiurgosoft/development
Browse files Browse the repository at this point in the history
Development
  • Loading branch information
Andrés committed Mar 12, 2015
2 parents c72130b + 4540eda commit 710cfd6
Show file tree
Hide file tree
Showing 51 changed files with 5,004 additions and 476 deletions.
7 changes: 5 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
language: cpp
compiler:
- g++

branches:
only:
- master
- development

before_install:
- sudo add-apt-repository -y ppa:ubuntu-toolchain-r/test
- sudo apt-get update -qq
install:
- sudo apt-get install -qq gcc-4.8 g++-4.8
- sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-4.8 90
- sudo apt-get install -y libglu-dev build-essential git cmake cmake-curses-gui xorg-dev libgl1-mesa-dev freeglut3-dev libpng-dev libcurl4-openssl-dev libfreetype6-dev libjpeg-dev libvorbis-dev libopenal-dev libphysfs-dev libgtk2.0-dev libasound-dev libpulse-dev libflac-dev libdumb1-dev
- git clone git://git.code.sf.net/p/alleg/allegro
- cd allegro
Expand Down
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Don´t Crush my Castle
=====================
_Version 0.7 (alpha)_
_Version 0.7.3 (alpha)_

Highly customizable tower defense style game

Expand Down Expand Up @@ -36,6 +36,10 @@ This Project is Open-Source under GNU GPL v3

**Attributions**

ALLEGRO 5 - http://alleg.sourceforge.net/git.html

TinyXML2 by Lee Thomason - https://github.com/leethomason/tinyxml2

example_clock.png (used for testing) is under CCLicense by [Jorge Durán Llanos] (https://github.com/Caesar95)
<a rel="license" href="http://creativecommons.org/licenses/by-nc-sa/4.0/"><img alt="Licencia de Creative Commons" style="border-width:0" src="https://i.creativecommons.org/l/by-nc-sa/4.0/88x31.png" /></a>

Expand Down
4 changes: 2 additions & 2 deletions include/controller/game_master.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
//VERSION: 0.7
//DESCRIPTION: control the IA and in-game stuff (spawning,movement etc..)

#ifndef GAME_MASTER_H
#define GAME_MASTER_H
#ifndef GAME_MASTER
#define GAME_MASTER

#include "game_objects.h"
#include "player.h"
Expand Down
13 changes: 10 additions & 3 deletions include/controller/game_objects.h
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
//TITLE: GAME_OBJECTS_H
//PROJECT: DON´T CRUSH MY CASTLE
//AUTHOR: Andrés Ortiz
//VERSION: 0.7
//VERSION: 0.7.2
//DESCRIPTION: stores all instantiated ofjects in the scene

#ifndef GAME_OBJECTS
#define GAME_OBJECTS

#include "enemy.h"
#include "tower.h"
#include "text_handler.h"
#include <list>

typedef unsigned int tower_id; //defines a id for a tile in the tileset
Expand All @@ -18,6 +19,7 @@ class game_objects {
private:
list<enemy> spawned_enemies;
map<tower_id,tower> spawned_towers;
map<string,text_handler> texts;
list<pair<list<enemy>::iterator,tower_atk> > spawned_attacks;
unsigned int reward;
tower_id current_id;
Expand All @@ -30,13 +32,17 @@ class game_objects {
void add_enemy(const enemy &new_enemy);
tower_id add_tower(const tower &new_tower);
void add_attack(const tower_atk &atk,list<enemy>::iterator target);
//adds a new text_handler, overriding any text with same tag
void add_text(const text_handler &new_text);
void remove_tower(tower_id id);
void remove_text(const string &tag);
void clear(); //removes all data (without destroying)

//CONSULT
unsigned int enemy_size() const;
unsigned int tower_size() const;
unsigned int attack_size() const;
unsigned int texts_size() const;
//return true if every list is empty
bool empty() const;
unsigned int killed_enemies() const;
Expand All @@ -48,7 +54,8 @@ class game_objects {
list<enemy>::const_iterator get_last_enemy() const;
tower *get_tower(tower_id id);
const tower *get_tower(tower_id id) const;

text_handler *get_text(const string &tag);
const text_handler *get_text(string &tag) const;
//updates all enemies and towers, removes unactive enemies, returns vector of towers ready to fire
vector<tower_id> update_towers();
//updates all enemies, returns all enemies in idle, set to invalid all attacks of killed enemy
Expand All @@ -61,7 +68,7 @@ class game_objects {

private:
void invalidate_attacks(vector<list<enemy>::iterator> to_invalidate);

void destroy_texts();
};


Expand Down
14 changes: 7 additions & 7 deletions include/controller/player.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,27 +13,27 @@ class player {
player_controller controller;
string name;
string current_tower;
unsigned int lifes;
unsigned int lives;
unsigned int coins;
bool active;
function<void()> lose_function;
public:
player();
player(const string &name,tower_set &towers,game_objects &objects,tilemap &game_map,unsigned int lifes,unsigned int coins,function<void()> lose_function);
player(tower_set &towers,game_objects &objects,tilemap &game_map,unsigned int lifes,unsigned int coins,function<void()> lose_function);
player(const string &name,tower_set &towers,game_objects &objects,tilemap &game_map,unsigned int lives,unsigned int coins,function<void()> lose_function);
player(tower_set &towers,game_objects &objects,tilemap &game_map,unsigned int lives,unsigned int coins,function<void()> lose_function);

~player();
//METHODS
//removes given lifes
void remove_life(unsigned int lifes_removes=1);
void recover_life(unsigned int lifes_recovered=1);
//removes given lives
void remove_life(unsigned int lives_removes=1);
void recover_life(unsigned int lives_recovered=1);
void add_coins(unsigned int coins);
void remove_coins(unsigned int coins);

bool is_active() const;
string get_name() const;
unsigned int get_coins() const;
unsigned int get_lifes() const;
unsigned int get_lives() const;
void set_current_tower(const string &tower);
set<string> get_tower_names() const;

Expand Down
54 changes: 17 additions & 37 deletions include/enemy/enemy.h
Original file line number Diff line number Diff line change
@@ -1,53 +1,30 @@
//TITLE: ENEMY_H
//PROJECT: DON´T CRUSH MY CASTLE
//AUTHOR: Andrés Ortiz
//VERSION: 0.7
//VERSION: 0.7.3
//DESCRIPTION: defines each single enemy

#ifndef ENEMY_H
#define ENEMY_H
#ifndef ENEMY
#define ENEMY

#include "al_anim.h"
#include "game_object.h"
#include <map>
#include "enemy_attributes.h"

enum enemy_animation {idle_anim,up_anim,down_anim,left_anim,right_anim,dead_anim}; //defines each animation for an enemy
const double level_ratio=0.3; //ratio used to increase base values per level
//defines the basic characteristics of an enemy kind
struct enemy_attributes {
map<enemy_animation,al_anim> animation; //stores all animations of an enemy
string name; //name of the enemy
double speed; //basic speed (pixels per seconds)
unsigned int max_life; //max (and initial) life of enemy
unsigned int armor; //armor of the enemy
unsigned int reward; //reward when killed
//Methods
enemy_attributes();
enemy_attributes(const string &name,unsigned int life,unsigned int armor,double enemy_speed,unsigned int reward=0);
enemy_attributes(const string &name,unsigned int life,unsigned int armor,double enemy_speed,const map<enemy_animation,al_anim> &animation,unsigned int reward=0);
~enemy_attributes();
//insert animation (erasing previous animations and reseting all counters)
void insert_animation(enemy_animation type,const al_anim &anim);
//increase values according to level
void increase_level(unsigned int level);
//clear all attributes (dont destroy bitmaps)
void clear();
//destroy all animations and clear data
void destroy();
//returns true if the enemy has all the necessary info
bool check() const;
};


class enemy : public game_object {
private:
enemy_attributes attributes; //basic info of enemy type
const enemy_attributes *attributes; //basic info of enemy type
map<enemy_animation,al_anim> animation; //stores all animations of an enemy

unsigned int life; //current life of enemy
unsigned int level; //level may change enemy parameters
double speed; //pixels per frame

pair<double,double> destiny; //position to move

bool reward_given;

enemy_animation current_animation;
public:
//CONSTRUCTORS
Expand All @@ -71,8 +48,10 @@ class enemy : public game_object {
unsigned int get_level() const;
//return max life
unsigned int get_max_life() const;
//returns reward when killed
unsigned int get_reward() const;
//returns reward when killed, also set reward given to true
unsigned int get_reward();
//return true if the reward has benn already given
bool is_reward_given() const;
//return the enemy destiny (where is moving)
pair<double,double> get_destiny() const;
//return true if enemy is alive(life>0)
Expand All @@ -83,7 +62,6 @@ class enemy : public game_object {
bool idle() const;
//return current aimation
enemy_animation get_current_animation() const;

//ENEMY CONTROL (make sure to call update in each iteration)
//stop the movement(idle) (final destination will be the current position)
void stop();
Expand All @@ -98,10 +76,10 @@ class enemy : public game_object {
//deactivates enemy and returns lives taken
unsigned int destiny_reached();
//update the movement,animation and all booleans
void update();
void virtual update();
//draw the current_animation in the enemy position
//note that draw the enemy with the position at its feet
void draw() const;
void virtual draw() const;
//check enemy class is working well, debug_log output if error or warning, return true if everything is ok
bool check() const;
// pair<double,double> get_position() const;
Expand All @@ -118,6 +96,8 @@ class enemy : public game_object {
void set_level(unsigned int level);
//sets movement animation
void set_movement_animation();
//return the incremenet of attributes at given level
unsigned int get_level_increment(unsigned int value) const;
};


Expand Down
41 changes: 41 additions & 0 deletions include/enemy/enemy_attributes.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
//TITLE: ENEMY_ATTRIBUTES_H
//PROJECT: DON´T CRUSH MY CASTLE
//AUTHOR: Andrés Ortiz
//VERSION: 0.7.4
//DESCRIPTION: defines each kind of enemy
#ifndef ENEMY_ATTRIBUTES
#define ENEMY_ATTRIBUTES

#include "game_object_attributes.h"
#include "al_anim.h"
#include <map>

const string enemy_xml_value="Enemy";
enum enemy_animation {idle_anim,up_anim,down_anim,left_anim,right_anim,dead_anim}; //defines each animation for an enemy
//defines the basic characteristics of an enemy kind
struct enemy_attributes : game_object_attributes {
map<enemy_animation,al_anim> animation; //stores all animations of an enemy
string name; //name of the enemy
double speed; //basic speed (pixels per seconds)
unsigned int max_life; //max (and initial) life of enemy
unsigned int armor; //armor of the enemy
unsigned int reward; //reward when killed
//Methods
enemy_attributes();
enemy_attributes(XMLElement *enemy_root);
enemy_attributes(const string &name,unsigned int life,unsigned int armor,double enemy_speed,unsigned int reward=0);
enemy_attributes(const string &name,unsigned int life,unsigned int armor,double enemy_speed,const map<enemy_animation,al_anim> &animation,unsigned int reward=0);
~enemy_attributes();

bool read_xml(const XMLElement *enemy_root);
// bool write_xml(XMLElement *enemy_root) const;
//insert animation (erasing previous animations and reseting all counters)
void insert_animation(enemy_animation type,const al_anim &anim);
//clear all attributes (dont destroy bitmaps)
void clear();
//destroy all animations and clear data
void destroy();
//returns true if the enemy has all the necessary info
bool check() const;
};
#endif
8 changes: 4 additions & 4 deletions include/enemy/enemy_set.h
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
//TITLE: ENEMY_SET_H
//PROJECT: DON´T CRUSH MY CASTLE
//AUTHOR: Andrés Ortiz
//VERSION: 0.7
//VERSION: 0.7.2
//DESCRIPTION: stores all kinds of enemies and spawn instances of each enemy

#ifndef ENEMY_SET_H
#define ENEMY_SET_H
#ifndef ENEMY_SET
#define ENEMY_SET

#include "enemy.h"

Expand All @@ -31,7 +31,7 @@ class enemy_set {
void clear();
//CONSULT
string get_name() const;
unsigned int get_size() const;
unsigned int size() const;
bool empty() const;
bool is_enemy(const string &name) const;

Expand Down
8 changes: 4 additions & 4 deletions include/map/tile.h
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
//TITLE: TILE_H
//PROJECT: DON´T CRUSH MY CASTLE
//AUTHOR: Andrés Ortiz
//VERSION: 0.7
//VERSION: 0.7.2
//DESCRIPTION: Defines one tile of a tileset

#ifndef TILE_H
#define TILE_H
#ifndef TILE
#define TILE

#include "al_utils.h"

Expand Down Expand Up @@ -41,7 +41,7 @@ class tile {
//draw the tile bitmap on x,y position, resizing it to width given
void draw_resized(float x,float y,unsigned int width) const;
//returns tile width
unsigned int get_size() const;
unsigned int size() const;
//check the class
bool check() const;
//OPERATORS
Expand Down
33 changes: 5 additions & 28 deletions include/tower/tower.h
Original file line number Diff line number Diff line change
@@ -1,40 +1,17 @@
//TITLE: TOWER_H
//PROJECT: DON´T CRUSH MY CASTLE
//AUTHOR: Andrés Ortiz
//VERSION: 0.7
//VERSION: 0.7.4
//DESCRIPTION: defines each player tower

#ifndef TOWER_H
#define TOWER_H

#include "tower_atk.h"


//defines the attributes of the tower
struct tower_attributes {
atk_attributes atk; //attack attributes
ALLEGRO_BITMAP *bitmap; //main bitmap of the towers (static)
// ALLEGRO_BITMAP *secondary_bitmap; //secondary bitmap (rotate)
unsigned int cost;
string name;
//METHODS
tower_attributes();
tower_attributes(const string &name,ALLEGRO_BITMAP *bitmap,const atk_attributes &atk,unsigned int cost);
~tower_attributes();
//return bitmap width (in pixels)
unsigned int get_width() const;
//returns bitmap height (in pixels)
unsigned int get_height() const;
//resize bitmap (overriding old) to given size
void resize(unsigned int width,unsigned int height);
bool check() const;
//destroy tower attributes (including bitmaps and attack attribute)
void destroy();
};
#include "tower_attributes.h"

class tower : public game_object {
private:
tower_attributes attributes;
const tower_attributes *attributes;
unsigned int atk_counter; //time to next attack (depending on delay) in frames
unsigned int atk_delay; //atk delay (in frames)
//change atk_delay to unsigned int (count as frames)
Expand All @@ -60,9 +37,9 @@ class tower : public game_object {
//return true if tower can attack (counter=0)
bool can_attack()const;
//update tower
void update();
void virtual update();
//draw tower
void draw() const;
void virtual draw() const;
//attacks an enemy (atk destiny will be that enemy), return the attack
tower_atk attack(const pair<double,double> target);
bool check() const;
Expand Down
Loading

0 comments on commit 710cfd6

Please sign in to comment.