Permalink
Browse files

Merge remote-tracking branch 'origin/master'

Conflicts:
	src/Revival/Player.cpp
	src/Revival/Player.h
  • Loading branch information...
2 parents 103820e + ed512ec commit 5f72294c8a4c6e7930af3ecc5ce4447acc128ac3 @dead-pixel-alex dead-pixel-alex committed Jan 28, 2012
View
@@ -0,0 +1,9 @@
+#pragma once
+
+#include "SpriteBase.h"
+
+class Map : public SpriteBase{
+public:
+ Map() {_solid=false;}
+ virtual bool IsKillZone(CorePosition pos)=0;
+};
View
@@ -1,15 +1,21 @@
#include "Universe.h"
#include "Powerup.h"
+#include "Player.h"
-Powerup::Powerup()
+Powerup::Powerup(CorePosition pos, PowerupType::Enum type)
{
texture = gEngine->CreateTexture(CoreFunctions::GetAppPath() + "/data/power-ups/icon-freeze.png");
texture->Load();
_size=CoreSize(60,60);
- _pos=CorePosition(720,1080);
+ _pos=pos;
_visible = true;
}
void Powerup::Update(float)
{
+ SpriteSet cols=CollisionDetect();
+ Player *player=dynamic_cast<Player*>(Universe::Instance()->_focus);
+ if(cols.count(player)){
+ Universe::Instance()->RemoveAndDeleteSprite(this);
+ }
}
View
@@ -2,9 +2,15 @@
#include "SpriteBase.h"
+namespace PowerupType{
+ enum Enum{
+ Freeze
+ };
+}
+
class Powerup : public SpriteBase
{
public:
- Powerup();
+ Powerup(CorePosition pos, PowerupType::Enum type);
void Update(float fTime);
};
@@ -25,10 +25,14 @@ CoreColor SpriteBase::GetPixel(CorePosition pos){
return gEngine->getPixelColor(texture->GetSurface(), pos.GetX(), pos.GetY());
}
-bool SpriteBase::GetVisible(){
+bool SpriteBase::IsVisible(){
return _visible;
}
+bool SpriteBase::IsSolid(){
+ return _solid;
+}
+
SpriteSet SpriteBase::CollisionDetect(){
return Universe::Instance()->CollisionDetect(_pos, _size, this);
}
View
@@ -21,6 +21,7 @@ class SpriteBase{
int _deltaAngle;
bool _visible;
+ bool _solid;
CoreGraphics *gEngine;
OpenGLTexture *texture;
@@ -41,5 +42,6 @@ class SpriteBase{
CorePosition GetPosition() {return _pos;}
CoreSize GetSize() {return _size;}
- bool GetVisible();
+ bool IsVisible();
+ bool IsSolid();
};
View
@@ -28,14 +28,18 @@ TestMap::TestMap()
lava3 = gEngine->CreateTexture(CoreFunctions::GetAppPath() + "/data/Level1/Lava3.png");
lava3->Load();
+ killzone = gEngine->CreateTexture(CoreFunctions::GetAppPath() + "/data/Level1/KillZone.png");
+ killzone->Load();
+
_size=CoreSize(3072,1536);
_pos=CorePosition(0,0);
_backgroundmistPos=CorePosition(0,0);
_foregroundmistPos=CorePosition(0,0);
- _pwrUp = new Powerup();
+ _pwrUp = new Powerup(CorePosition(800,1080), PowerupType::Freeze);
+ Universe::Instance()->AddSprite(_pwrUp);
_visible=true;
lastMistScroll = 0.0F;
@@ -90,10 +94,14 @@ void TestMap::Draw()
color.b = 0;
this->gEngine->DrawString(CoreFunctions::addIntToString("PosY: ", _pos.GetY()),textPos,color);
- _pwrUp->Draw();
+ //_pwrUp->Draw();
}
}
CoreColor TestMap::GetPixel(CorePosition pos){
return gEngine->getPixelColor(collision->GetSurface(), pos.GetX(), pos.GetY());
+}
+
+bool TestMap::IsKillZone(CorePosition pos){
+ return gEngine->getPixelColor(killzone->GetSurface(), pos.GetX(), pos.GetY()).rgba() == 0xff0000ff;
}
View
@@ -2,14 +2,16 @@
#include "SpriteBase.h"
#include "Powerup.h"
+#include "Map.h"
-class TestMap : public SpriteBase {
+class TestMap : public Map {
public:
TestMap();
void Update(float);
void Draw();
CoreColor GetPixel(CorePosition pos);
+ bool IsKillZone(CorePosition pos);
private:
float lastMistScroll;
float lastLavaChange;
@@ -25,6 +27,8 @@ class TestMap : public SpriteBase {
OpenGLTexture * lava2;
OpenGLTexture * lava3;
+ OpenGLTexture * killzone;
+
Powerup * _pwrUp;
int lavaStep;
View
@@ -2,6 +2,7 @@
#include "TestSprite.h"
#include "TestMap.h"
#include "Player.h"
+#include <iostream>
SDL_bool SDL_HasIntersection(const SDL_Rect * A, const SDL_Rect * B)
{
@@ -68,6 +69,12 @@ void Universe::Update(float fTime)
SpriteBase *ptr = *i;
ptr->Update(fTime);
}
+
+ for(SpriteItr i=_deletes.begin(); i!=_deletes.end(); ++i){
+ _sprites.erase(*i);
+ delete *i;
+ }
+ _deletes.clear();
}
void Universe::Draw()
@@ -100,7 +107,7 @@ SpriteSet Universe::CollisionDetect(CorePosition pos, CoreSize size, SpriteBase
for(SpriteItr i=_sprites.begin();i!=_sprites.end();++i){
if(*i!=ignore){
SpriteBase *sprite=*i;
- if(sprite->GetVisible()){
+ if(sprite->IsVisible() && sprite->IsSolid()){
SDL_Rect secRect;
secRect.x=sprite->GetPosition().GetX();
secRect.y=sprite->GetPosition().GetY();
@@ -113,4 +120,8 @@ SpriteSet Universe::CollisionDetect(CorePosition pos, CoreSize size, SpriteBase
}
}
return ret;
+}
+
+void Universe::RemoveAndDeleteSprite(SpriteBase *sprite){
+ _deletes.insert(sprite);
}
View
@@ -2,6 +2,7 @@
#include "../CoreEngine/CoreGraphics.h"
#include "SpriteBase.h"
+#include "Map.h"
#include <set>
class CoreGraphics;
@@ -22,7 +23,7 @@ class Universe {
bool IsKeyDown(SDLKey key);
- SpriteBase *_currentMap;
+ Map *_currentMap;
SpriteBase *_focus;
CorePosition _worldOffset;
@@ -36,5 +37,6 @@ class Universe {
float rotation;
SpriteSet _sprites;
+ SpriteSet _deletes;
KeySet _keys;
};

0 comments on commit 5f72294

Please sign in to comment.