Browse files

Initial version

  • Loading branch information...
0 parents commit 985852570b7b8d1e214f61b98552a8e988954296 @bzar committed Jun 18, 2011
3 .gitmodules
@@ -0,0 +1,3 @@
+[submodule "penjin"]
+ path = penjin
+ url = https://github.com/pokeparadox/PenjinTwo.git
26 game/ball.cpp
@@ -0,0 +1,26 @@
+#include "ball.h"
+
+Ball::Ball() :
+ Penjin::Sprite(),
+ velocity(1.0, 1.0), speed(1.0)
+{
+ load("img/ball.png");
+}
+
+void Ball::update()
+{
+ position += velocity;
+ speed += 0.001;
+}
+
+void Ball::setDirection(Penjin::Vector2d<float> const& newDirection)
+{
+ velocity = newDirection;
+ velocity = velocity.unit();
+ velocity *= speed;
+}
+
+Penjin::Vector2d<float> const& Ball::getVelocity() const
+{
+ return velocity;
+}
20 game/ball.h
@@ -0,0 +1,20 @@
+#ifndef BALL_H
+#define BALL_H
+
+#include "Sprite.h"
+
+class Ball : public Penjin::Sprite
+{
+public:
+ Ball();
+
+ void update();
+ void setDirection(Penjin::Vector2d<float> const& newDirection);
+ Penjin::Vector2d<float> const& getVelocity() const;
+
+private:
+ Penjin::Vector2d<float> velocity;
+ float speed;
+};
+
+#endif
7 game/brick.cpp
@@ -0,0 +1,7 @@
+#include "brick.h"
+
+Brick::Brick() :
+ Penjin::Sprite()
+{
+ load("img/brick.png");
+}
15 game/brick.h
@@ -0,0 +1,15 @@
+#ifndef BRICK_H
+#define BRICK_H
+
+#include "Sprite.h"
+
+class Brick : public Penjin::Sprite
+{
+public:
+ Brick();
+
+private:
+
+};
+
+#endif
26 game/game.pro
@@ -0,0 +1,26 @@
+TEMPLATE = app
+TARGET = penjinoid
+DESTDIR = ../target
+QT -= core gui
+
+INCLUDEPATH += ../penjin
+LIBS += -L../penjin -lpenjin
+DEFINES += PENJIN_SDL PLATFORM_PC _LINUX
+
+HEADERS = \
+ ball.h \
+ brick.h \
+ gamestate.h \
+ paddle.h \
+ penjinoid.h
+
+SOURCES = \
+ ball.cpp \
+ brick.cpp \
+ gamestate.cpp \
+ main.cpp \
+ paddle.cpp \
+ penjinoid.cpp
+
+OTHER_FILES = \
+ ../target/config/settings.ini
113 game/game.pro.user
@@ -0,0 +1,113 @@
+<!DOCTYPE QtCreatorProject>
+<qtcreator>
+ <data>
+ <variable>ProjectExplorer.Project.ActiveTarget</variable>
+ <value type="int">0</value>
+ </data>
+ <data>
+ <variable>ProjectExplorer.Project.EditorSettings</variable>
+ <valuemap type="QVariantMap">
+ <value key="EditorConfiguration.Codec" type="QByteArray">UTF-8</value>
+ </valuemap>
+ </data>
+ <data>
+ <variable>ProjectExplorer.Project.Target.0</variable>
+ <valuemap type="QVariantMap">
+ <value key="ProjectExplorer.ProjectConfiguration.DisplayName" type="QString">Desktop</value>
+ <value key="ProjectExplorer.ProjectConfiguration.Id" type="QString">Qt4ProjectManager.Target.DesktopTarget</value>
+ <value key="ProjectExplorer.Target.ActiveBuildConfiguration" type="int">0</value>
+ <value key="ProjectExplorer.Target.ActiveRunConfiguration" type="int">0</value>
+ <valuemap key="ProjectExplorer.Target.BuildConfiguration.0" type="QVariantMap">
+ <valuemap key="ProjectExplorer.BuildConfiguration.BuildStep.0" type="QVariantMap">
+ <value key="ProjectExplorer.ProjectConfiguration.DisplayName" type="QString">qmake</value>
+ <value key="ProjectExplorer.ProjectConfiguration.Id" type="QString">QtProjectManager.QMakeBuildStep</value>
+ <valuelist key="QtProjectManager.QMakeBuildStep.QMakeArguments" type="QVariantList"/>
+ </valuemap>
+ <valuemap key="ProjectExplorer.BuildConfiguration.BuildStep.1" type="QVariantMap">
+ <value key="ProjectExplorer.ProjectConfiguration.DisplayName" type="QString">Make</value>
+ <value key="ProjectExplorer.ProjectConfiguration.Id" type="QString">Qt4ProjectManager.MakeStep</value>
+ <value key="Qt4ProjectManager.MakeStep.Clean" type="bool">false</value>
+ <valuelist key="Qt4ProjectManager.MakeStep.MakeArguments" type="QVariantList"/>
+ <value key="Qt4ProjectManager.MakeStep.MakeCommand" type="QString"></value>
+ </valuemap>
+ <value key="ProjectExplorer.BuildConfiguration.BuildStepsCount" type="int">2</value>
+ <valuemap key="ProjectExplorer.BuildConfiguration.CleanStep.0" type="QVariantMap">
+ <value key="ProjectExplorer.ProjectConfiguration.DisplayName" type="QString">Make</value>
+ <value key="ProjectExplorer.ProjectConfiguration.Id" type="QString">Qt4ProjectManager.MakeStep</value>
+ <value key="Qt4ProjectManager.MakeStep.Clean" type="bool">true</value>
+ <valuelist key="Qt4ProjectManager.MakeStep.MakeArguments" type="QVariantList">
+ <value type="QString">clean</value>
+ </valuelist>
+ <value key="Qt4ProjectManager.MakeStep.MakeCommand" type="QString"></value>
+ </valuemap>
+ <value key="ProjectExplorer.BuildConfiguration.CleanStepsCount" type="int">1</value>
+ <value key="ProjectExplorer.BuildConfiguration.ClearSystemEnvironment" type="bool">false</value>
+ <valuelist key="ProjectExplorer.BuildConfiguration.UserEnvironmentChanges" type="QVariantList"/>
+ <value key="ProjectExplorer.ProjectConfiguration.DisplayName" type="QString">Debug</value>
+ <value key="ProjectExplorer.ProjectConfiguration.Id" type="QString">Qt4ProjectManager.Qt4BuildConfiguration</value>
+ <value key="Qt4ProjectManager.Qt4BuildConfiguration.BuildConfiguration" type="int">2</value>
+ <value key="Qt4ProjectManager.Qt4BuildConfiguration.BuildDirectory" type="QString">/home/bzar/src/penjinoid-build-desktop</value>
+ <value key="Qt4ProjectManager.Qt4BuildConfiguration.QtVersionId" type="int">2</value>
+ <value key="Qt4ProjectManager.Qt4BuildConfiguration.ToolChain" type="int">0</value>
+ <value key="Qt4ProjectManager.Qt4BuildConfiguration.UseShadowBuild" type="bool">true</value>
+ </valuemap>
+ <valuemap key="ProjectExplorer.Target.BuildConfiguration.1" type="QVariantMap">
+ <valuemap key="ProjectExplorer.BuildConfiguration.BuildStep.0" type="QVariantMap">
+ <value key="ProjectExplorer.ProjectConfiguration.DisplayName" type="QString">qmake</value>
+ <value key="ProjectExplorer.ProjectConfiguration.Id" type="QString">QtProjectManager.QMakeBuildStep</value>
+ <valuelist key="QtProjectManager.QMakeBuildStep.QMakeArguments" type="QVariantList"/>
+ </valuemap>
+ <valuemap key="ProjectExplorer.BuildConfiguration.BuildStep.1" type="QVariantMap">
+ <value key="ProjectExplorer.ProjectConfiguration.DisplayName" type="QString">Make</value>
+ <value key="ProjectExplorer.ProjectConfiguration.Id" type="QString">Qt4ProjectManager.MakeStep</value>
+ <value key="Qt4ProjectManager.MakeStep.Clean" type="bool">false</value>
+ <valuelist key="Qt4ProjectManager.MakeStep.MakeArguments" type="QVariantList"/>
+ <value key="Qt4ProjectManager.MakeStep.MakeCommand" type="QString"></value>
+ </valuemap>
+ <value key="ProjectExplorer.BuildConfiguration.BuildStepsCount" type="int">2</value>
+ <valuemap key="ProjectExplorer.BuildConfiguration.CleanStep.0" type="QVariantMap">
+ <value key="ProjectExplorer.ProjectConfiguration.DisplayName" type="QString">Make</value>
+ <value key="ProjectExplorer.ProjectConfiguration.Id" type="QString">Qt4ProjectManager.MakeStep</value>
+ <value key="Qt4ProjectManager.MakeStep.Clean" type="bool">true</value>
+ <valuelist key="Qt4ProjectManager.MakeStep.MakeArguments" type="QVariantList">
+ <value type="QString">clean</value>
+ </valuelist>
+ <value key="Qt4ProjectManager.MakeStep.MakeCommand" type="QString"></value>
+ </valuemap>
+ <value key="ProjectExplorer.BuildConfiguration.CleanStepsCount" type="int">1</value>
+ <value key="ProjectExplorer.BuildConfiguration.ClearSystemEnvironment" type="bool">false</value>
+ <valuelist key="ProjectExplorer.BuildConfiguration.UserEnvironmentChanges" type="QVariantList"/>
+ <value key="ProjectExplorer.ProjectConfiguration.DisplayName" type="QString">Release</value>
+ <value key="ProjectExplorer.ProjectConfiguration.Id" type="QString">Qt4ProjectManager.Qt4BuildConfiguration</value>
+ <value key="Qt4ProjectManager.Qt4BuildConfiguration.BuildConfiguration" type="int">0</value>
+ <value key="Qt4ProjectManager.Qt4BuildConfiguration.BuildDirectory" type="QString">/home/bzar/src/penjinoid-build-desktop</value>
+ <value key="Qt4ProjectManager.Qt4BuildConfiguration.QtVersionId" type="int">2</value>
+ <value key="Qt4ProjectManager.Qt4BuildConfiguration.ToolChain" type="int">0</value>
+ <value key="Qt4ProjectManager.Qt4BuildConfiguration.UseShadowBuild" type="bool">true</value>
+ </valuemap>
+ <value key="ProjectExplorer.Target.BuildConfigurationCount" type="int">2</value>
+ <valuemap key="ProjectExplorer.Target.RunConfiguration.0" type="QVariantMap">
+ <value key="ProjectExplorer.ProjectConfiguration.DisplayName" type="QString">penjinoid</value>
+ <value key="ProjectExplorer.ProjectConfiguration.Id" type="QString">Qt4ProjectManager.Qt4RunConfiguration</value>
+ <value key="Qt4ProjectManager.Qt4RunConfiguration.BaseEnvironmentBase" type="int">2</value>
+ <valuelist key="Qt4ProjectManager.Qt4RunConfiguration.CommandLineArguments" type="QVariantList"/>
+ <value key="Qt4ProjectManager.Qt4RunConfiguration.ProFile" type="QString">penjinoid.pro</value>
+ <value key="Qt4ProjectManager.Qt4RunConfiguration.UseDyldImageSuffix" type="bool">false</value>
+ <value key="Qt4ProjectManager.Qt4RunConfiguration.UseTerminal" type="bool">false</value>
+ <valuelist key="Qt4ProjectManager.Qt4RunConfiguration.UserEnvironmentChanges" type="QVariantList"/>
+ <value key="Qt4ProjectManager.Qt4RunConfiguration.UserSetName" type="bool">false</value>
+ <value key="Qt4ProjectManager.Qt4RunConfiguration.UserSetWorkingDirectory" type="bool">false</value>
+ <value key="Qt4ProjectManager.Qt4RunConfiguration.UserWorkingDirectory" type="QString"></value>
+ </valuemap>
+ <value key="ProjectExplorer.Target.RunConfigurationCount" type="int">1</value>
+ </valuemap>
+ </data>
+ <data>
+ <variable>ProjectExplorer.Project.TargetCount</variable>
+ <value type="int">1</value>
+ </data>
+ <data>
+ <variable>ProjectExplorer.Project.Updater.FileVersion</variable>
+ <value type="int">4</value>
+ </data>
+</qtcreator>
147 game/gamestate.cpp
@@ -0,0 +1,147 @@
+#include "gamestate.h"
+#include <iostream>
+
+GameState::GameState() :
+ Penjin::ApplicationState(),
+ paddle(), ball(), bricks()
+{
+
+}
+
+GameState::~GameState()
+{
+
+}
+
+void GameState::init()
+{
+ paddle.setPosition(168, 216);
+ ball.setPosition(184, 140);
+
+ for(int y = 0; y < 6; ++y) {
+ for(int x = 0; x < 10; ++x) {
+ Brick* brick = new Brick();
+ brick->setPosition(x*40, y*16);
+ bricks.push_back(brick);
+ }
+ }
+}
+
+void GameState::render()
+{
+ Penjin::GFX::getInstance()->clear();
+ paddle.render();
+ ball.render();
+ for(std::vector<Brick*>::iterator i = bricks.begin(); i != bricks.end(); ++i)
+ {
+ (*i)->render();
+ }
+}
+
+void GameState::update()
+{
+ paddle.update();
+ ball.update();
+
+ Penjin::CollisionRegion* paddleCollisionRegion = paddle.getCollisionRegion();
+ Penjin::CollisionRegion* ballCollisionRegion = ball.getCollisionRegion();
+ Penjin::CollisionInfo ballPaddleCollision = ballCollisionRegion->hitTest(paddleCollisionRegion, true);
+
+ Penjin::Vector2d<float> newDirection = ball.getVelocity();
+
+ if(ballPaddleCollision.hasCollided)
+ {
+ newDirection.setX(((ball.getPosition().x + ball.getWidth()/2) - (paddle.getPosition().x + paddle.getWidth()/2))/10.0);
+ newDirection.setY(-1.0);
+ }
+
+ if((ballCollisionRegion->hitTest(0, ball.getPosition().y, true) && newDirection.x < 0) ||
+ (ballCollisionRegion->hitTest(Penjin::GFX::getInstance()->getWidth(), ball.getPosition().y, true) && newDirection.x > 0))
+ {
+ newDirection.setX(-newDirection.x);
+ }
+ if(ballCollisionRegion->hitTest(ball.getPosition().x, 0, true) && newDirection.y < 0)
+ {
+ newDirection.setY(-newDirection.y);
+ }
+
+ if(ballCollisionRegion->hitTest(ball.getPosition().x, Penjin::GFX::getInstance()->getHeight(), true) && newDirection.y > 0)
+ {
+ std::cout << "You lose!" << endl;
+ shouldQuit = true;
+ }
+
+ for(std::vector<Brick*>::iterator i = bricks.begin(); i != bricks.end(); ++i)
+ {
+ Penjin::CollisionRegion* brickCollisionRegion = (*i)->getCollisionRegion();
+ Penjin::CollisionInfo ballBrickCollision = ballCollisionRegion->hitTest(brickCollisionRegion, true);
+ if(ballBrickCollision.hasCollided)
+ {
+ switch(ballBrickCollision.direction.value)
+ {
+ case Penjin::diTOP:
+ case Penjin::diBOTTOM:
+ {
+ newDirection.setY(-newDirection.y);
+ break;
+ }
+ case Penjin::diLEFT:
+ case Penjin::diRIGHT:
+ {
+ newDirection.setX(-newDirection.x);
+ break;
+ }
+ case Penjin::diBOTTOMLEFT:
+ case Penjin::diBOTTOMRIGHT:
+ case Penjin::diTOPLEFT:
+ case Penjin::diTOPRIGHT:
+ {
+ newDirection.setX(-newDirection.x);
+ newDirection.setY(-newDirection.y);
+ break;
+ }
+ }
+
+ i = bricks.erase(i);
+ if(i == bricks.end())
+ {
+ break;
+ }
+ }
+
+ if(bricks.size() == 0)
+ {
+ std::cout << "You win!" << endl;
+ shouldQuit = true;
+ }
+ }
+
+ ball.setDirection(newDirection);
+}
+
+void GameState::input()
+{
+ Penjin::SimpleJoy* joy = Penjin::Joy::getInstance();
+ Penjin::CollisionRegion* paddleCollisionRegion = paddle.getCollisionRegion();
+ if(joy->isLeft() &&
+ !paddleCollisionRegion->hitTest(0, paddle.getPosition().y, true))
+ {
+ paddle.moveLeft();
+ }
+ if(joy->isRight() &&
+ !paddleCollisionRegion->hitTest(Penjin::GFX::getInstance()->getWidth(),
+ paddle.getPosition().y, true))
+ {
+ paddle.moveRight();
+ }
+}
+
+void GameState::clear()
+{
+ for(std::vector<Brick*>::iterator i = bricks.begin(); i != bricks.end(); ++i)
+ {
+ delete *i;
+ *i = 0;
+ }
+}
+
29 game/gamestate.h
@@ -0,0 +1,29 @@
+#ifndef GAMESTATE_H
+#define GAMESTATE_H
+
+#include "ApplicationState.h"
+#include "paddle.h"
+#include "ball.h"
+#include "brick.h"
+
+#include <vector>
+
+class GameState: public Penjin::ApplicationState
+{
+public:
+ GameState();
+
+ ~GameState();
+ void init();
+ void render();
+ void update();
+ void input();
+ void clear();
+
+private:
+ Paddle paddle;
+ Ball ball;
+ std::vector<Brick*> bricks;
+};
+
+#endif
9 game/main.cpp
@@ -0,0 +1,9 @@
+#include "penjinoid.h"
+
+int main(int argc, char** argv)
+{
+ Penjinoid penjinoid;
+ penjinoid.loop();
+ return Penjin::PENJIN_OK;
+}
+
17 game/paddle.cpp
@@ -0,0 +1,17 @@
+#include "paddle.h"
+
+Paddle::Paddle() :
+ Penjin::Sprite()
+{
+ load("img/paddle.png");
+}
+
+void Paddle::moveLeft()
+{
+ position.x -= 3.0;
+}
+
+void Paddle::moveRight()
+{
+ position.x += 3.0;
+}
18 game/paddle.h
@@ -0,0 +1,18 @@
+#ifndef PADDLE_H
+#define PADDLE_H
+
+#include "Sprite.h"
+
+class Paddle : public Penjin::Sprite
+{
+public:
+ Paddle();
+
+ void moveLeft();
+ void moveRight();
+
+private:
+
+};
+
+#endif
11 game/penjinoid.cpp
@@ -0,0 +1,11 @@
+#include "penjinoid.h"
+#include "gamestate.h"
+#include "StateManager.h"
+
+Penjinoid::Penjinoid()
+{
+ Penjin::StateManager* stateManager = Penjin::StateMan::getInstance();
+ stateManager->addState(STATE_GAME, new GameState());
+ stateManager->setNextState(STATE_GAME);
+ stateManager->stateManagement();
+}
14 game/penjinoid.h
@@ -0,0 +1,14 @@
+#ifndef PENJINOID_H
+#define PENJINOID_H
+
+#include "Game2d.h"
+
+class Penjinoid : public Penjin::Game2d
+{
+public:
+ Penjinoid();
+
+ enum States { STATE_GAME };
+};
+
+#endif
1 penjin
@@ -0,0 +1 @@
+Subproject commit 3252e701ac59ce8ae2d748a733a1e394fade9993
3 penjinoid.pro
@@ -0,0 +1,3 @@
+TEMPLATE = subdirs
+SUBDIRS = penjin game
+game.depends = penjin
11 target/config/settings.ini
@@ -0,0 +1,11 @@
+[Locale]
+LanguageFolder = strings
+Language = en_GB
+
+
+[Video]
+FrameRate = 60
+Width = 400
+Height = 240
+BitsPerPixel = 0
+Fullscreen = False
BIN target/img/ball.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
BIN target/img/brick.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
BIN target/img/paddle.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 9858525

Please sign in to comment.