[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: playground/games/astrododge
From: Rivo Laks <rivolaks () hot ! ee>
Date: 2009-07-12 19:30:00
Message-ID: 1247427000.713166.28721.nullmailer () svn ! kde ! org
[Download RAW message or body]
SVN commit 995459 by rivol:
Add rudimentary support for planets, and an earth into the default level for testing.
This is still very much imcomplete and implementation details will change, but I just \
want to get this patch off my HDD for now.
M +3 -0 data/levels/test1.level
M +1 -0 src/CMakeLists.txt
M +12 -0 src/gameview.cpp
M +2 -0 src/gameview.h
M +13 -0 src/gameworld.cpp
M +6 -0 src/gameworld.h
M +34 -0 src/levelloader.cpp
M +1 -0 src/levelloader.h
--- trunk/playground/games/astrododge/data/levels/test1.level #995458:995459
@@ -19,6 +19,9 @@
<Object name="cube">
<Position x="1050" y="100" z="400" />
</Object>
+ <Planet type="earth" radius="1000">
+ <Position x="5000" y="1000" z="4000" />
+ </Planet>
</Objects>
<Track>
--- trunk/playground/games/astrododge/src/CMakeLists.txt #995458:995459
@@ -13,6 +13,7 @@
main.cpp
mainwindow.cpp
model.cpp
+ planet.cpp
ship.cpp
)
kde4_add_ui_files(astrododge_SRCS lodinfowidget.ui)
--- trunk/playground/games/astrododge/src/gameview.cpp #995458:995459
@@ -33,6 +33,7 @@
#include <KDebug>
#include <KStandardDirs>
#include <QTimer>
+#include "planet.h"
using namespace KGLLib;
@@ -57,6 +58,13 @@
mSpaceMesh = new Mesh();
Shapes::createCube(mSpaceMesh);
mSpaceMesh->setTexture(mSpaceTexture);
+
+ mEarthTex = new Texture(mWorld->dataPath() + "textures/earth.png");
+ mEarthTex->setWrapMode(GL_CLAMP);
+
+ mEarthMesh = new Mesh();
+ Shapes::createSphere(mEarthMesh, 6);
+ mEarthMesh->setTexture(mEarthTex);
}
void GameView::setupWorldView()
@@ -96,6 +104,10 @@
glLightfv(GL_LIGHT0, GL_POSITION, Vector4f(-100000.0, 60000.0, 20000.0, \
1.0).data()); glEnable(GL_DEPTH_TEST);
+ foreach (Planet* p, *mWorld->planets()) {
+ p->render();
+ }
+
// Render asteroids
renderAsteroids();
--- trunk/playground/games/astrododge/src/gameview.h #995458:995459
@@ -56,6 +56,8 @@
float mDetailLevel;
KGLLib::Texture* mSpaceTexture;
KGLLib::Mesh* mSpaceMesh;
+ KGLLib::Texture* mEarthTex;
+ KGLLib::Mesh* mEarthMesh;
};
#endif // GAMEVIEW_H
--- trunk/playground/games/astrododge/src/gameworld.cpp #995458:995459
@@ -24,12 +24,14 @@
#include "bullet.h"
#include "model.h"
#include "levelloader.h"
+#include "planet.h"
#include <kgllib/texture.h>
#include <kgllib/program.h>
#include <kgllib/mesh.h>
#include <kgllib/modelloader.h>
#include <kgllib/geometrybuffer.h>
+#include <kgllib/shapes.h>
#include <KDebug>
#include <KConfig>
@@ -333,6 +335,17 @@
mObjects.append(obj);
}
+Planet* GameWorld::addPlanet(const QString& planet)
+{
+ Mesh* m = new Mesh();
+ KGLLib::Shapes::createSphere(m, 4);
+ m->setTexture(objectTexture("earth.png"));
+
+ Planet* p = new Planet(m);
+ mPlanets.append(p);
+ return p;
+}
+
void GameWorld::slotRotateShip(float dx, float dy, float dz)
{
mShip->rotvelocity += Vector3f(dx, -dy, dz) * 200;
--- trunk/playground/games/astrododge/src/gameworld.h #995458:995459
@@ -26,6 +26,7 @@
#include "mymath.h"
#include "gameobject.h"
+
#include <ode/ode.h>
class Ship;
@@ -33,6 +34,7 @@
class Bullet;
class InputHandler;
class Model;
+class Planet;
class OctreeNode;
@@ -69,6 +71,9 @@
void addObject(GameObject* obj);
+ Planet* addPlanet(const QString& type);
+ const QList<Planet*>* planets() const { return &mPlanets; }
+
void handleCollisionBetween(dGeomID o0, dGeomID o1);
void createAsteroids(int count, float mean, float variance, float min, float \
max, @@ -126,6 +131,7 @@
Ship* mShip;
QList<GameObject*> mObjects;
QList<Bullet*> mBullets;
+ QList<Planet*> mPlanets;
bool mGamePaused;
float mTime;
int mNextObjectId;
--- trunk/playground/games/astrododge/src/levelloader.cpp #995458:995459
@@ -20,6 +20,7 @@
#include "gameworld.h"
#include "gameobject.h"
#include "ship.h"
+#include "planet.h"
#include <QDomElement>
#include <QFile>
@@ -105,6 +106,14 @@
}
}
+ // Planets
+ QDomNodeList planetList = objectsTag.elementsByTagName("Planet");
+ for (int i = 0; i < planetList.count(); i++) {
+ if (!loadPlanet(planetList.item(i).toElement())) {
+ return false;
+ }
+ }
+
return true;
}
@@ -254,3 +263,28 @@
return true;
}
+
+bool LevelLoader::loadPlanet(const QDomElement& elem)
+{
+ if (elem.isNull()) {
+ kError() << "NULL element";
+ return false;
+ }
+
+ Vector3f pos;
+ if (!loadVector(elem.firstChildElement("Position"), &pos)) {
+ return false;
+ }
+
+ QString type = elem.attribute("type");
+ int radius = elem.attribute("radius").toInt();
+
+ Planet* planet = mWorld->addPlanet(type);
+ if (!planet) {
+ return false;
+ }
+ planet->setPosition(pos);
+ planet->setRadius(radius);
+
+ return true;
+}
--- trunk/playground/games/astrododge/src/levelloader.h #995458:995459
@@ -42,6 +42,7 @@
bool loadVector(const QDomElement& elem, Vector3f* pos);
bool loadTrack(const QDomElement& elem);
bool loadPlayer(const QDomElement& elem);
+ bool loadPlanet(const QDomElement& elem);
private:
GameWorld* mWorld;
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic