...
 
Commits (3)
......@@ -8,6 +8,7 @@
class HUD{
public :
enum Dir{ TL , TR , BL , BR };
struct Meter{
int cv; int mv; Agent::Type upType,downType;
};
......@@ -16,7 +17,7 @@ class HUD{
int size;
};
HUD(sf::RenderWindow& window, HUD_data* data);
HUD(sf::RenderWindow& window, HUD_data* data, Dir d);
void draw();
void update(sf::Time dt);
......
......@@ -15,7 +15,7 @@ public :
private :
sf::RenderWindow mWindow;
World *mWorld;
HUD mHUD;
std::array<HUD*,2> mHUD;
sf::Time TimePerFrame;
};
#pragma once
#include <SFML/Graphics.hpp>
#include <set>
class Input{
public :
virtual bool isKeyPressed(sf::Keyboard::Key k);
virtual void update();
protected :
void press(sf::Keyboard::Key k);
void release(sf::Keyboard::Key k);
private :
std::set<sf::Keyboard::Key> pressed;
};
class KeyInput : public Input {
public :
virtual bool isKeyPressed(sf::Keyboard::Key k);
virtual void update();
};
......@@ -6,6 +6,7 @@
#include "category.hpp"
#include "sword.hpp"
#include "collectible.hpp"
#include "input.hpp"
class Player : public Alive{
......@@ -13,7 +14,7 @@ public :
virtual Agent::Type typeOfState();
public :
Player(TextureHolder const& Textures);
Player(TextureHolder const& Textures, Input* inp);
void q_spell();
void w_spell(int dir);
......@@ -36,6 +37,7 @@ public :
virtual void onCollideWith(SceneNode& collider);
private :
Input *input;
bool mIsQAvailable;
sf::Time mQCD, mQElapse;
......
......@@ -5,6 +5,7 @@
#include "room.hpp"
#include "carte.hpp"
#include "input.hpp"
#include "sceneNode.hpp"
#include "spriteNode.hpp"
#include "player.hpp"
......@@ -28,15 +29,16 @@ public:
void update(sf::Time dt);
void draw();
void spawnPlayer(Room* room);
void spawnPlayer(int i, Room* room, Input* inp);
int getPlayerHP() const;
Player* getPlayer() const{return mPlayer;}
// Player* getPlayer() const{return mPlayer[0];}
HUD::HUD_data* getHUDLocator(){return mData;}
HUD::HUD_data* getHUDLocator(int i){return mData[i];}
private:
void checkCollision();
void fillData();
void fillData(int i);
void makeData(int i);
private:
sf::RenderWindow& mWindow;
......@@ -47,8 +49,8 @@ private:
Carte mCarte;
SceneNode mSceneGraph;
Player* mPlayer;
std::array<Player*,2> mPlayer;
Room* mRoom;
HUD::HUD_data* mData;
std::array<HUD::HUD_data*,2> mData;
};
......@@ -2,7 +2,7 @@
#include <iostream>
HUD::HUD(sf::RenderWindow& window, HUD::HUD_data* data)
HUD::HUD(sf::RenderWindow& window, HUD::HUD_data* data, HUD::Dir d)
: mWindow(window), mView(window.getDefaultView()),
mBounds(0.f,0.f,mView.getSize().x,mView.getSize().y), mData(data){
......@@ -13,7 +13,20 @@ HUD::HUD(sf::RenderWindow& window, HUD::HUD_data* data)
for(int j = 0 ; j < mData->meters[i].mv ; ++j){
mContent[i][j] = new SpriteNode(mData->meters[i].upType, mTextures);
mRoot.attachChild(mContent[i][j]);
mContent[i][j]->move(32*j+16,32*i+16);
switch(d){
case TL :
mContent[i][j]->move(mView.getSize().x-32*j-16,32*i+16);
break;
case TR :
mContent[i][j]->move(32*j+16,32*i+16);
break;
case BL :
mContent[i][j]->move(32*j+16,mView.getSize().y-32*i-16);
break;
case BR :
mContent[i][j]->move(mView.getSize().x-32*j-16,mView.getSize().y-32*i-16);
break;
}
}
}
}
......
......@@ -97,7 +97,7 @@ void Alive::onCollideWith(SceneNode& collider){
hit(static_cast<Damageable&>(collider).isPoisonous(),
static_cast<Damageable&>(collider).getDMG());
break;
case Category::Ennemy : case Category::Player :
case Category::Ennemy :
hit(false);
break;
}
......
#include "../headers/game.hpp"
#include "../headers/HUD.hpp"
Game::Game() : mWindow(sf::VideoMode(1920, 1080), "LSV Fighters"), mWorld(new World(mWindow)),
mHUD(mWindow,mWorld->getHUDLocator()){
TimePerFrame = sf::seconds(1.f/60.f);
Game::Game() : mWindow(sf::VideoMode(1920, 1080), "LSV Fighters"),
mWorld(new World(mWindow)){
mHUD[0] = new HUD(mWindow,mWorld->getHUDLocator(0), HUD::TL);
mHUD[1] = new HUD(mWindow,mWorld->getHUDLocator(1), HUD::TR);
TimePerFrame = sf::seconds(1.f/60.f);
}
void Game::run(){
......@@ -32,19 +34,23 @@ void Game::processEvents(){
&& sf::Keyboard::isKeyPressed(sf::Keyboard::Q)) mWindow.close();
if(sf::Keyboard::isKeyPressed(sf::Keyboard::LControl)
&& sf::Keyboard::isKeyPressed(sf::Keyboard::R)){
delete mWorld; mWorld = new World(mWindow); mHUD.updateHUDlocator(mWorld->getHUDLocator());
delete mWorld; mWorld = new World(mWindow);
mHUD[0]->updateHUDlocator(mWorld->getHUDLocator(0));
mHUD[1]->updateHUDlocator(mWorld->getHUDLocator(1));
}
}
void Game::update(sf::Time deltaTime){
mWorld->update(deltaTime);
mHUD.update(deltaTime);
mHUD[0]->update(deltaTime);
mHUD[1]->update(deltaTime);
}
void Game::render(){
mWindow.clear();
mWorld->draw();
mHUD.draw();
mHUD[0]->draw();
mHUD[1]->draw();
mWindow.display();
}
#include "../headers/input.hpp"
void Input::press(sf::Keyboard::Key k){
pressed.insert(k);
}
void Input::release(sf::Keyboard::Key k){
pressed.erase(k);
}
void Input::update(){}
bool Input::isKeyPressed(sf::Keyboard::Key k){
return pressed.find(k) != pressed.end();
}
void KeyInput::update(){}
bool KeyInput::isKeyPressed(sf::Keyboard::Key k){
return sf::Keyboard::isKeyPressed(k);
}
......@@ -15,10 +15,11 @@ Agent::Type Player::typeOfState(){
}
}
Player::Player(TextureHolder const& textures)
Player::Player(TextureHolder const& textures, Input *inp)
: Alive(Agent::Player,textures,8,Entity::Player), mIsQAvailable(true), mIsWAvailable(true), mW(false),
unsing_poison(false), unsing_dagger(false),
poison_stack(0), coin_stack(4), key_stack(0), dagger_stack(0){
poison_stack(0), coin_stack(4), key_stack(0), dagger_stack(0),
input(inp) {
mQCD = sf::seconds(8.f);
mWCD = sf::seconds(1.f);
}
......@@ -83,24 +84,24 @@ void Player::act(sf::Time dt){
}
void Player::keyBindings(){
if(sf::Keyboard::isKeyPressed(sf::Keyboard::Left)) moveLeft();
if(sf::Keyboard::isKeyPressed(sf::Keyboard::Right)) moveRight();
if(sf::Keyboard::isKeyPressed(sf::Keyboard::Up)) moveUp();
if(sf::Keyboard::isKeyPressed(sf::Keyboard::Down)) moveDown();
if(input->isKeyPressed(sf::Keyboard::Left)) moveLeft();
if(input->isKeyPressed(sf::Keyboard::Right)) moveRight();
if(input->isKeyPressed(sf::Keyboard::Up)) moveUp();
if(input->isKeyPressed(sf::Keyboard::Down)) moveDown();
if(sf::Keyboard::isKeyPressed(sf::Keyboard::Space)) q_spell();
if(sf::Keyboard::isKeyPressed(sf::Keyboard::Z)){
if(input->isKeyPressed(sf::Keyboard::Space)) q_spell();
if(input->isKeyPressed(sf::Keyboard::Z)){
if(unsing_dagger) e_spell(3); else w_spell(3);}
if(sf::Keyboard::isKeyPressed(sf::Keyboard::Q)){
if(input->isKeyPressed(sf::Keyboard::Q)){
if(unsing_dagger) e_spell(2); else w_spell(2);}
if(sf::Keyboard::isKeyPressed(sf::Keyboard::S)){
if(input->isKeyPressed(sf::Keyboard::S)){
if(unsing_dagger) e_spell(1); else w_spell(1);}
if(sf::Keyboard::isKeyPressed(sf::Keyboard::D)){
if(input->isKeyPressed(sf::Keyboard::D)){
if(unsing_dagger) e_spell(0); else w_spell(0);}
if(sf::Keyboard::isKeyPressed(sf::Keyboard::E) && !unsing_poison && poison_stack > 0){
if(input->isKeyPressed(sf::Keyboard::E) && !unsing_poison && poison_stack > 0){
unsing_poison = true; --poison_stack;
}
if(sf::Keyboard::isKeyPressed(sf::Keyboard::A) && !unsing_dagger && dagger_stack > 0){
if(input->isKeyPressed(sf::Keyboard::A) && !unsing_dagger && dagger_stack > 0){
unsing_dagger = true; --dagger_stack;
}
}
......
......@@ -6,46 +6,46 @@ World::World(sf::RenderWindow& window)
mWorldBounds(0.f,0.f,mWorldView.getSize().x,mWorldView.getSize().y),
mCarte(mTextures,mWorldBounds,0.9f,0.9f,0.4f,20,this){
mRoom = mCarte.checkIn();
spawnPlayer(mRoom);
spawnPlayer(0,mRoom, new KeyInput());
spawnPlayer(1,mRoom, new Input());
mSceneGraph.attachChild(mRoom);
mData = new HUD::HUD_data;
mData->size = 5;
mData->meters = new HUD::Meter[mData->size];
mData->meters[0].cv = mData->meters[0].mv = getPlayerHP();
mData->meters[0].upType = Agent::HP_full; mData->meters[0].downType = Agent::HP_down;
mData->meters[1].mv = 10; mData->meters[1].cv = 0;
mData->meters[1].upType = Agent::Poison; mData->meters[1].downType = Agent::Void;
mData->meters[2].mv = 10; mData->meters[2].cv = 0;
mData->meters[2].upType = Agent::Coin; mData->meters[2].downType = Agent::Void;
mData->meters[3].mv = 10; mData->meters[3].cv = 0;
mData->meters[3].upType = Agent::Key; mData->meters[3].downType = Agent::Void;
mData->meters[4].mv = 10; mData->meters[4].cv = 0;
mData->meters[4].upType = Agent::Dagger; mData->meters[4].downType = Agent::Void;
makeData(0); makeData(1);
}
World::~World(){
delete mData;
delete mData[0], mData[1];
}
void World::fillData(){
mData->meters[0].cv = getPlayerHP();
mData->meters[1].cv = mPlayer->getPoisonStack();
mData->meters[2].cv = mPlayer->getCoins();
mData->meters[3].cv = mPlayer->getKeys();
mData->meters[4].cv = mPlayer->getDaggers();
void World::makeData(int i){
mData[i] = new HUD::HUD_data;
mData[i]->size = 5;
mData[i]->meters = new HUD::Meter[mData[i]->size];
mData[i]->meters[0].cv = mData[i]->meters[0].mv = mPlayer[i]->getHP();
mData[i]->meters[0].upType = Agent::HP_full; mData[i]->meters[0].downType = Agent::HP_down;
mData[i]->meters[1].mv = 10; mData[i]->meters[1].cv = 0;
mData[i]->meters[1].upType = Agent::Poison; mData[i]->meters[1].downType = Agent::Void;
mData[i]->meters[2].mv = 10; mData[i]->meters[2].cv = 0;
mData[i]->meters[2].upType = Agent::Coin; mData[i]->meters[2].downType = Agent::Void;
mData[i]->meters[3].mv = 10; mData[i]->meters[3].cv = 0;
mData[i]->meters[3].upType = Agent::Key; mData[i]->meters[3].downType = Agent::Void;
mData[i]->meters[4].mv = 10; mData[i]->meters[4].cv = 0;
mData[i]->meters[4].upType = Agent::Dagger; mData[i]->meters[4].downType = Agent::Void;
}
void World::spawnPlayer(Room* room){
mPlayer = new Player(mTextures);
room->attachPlayer(mPlayer);
void World::fillData(int i){
mData[i]->meters[0].cv = mPlayer[i]->getHP();
mData[i]->meters[1].cv = mPlayer[i]->getPoisonStack();
mData[i]->meters[2].cv = mPlayer[i]->getCoins();
mData[i]->meters[3].cv = mPlayer[i]->getKeys();
mData[i]->meters[4].cv = mPlayer[i]->getDaggers();
}
int World::getPlayerHP() const{
return mPlayer->getHP();
void World::spawnPlayer(int i, Room* room, Input *inp){
mPlayer[i] = new Player(mTextures, inp);
room->attachPlayer(mPlayer[i]);
}
void World::draw(){
mWindow.draw(mSceneGraph);
}
......@@ -56,7 +56,7 @@ void World::update(sf::Time dt){
mSceneGraph.update(dt);
mSceneGraph.removeWrecks(bounds);
checkCollision();
fillData();
fillData(0); fillData(1);
}
void World::checkCollision(){
......@@ -69,15 +69,18 @@ void World::checkCollision(){
}
for(auto &pair : stack){
if(pair.first->identify() == Category::Player && pair.second->identify() == Category::Door){
if(static_cast<Door&>(*pair.second).lockLevel() <= static_cast<Player&>(*pair.first).getKeys()){
mPlayer = static_cast<Player*>(mRoom->detachPlayer(*mPlayer));
if(static_cast<Door&>(*pair.second).lockLevel()
<= static_cast<Player&>(*pair.first).getKeys()){
mPlayer[0] = static_cast<Player*>(mRoom->detachPlayer(*mPlayer[0]));
mPlayer[1] = static_cast<Player*>(mRoom->detachPlayer(*mPlayer[1]));
Room* room = static_cast<Room*>(mSceneGraph.detachChild(*mRoom));
mCarte.checkOut(room);
mCarte.move(static_cast<Door&>(*pair.second).getDir());
mRoom->reset();
mRoom = mCarte.checkIn();
mRoom->spawnAt(static_cast<Door&>(*pair.second).getDir());
mRoom->attachPlayer(mPlayer);
mRoom->attachPlayer(mPlayer[0]);
mRoom->attachPlayer(mPlayer[1]);
mSceneGraph.attachChild(mRoom);
}
}
......