Merge branch 'master' of github.com:ralucado/WaveGGJ17

This commit is contained in:
marti.lloveras 2017-01-21 04:31:29 +01:00
commit 64a48d69fb
17 changed files with 229 additions and 10 deletions

View file

@ -11,7 +11,11 @@ SOURCES += main.cpp \
character.cpp \
compas.cpp \
scene.cpp \
menu.cpp
menu.cpp \
combat.cpp \
player.cpp \
iaenemy.cpp \
actor.cpp
HEADERS += \
game.hpp \
@ -21,4 +25,8 @@ HEADERS += \
character.hpp \
compas.hpp \
scene.hpp \
menu.hpp
menu.hpp \
combat.hpp \
player.hpp \
iaenemy.hpp \
actor.hpp

7
VaporWaveWars/actor.cpp Normal file
View file

@ -0,0 +1,7 @@
#include "actor.hpp"
Actor::Actor() {}
void Actor::draw(sf::RenderWindow *window) {
}

17
VaporWaveWars/actor.hpp Normal file
View file

@ -0,0 +1,17 @@
#ifndef ENEMY_H
#define ENEMY_H
#include "commons.hpp"
class Actor
{
public:
Actor();
virtual bool update(float deltaTime, sf::RenderWindow *window) = 0;
void draw(sf::RenderWindow *window) ;
virtual bool event(sf::Event e) = 0;
protected:
bool animate;
};
#endif // ENEMY_H

View file

