[Orxonox-commit 6908] r11529 - in code/branches/FlappyOrx_HS17: data/levels data/levels/templates src/modules/flappyorx
pascscha at orxonox.net
pascscha at orxonox.net
Mon Nov 6 12:52:38 CET 2017
Author: pascscha
Date: 2017-11-06 12:52:38 +0100 (Mon, 06 Nov 2017)
New Revision: 11529
Modified:
code/branches/FlappyOrx_HS17/data/levels/FlappyOrx.oxw
code/branches/FlappyOrx_HS17/data/levels/templates/spaceshipFlappyOrx.oxt
code/branches/FlappyOrx_HS17/src/modules/flappyorx/CMakeLists.txt
code/branches/FlappyOrx_HS17/src/modules/flappyorx/FlappyOrx.cc
code/branches/FlappyOrx_HS17/src/modules/flappyorx/FlappyOrx.h
code/branches/FlappyOrx_HS17/src/modules/flappyorx/FlappyOrxShip.cc
Log:
Asteroid Clusters
Modified: code/branches/FlappyOrx_HS17/data/levels/FlappyOrx.oxw
===================================================================
--- code/branches/FlappyOrx_HS17/data/levels/FlappyOrx.oxw 2017-11-04 16:04:59 UTC (rev 11528)
+++ code/branches/FlappyOrx_HS17/data/levels/FlappyOrx.oxw 2017-11-06 11:52:38 UTC (rev 11529)
@@ -47,6 +47,38 @@
<FlappyOrxCenterPoint name=flappyorxcenter />
+
+
+ <?lua
+ for i = 1, 6, 1 do
+ for j = 3, 12,3 do
+ ?>
+
+ <Template name=Asteroid<?lua print(j) ?>_<?lua print(i) ?>>
+ <MovableEntity
+ collisionType = dynamic
+ linearDamping = 0.8
+ angularDamping = 0
+ scale = "<?lua print(j) ?>"
+ collisiondamage = 10000
+ enablecollisiondamage = true
+ >
+
+ <attached>
+ <Model mass="1000" mesh="ast<?lua print(i) ?>.mesh" />
+ </attached>
+ <collisionShapes>
+ <SphereCollisionShape radius="<?lua print(j) ?>" />
+ </collisionShapes>
+ </MovableEntity>
+ </Template>
+
+ <?lua
+ end
+ end
+ ?>
+
+ <!--
<?lua
for i = 1, 30, 1 do
j = math.random()
@@ -91,6 +123,8 @@
<?lua
end
?>
+ -->
+
+
</Scene>
-</Level>
-
+</Level>
\ No newline at end of file
Modified: code/branches/FlappyOrx_HS17/data/levels/templates/spaceshipFlappyOrx.oxt
===================================================================
--- code/branches/FlappyOrx_HS17/data/levels/templates/spaceshipFlappyOrx.oxt 2017-11-04 16:04:59 UTC (rev 11528)
+++ code/branches/FlappyOrx_HS17/data/levels/templates/spaceshipFlappyOrx.oxt 2017-11-06 11:52:38 UTC (rev 11529)
@@ -42,7 +42,7 @@
speed = 100
UpwardThrust = 200
- gravity = 18
+ gravity = 500
>
<engines>
<MultiStateEngine position=" 7.6, 0, 6" template=spaceshipFlappyOrxengine />
Modified: code/branches/FlappyOrx_HS17/src/modules/flappyorx/CMakeLists.txt
===================================================================
--- code/branches/FlappyOrx_HS17/src/modules/flappyorx/CMakeLists.txt 2017-11-04 16:04:59 UTC (rev 11528)
+++ code/branches/FlappyOrx_HS17/src/modules/flappyorx/CMakeLists.txt 2017-11-06 11:52:38 UTC (rev 11529)
@@ -6,6 +6,7 @@
FlappyOrxWeapon.cc
FlappyOrxWeaponEnemy.cc
FlappyOrxHUDinfo.cc
+ FlappyOrxAsteroid.cc
END_BUILD_UNIT
)
Modified: code/branches/FlappyOrx_HS17/src/modules/flappyorx/FlappyOrx.cc
===================================================================
--- code/branches/FlappyOrx_HS17/src/modules/flappyorx/FlappyOrx.cc 2017-11-04 16:04:59 UTC (rev 11528)
+++ code/branches/FlappyOrx_HS17/src/modules/flappyorx/FlappyOrx.cc 2017-11-06 11:52:38 UTC (rev 11529)
@@ -46,6 +46,7 @@
#include "FlappyOrxCenterPoint.h"
#include "FlappyOrxShip.h"
+#include "FlappyOrxAsteroid.h"
#include "core/command/ConsoleCommand.h"
#include "worldentities/ExplosionPart.h"
@@ -66,34 +67,27 @@
bShowLevel = false;
multiplier = 1;
b_combo = false;
-
+ this->spawnDistance=300;
+ this->tubeOffsetX=500;
this->setHUDTemplate("FlappyOrxHUD");
}
+ void FlappyOrx::updatePlayerPos(int x){
+ if(this->tubes.size()==0||x-this->tubes.back()-tubeOffsetX>spawnDistance){
+ spawnTube();
+ this->tubes.push(x+tubeOffsetX);
+ }
+ if(this->tubes.size()!=0&&x>this->tubes.front()){
+ this->tubes.pop();
+ levelUp();
+ }
+ }
+
void FlappyOrx::levelUp()
{
level++;
- if (getPlayer() != nullptr)
- {
- for (int i = 0; i < 7; i++)
- {
-
- WeakPtr<ExplosionPart> chunk5 = new ExplosionPart(this->center_->getContext());
- chunk5->setPosition(this->center_->getPosition());
- chunk5->setVelocity(Vector3(1000, 0, 0)); //player->getVelocity()
- chunk5->setScale(10);
- chunk5->setEffect1("Orxonox/explosion2b");
- chunk5->setEffect2("Orxonox/smoke6");
- chunk5->setMinSpeed(0);
- chunk5->setMaxSpeed(0);
- chunk5->Explode();
-
- }
- }
- addPoints(multiplier * 42);
- multiplier *= 2;
- toggleShowLevel();
- showLevelTimer.setTimer(1.0f, false, createExecutor(createFunctor(&FlappyOrx::toggleShowLevel, this)));
+ //toggleShowLevel();
+ //showLevelTimer.setTimer(3.0f, false, createExecutor(createFunctor(&FlappyOrx::toggleShowLevel, this)));
}
FlappyOrxShip* FlappyOrx::getPlayer()
@@ -107,8 +101,65 @@
return player;
}
+ void FlappyOrx::spawnTube()
+ {
+ int space = 90;
+ int height = (float(rand())/RAND_MAX-0.5)*(280-space);
+
+ if (getPlayer() == nullptr)
+ return;
+ Vector3 pos = player->getPosition();
+ asteroidField(pos.x+tubeOffsetX,height-space/2,0.8);
+ asteroidField(pos.x+tubeOffsetX,height+space/2,-0.8);
+ }
+
+ void FlappyOrx::asteroidField(int x, int y, float slope){
+ int r = 20;
+ int noadd = 0;
+
+ ClearAsteroids();
+ Circle newAsteroid = Circle();
+ while(r>0){
+ if(slope>0)
+ newAsteroid.y=float(rand())/RAND_MAX*(150+y)-150;
+ else
+ newAsteroid.y=float(rand())/RAND_MAX*(150-y)+y;
+
+ newAsteroid.x=x+(float(rand())/RAND_MAX-0.5)*(y-newAsteroid.y)/slope;
+ newAsteroid.r=r;
+
+ int i = addIfPossible(newAsteroid);
+ if(i==0)
+ noadd++;
+ else if(i==2)
+ r=0;
+ if(noadd>=5){
+ noadd=0;
+ r-=5;
+ }
+ }
+ }
+
+ void FlappyOrx::createAsteroid(Circle &c){
+ orxout() << "created Asteroid at x="<<c.x<<" y="<<c.y << std::endl;
+ MovableEntity* newAsteroid = new MovableEntity(this->center_->getContext());
+ if(c.r<=5)
+ newAsteroid->addTemplate(Asteroid5[rand()%6]);
+ else if(c.r<=10)
+ newAsteroid->addTemplate(Asteroid10[rand()%6]);
+ else if(c.r<=15)
+ newAsteroid->addTemplate(Asteroid15[rand()%6]);
+ else
+ newAsteroid->addTemplate(Asteroid20[rand()%6]);
+
+ newAsteroid->setPosition(Vector3(c.x, 0, c.y));
+ newAsteroid->setOrientation(Vector3::UNIT_Z, Degree(rand()%360));
+ newAsteroid->setOrientation(Vector3::UNIT_Y, Degree(rand()%360));
+
+ }
+
void FlappyOrx::setCenterpoint(FlappyOrxCenterPoint* center)
{
this->center_ = center;
Modified: code/branches/FlappyOrx_HS17/src/modules/flappyorx/FlappyOrx.h
===================================================================
--- code/branches/FlappyOrx_HS17/src/modules/flappyorx/FlappyOrx.h 2017-11-04 16:04:59 UTC (rev 11528)
+++ code/branches/FlappyOrx_HS17/src/modules/flappyorx/FlappyOrx.h 2017-11-06 11:52:38 UTC (rev 11529)
@@ -40,9 +40,26 @@
#include "gametypes/Deathmatch.h"
#include "tools/Timer.h"
+
namespace orxonox
{
+ struct Circle{
+ int r;
+ int x;
+ int y;
+ Circle(int new_r, int new_x, int new_y){
+ r=new_r;
+ x=new_x;
+ y=new_y;
+ }
+ Circle(){
+ r=0;
+ x=0;
+ y=0;
+ }
+ };
+
class _FlappyOrxExport FlappyOrx : public Deathmatch
{
public:
@@ -52,8 +69,11 @@
virtual void end() override;
virtual void addBots(unsigned int amount) override{} //<! overwrite function in order to bypass the addbots command
- void spawnEnemy();
-
+ void updatePlayerPos(int x);
+ void createAsteroid(Circle &c);
+ void asteroidField(int x, int y, float slope);
+ void spawnTube();
+
void setCenterpoint(FlappyOrxCenterPoint* center);
int getLives(){return this->lives;}
@@ -70,8 +90,50 @@
int multiplier;
bool bEndGame;
bool bShowLevel;
+ std::queue<int> tubes;
+ int spawnDistance;
+ int tubeOffsetX;
private:
void toggleShowLevel(){bShowLevel = !bShowLevel;}
+
+ const static int nAst = 7;
+ Circle Asteroids[nAst];
+
+ void ClearAsteroids(){
+ for(int i = 0; i<this->nAst; i++){
+ Asteroids[i].r=0;
+ }
+ }
+
+
+ bool Collision(Circle &c1, Circle &c2){
+ if(c1.r==0 || c2.r==0)
+ return false;
+ int x = c1.x - c2.x;
+ int y = c1.y - c2.y;
+ int r = c1.r + c2.r;
+
+ return x*x+y*y<r*r*1.5;
+ }
+
+ int addIfPossible(Circle c){
+ int i;
+ for(i=0; i<this->nAst && this->Asteroids[i].r!=0;i++){
+ if(Collision(c,this->Asteroids[i])){
+ return 0;
+ }
+ }
+ if(i==nAst)
+ return 2;
+ this->Asteroids[i].x=c.x;
+ this->Asteroids[i].y=c.y;
+ this->Asteroids[i].r=c.r;
+ createAsteroid(c);
+ return 1;
+ }
+
+
+
FlappyOrxShip* getPlayer();
WeakPtr<FlappyOrxCenterPoint> center_;
WeakPtr<FlappyOrxShip> player;
@@ -83,6 +145,13 @@
int level;
int point;
bool b_combo;
+ std::string Asteroid5[6] = {"Asteroid3_1","Asteroid3_2","Asteroid3_3","Asteroid3_4","Asteroid3_5","Asteroid3_6"};
+ std::string Asteroid10[6] = {"Asteroid6_1","Asteroid6_2","Asteroid6_3","Asteroid6_4","Asteroid6_5","Asteroid6_6"};
+ std::string Asteroid15[6] = {"Asteroid9_1","Asteroid9_2","Asteroid9_3","Asteroid9_4","Asteroid9_5","Asteroid9_6"};
+ std::string Asteroid20[6] = {"Asteroid12_1","Asteroid12_2","Asteroid12_3","Asteroid12_4","Asteroid12_5","Asteroid12_6"};
+
+
+
};
}
Modified: code/branches/FlappyOrx_HS17/src/modules/flappyorx/FlappyOrxShip.cc
===================================================================
--- code/branches/FlappyOrx_HS17/src/modules/flappyorx/FlappyOrxShip.cc 2017-11-04 16:04:59 UTC (rev 11528)
+++ code/branches/FlappyOrx_HS17/src/modules/flappyorx/FlappyOrxShip.cc 2017-11-06 11:52:38 UTC (rev 11529)
@@ -72,15 +72,20 @@
getGame()->end();
}
Vector3 pos = getPosition();
- velocity.y += gravity;
+
+ getGame()->updatePlayerPos(pos.x);
+
+
+ velocity.y += gravity*dt;
if(isFlapping){
isFlapping = false;
- velocity.y = -UpwardThrust;
+ if(pos.z > -150)
+ velocity.y = -UpwardThrust;
}
pos += Vector3(speed + velocity.x, 0, velocity.y) * dt;
- if(pos.z < -150 || pos.z > 150){
+ if(pos.z > 150){
pos.z=0;
velocity.y = 0;
}
@@ -93,6 +98,7 @@
return;
}
+
// Camera
Camera* camera = this->getCamera();
if (camera != nullptr)
@@ -101,6 +107,7 @@
camera->setOrientation(Vector3::UNIT_Z, Degree(90));
}
+
setPosition(pos);
setOrientation(Vector3::UNIT_Y, Degree(270));
More information about the Orxonox-commit
mailing list