Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Amunak committed Feb 17, 2015
0 parents commit 20b3e8f
Show file tree
Hide file tree
Showing 30 changed files with 5,692 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
doc/
*.7z
*.o
*.exe
2,361 changes: 2,361 additions & 0 deletions Doxyfile

Large diffs are not rendered by default.

43 changes: 43 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
CXX=g++
LD=g++
CFLAGS=-Wall -pedantic -Wno-long-long -std=c++11
LDLIB=-lmenu -lpanel -lncurses
SRC=src
OUT=bomber

all: compile doc

compile: Blocks.o CBomb.o CCoord.o CEntity.o CGame.o CNetwork.o CPickup.o CScreen.o CTile.o CWorld.o LivingEntities.o main.o
$(LD) $(CFLAGS) $^ -o $(OUT) $(LDLIB)

#compile:
# $(LD) $(CFLAGS) -o $(OUT) $(SRC)/*.cpp $(LDLIB)

doc:
doxygen Doxyfile

run: compile
./$(OUT)

clean:
rm -f *.o $(OUT)
rm -fr doc/

main.o:
g++ -Wall -pedantic -Wno-long-long -O0 -ggdb -std=c++11 -c -o main.o src/main.cpp

%.o: $(SRC)/%.cpp $(SRC)/%.h
$(CXX) $(CFLAGS) -c -o $@ $<

Blocks.o: $(SRC)/Blocks.cpp $(SRC)/Blocks.h $(SRC)/CTile.h
CBomb.o: $(SRC)/CBomb.cpp $(SRC)/CBomb.h $(SRC)/CEntity.h $(SRC)/CTile.h $(SRC)/CCoord.h $(SRC)/LivingEntities.h $(SRC)/CWorld.h $(SRC)/Blocks.h $(SRC)/CPickup.h $(SRC)/CGame.h
CCoord.o: $(SRC)/CCoord.cpp $(SRC)/CCoord.h $(SRC)/CTile.h $(SRC)/CGame.h $(SRC)/CWorld.h $(SRC)/Blocks.h $(SRC)/CEntity.h $(SRC)/LivingEntities.h $(SRC)/CPickup.h
CEntity.o: $(SRC)/CEntity.cpp $(SRC)/CEntity.h $(SRC)/CTile.h $(SRC)/CCoord.h $(SRC)/CGame.h $(SRC)/CWorld.h $(SRC)/Blocks.h $(SRC)/LivingEntities.h $(SRC)/CPickup.h
CGame.o: $(SRC)/CGame.cpp $(SRC)/CGame.h $(SRC)/CWorld.h $(SRC)/Blocks.h $(SRC)/CTile.h $(SRC)/CCoord.h $(SRC)/CEntity.h $(SRC)/LivingEntities.h $(SRC)/CPickup.h $(SRC)/CNetwork.h
CNetwork.o: $(SRC)/CNetwork.cpp $(SRC)/CNetwork.h $(SRC)/CGame.h $(SRC)/CWorld.h $(SRC)/Blocks.h $(SRC)/CTile.h $(SRC)/CCoord.h $(SRC)/CEntity.h $(SRC)/LivingEntities.h $(SRC)/CPickup.h
CPickup.o: $(SRC)/CPickup.cpp $(SRC)/CPickup.h $(SRC)/CEntity.h $(SRC)/CTile.h $(SRC)/CCoord.h
CScreen.o: $(SRC)/CScreen.cpp $(SRC)/CScreen.h $(SRC)/CCoord.h
CTile.o: $(SRC)/CTile.cpp $(SRC)/CTile.h
CWorld.o: $(SRC)/CWorld.cpp $(SRC)/CWorld.h $(SRC)/Blocks.h $(SRC)/CTile.h $(SRC)/CCoord.h $(SRC)/CEntity.h $(SRC)/LivingEntities.h $(SRC)/CPickup.h $(SRC)/CGame.h $(SRC)/CBomb.h
LivingEntities.o: $(SRC)/LivingEntities.cpp $(SRC)/LivingEntities.h $(SRC)/CEntity.h $(SRC)/CTile.h $(SRC)/CCoord.h $(SRC)/CWorld.h $(SRC)/Blocks.h $(SRC)/CPickup.h $(SRC)/CGame.h $(SRC)/CBomb.h
main.o: $(SRC)/main.cpp $(SRC)/CGame.h $(SRC)/CWorld.h $(SRC)/Blocks.h $(SRC)/CTile.h $(SRC)/CCoord.h $(SRC)/CEntity.h $(SRC)/LivingEntities.h $(SRC)/CPickup.h $(SRC)/CNetwork.h
13 changes: 13 additions & 0 deletions examples/AIWars.bmap
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
XXXXXXXXXXXXXXX
XB OCOXOXOOC BX
X COOOXOXOXOC X
XCOXOOXOOOXOOCX
XOOOOOOOOOOOOOX
XCCCXX CXCCXXXX
XCCCC BXB CCCCX
XXXXCCXC XXCCCX
XOOOOOOOOOOOOOX
XCOOXOOOXOOXOCX
X COXOXOXOOOC X
XB COOXOXOOC BX
XXXXXXXXXXXXXXX
13 changes: 13 additions & 0 deletions examples/Monsters.bmap
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
XXXXXXXXXXXXXXX
XOOXOC C COXOOX
XOOXOX B XOXOOX
XOOOOOX XOOOOOX
XCXCOOOOOOOCXCX
Xm XCCXCCX mX
XXCCXOOmOOXCCXX
Xm XCCXCCX mX
XCXCOOOOOOOCxCX
XOOXOOX XOOXOOX
XOOXOX B XOXOOX
XOOOOC C COOOOX
XXXXXXXXXXXXXXX
1 change: 1 addition & 0 deletions prohlaseni.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Prohlasuji, ze jsem semestralni praci vytvoril sam, vlastnimi silami a ze jsem program odnikud nezkopiroval.
29 changes: 29 additions & 0 deletions src/Blocks.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#include "Blocks.h"
#include "CTile.h"

CBlock::CBlock() : m_destructible(false), m_passable(true), m_tile(CTile()) {
}

CBlock::CBlock(const CTile & tile, const bool destr, const bool pass) :
m_destructible(destr), m_passable(pass), m_tile(tile) {
}

void CBlock::Draw() const {
m_tile.Draw();
}

bool CBlock::IsDestructible() const {
return m_destructible;
}

bool CBlock::IsPassable() const {
return m_passable;
}

CBedrockBlock::CBedrockBlock(const CTile & tile) :
CBlock(tile, false, false) {
}

CCrateBlock::CCrateBlock(const CTile & tile) :
CBlock(tile, true, false) {
}
59 changes: 59 additions & 0 deletions src/Blocks.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#ifndef CBLOCK_H
#define CBLOCK_H

#include "CTile.h"

/**
* Represents a world's block
*/
class CBlock {
public:
/**
* Create a block with default tile
*/
CBlock();

/**
* Create a block with specified characteristics
* @param tile the tile this block is made of
* @param destructible should it be destructible?
* @param passable should it be passable (have collision)?
*/
CBlock(const CTile &, const bool = false, const bool = true);

/**
* Draws the block at current position
*/
void Draw() const;

/**
* Checks if the block is destructible
* @return true if destructible
*/
bool IsDestructible() const;

/**
* Checks if the block is passable
* @return true if passable
*/
bool IsPassable() const;

private:
bool m_destructible;
bool m_passable;
CTile m_tile;

};

class CBedrockBlock : public CBlock {
public:
CBedrockBlock(const CTile & = CTile(ACS_CKBOARD));
};

class CCrateBlock : public CBlock {
public:
CCrateBlock(const CTile & = CTile(ACS_ULCORNER, ACS_HLINE, ACS_URCORNER, ACS_LLCORNER, ACS_HLINE, ACS_LRCORNER));
};

#endif /* CBLOCK_H */

106 changes: 106 additions & 0 deletions src/CBomb.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
#include <algorithm>

#include "CBomb.h"
#include "CGame.h"

CBomb::CBomb(CBomberman* owner) :
CEntity(owner->GetPosition(), "Bomb", CTile('B', 'O', 'M', '<', '5', '>'), true), m_owner(owner), m_flameSize(owner->GetFlameSize()), m_detonationTime(owner->HasRemoteDetonation() ? 250 : 50) {
if (m_detonationTime > 99)
GetTile()[4] = '+';
}

bool CBomb::Tick() {
if (m_detonationTime > 200)
return false;

if (--m_detonationTime < 1) {
Detonate();
return true;
}

if (m_detonationTime % 10 == 0) {
GetTile()[4] = (m_detonationTime < 100) ? to_string(m_detonationTime / 10).at(0) : '+';
return true;
}

return false;
}

