Skip to content
This repository has been archived by the owner on Jun 3, 2023. It is now read-only.

*** #4

Closed
wants to merge 4 commits into from
Closed
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
4 changes: 4 additions & 0 deletions SpaceWars2/CommonData.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@
#include <Siv3D.hpp>
#include "Config.hpp"

#include "./functions/Player.hpp"

typedef struct {
int count = 0;
Texture background = Texture(L"images/background.png");
Player LPlayer;
Player RPlayer;
} CommonData;
33 changes: 32 additions & 1 deletion SpaceWars2/functions/Player.cpp
Original file line number Diff line number Diff line change
@@ -1 +1,32 @@
#pragma once
#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);
}
13 changes: 12 additions & 1 deletion SpaceWars2/functions/Player.hpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
#pragma once
#include <Siv3D.hpp>
#include "../Config.hpp"
#include "../Config.hpp"

class Player {
public:
int32 posX;
int32 posY;
bool isLeft;
Circle ship;

void Init(int32, int32, bool);
void Control();
};
14 changes: 8 additions & 6 deletions SpaceWars2/scenes/Game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"));
}