[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-06-29 18:50:34
Message-ID: 1246301434.091576.12319.nullmailer () svn ! kde ! org
[Download RAW message or body]
SVN commit 989223 by rivol:
- Use KActions for new game, quit and dodging actions. This also means added \
LibKDEGames dependancy.
- You can now dodge (= move quickly sideways) with the ship.
- Damp ship's velocity and limit its thrust.
M +1 -0 CMakeLists.txt
M +2 -2 src/CMakeLists.txt
M +44 -13 src/mainwindow.cpp
M +8 -0 src/mainwindow.h
M +1 -1 src/model.cpp
M +10 -0 src/ship.cpp
M +1 -0 src/ship.h
--- trunk/playground/games/astrododge/CMakeLists.txt #989222:989223
@@ -8,6 +8,7 @@
find_package(KGLLib REQUIRED)
find_package(Eigen2 REQUIRED)
find_package(ODE REQUIRED)
+find_package(LibKDEGames REQUIRED)
include(KDE4Defaults)
if(NOT OPENGL_GLU_FOUND)
--- trunk/playground/games/astrododge/src/CMakeLists.txt #989222:989223
@@ -1,4 +1,4 @@
-include_directories(${ODE_INCLUDE_DIRS})
+include_directories(${ODE_INCLUDE_DIRS} ${KDEGAMES_INCLUDE_DIRS})
set(astrododge_SRCS
asteroid.cpp
@@ -16,6 +16,6 @@
kde4_add_ui_files(astrododge_SRCS lodinfowidget.ui)
kde4_add_executable(astrododge ${astrododge_SRCS})
-target_link_libraries(astrododge ${KDE4_KDEUI_LIBS} ${KGLLIB_LIBRARY} \
${KGLLIB_EXTRAS_LIBRARY} ${ODE_LIBRARIES}) +target_link_libraries(astrododge \
${KDE4_KDEUI_LIBS} ${KGLLIB_LIBRARY} ${KGLLIB_EXTRAS_LIBRARY} ${ODE_LIBRARIES} \
${KDEGAMES_LIBRARY}) install(TARGETS astrododge ${INSTALL_TARGETS_DEFAULT_ARGS}})
install(FILES astrododge.desktop DESTINATION ${XDG_APPS_INSTALL_DIR})
--- trunk/playground/games/astrododge/src/mainwindow.cpp #989222:989223
@@ -20,10 +20,7 @@
#include "ship.h"
#include "asteroid.h"
#include "gameworld.h"
-#include "inputhandler.h"
#include "bullet.h"
-#include "lodinfowidget.h"
-#include "model.h"
#include "gameview.h"
#include "displaywidget.h"
@@ -31,19 +28,14 @@
#include <QTimer>
#include <QApplication>
-#include <QMessageBox>
-#include <QtDebug>
-#include <QPushButton>
-#include <QLabel>
-#include <QLayout>
-#include <QSpinBox>
+#include <QWheelEvent>
#include <KGlobal>
#include <KStandardDirs>
-#include <KConfig>
-#include <KConfigGroup>
#include <KDebug>
-#include <QWheelEvent>
+#include <KAction>
+#include <KActionCollection>
+#include <KStandardGameAction>
MainWindow::MainWindow() : KXmlGuiWindow()
@@ -63,6 +55,9 @@
setMinimumSize(640, 480);
+ setupActions();
+ setupGUI();
+
mDisplay->showMainMenu();
connect(mDisplay, SIGNAL(startNewGame()), this, SLOT(startNewGame()));
}
@@ -71,6 +66,34 @@
{
}
+void MainWindow::setupActions()
+{
+ // Dodge actions
+ KAction* dodgeLeftAction = new KAction("Dodge left", this);
+ dodgeLeftAction->setShortcut(Qt::Key_A);
+ actionCollection()->addAction("dodge_left", dodgeLeftAction);
+ connect(dodgeLeftAction, SIGNAL(triggered(bool)), this, SLOT(dodgeLeft()));
+
+ KAction* dodgeRightAction = new KAction("Dodge right", this);
+ dodgeRightAction->setShortcut(Qt::Key_D);
+ actionCollection()->addAction("dodge_right", dodgeRightAction);
+ connect(dodgeRightAction, SIGNAL(triggered(bool)), this, SLOT(dodgeRight()));
+
+ KAction* dodgeUpAction = new KAction("Dodge up", this);
+ dodgeUpAction->setShortcut(Qt::Key_W);
+ actionCollection()->addAction("dodge_up", dodgeUpAction);
+ connect(dodgeUpAction, SIGNAL(triggered(bool)), this, SLOT(dodgeUp()));
+
+ KAction* dodgeDownAction = new KAction("Dodge down", this);
+ dodgeDownAction->setShortcut(Qt::Key_S);
+ actionCollection()->addAction("dodge_down", dodgeDownAction);
+ connect(dodgeDownAction, SIGNAL(triggered(bool)), this, SLOT(dodgeDown()));
+
+ // Game state actions
+ KStandardGameAction::gameNew(this, SLOT(startNewGame()), actionCollection());
+ KStandardGameAction::quit(this, SLOT(close()), actionCollection());
+}
+
void MainWindow::startNewGame()
{
kDebug();
@@ -97,5 +120,13 @@
return;
}
- mWorld->ship()->thrust += (e->delta() / 120.0f * 0.2f);
+ mWorld->ship()->thrust += (e->delta() / 120.0f * 2.0f);
+ mWorld->ship()->thrust = qBound(0.0f, mWorld->ship()->thrust, 20.0f);
}
+
+void MainWindow::dodge(int x, int y)
+{
+ if (mGameRunning) {
+ mWorld->ship()->dodge(x, y);
+ }
+}
--- trunk/playground/games/astrododge/src/mainwindow.h #989222:989223
@@ -57,9 +57,17 @@
public slots:
void startNewGame();
+ void dodgeLeft() { dodge(-1, 0); }
+ void dodgeRight() { dodge( 1, 0); }
+ void dodgeUp() { dodge( 0, 1); }
+ void dodgeDown() { dodge( 0, -1); }
+ void dodge(int x, int y);
+
protected:
virtual void wheelEvent(QWheelEvent*);
+ void setupActions();
+
private:
DisplayWidget* mDisplay;
GameWorld* mWorld;
--- trunk/playground/games/astrododge/src/model.cpp #989222:989223
@@ -161,7 +161,7 @@
Mesh* Model::collisionMesh() const
{
- int lod = qMin(3, mLODs.count()-1);
+ int lod = qMin(4, mLODs.count()-1);
return mLODs[lod];
}
--- trunk/playground/games/astrododge/src/ship.cpp #989222:989223
@@ -43,6 +43,10 @@
const dReal* angvel = dBodyGetAngularVel(body);
const float damp = 0.995f;
dBodySetAngularVel(body, angvel[0] * damp, angvel[1] * damp, angvel[2] * damp);
+
+ const dReal* linvel = dBodyGetLinearVel(body);
+ const float linDamp = 0.98f;
+ dBodySetLinearVel(body, linvel[0]*linDamp, linvel[1]*linDamp, \
linvel[2]*linDamp); }
void Ship::collision(const Vector3f& force)
@@ -61,3 +65,9 @@
dBodyAddRelForceAtRelPos(body, -rot.x(), -rot.y(), 0, 0, 0, 1);
}
+void Ship::dodge(int x, int y)
+{
+ const int multiplier = 1000000;
+ dBodyAddRelForce(body, x*multiplier, y*multiplier, 0);
+}
+
--- trunk/playground/games/astrododge/src/ship.h #989222:989223
@@ -35,6 +35,7 @@
virtual void advance(float elapsed);
virtual void collision(const Vector3f& force);
virtual void addRotation(const Vector3f& rot);
+ void dodge(int x, int y);
float acceleration;
float thrust;
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic