Skip to content

Commit

Permalink
ImageKeys do not have to be sent
Browse files Browse the repository at this point in the history
  • Loading branch information
opatut committed Apr 16, 2010
1 parent 6d388fc commit f296d18
Show file tree
Hide file tree
Showing 10 changed files with 6 additions and 21 deletions.
1 change: 1 addition & 0 deletions src/entity/Building.cpp
Expand Up @@ -2,6 +2,7 @@
#include <iostream>

Building::Building() {
mImageKey = "building";
mType = ENTITY_TYPE_BUILDING;
mAnimationFPS = 1;
mAnimationIndex = 0;
Expand Down
1 change: 1 addition & 0 deletions src/entity/CannonTurret.cpp
@@ -1,6 +1,7 @@
#include "CannonTurret.hpp"

CannonTurret::CannonTurret() {
mImageKey = "turret1";
mAnimationFPS = 1;
mAnimationIndex = 0;
mPosX = 0;
Expand Down
9 changes: 0 additions & 9 deletions src/entity/IEntity.cpp
Expand Up @@ -72,13 +72,6 @@ void IEntity::SetAnimationFPS(sf::Uint16 FPS){
mAnimationFPS = FPS;
}

std::string IEntity::GetImageKey()const {
return mImageKey;
}
void IEntity::SetImageKey(const std::string& key){
mImageKey = key;
}

void IEntity::UpdateAnimation(float blocksize) {
// Get Length of Animation in Frames
sf::Uint16 framesPerLoop = mSprite.GetImage()->GetWidth() / (mDimX*blocksize);
Expand All @@ -103,7 +96,6 @@ void IEntity::UpdateAnimation(float blocksize) {
}

void IEntity::SerializeIntoPacket(sf::Packet& packet) const {
packet << mImageKey;
packet << mAnimationIndex;
packet << mAnimationFPS;
packet << mLifeTime;
Expand All @@ -116,7 +108,6 @@ void IEntity::SerializeIntoPacket(sf::Packet& packet) const {
}

void IEntity::SerializeFromPacket(sf::Packet& packet) {
packet >> mImageKey;
packet >> mAnimationIndex;
packet >> mAnimationFPS;
packet >> mLifeTime;
Expand Down
6 changes: 1 addition & 5 deletions src/entity/IEntity.hpp
Expand Up @@ -44,9 +44,6 @@ class IEntity : boost::noncopyable {
sf::Uint16 GetAnimationFPS() const;
void SetAnimationFPS(sf::Uint16 FPS);

std::string GetImageKey() const;
void SetImageKey(const std::string& key);

void SerializeIntoPacket(sf::Packet& packet) const;
void SerializeFromPacket(sf::Packet& packet);

Expand All @@ -56,12 +53,11 @@ class IEntity : boost::noncopyable {
protected:
sf::Uint16 mType;

std::string mImageKey;

static const sf::Uint16 mCost = 0;
sf::Sprite mSprite;
sf::Uint16 mAnimationIndex;
sf::Uint16 mAnimationFPS;
std::string mImageKey;
float mLifeTime;
float mPosX;
float mPosY;
Expand Down
1 change: 1 addition & 0 deletions src/entity/PowerGenerator.cpp
Expand Up @@ -2,6 +2,7 @@
#include <iostream>

PowerGenerator::PowerGenerator() {
mImageKey = "generator";
mAnimationFPS = 3;
mAnimationIndex = 0;
mPosX = 0;
Expand Down
1 change: 0 additions & 1 deletion src/entity/PowerGenerator.hpp
Expand Up @@ -15,7 +15,6 @@ class PowerGenerator : public IEntity{
private:
static const sf::Uint16 mCost = 1000;
static const sf::Uint16 mPower = 200;

};

#endif
1 change: 1 addition & 0 deletions src/entity/RocketLauncher.cpp
@@ -1,6 +1,7 @@
#include "RocketLauncher.hpp"

RocketLauncher::RocketLauncher() {
mImageKey = "turret2";
mAnimationFPS = 1;
mAnimationIndex = 0;
mPosX = 0;
Expand Down
1 change: 0 additions & 1 deletion src/server/server.cpp
Expand Up @@ -61,7 +61,6 @@ void ServerApp::HandleRequest() {
if (sqy < 10 and !mWorld.BlockExistsAt(sqx,sqy) and (sqy==9 or mWorld.BlockExistsAt(sqx,sqy+1))) {
// Create entity
Building* b = new Building();
b->SetImageKey("building");
b->SetPosition(sf::Vector2f(sqx, sqy));
b->SetDimension(sf::Vector2f(1,1));
mWorld.AddEntity(b);
Expand Down
4 changes: 0 additions & 4 deletions src/states/playstate.cpp
Expand Up @@ -358,7 +358,6 @@ void PlayState::PlaceBlock(int x, int y) {
} else {
//if (m_blocks[x][y+1]!=0 && m_blocks[x][y+1]->m_type != BLOCKTYPE_EMPTY) {
Building* b = new Building();
b->SetImageKey("building");
b->SetPosition(sf::Vector2f(x,y));
b->SetDimension(sf::Vector2f(1,1));
mGameEngine->GetWorld().AddEntity(b);
Expand All @@ -376,7 +375,6 @@ void PlayState::PlaceCannonTurret(int x, int y) {
std::cout << "Cannot place the block right there!";
} else {
CannonTurret* c = new CannonTurret();
c->SetImageKey("turret1");
c->SetPosition(sf::Vector2f(x, y));
c->SetDimension(sf::Vector2f(1,1));
mGameEngine->GetWorld().AddEntity(c);
Expand All @@ -388,7 +386,6 @@ void PlayState::PlaceRocketLauncher(int x, int y) {
std::cout << "Cannot place the block right there!";
} else {
RocketLauncher* c = new RocketLauncher();
c->SetImageKey("turret2");
c->SetPosition(sf::Vector2f(x, y));
c->SetDimension(sf::Vector2f(1,1));
mGameEngine->GetWorld().AddEntity(c);
Expand All @@ -400,7 +397,6 @@ void PlayState::PlacePowerGenerator(sf::Uint16 x, sf::Uint16 y) {
std::cout << "Cannot place the block right there!";
} else {
PowerGenerator* c = new PowerGenerator();
c->SetImageKey("generator");
c->SetPosition(sf::Vector2f(x, y));
c->SetDimension(sf::Vector2f(0.5, 0.5));
mGameEngine->GetWorld().AddEntity(c);
Expand Down
2 changes: 1 addition & 1 deletion src/world/World.cpp
Expand Up @@ -38,7 +38,7 @@ void World::Draw(sf::RenderTarget& target, float blocksize, sf::Vector2f offset)

bool World::BlockExistsAt(float x, float y) const {
for ( EntityMap::const_iterator i = mEntities.begin(); i!=mEntities.end(); ++i ){
if (i->second->GetPosition().x == x and i->second->GetPosition().y == y and i->second->GetImageKey()=="building")
if (i->second->GetPosition().x == x and i->second->GetPosition().y == y and i->second->GetType()==ENTITY_TYPE_BUILDING)
return true;
}
return false;
Expand Down

0 comments on commit f296d18

Please sign in to comment.