Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Powerup #3

Merged
merged 2 commits into from
Nov 6, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
<_ProjectFileVersion>10.0.30319.1</_ProjectFileVersion>
<OutDir Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">bin\</OutDir>
<IntDir Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">obj\$(Configuration)\</IntDir>
<LinkIncremental Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</LinkIncremental>
<LinkIncremental Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">false</LinkIncremental>
<GenerateManifest Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</GenerateManifest>
<OutDir Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">bin\</OutDir>
<IntDir Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">obj\$(Configuration)\</IntDir>
Expand Down Expand Up @@ -108,6 +108,7 @@
<ClCompile Include="src\display\npc\human.cpp" />
<ClCompile Include="src\display\VelStats.cpp" />
<ClCompile Include="src\Game.cpp" />
<ClCompile Include="src\game\PowerUp.cpp" />
<ClCompile Include="src\kinect\KinectInterface.cpp" />
<ClCompile Include="src\main.cpp" />
<ClCompile Include="src\player.cpp" />
Expand Down Expand Up @@ -197,6 +198,8 @@
<ClInclude Include="src\display\npc\human.h" />
<ClInclude Include="src\display\VelStats.h" />
<ClInclude Include="src\Game.h" />
<ClInclude Include="src\game\GenericData.h" />
<ClInclude Include="src\game\PowerUp.h" />
<ClInclude Include="src\kinect\KinectInterface.h" />
<ClInclude Include="src\panelUI.h" />
<ClInclude Include="src\player.h" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,9 @@
<ClCompile Include="src\display\npc\cop.cpp">
<Filter>src\display\npc</Filter>
</ClCompile>
<ClCompile Include="src\game\PowerUp.cpp">
<Filter>src\game</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<Filter Include="src">
Expand Down Expand Up @@ -435,6 +438,9 @@
<Filter Include="src\display\npc">
<UniqueIdentifier>{82a6b208-5527-4a72-9799-e2f22ef3b9ab}</UniqueIdentifier>
</Filter>
<Filter Include="src\game">
<UniqueIdentifier>{2cc2ac13-7089-410b-95bc-2bd165d19cfa}</UniqueIdentifier>
</Filter>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\..\..\addons\ofxOpenCv\src\ofxCvBlob.h">
Expand Down Expand Up @@ -1133,5 +1139,11 @@
<ClInclude Include="src\display\npc\bomb.h">
<Filter>src\display\npc</Filter>
</ClInclude>
<ClInclude Include="src\game\PowerUp.h">
<Filter>src\game</Filter>
</ClInclude>
<ClInclude Include="src\game\GenericData.h">
<Filter>src\game</Filter>
</ClInclude>
</ItemGroup>
</Project>
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ void Bicicletorama::setup()

arduino.setup();
kinect.setup(box2d.getWorld());
game.setup(box2d.getWorld(), &arduino);
game.setup(&box2d, &arduino);
borda.setup(&kinect.contourFinder);
menu.setup();
m_panel.setup(&kinect, &game);
Expand Down
72 changes: 70 additions & 2 deletions of_v0.7.4_vs2010_release/apps/myApps/Bicicletorama/src/Game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,15 @@


//--------------------------------------------------------------
void Game::setup(b2World * _world, Arduino * _arduino)
void Game::setup(ofxBox2d * _box2d, Arduino * _arduino)
{
world = _world;
box2d = _box2d;
world = box2d->getWorld();
arduino = _arduino;

// register the listener so that we get the events
ofAddListener(box2d->contactStartEvents, this, &Game::contactStart);
ofAddListener(box2d->contactEndEvents, this, &Game::contactEnd);

//background
background.loadImage("images/background.jpg");
Expand Down Expand Up @@ -50,6 +55,9 @@ void Game::setup(b2World * _world, Arduino * _arduino)

//timer
lastGameTimer = -1;


powerUpList.push_back(new PowerUp(world));

}

Expand All @@ -67,6 +75,11 @@ void Game::update()
}
}

//power up
for(int i=powerUpList.size()-1; i >= 0; i--){
powerUpList[i]->update();
}

