[Orxonox-commit 6934] r11555 - in code/branches/Asteroid_HS17: data/levels data/levels/templates src/modules/asteroids
vyang at orxonox.net
vyang at orxonox.net
Mon Nov 13 16:05:34 CET 2017
Author: vyang
Date: 2017-11-13 16:05:34 +0100 (Mon, 13 Nov 2017)
New Revision: 11555
Modified:
code/branches/Asteroid_HS17/data/levels/Asteroids.oxw
code/branches/Asteroid_HS17/data/levels/templates/spaceshipAsteroids.oxt
code/branches/Asteroid_HS17/src/modules/asteroids/Asteroids.cc
code/branches/Asteroid_HS17/src/modules/asteroids/Asteroids.h
code/branches/Asteroid_HS17/src/modules/asteroids/AsteroidsShip.cc
code/branches/Asteroid_HS17/src/modules/asteroids/AsteroidsShip.h
code/branches/Asteroid_HS17/src/modules/asteroids/AsteroidsStone.cc
code/branches/Asteroid_HS17/src/modules/asteroids/AsteroidsStone.h
Log:
Level file: korrekte Kameraposition, Raumschiff bewegt sich nicht, schiesst aber -> wird AsteroidsShip ueberhaupt geladen? AsteroidsShip: neue Steuerung (vgl Jump, Rotation muss noch angepasst werden)
Modified: code/branches/Asteroid_HS17/data/levels/Asteroids.oxw
===================================================================
--- code/branches/Asteroid_HS17/data/levels/Asteroids.oxw 2017-11-13 14:44:45 UTC (rev 11554)
+++ code/branches/Asteroid_HS17/data/levels/Asteroids.oxw 2017-11-13 15:05:34 UTC (rev 11555)
@@ -6,35 +6,21 @@
/>
+<!--wird immer gebraucht-->
<?lua
include("stats.oxo")
include("templates/lodInformation.oxt")
?>
+
<?lua
- include("templates/spaceshipAssff2.oxt")
- include("templates/spaceshipPirate.oxt")
include("templates/spaceshipAsteroids.oxt")
- include("overlays/InvaderHUD.oxo")
?>
-<Template name=asteroidsshipcamera defaults=0>
- <AsteroidsShip>
- <camerapositions>
- <CameraPosition position="55,75,200" absolute=true />
- <!--CameraPosition position="0,50,160" drag=true mouselook=true />
- <CameraPosition position="0,50,0" pitch=-90 drag=true mouselook=true /-->
- </camerapositions>
- </AsteroidsShip>
-</Template>
+<!--Templates schreiben oder von spaceship kopieren-->
-<Template name=asteroidsship>
- <AsteroidsShip camerapositiontemplate=asteroidsshipcamera>
- </AsteroidsShip>
-</Template>
-
<Level
- plugins = asteroids
+ plugin = asteroids
gametype = Asteroids
>
<templates>
@@ -43,20 +29,31 @@
<?lua include("includes/notifications.oxi") ?>
<!-- ambientlight = "0.8, 0.8, 0.8"
- skybox = "Orxonox/Starbox" -->
+ skybox = "Orxonox/Starbox"
+ WorldRange lieber im src einschraenken-->
<Scene
ambientlight = "0.8, 0.7, 0.4"
skybox = "Orxonox/skyBoxBasic"
+ negativeWorldRange = "-100000, -100000, -100000"
+ positiveWorldRange = " 100000, 100000, 100000"
>
+
+ <WorldAmbientSound
+ source="Earth.ogg"
+ looping="true"
+ playOnLoad="true"
+ />
<!-- <Light type=directional position="0,0,0" direction="0.253, 0.593, -0.765" diffuse="1.0, 0.9, 0.9, 1.0" specular="1.0, 0.9, 0.9, 1.0"/> -->
<Light type=directional position="1100, 11000, -7000" lookat="0, 0, 0" diffuse="1.0, 0.9, 0.9, 1.0" specular="1.0, 0.9, 0.9, 1.0" />
- <SpawnPoint team=0 position="-200,0,0" lookat="0,0,0" spawnclass=AsteroidsShip pawndesign=asteroidsship />
+ <SpawnPoint team=0 position="0,0,0" lookat="0,0,0" spawnclass=AsteroidsShip pawndesign=spaceshipasteroids/>
+
<DistanceTrigger name="start" position="-200,0,0" target="Pawn" distance=10 stayActive="true" delay=0 />
+ <AsteroidsCenterPoint name=asteroidscenter />
- <AsteroidsCenterPoint name=asteroidscenter />
+ <Model mesh="axes.mesh" scale=10 position="0,0,-100" />
</Scene>
Modified: code/branches/Asteroid_HS17/data/levels/templates/spaceshipAsteroids.oxt
===================================================================
--- code/branches/Asteroid_HS17/data/levels/templates/spaceshipAsteroids.oxt 2017-11-13 14:44:45 UTC (rev 11554)
+++ code/branches/Asteroid_HS17/data/levels/templates/spaceshipAsteroids.oxt 2017-11-13 15:05:34 UTC (rev 11555)
@@ -1,4 +1,4 @@
-<Template name=spaceshipescort>
+<Template name=spaceshipasteroids>
<SpaceShip
hudtemplate = spaceshiphud
camerapositiontemplate = spaceshipescortcameras
@@ -76,7 +76,7 @@
<Template name=spaceshipescortcameras defaults=0>
<SpaceShip>
<camerapositions>
- <CameraPosition position="0,150,0" pitch=-90 absolute=true />
+ <CameraPosition position="0,300,0" pitch=-90 absolute=true />
<CameraPosition position="0,50,160" drag=true mouselook=true />
<CameraPosition position="0,40,125" drag=true mouselook=true />
<CameraPosition position="0,30, 90" drag=true mouselook=true />
Modified: code/branches/Asteroid_HS17/src/modules/asteroids/Asteroids.cc
===================================================================
--- code/branches/Asteroid_HS17/src/modules/asteroids/Asteroids.cc 2017-11-13 14:44:45 UTC (rev 11554)
+++ code/branches/Asteroid_HS17/src/modules/asteroids/Asteroids.cc 2017-11-13 15:05:34 UTC (rev 11555)
@@ -59,12 +59,13 @@
RegisterObject(Asteroids);
this->numberOfBots_ = 0; //sets number of default bots temporarly to 0
this->center_ = nullptr;
+ this->lives = 3;
bEndGame = false;
lives = 3;
point = 0;
// Pre-set the timer, but don't start it yet.
- this->enemySpawnTimer_.setTimer(5.0, true, createExecutor(createFunctor(&Asteroids::spawnStone, this)));
+ //this->enemySpawnTimer_.setTimer(5.0, true, createExecutor(createFunctor(&Asteroids::spawnStone, this)));
}
//spawnt durch den Timer Asteroiden, denk dran, dass falls ein Asteroid stirbt er in 2 teile geteilt wird
@@ -78,35 +79,20 @@
newStone->setAsteroidsPlayer(player);
}
- /**
- @brief
- Destructor. Cleans up, if initialized.
- */
- Asteroids::~Asteroids()
+ void Asteroids::spawnStone(int newsize)
{
- if (this->isInitialized())
- this->cleanup();
- }
+ //no player -> should end game?
+ if(getPlayer() == nullptr) return;
+ //invalid size
+ if(newsize > 3 || newsize < 1) return;
+ AsteroidsStone* newStone;
+ newStone = new AsteroidsStone(this->center_->getContext());
+ newStone.size = newsize;
+ if(newsize == 1) newStone->addTemplate("asteroidsstone1");
+ else if(newsize == 2) newStone->addTemplate("asteroidsstone2");
+ else newStone->addTemplate("asteroidsstone3");
+ newStone->setAsteroidsPlayer(player);
- /**
- @brief
- Cleans up the Gametype by destroying all of the objects in the game - spaceship and asteroids.
- */
- void Asteroids::cleanup()
- {
- if (this->stones_ != nullptr) // Destroy the ball, if present.
- {
- this->stones_->destroy();
- this->stones_ = nullptr;
- }
-
- // Destroy AsteroidsShip
-
- if (this->player != nullptr)
- {
- this->player->destroy();
- this->player = nullptr;
- }
}
AsteroidsShip* Asteroids::getPlayer()
@@ -166,4 +152,4 @@
// Instead startMainMenu, this won't crash.
GSLevel::startMainMenu();
}
-}
+}
\ No newline at end of file
Modified: code/branches/Asteroid_HS17/src/modules/asteroids/Asteroids.h
===================================================================
--- code/branches/Asteroid_HS17/src/modules/asteroids/Asteroids.h 2017-11-13 14:44:45 UTC (rev 11554)
+++ code/branches/Asteroid_HS17/src/modules/asteroids/Asteroids.h 2017-11-13 15:05:34 UTC (rev 11555)
@@ -66,8 +66,6 @@
bool bEndGame;
private:
- void toggleShowLevel(){bShowLevel = !bShowLevel;}
- void cleanup(void); //!< Cleans up the Gametype by destroying the ball and the bats.
AsteroidsShip* getPlayer();
WeakPtr<AsteroidsCenterPoint> center_;
WeakPtr<AsteroidsShip> player;
@@ -74,13 +72,13 @@
WeakPtr<Camera> camera;
WeakPtr<AsteroidsStones> stones_;
- Timer enemySpawnTimer;
+
//Context* context;
- int level;
+ int lives;
int point;
- bool b_combo;
Timer starttimer_; //!< A timer to delay the start of the game.
+ Timer enemySpawnTimer;
};
}
Modified: code/branches/Asteroid_HS17/src/modules/asteroids/AsteroidsShip.cc
===================================================================
--- code/branches/Asteroid_HS17/src/modules/asteroids/AsteroidsShip.cc 2017-11-13 14:44:45 UTC (rev 11554)
+++ code/branches/Asteroid_HS17/src/modules/asteroids/AsteroidsShip.cc 2017-11-13 15:05:34 UTC (rev 11555)
@@ -18,10 +18,8 @@
{
RegisterObject(AsteroidsShip);
- angle= 0.0f;
+ direction= 0.0f;
-
-
isFireing = false;
damping = 0.90;
@@ -29,77 +27,68 @@
lastTimeLeft = 0;
lastTime = 0;
- height = this->getGame()->center_->getFieldHeight();
- width = this->getGame()->center_->getFieldWidth();
-
- force.x =0;
- force.y =0;
-
- velocity.x = 0;
- velocity.y = 0;
-
+ height = 600;
+ width = 1000;
}
- //Destructor
- AsteroidsShip::~AsteroidsShip()
- {
- if (this->isInitialized())
- this->cleanup();
- }
-
-
//update coordinates and velocity
void AsteroidsShip::tick(float dt)
{
+ orxout() << "ich ticke!"<< endl;
+ SUPER(AsteroidsShip, tick, dt);
+
//Movement computation beachte Beschleunigung?
Vector3 pos = getPosition();
+ Vector3 vel = getVelocity();
- float speed = sqrt(velocity.x*velocity.x+ velocity.y*velocity.y);
+ float speed = sqrt(vel.x*vel.x+ vel.z*velo.z);
+
+
+ //Daempfung falls das spaceship zu schnell wird
if(speed > maxspeed)
{
- velocity.x *= maxspeed/speed;
- velocity.y *= mayspeed/speed;
+ vel.x *= maxspeed/speed;
+ vel.z *= mayspeed/speed;
}
- pos.x += velocity.x*dt;
- pos.y += velocity.y*dt;
+ if(moveUpPressed_)
+ {
+ //Gas geben
+ vel.x += 1;
+ vel.z += 1;
+ }else if(moveDownPressed_){
+ //Bremsen
+ vel.x += 1;
+ vel.z += 1;
+ }else if(moveLeftPressed_){
+ //rotate left
+ }else if (moveRightPressed_){
+ //rotateright
+ }
- //haelt ship innerhalb des Kamerafensters
- if(x>width) x=0;
- if(x<0) x=width;
- if(y>height) y=0;
- if(y<0) y=height);
+ setVelocity(vel);
+
+ pos.x += vel.x*dt;
+ pos.z += vel.z*dt;
+
+ //haelt ship innerhalb des Kamerafensters, kommt oben bzw seitlich wieder raus. Man spawnt in (0,0)
+ if(pos.x > width/2) pos.x = -width/2;
+ if(pos.x < -width/2) pos.x = width/2;
+ if(pos.z > height/2) pos.z = -height/2;
+ if(pos.z < -height/2) pos.z = height/2;
+
+
//Schiessen wenn geschossen wurde
// shoot!
-/*
+
if (isFireing)
ControllableEntity::fire(0);
- */
+
- //Execute movement
- if (this->hasLocalController())
- {
- force.x += 1;
- force.y += 1;
-
- }
-
-
-
- //Camera ticken? Bleibt eigentlich am selben Ort...irgendwo initialisieren
- Camera* camera = this->getCamera();
- if (camera != nullptr)
- {
- camera->setPosition(Vector3(0,cameradistance, 0));
- camera->setOrientation(Vector3::UNIT_Z, Degree(90));
- }
-
-
-
// bring back on track!
if(pos.y != 0)
{
@@ -106,31 +95,69 @@
pos.y = 0;
}
- velocity.x *= damping;
- velocity.y *= damping;
+ //Reibung?
+ vel.x *= damping;
+ vel.y *= damping;
+
setPosition(pos);
- setOrientation(Vector3::UNIT_Y, Degree(270));
+ setOrientation(Vector3::UNIT_Y, Degree(direction));
- SUPER(AsteroidsShip, tick, dt);
+ // Reset key variables
+ moveUpPressed_ = false;
+ moveDownPressed_ = false;
+ moveLeftPressed_ = false;
+ moveDownPressed_ = false;
+
}
void AsteroidsShip::moveFrontBack(const Vector2& value)
{
- velocity.x += 1;
- }
+ if (value.x > 0)
+ {
+ moveUpPressed_ = true;
+ moveDownPressed_ = false
+ if(moveUpPressed_)
+ {
+ orxout() << "up" << endl;
+ }
+ }
+ else
+ {
+ moveUpPressed_ = false;
+ moveDownPressed_ = true;
+ if(moveDownPressed_)
+ {
+ orxout() << "down" << endl;
+ }
+ }
+ }
- void AsteroidsShip::moveUpDown(const Vector2& value)
+ void AsteroidsShip::moveRightLeft(const Vector2& value)
{
- velocity.y +=1;
+ if (value.x > 0)
+ {
+ moveLeftPressed_ = false;
+ moveRightPressed_ = true;
+ }
+ if(moveRightPressed_)
+ {
+ orxout() << "right" << endl;
+ }
+ else
+ {
+ moveLeftPressed_ = true;
+ moveRightPressed_ = false;
+ if(moveLeftPressed_)
+ {
+ orxout() << "left" << endl;
+ }
+ }
}
- void AsteroidsShip::moveFrontLeftRight(const Vector2& value)
- {
+
- }
-
Asteroids* AsteroidsShip::getGame()
{
if (game == nullptr)
Modified: code/branches/Asteroid_HS17/src/modules/asteroids/AsteroidsShip.h
===================================================================
--- code/branches/Asteroid_HS17/src/modules/asteroids/AsteroidsShip.h 2017-11-13 14:44:45 UTC (rev 11554)
+++ code/branches/Asteroid_HS17/src/modules/asteroids/AsteroidsShip.h 2017-11-13 15:05:34 UTC (rev 11555)
@@ -52,13 +52,12 @@
virtual void tick(float dt) override;
- // overwrite for 2d movement
+ //overwrite for 2d movement
virtual void moveFrontBack(const Vector2& value) override;
virtual void moveRightLeft(const Vector2& value) override;
- virtual void moveUpDown(const Vector2& value) override;
// Starts or stops fireing
- virtual void boost(bool bBoost) override;
+ //virtual void boost(bool bBoost) override;
void setCenterpoint(AsteroidsCenterPoint* center)
@@ -68,15 +67,13 @@
virtual void addBots(unsigned int amount) override{} //<! overwrite function in order to bypass the addbots command
bool bEndGame;
- bool bShowLevel;
int lives;
- float angle, radius;
- float damping, posforeward;
+ float direction;
+ float damping;
bool isFireing;
- float dx, dy;
const float maxspeed = 500;
- const float cameradistance = 100;
+
//Nachschauen wie gross das Spielfeld ist!
float height;
float width;
@@ -90,13 +87,10 @@
Asteroids* getGame();
WeakPtr<Asteroids> game;
WeakPtr<WorldEntity> lastEntity;
- Camera* camera;
float lastTimeFront, lastTimeLeft, lastTime;
- struct Vector
- {
- float x;
- float y;
- }force, velocity
+
+ //Controller
+ bool moveUpPressed_, moveDownPressed_, moveRightPressed_, moveLeftPressed_;
};
}
Modified: code/branches/Asteroid_HS17/src/modules/asteroids/AsteroidsStone.cc
===================================================================
--- code/branches/Asteroid_HS17/src/modules/asteroids/AsteroidsStone.cc 2017-11-13 14:44:45 UTC (rev 11554)
+++ code/branches/Asteroid_HS17/src/modules/asteroids/AsteroidsStone.cc 2017-11-13 15:05:34 UTC (rev 11555)
@@ -27,8 +27,8 @@
*/
/**
- @file InvaderEnemy.h
- @brief Declaration of the InvaderEnemy class.
+ @file AsteroidsEnemy.h
+ @brief Declaration of the AsteroidsEnemy class.
*/
#include "AsteroidsStone.h"
@@ -35,9 +35,11 @@
#include "core/CoreIncludes.h"
#include "Asteroids.h"
#include "AsteroidsShip.h"
+#include <cstdlib>
#include <cmath>
#include "util/Math.h"
+const float delta = 3;
namespace orxonox
{
@@ -47,16 +49,30 @@
{
RegisterObject(AsteroidsStone);
+ direction = 0;
+ //Spielfeld x als Horizontale und z als Vertikale
+ fieldWidth_ = this->getGame()->center_->getFieldWidth;
+ fieldHeigth_ = this->getGame()->center_->getFieldHeight;
+
+
+ //Random size 1, 2, 3 ->muss noch realisiert werden. Templates erstellen
+ this.size = 1;
maxspeed = 50.0f;
//Random Spawn? pos= random? -> spawn durch timer in der Asteroids Klasse
- this->setPosition(rnd(0, fieldWidth_), rnd(0, fieldHeigth_), 0);
+ this->setPosition(rnd(fieldWidth_), 0, rnd(fieldHeigth));
- //random Geschwindigkeit und Richtung
- velocity.x = rnd(0, maxspeed);
- velocity.y = rnd(0, maxspeed);
- this->context = context;
+ //random Geschwindigkeit und Richtung
+ velocity.x = rnd(maxspeed);
+ velocity.y = rnd(maxspeed);
}
+ inline bool AsteroidsStone::collidesAgainst(WorldEntity* otherObject, const btCollisionShape* ownCollisionShape, btManifoldPoint& contactPoint)
+ {
+ if(orxonox_cast<AsteroidsShip*>(otherObject))
+ removeHealth(2000);
+ return false;
+ }
+
void Asteroids::death()
{
if(this->size == 1){
@@ -63,38 +79,60 @@
Pawn::death();
}else if(this->size == 2){
Pawn::death();
-
//Wie mache ich das ? Eigentlich in der game Klasse? sonst zeigt der Pointer auf einen falschen Bereich
-
for(int i = 0; i<2; i++)
{
AsteroidsStone* newStone;
- newStone = new AsteroidsStone(this->context);
+ newStone = new AsteroidsStone(this->getGame()->center_->getContext());
newStone->addTemplate("asteroidsstone");
- newStone->setAsteroidsPlayer(player);
+ newStone->setAsteroidsPlayer(this->getGame()->player);
}
}
}
+
+ Asteroids* AsteroidsStone::getGame()
+ {
+ if (game == nullptr)
+ {
+ for (Asteroids* Asteroids : ObjectList<Asteroids>())
+ game = asteroids;
+ }
+ return game;
+ }
+
//Bis hier geschrieben
void AsteroidsStone::tick(float dt)
{
- Vector3 pos = this->getPosition();
- pos.x += velocity.x*dt;
- pos.z += velocity.y*dt;
+ Vector3 pos = getPosition();
+
+
+
+ //bounce on the borders
+ if(pos.x-delta <= 0 || pos.x+delta >= fieldWidth_)
+ direction = -direction;
+
+
+
+ //zurück bringen
if(pos.y != 0){
pos.y=0;
}
+
+ //spin
+
+ setOrientation()
setPosition(pos);
+
SUPER(AsteroidsStone, tick, dt);
}
inline bool AsteroidsStone::collidesAgainst(WorldEntity* otherObject, const btCollisionShape* ownCollisionShape, btManifoldPoint& contactPoint)
{
- if(orxonox_cast<InvaderShip*>(otherObject))
+ if(orxonox_cast<AsteroidsShip*>(otherObject))
removeHealth(2000);
return false;
}
Modified: code/branches/Asteroid_HS17/src/modules/asteroids/AsteroidsStone.h
===================================================================
--- code/branches/Asteroid_HS17/src/modules/asteroids/AsteroidsStone.h 2017-11-13 14:44:45 UTC (rev 11554)
+++ code/branches/Asteroid_HS17/src/modules/asteroids/AsteroidsStone.h 2017-11-13 15:05:34 UTC (rev 11555)
@@ -49,23 +49,27 @@
//Es gibt 3 Groessen von Meteroiden gross, mittel, klein, gross ->2 mittleren, mittel -> 2 kleinen, kleine-> verschwinden
int size;
- int level;
+
virtual void setAsteroidsPlayer(AsteroidsShip* player){this->player = player;}
+ virtual bool collidesAgainst(WorldEntity* otherObject, const btCollisionShape* ownCollisionShape, btManifoldPoint& contactPoint) override;
+
protected:
+ Asteroids* getGame();
+ WeakPtr<Asteroids> game;
+
virtual void death() override;
//herausfinden->ueber Kamera Einstellung wie bei Pong?
- float fieldWidth_=500;
- float fieldHeight_=700;
+ float fieldWidth_;
+ float fieldHeight_;
Vector2 velocity;
float maxspeed;
+ float direction;
- private:
- Context* context;
};
}
More information about the Orxonox-commit
mailing list