diff --git a/SpaceWars2/CommonData.hpp b/SpaceWars2/CommonData.hpp index a277d20..82254aa 100644 --- a/SpaceWars2/CommonData.hpp +++ b/SpaceWars2/CommonData.hpp @@ -2,7 +2,11 @@ #include #include "Config.hpp" +#include "./functions/Player.hpp" + typedef struct { int count = 0; Texture background = Texture(L"images/background.png"); + Player LPlayer; + Player RPlayer; } CommonData; diff --git a/SpaceWars2/functions/Player.cpp b/SpaceWars2/functions/Player.cpp index 7b9637e..bd53492 100644 --- a/SpaceWars2/functions/Player.cpp +++ b/SpaceWars2/functions/Player.cpp @@ -1 +1,32 @@ -#pragma once \ No newline at end of file +#pragma once +#include "Player.hpp" + +#define SPEED 3 + +void Player::Init(int32 _x, int32 _y, bool _isLeft){ + posX = _x; + posY = _y; + isLeft = _isLeft; +} + +void Player::Control(){ + int32 tmpX = 0, tmpY = 0; + Rect tmpZoon; + tmpX = this->posX; + tmpY = this->posY; + + if(this->isLeft){ + tmpZoon = Rect(0, 0, Config::Width / 2, Config::Height); + if(Input::KeyD.pressed && tmpZoon.contains(Circle(this->posX + SPEED, this->posY, 40))) this->posX += SPEED; + if(Input::KeyA.pressed && tmpZoon.contains(Circle(this->posX - SPEED, this->posY, 40))) this->posX -= SPEED; + if(Input::KeyW.pressed && tmpZoon.contains(Circle(this->posX, this->posY - SPEED, 40))) this->posY -= SPEED; + if(Input::KeyS.pressed && tmpZoon.contains(Circle(this->posX, this->posY + SPEED, 40))) this->posY += SPEED; + }else{ + tmpZoon = Rect(Config::Width/2, 0, Config::Width / 2, Config::Height); + if(Input::KeySemicolon.pressed && tmpZoon.contains(Circle(this->posX + SPEED, this->posY, 40))) this->posX += SPEED; + if(Input::KeyK.pressed && tmpZoon.contains(Circle(this->posX - SPEED, this->posY, 40))) this->posX -= SPEED; + if(Input::KeyO.pressed && tmpZoon.contains(Circle(this->posX, this->posY - SPEED, 40))) this->posY -= SPEED; + if(Input::KeyL.pressed && tmpZoon.contains(Circle(this->posX, this->posY + SPEED, 40))) this->posY += SPEED; + } + this->ship = Circle(this->posX, this->posY, 40); +} \ No newline at end of file diff --git a/SpaceWars2/functions/Player.hpp b/SpaceWars2/functions/Player.hpp index bbdb23b..4e90d4c 100644 --- a/SpaceWars2/functions/Player.hpp +++ b/SpaceWars2/functions/Player.hpp @@ -1,3 +1,14 @@ #pragma once #include -#include "../Config.hpp" \ No newline at end of file +#include "../Config.hpp" + +class Player { + public: + int32 posX; + int32 posY; + bool isLeft; + Circle ship; + + void Init(int32, int32, bool); + void Control(); +}; diff --git a/SpaceWars2/scenes/Game.cpp b/SpaceWars2/scenes/Game.cpp index 4252642..dde3193 100644 --- a/SpaceWars2/scenes/Game.cpp +++ b/SpaceWars2/scenes/Game.cpp @@ -2,24 +2,26 @@ #include "Game.hpp" #include "../Config.hpp" +#include "../functions/Player.hpp" + void Game::init() { this->CicaR32 = Font(32, L"Cica"); // :ac: m_data->count++; Println(m_data->count); + m_data->LPlayer.Init(40, 540, true); + m_data->RPlayer.Init(1880, 540, false); } void Game::update() { if (Input::KeyEnter.clicked) changeScene(L"Finish"); - if (this->mode) - y++; - else - y--; - if (y < 0)mode = true; - if (y > 800)mode = false; + m_data->LPlayer.Control(); + m_data->RPlayer.Control(); } void Game::draw() const { m_data->background.resize(Config::Width, Config::Height).draw(); CicaR32(L"I am game scene! Hello!").drawCenter(y/*200*/, Color(L"#ffffff")); + m_data->LPlayer.ship.draw(Color(L"#ff0000")); + m_data->RPlayer.ship.draw(Color(L"#0000ff")); }