//players
if (!locked)
{
Expand Down Expand Up @@ -134,6 +147,11 @@ void Game::draw()
ofSetColor(255);
canvas.draw(0,0);

//powerup
for(int i=powerUpList.size()-1; i >= 0; i--){
powerUpList[i]->draw();
}

//players
ofSetColor(255);
for (int i=0; i<TOTAL_PLAYERS; i++) {
Expand Down Expand Up @@ -261,3 +279,53 @@ void Game::onCopAttack(attack & a)
b.setup(a.startX, a.startY, a.endX, a.endY);
bombs.push_back(b);
}


//--------------------------------------------------------------
// Box2D Contact System
//--------------------------------------------------------------

void Game::contactStart(ofxBox2dContactArgs &e) {
if(e.a != NULL && e.b != NULL) {

//power up
checkContactStart_powerUp(e.a, e.b);
checkContactStart_powerUp(e.b, e.a);

}
}

void Game::contactEnd(ofxBox2dContactArgs &e) {
if(e.a != NULL && e.b != NULL) {

//power up
checkContactEnd_powerUp(e.a, e.b);
checkContactEnd_powerUp(e.b, e.a);
}
}

void Game::checkContactStart_powerUp(b2Fixture * a, b2Fixture * b) {

GenericData * dataA = (GenericData*)a->GetBody()->GetUserData();
if (dataA != NULL && dataA->name == "powerup") {

GenericData * dataB = (GenericData*)b->GetBody()->GetUserData();
if (dataB != NULL && dataB->name == "bike") {
player * p = (player*)dataB->data;
p->addPowerUp();
}
}
}

void Game::checkContactEnd_powerUp(b2Fixture * a, b2Fixture * b) {

GenericData * dataA = (GenericData *)(a->GetBody()->GetUserData());
if (dataA != NULL && dataA->name == "powerup") {

GenericData * dataB = (GenericData *)(b->GetBody()->GetUserData());
if (dataB != NULL && dataB->name == "bike") {
player * p = (player*)dataB->data;
p->removePowerUp();
}
}
}
21 changes: 15 additions & 6 deletions of_v0.7.4_vs2010_release/apps/myApps/Bicicletorama/src/Game.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,30 +10,30 @@
#include "bomb.h"
#include "civil.h"
#include "sound.h"
#include "game/GenericData.h"
#include "game/PowerUp.h"


class Game {

public:

void setup(b2World * _world, Arduino * _arduino);
void setup(ofxBox2d * _box2d, Arduino * _arduino);
void update();
void draw();

void keyReleased(int key);
void mouseDragged(int x, int y, int button);
void mousePressed(int x, int y, int button);

void updatePlayersDirection(float direction[TOTAL_PLAYERS]);
void updatePlayersDistance(float distance[TOTAL_PLAYERS]);

player playerList[TOTAL_PLAYERS];


private:

Arduino * arduino;
ofxBox2d * box2d;
b2World * world;
Arduino * arduino;

void startGame();
int startGameMillis;
Expand All @@ -57,5 +57,14 @@ class Game {

vector<bomb> bombs;
ofFbo bombCanvas;


vector<PowerUp*> powerUpList;


void contactStart(ofxBox2dContactArgs &e);
void contactEnd(ofxBox2dContactArgs &e);

void checkContactStart_powerUp(b2Fixture * a, b2Fixture * b);
void checkContactEnd_powerUp(b2Fixture * a, b2Fixture * b);

};
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#pragma once

#include <string>

class GenericData {
public:

GenericData(const std::string & _name = "", void * _data = NULL) {
name = _name;
data = _data;
}

std::string name;
void * data;
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@

#include "PowerUp.h"

PowerUp::PowerUp(b2World * b2dworld)
{
box.fixture.isSensor = true;

box.setup(b2dworld, 0, 0, 100, 20);
box.setData(new GenericData("powerup", this));

box.setPosition(400,120);

//box.fixture
}

void PowerUp::update() {
//timer para se auto destruir
}

void PowerUp::draw() {
box.draw();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#pragma once

#include "ofxBox2d.h"
#include "game/GenericData.h"


class PowerUp {

public:

PowerUp(b2World * b2dworld);

void update();
void draw();

protected:

ofImage image;
ofxBox2dRect box;

};
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,15 @@ void player::setup(int _playerID, b2World * b2dworld)
//box2d
bike.setPhysics(BIKE_DENSITY, BIKE_BOUNCE, BIKE_FRICTION);
bike.setup(b2dworld, 0, 0, BIKE_WIDTH, BIKE_HEIGHT);
bike.setData(new GenericData("bike", this));

frontWheel.setPhysics(BIKE_DENSITY, BIKE_BOUNCE, BIKE_FRICTION);
frontWheel.setup(b2dworld, 0, -BIKE_HEIGHT, WHEEL_WIDTH, WHEEL_HEIGHT);
frontWheel.setData(new GenericData("frontWheel", this));

rearWheel.setPhysics(BIKE_DENSITY, BIKE_BOUNCE, BIKE_FRICTION);
rearWheel.setup(b2dworld, 0, +BIKE_HEIGHT, WHEEL_WIDTH, WHEEL_HEIGHT);
rearWheel.setup(b2dworld, 0, +BIKE_HEIGHT, WHEEL_WIDTH, WHEEL_HEIGHT);
rearWheel.setData(new GenericData("rearWheel", this));

b2RevoluteJointDef* frontJointDef = new b2RevoluteJointDef();
frontJointDef->Initialize(bike.body, frontWheel.body, frontWheel.body->GetWorldCenter());
Expand Down Expand Up @@ -167,6 +170,16 @@ void player::applyImpulse()
spriteBike.nextFrame();
}

void player::addPowerUp()
{
HORSEPOWERS *= 4;
}

void player::removePowerUp()
{
HORSEPOWERS /= 4;
}

void player::update()
{
killOrthogonalVelocity(frontWheel.body);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "ofxBox2d.h"
#include "ofxSpriteManager.h"
#include "Configuration.h"
#include "game/GenericData.h"


class player {
Expand Down Expand Up @@ -35,6 +36,9 @@ class player {
void applyImpulse();

float getVelocity();

void addPowerUp();
void removePowerUp();

int x;
int y;
Expand Down
Binary file not shown.
Binary file not shown.