@ -71,7 +71,7 @@ void Button::handleMouseEvent(sf::Event& event){
void Button::initTexture(std::string path){
_clicks = 0;
_state = ButtonState::off;
if(!_texture.loadFromFile(path)) std::cout << "failed to load button texture!!" << std::endl;
ASSERT(_texture.loadFromFile(path));
setTexture(_texture);
_xSize = _texture.getSize().x;
_ySize = _texture.getSize().y/4;

29
VaporWaveWars/combat.cpp Normal file
View file

@ -0,0 +1,29 @@
#include "combat.hpp"
Combat::Combat() {
ia = playerOneTurn = true;
enemy = new IaEnemy();
}
Combat::Combat(bool ia) {
this->ia = ia;
playerOneTurn = true;
if (ia) enemy = new IaEnemy();
else enemy = new Player();
}
void Combat::update(float deltaTime, sf::RenderWindow *window) {
if (playerOneTurn) player.update(deltaTime, window);
else if (ia) playerOneTurn = enemy->update(deltaTime, window);
}
void Combat::draw(sf::RenderWindow *window) {
player.draw(window);
enemy->draw(window);
}
void Combat::updateEvents(sf::Event e) {
if (playerOneTurn) playerOneTurn = player.event(e);
else if (!ia) playerOneTurn = !enemy->event(e);
}

28
VaporWaveWars/combat.hpp Normal file
View file

@ -0,0 +1,28 @@
#ifndef COMBAT_H
#define COMBAT_H
#include "commons.hpp"
#include "compas.hpp"
#include "scene.hpp"
#include "player.hpp"
#include "iaenemy.hpp"
#include "actor.hpp"
class Combat : public Scene {
public:
Combat();
Combat(bool ia);
Combat(const Combat& m) = delete;
Combat(const Combat&& m) = delete;
Combat& operator=(Combat& m) = delete;
Combat& operator=(Combat&& m) = delete;
void update(float deltaTime, sf::RenderWindow *window) final override;
void draw(sf::RenderWindow *window) final override;
void updateEvents(sf::Event e) final override;
private:
bool playerOneTurn, ia;
Player player;
Actor *enemy;
};
#endif // COMBAT_H

View file

@ -26,6 +26,7 @@ void Game::run() {
float time = c.getElapsedTime().asSeconds();
float deltaTime = time-oldTime;
oldTime = time;
//std::cout << deltaTime << std::endl;
update(deltaTime, &window);
draw( &window);
}

10
VaporWaveWars/iaenemy.cpp Normal file
View file

@ -0,0 +1,10 @@
#include "iaenemy.hpp"
IaEnemy::IaEnemy() {}
bool IaEnemy::update(float deltaTime, sf::RenderWindow *window) {
//some playe return true
return true;
}
bool IaEnemy::event(sf::Event e) {return false;}

13
VaporWaveWars/iaenemy.hpp Normal file
View file

@ -0,0 +1,13 @@
#ifndef IAENEMY_H
#define IAENEMY_H
#include "actor.hpp"
class IaEnemy : public Actor {
public:
IaEnemy();
bool update(float deltaTime, sf::RenderWindow *window) final override;
bool event(sf::Event e) final override;
};
#endif // IAENEMY_H

View file

@ -32,7 +32,7 @@ void Menu::updateEvents(sf::Event e){
}
MyGame* g = static_cast<MyGame*>(Game::i());
if (_start.getClicks() > 0){
// g->changeScene(GameScene::inGame);
g->changeScene(GameScene::inGame);
std::cout << "Game not ready to be played. Please Wait." << std::endl;
}
else if(_exit.getClicks() > 0) g->isRunning = false;

View file

@ -4,6 +4,9 @@ MyGame::MyGame() {
_scene = GameScene::menu;
_scenes = std::vector<Scene*>(SCENE_NUM);
_scenes[GameScene::menu] = &_menu;
_scenes[GameScene::inGame] = &_combat;
_scenes[GameScene::help] = &_menu;
_scenes[GameScene::credits] = &_menu;
std::cout << "in menu" << std::endl;
}
@ -11,7 +14,6 @@ MyGame::~MyGame() {
}
MyGame* i(){
return static_cast<MyGame*>(Game::i());
}
void MyGame::changeScene(GameScene::gameScene n){
@ -20,7 +22,7 @@ void MyGame::changeScene(GameScene::gameScene n){
// Main game loop
void MyGame::update(float deltaTime, sf::RenderWindow*window) {
// std::cout << deltaTime << std::endl;
// std::cout << deltaTime << std::endl;
sf::Event event;
while(window->pollEvent(event)){
switch (event.type) {

View file

@ -3,7 +3,7 @@
#include "game.hpp"
#include "menu.hpp"
#include "combat.hpp"
class MyGame : public Game{
public:
MyGame();
@ -14,6 +14,7 @@ private:
GameScene::gameScene _scene;
std::vector<Scene*> _scenes;
Menu _menu;
Combat _combat;
virtual void update(float deltaTime, sf::RenderWindow *window) final override;
virtual void draw(sf::RenderWindow *window) final override;
};

31
VaporWaveWars/player.cpp Normal file
View file

@ -0,0 +1,31 @@
#include "player.hpp"
Player::Player() {
animate = false;
}
bool Player::update(float deltaTime, sf::RenderWindow *window) {
if (deltaTime > BLACKVALUE) compas.incraeseTime();
return false;
}
bool Player::event(sf::Event e) {
switch(e.type) {
case (sf::Event::KeyPressed):
if(e.key.code == sf::Keyboard::C) compas.start();
if(e.key.code == sf::Keyboard::Space) {
compas.add();
animate = true;
}
break;
case (sf::Event::KeyReleased):
if (e.key.code == sf::Keyboard::C) {
compas.end();
return false;
}
break;
default:
break;
}
return true;
}

16
VaporWaveWars/player.hpp Normal file
View file

@ -0,0 +1,16 @@
#ifndef PLAYER_H
#define PLAYER_H
#include "commons.hpp"
#include "compas.hpp"
#include "actor.hpp"
class Player : public Actor {
public:
Player();
bool update(float deltaTime, sf::RenderWindow *window) final override;
bool event(sf::Event e) final override;
private:
Compas compas;
};
#endif // PLAYER_H

View file

@ -0,0 +1,34 @@
#include "playscene.hpp"
PlayScene::PlayScene(){
}
void PlayScene::update(float deltaTime, sf::RenderWindow*window){
//float dx = InputManager::action(InputAction::moveX0);
//_buttons[0]->move(dx,0);
//std::cout << dx << std::endl;
for(unsigned int i = 0; i < _buttons.size(); ++i){
_buttons[i]->update(window->mapPixelToCoords(sf::Vector2i(sf::Mouse::getPosition(*window))));
}
}
void PlayScene::draw(sf::RenderWindow* window){
for(unsigned int i = 0; i < _buttons.size(); ++i){
window->draw(*_buttons[i]);
}
}
void PlayScene::updateEvents(sf::Event e){
// std::cout << "update menu buttons" << std::endl;
for(unsigned int i = 0; i < _buttons.size(); ++i){
_buttons[i]->handleMouseEvent(e);
}
MyGame* g = static_cast<MyGame*>(Game::i());
if (_start.getClicks() > 0){
// g->changeScene(GameScene::inGame);
std::cout << "Game not ready to be played. Please Wait." << std::endl;
}
else if(_exit.getClicks() > 0) g->isRunning = false;
}

View file

@ -0,0 +1,22 @@
#ifndef PLAYSCENE_HPP
#define PLAYSCENE_HPP
#include "scene.hpp"
class PlayScene : public Scene{
public:
PlayScene();
PlayScene(const Menu& m) = delete;
PlayScene(const Menu&& m) = delete;
PlayScene& operator=(Menu& m) = delete;
PlayScene& operator=(Menu&& m) = delete;
void update(float deltaTime, sf::RenderWindow *window) final override;
void draw(sf::RenderWindow *window) final override;
void updateEvents(sf::Event e) final override;
private:
sf::Texture _backgroundTexture;
sf::Sprite background;
};
#endif // PLAYSCENE_HPP

View file

@ -10,7 +10,7 @@ class Scene
virtual ~Scene();
virtual void update(float deltaTime, sf::RenderWindow *window) = 0;
virtual void draw(sf::RenderWindow *window) = 0;
virtual void updateEvents(sf::Event) = 0;
virtual void updateEvents(sf::Event e) = 0;
protected:
Game* parent;
};