void CBomb::Detonate() {
m_detonationTime = 0;
CGame::PrintDebug("Bomb detonated!");
m_owner->AddBomb();

PlaceFlame(GetPosition());
CCoord c;
for (unsigned short int j = 0; j < 4; j++) {
c = GetPosition();
for (int i = 0; i < m_flameSize; i++) {
c.Move(static_cast<CCoord::direction> (j));
// chain detonation
shared_ptr<CBomb> bomb = NULL;
for (auto i = CGame::GetWorld().GetEntities().rbegin(); i != CGame::GetWorld().GetEntities().rend(); ++i) {
if ((bomb = dynamic_pointer_cast<CBomb>(*i)) && bomb->GetPosition() == c && bomb->m_detonationTime > 0) {
bomb->Detonate();
break;
}
}

const CBlock & b = CGame::GetWorld().GetBlock(c);
if (b.IsPassable())
PlaceFlame(c);
else if (b.IsDestructible()) {
PlaceFlame(c);
CGame::GetWorld().SetBlock(c, CBlock());
// chance to spawn a pickup
if (rand() % 100 > 62)
CGame::GetWorld().AddEntity(CWorld::entity_pointer(new CPickup(c)));
break;
} else {
break;
}
}
}

SetRemoveFlag();
}

void CBomb::PlaceFlame(const CCoord & loc) const {
CGame::GetWorld().SetBlock(loc, CBlock());
CGame::GetWorld().AddEntity(CWorld::entity_pointer(new CBombFlame(loc)));
CWorld::eliving_pointer e = NULL;

for (auto i = CGame::GetWorld().GetEntities().begin(); i != CGame::GetWorld().GetEntities().end(); ++i)
if ((e = dynamic_pointer_cast<CLivingEntity>(*i)) && e->GetPosition() == loc)
e->ModifyHealth(-1);
}

CBombFlame::CBombFlame(const CCoord & loc) :
CEntity(loc, "Flame", CTile('X'), false), m_extinguishTime(22) {
RandomizeAppearance();
}

CBomberman* CBomb::GetOwner() {
return m_owner;
}

/**
* @todo implement
*/
void CBombFlame::RandomizeAppearance() {
for (short unsigned int i = 0; i < 6; i++)
GetTile()[i] = (rand() % 2 == 0) ? 'X' : 'x';
}

bool CBombFlame::Tick() {
if (--m_extinguishTime < 1) {
SetRemoveFlag();
return true;
}

if (m_extinguishTime % 2 == 0) {
RandomizeAppearance();
return true;
}
return false;
}
86 changes: 86 additions & 0 deletions src/CBomb.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
#ifndef CBOMB_H
#define CBOMB_H

#include "CEntity.h"
#include "LivingEntities.h"
#include "CWorld.h"

class CBomb : public CEntity {
public:
/**
* Creates a bomb
*
* All data is taken from the owner
* @param pointer to this bomb's owner
*/
CBomb(CBomberman*);

/**
* @see CEntity::Tick
*/
bool Tick();

/**
* Returns pointer to this bomb's owner
*/
CBomberman* GetOwner();

/**
* Detonates the bomb spawning flames and removing destructible blocks
*/
void Detonate();

private:
/**
* Pointer to owner of this bomb
*/
CBomberman* m_owner;

/**
* Size (range) of flame that will be spawned on detonation
*/
CLivingEntity::stat_type m_flameSize;

/**
* Detonation time in ticks
*
* Bomb detonates when this reaches 0
* When over 200, the bomb does NOT detonate
*/
CLivingEntity::stat_type m_detonationTime;

/**
* Places a bomb flame in target location (and destroys anything that is currently standing there)
* @param loc location of the flame
*/
void PlaceFlame(const CCoord &) const;
};

class CBombFlame : public CEntity {
public:
/**
* Create a flame in location loc
* @param loc flame location
*/
CBombFlame(const CCoord &);

/**
* Processess tick
* @see CEntity::Tick
*/
virtual bool Tick();

private:
/**
* Time in ticks until the fire is extinguished
*/
CLivingEntity::stat_type m_extinguishTime;

/**
* Randomizes this flame's tile
*/
void RandomizeAppearance();
};

#endif /* CBOMB_H */

Loading

0 comments on commit 20b3e8f

Please sign in to comment.