[Orxonox-commit 7018] r11637 - in code/branches/Asteroid_HS17: data/levels data/levels/templates src/modules/asteroids2D
vyang at orxonox.net
vyang at orxonox.net
Mon Dec 4 16:17:43 CET 2017
Author: vyang
Date: 2017-12-04 16:17:43 +0100 (Mon, 04 Dec 2017)
New Revision: 11637
Modified:
code/branches/Asteroid_HS17/data/levels/Asteroids2D.oxw
code/branches/Asteroid_HS17/data/levels/templates/asteroidsAsteroids2D.oxt
code/branches/Asteroid_HS17/data/levels/templates/spaceshipAsteroids2D.oxt
code/branches/Asteroid_HS17/src/modules/asteroids2D/Asteroids2D.cc
code/branches/Asteroid_HS17/src/modules/asteroids2D/Asteroids2D.h
code/branches/Asteroid_HS17/src/modules/asteroids2D/Asteroids2DHUDinfo.cc
code/branches/Asteroid_HS17/src/modules/asteroids2D/Asteroids2DHUDinfo.h
code/branches/Asteroid_HS17/src/modules/asteroids2D/Asteroids2DShip.cc
code/branches/Asteroid_HS17/src/modules/asteroids2D/Asteroids2DShip.h
code/branches/Asteroid_HS17/src/modules/asteroids2D/Asteroids2DStone.cc
code/branches/Asteroid_HS17/src/modules/asteroids2D/Asteroids2DStone.h
Log:
Asteroiden werden generiert und bewegen sich, HUD muss noch angepasst werden, Punkte und Health und Leben anzeigen. Raumschiff kann noch nicht schiessen, evtl auch Schutzfunktion -> nachdem ein Leben verloren wurde 2s Immunitaet?
Modified: code/branches/Asteroid_HS17/data/levels/Asteroids2D.oxw
===================================================================
--- code/branches/Asteroid_HS17/data/levels/Asteroids2D.oxw 2017-12-04 15:15:59 UTC (rev 11636)
+++ code/branches/Asteroid_HS17/data/levels/Asteroids2D.oxw 2017-12-04 15:17:43 UTC (rev 11637)
@@ -16,7 +16,7 @@
include("templates/spaceshipAsteroids2D.oxt")
include("templates/enemyInvader.oxt")
include("overlays/Asteroids2DHUD.oxo")
- include("templates/asteroidsAsteroids2D.oxt)
+ include("templates/asteroidsAsteroids2D.oxt")
?>
<Level
@@ -75,22 +75,6 @@
end
?>-->
-
- <Asteroids2DStone
- collisionType = dynamic
- linearDamping = 0.8
- angularDamping = 1
- scale= 10
- enablecollisiondamage = true
- >
- <attached>
- <Model mass= 8000 mesh="ast1.mesh" />
- </attached>
- <collisionShapes>
- <SphereCollisionShape radius="10" />
- </collisionShapes>
- </Asteroids2DStone>
-
<Asteroids2DCenterPoint name=asteroids2Dcenter />
Modified: code/branches/Asteroid_HS17/data/levels/templates/asteroidsAsteroids2D.oxt
===================================================================
--- code/branches/Asteroid_HS17/data/levels/templates/asteroidsAsteroids2D.oxt 2017-12-04 15:15:59 UTC (rev 11636)
+++ code/branches/Asteroid_HS17/data/levels/templates/asteroidsAsteroids2D.oxt 2017-12-04 15:17:43 UTC (rev 11637)
@@ -1,8 +1,8 @@
<Template name = stone1>
<Asteroids2DStone
collisionType = dynamic
- linearDamping = 0.8
- angularDamping = 1
+ linearDamping = 0
+ angularDamping = 0
scale= 10
enablecollisiondamage = true
@@ -22,8 +22,8 @@
<Template name = stone2>
<Asteroids2DStone
collisionType = dynamic
- linearDamping = 0.8
- angularDamping = 1
+ linearDamping = 0
+ angularDamping = 0
scale= 20
enablecollisiondamage = true
@@ -32,7 +32,7 @@
initialhealth = 10
>
<attached>
- <Model mass= 8000 mesh="ast2.mesh" />
+ <Model mass= 8000 mesh="ast1.mesh" />
</attached>
<collisionShapes>
<SphereCollisionShape radius="20" />
@@ -43,8 +43,8 @@
<Template name = stone3>
<Asteroids2DStone
collisionType = dynamic
- linearDamping = 0.8
- angularDamping = 1
+ linearDamping = 0
+ angularDamping = 0
scale= 30
enablecollisiondamage = true
@@ -53,7 +53,7 @@
initialhealth = 10
>
<attached>
- <Model mass= 16000 mesh="ast3.mesh" />
+ <Model mass= 16000 mesh="ast1.mesh" />
</attached>
<collisionShapes>
<SphereCollisionShape radius="30" />
Modified: code/branches/Asteroid_HS17/data/levels/templates/spaceshipAsteroids2D.oxt
===================================================================
--- code/branches/Asteroid_HS17/data/levels/templates/spaceshipAsteroids2D.oxt 2017-12-04 15:15:59 UTC (rev 11636)
+++ code/branches/Asteroid_HS17/data/levels/templates/spaceshipAsteroids2D.oxt 2017-12-04 15:17:43 UTC (rev 11637)
@@ -6,9 +6,9 @@
spawnparticleduration = 3
explosionchunks = 4
- health = 40
- maxhealth = 40
- initialhealth = 40
+ health = 1000
+ maxhealth = 1000
+ initialhealth = 1000
shieldhealth = 20
initialshieldhealth = 20
Modified: code/branches/Asteroid_HS17/src/modules/asteroids2D/Asteroids2D.cc
===================================================================
--- code/branches/Asteroid_HS17/src/modules/asteroids2D/Asteroids2D.cc 2017-12-04 15:15:59 UTC (rev 11636)
+++ code/branches/Asteroid_HS17/src/modules/asteroids2D/Asteroids2D.cc 2017-12-04 15:17:43 UTC (rev 11637)
@@ -51,7 +51,7 @@
RegisterObject(Asteroids2D);
bEndGame = false;
- lives = 3;
+ lives = 5;
level = 1;
point = 0;
bShowLevel = false;
@@ -61,7 +61,7 @@
this->numberOfBots_ = 0; //sets number of default bots temporarly to 0
this->center_ = nullptr;
this->setHUDTemplate("Asteroids2DHUD");
- levelupTimer.setTimer(100.0f, true, createExecutor(createFunctor(&Asteroids2D::levelUp, this)));
+ levelupTimer.setTimer(60.0f, true, createExecutor(createFunctor(&Asteroids2D::levelUp, this)));
}
@@ -71,6 +71,8 @@
level++;
if (getPlayer() != nullptr)
{
+
+ //kann schoener gemacht werden
for (int i = 0; i < 7; i++)
{
WeakPtr<ExplosionPart> chunk5 = new ExplosionPart(this->center_->getContext());
@@ -83,10 +85,12 @@
}
}
- addPoints(multiplier * 42);
+ addPoints(multiplier * 20);
multiplier *= 2;
toggleShowLevel();
showLevelTimer.setTimer(1.0f, false, createExecutor(createFunctor(&Asteroids2D::toggleShowLevel, this)));
+
+
//Nach jedem Level Up werden mehr Steine gespawnt -> abhängig vom Schwierigkeitsgrad
for(int i = 0; i < level*2; i++){
spawnStone();
@@ -99,10 +103,12 @@
//Do this only for the first tick, generate 5 stones for the beginning
if(this->firstTick_)
{
+ getPlayer();
for(int i = 0; i < 5; ++i)
{
spawnStone();
}
+
this->firstTick_ = false;
}
@@ -111,8 +117,6 @@
void Asteroids2D::spawnStone()
{
- if (getPlayer() == nullptr)
- return;
Asteroids2DStone* newStone = new Asteroids2DStone(this->center_->getContext());
newStone->setAsteroids2DPlayer(player);
@@ -131,8 +135,6 @@
break;
}
-
-
}
Asteroids2DShip* Asteroids2D::getPlayer()
Modified: code/branches/Asteroid_HS17/src/modules/asteroids2D/Asteroids2D.h
===================================================================
--- code/branches/Asteroid_HS17/src/modules/asteroids2D/Asteroids2D.h 2017-12-04 15:15:59 UTC (rev 11636)
+++ code/branches/Asteroid_HS17/src/modules/asteroids2D/Asteroids2D.h 2017-12-04 15:17:43 UTC (rev 11637)
@@ -78,20 +78,24 @@
void levelUp();
+
+ //For HUD
int getLives(){return this->lives;}
int getLevel(){return this->level;}
int getPoints(){return this->point;}
int getMultiplier(){return this->multiplier;}
+ //Generate Stones
void spawnStone();
void setCenterpoint(Asteroids2DCenterPoint* center)
- { this->center_ = center; }
+ { this->center_ = center; }
+ void addPoints(int numPoints);
virtual void addBots(unsigned int amount) override{} //<! overwrite function in order to bypass the addbots command
// checks if multiplier should be reset.
void costLife();
+ Asteroids2DShip* getPlayer();
-
bool bEndGame;
bool bShowLevel;
int lives;
@@ -100,10 +104,9 @@
private:
- Asteroids2DShip* getPlayer();
+
WeakPtr<Asteroids2DShip> player;
void toggleShowLevel(){bShowLevel = !bShowLevel;}
- void addPoints(int numPoints);
WeakPtr<Asteroids2DCenterPoint> center_;
int level;
Modified: code/branches/Asteroid_HS17/src/modules/asteroids2D/Asteroids2DHUDinfo.cc
===================================================================
--- code/branches/Asteroid_HS17/src/modules/asteroids2D/Asteroids2DHUDinfo.cc 2017-12-04 15:15:59 UTC (rev 11636)
+++ code/branches/Asteroid_HS17/src/modules/asteroids2D/Asteroids2DHUDinfo.cc 2017-12-04 15:17:43 UTC (rev 11637)
@@ -40,7 +40,9 @@
RegisterObject(Asteroids2DHUDinfo);
this->Asteroids2DGame = nullptr;
+ this->Ship = nullptr;
this->bShowPoints_ = true;
+ this->bShowHealth_ = true;
}
void Asteroids2DHUDinfo::XMLPort(Element& xmlelement, XMLPort::Mode mode)
@@ -48,6 +50,7 @@
SUPER(Asteroids2DHUDinfo, XMLPort, xmlelement, mode);
XMLPortParam(Asteroids2DHUDinfo,"showPoints", setShowPoints, getShowPoints, xmlelement, mode).defaultValues(false);
+ XMLPortParam(Asteroids2DHUDinfo,"showHealth", setShowHealth, getShowHealth, xmlelement, mode).defaultValues(false);
}
void Asteroids2DHUDinfo::tick(float dt)
@@ -73,6 +76,25 @@
this->setCaption(points);
}
}
+
+ /*if(this->bShowHealth_)
+ {
+ const std::string& health = multi_cast<std::string>(this->Ship->getHealth());
+ if (this->Asteroids2DGame->lives <= 0)
+ {
+ setTextSize(0.2);
+ setPosition(Vector2(0.1, 0.02));
+ this->setCaption("Final score:\n" + health);
+ this->setColour(ColourValue(1, 0, 0, 1));
+ }
+ else
+ {
+ setTextSize(0.04);
+ setPosition(Vector2(0.2, 0.02));
+ this->setColour(ColourValue(1, 1, 1, 1));
+ this->setCaption(health);
+ }
+ }*/
}
void Asteroids2DHUDinfo::changedOwner()
@@ -79,9 +101,10 @@
{
SUPER(Asteroids2DHUDinfo, changedOwner);
- if (this->getOwner() && this->getOwner()->getGametype())
+ if (this->getOwner() && this->getOwner()->getGametype())//&& this->getOwner->getPlayer())
{
this->Asteroids2DGame = orxonox_cast<Asteroids2D*>(this->getOwner()->getGametype());
+ //this->Ship = orxonox_cast<Asteroids2DShip*>(this->getOwner()->getPlayer());
}
else
{
Modified: code/branches/Asteroid_HS17/src/modules/asteroids2D/Asteroids2DHUDinfo.h
===================================================================
--- code/branches/Asteroid_HS17/src/modules/asteroids2D/Asteroids2DHUDinfo.h 2017-12-04 15:15:59 UTC (rev 11636)
+++ code/branches/Asteroid_HS17/src/modules/asteroids2D/Asteroids2DHUDinfo.h 2017-12-04 15:17:43 UTC (rev 11637)
@@ -52,10 +52,17 @@
inline bool getShowPoints() const
{ return this->bShowPoints_; }
+ inline void setShowHealth(bool value)
+ { this->bShowHealth_ = value; }
+ inline bool getShowHealth() const
+ { return this->bShowHealth_; }
+
private:
Asteroids2D* Asteroids2DGame;
+ Asteroids2DShip* Ship;
bool bShowPoints_;
+ bool bShowHealth_;
};
}
#endif /* _Asteroids2DHUDinfo_H__ */
Modified: code/branches/Asteroid_HS17/src/modules/asteroids2D/Asteroids2DShip.cc
===================================================================
--- code/branches/Asteroid_HS17/src/modules/asteroids2D/Asteroids2DShip.cc 2017-12-04 15:15:59 UTC (rev 11636)
+++ code/branches/Asteroid_HS17/src/modules/asteroids2D/Asteroids2DShip.cc 2017-12-04 15:17:43 UTC (rev 11637)
@@ -36,6 +36,7 @@
*/
#include "Asteroids2DShip.h"
+#include "Asteroids2DStone.h"
#include "core/CoreIncludes.h"
namespace orxonox
@@ -88,22 +89,6 @@
getGame()->levelUp();
}
-/* void Asteroids2DShip::moveFrontBack(const Vector2& value)
- {
- //lastTimeFront = 0;
- //desiredVelocity.y = value.y * speed * 42;
- orxout() << "FrontBack" << endl;
- SUPER(Asteroids2DShip, moveFrontBack, value);
- }
-
- void Asteroids2DShip::moveRightLeft(const Vector2& value)
- {
- //lastTimeLeft = 0;
- //desiredVelocity.x = value.x * speed;
- orxout() << "RightLeft" << endl;
- SUPER(Asteroids2DShip, moveFrontBack, value);
- }
- */
void Asteroids2DShip::boost(bool bBoost)
{
//getGame()->bEndGame = bBoost;
@@ -111,9 +96,8 @@
inline bool Asteroids2DShip::collidesAgainst(WorldEntity* otherObject, const btCollisionShape* ownCollisionShape, btManifoldPoint& contactPoint)
{
-
removeHealth(100);
- this->death();
+ getGame()->addPoints(10);
return false;
}
Modified: code/branches/Asteroid_HS17/src/modules/asteroids2D/Asteroids2DShip.h
===================================================================
--- code/branches/Asteroid_HS17/src/modules/asteroids2D/Asteroids2DShip.h 2017-12-04 15:15:59 UTC (rev 11636)
+++ code/branches/Asteroid_HS17/src/modules/asteroids2D/Asteroids2DShip.h 2017-12-04 15:17:43 UTC (rev 11637)
@@ -56,10 +56,6 @@
virtual void tick(float dt) override;
- // overwrite for 2d movement
- //virtual void moveFrontBack(const Vector2& value) override;
- //virtual void moveRightLeft(const Vector2& value) override;
-
// Starts or stops fireing
virtual void boost(bool bBoost) override;
Modified: code/branches/Asteroid_HS17/src/modules/asteroids2D/Asteroids2DStone.cc
===================================================================
--- code/branches/Asteroid_HS17/src/modules/asteroids2D/Asteroids2DStone.cc 2017-12-04 15:15:59 UTC (rev 11636)
+++ code/branches/Asteroid_HS17/src/modules/asteroids2D/Asteroids2DStone.cc 2017-12-04 15:17:43 UTC (rev 11637)
@@ -43,13 +43,25 @@
Asteroids2DStone::Asteroids2DStone(Context* context) : Pawn(context)
{
RegisterObject(Asteroids2DStone);
- this->size = 1;
+ this->size = rand()%3+1;
this->width = 1043;
this->height = 646;
this->setPosition(randomPosition(this->width, this->height));
+ this->setCollisionTypeStr("dynamic");
this->setVelocity(randomVelocity(MAX_SPEED));
}
+ Asteroids2DStone::Asteroids2DStone(Context* c, int sze, Vector3 pos) : Pawn(c)
+ {
+ RegisterObject(Asteroids2DStone);
+ this->size = sze;
+ this->width = 1043;
+ this->height = 646;
+ this->setPosition(pos);
+ this->setCollisionTypeStr("dynamic");
+ this->setVelocity(randomVelocity(MAX_SPEED));
+ }
+
Vector3 Asteroids2DStone::randomPosition(float maxwidth, float maxheight)
{
Vector3 pos;
@@ -73,16 +85,52 @@
{
SUPER(Asteroids2DStone, tick, dt);
Vector3 pos = this->getPosition();
- if(pos.x >= width/2 || pos.x <= -width/2 || pos.z >= height/2 || pos.z <= -height/2)
+
+ if(pos.x >= width/2){
+ pos.x = -width/2;
+ }else if(pos.x <= -width/2){
+ pos.x = -width/2;
+ }else if(pos.z >= height/2){
+ pos.z = -height/2;
+ }else if(pos.z <= -height/2){
+ pos.z = -width/2;
+ }
+
+ this->setPosition(pos);
+
+ }
+
+ inline bool Asteroids2DStone::collidesAgainst(WorldEntity* otherObject, const btCollisionShape* ownCollisionShape, btManifoldPoint& contactPoint)
+ {
+ if(orxonox_cast<Asteroids2DShip*>(otherObject))
{
- Quaternion orientation = this->getOrientation();
- orientation.w -= 180;
- this->setOrientation(Vector3::UNIT_Y, Degree(orientation.w));
+ this->split();
}
+ return false;
+ }
+ void Asteroids2DStone::split()
+ {
+ if(size == 1)
+ {
+ this->death();
+
+ }else if(size == 2){
+ Asteroids2DStone* newStone1 = new Asteroids2DStone(this->getContext(), 1, this->getPosition());
+ newStone1->addTemplate("stone1");
+ Asteroids2DStone* newStone2 = new Asteroids2DStone(this->getContext(), 1, this->getPosition());
+ newStone2->addTemplate("stone1");
+ }else{
+ Asteroids2DStone* newStone1 = new Asteroids2DStone(this->getContext(), 2, this->getPosition());
+ newStone1->addTemplate("stone1");
+ Asteroids2DStone* newStone2 = new Asteroids2DStone(this->getContext(), 2, this->getPosition());
+ newStone2->addTemplate("stone1");
+ }
}
+
+
//Overload kill function to generate 2 asteriods
/*void Asteroids2DStone::kill()
{
Modified: code/branches/Asteroid_HS17/src/modules/asteroids2D/Asteroids2DStone.h
===================================================================
--- code/branches/Asteroid_HS17/src/modules/asteroids2D/Asteroids2DStone.h 2017-12-04 15:15:59 UTC (rev 11636)
+++ code/branches/Asteroid_HS17/src/modules/asteroids2D/Asteroids2DStone.h 2017-12-04 15:17:43 UTC (rev 11637)
@@ -47,17 +47,22 @@
{
public:
Asteroids2DStone(Context* context);
+ Asteroids2DStone(Context* c, int sze, Vector3 pos);
+
virtual void tick(float dt) override;
Vector3 randomPosition (float maxwidth, float maxheight);
Vector3 randomVelocity(float maxspeed);
void setAsteroids2DPlayer(Asteroids2DShip* player){this->player = player;};
virtual int getSize(){ return this->size;}
+ virtual bool collidesAgainst(WorldEntity* otherObject, const btCollisionShape* ownCollisionShape, btManifoldPoint& contactPoint) override;
+ virtual void split();
private:
WeakPtr<Asteroids2DShip> player;
int size; // three sizes, 3-> two 2s, 2-> two 1s, 1-> die
float width, height; //field
- float MAX_SPEED = 500;
+ float MAX_SPEED = 100;
+ float delta = 5;
};
}
More information about the Orxonox-commit
mailing list