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

#1-自機の作成 #6

Merged
merged 5 commits into from
Oct 9, 2018
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
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;
30 changes: 29 additions & 1 deletion SpaceWars2/functions/Player.cpp
Original file line number Diff line number Diff line change
@@ -1 +1,29 @@
#pragma once
#pragma once
#include "Player.hpp"

#define PLAYER_SPEED 10

void Player::Init(int32 _x, int32 _y, bool _isLeft){
posX = _x;
posY = _y;
isLeft = _isLeft;
}

void Player::Control(){
Rect tmpZoon;

if(isLeft){
tmpZoon = Rect(0, 0, Config::Width / 2, Config::Height);
if(Input::KeyD.pressed && tmpZoon.contains(Circle(posX + PLAYER_SPEED, posY, 40))) posX += PLAYER_SPEED;
if(Input::KeyA.pressed && tmpZoon.contains(Circle(posX - PLAYER_SPEED, posY, 40))) posX -= PLAYER_SPEED;
if(Input::KeyW.pressed && tmpZoon.contains(Circle(posX, posY - PLAYER_SPEED, 40))) posY -= PLAYER_SPEED;
if(Input::KeyS.pressed && tmpZoon.contains(Circle(posX, posY + PLAYER_SPEED, 40))) posY += PLAYER_SPEED;
}else{
tmpZoon = Rect(Config::Width/2, 0, Config::Width / 2, Config::Height);
if(Input::KeySemicolon.pressed && tmpZoon.contains(Circle(posX + PLAYER_SPEED, posY, 40))) posX += PLAYER_SPEED;
if(Input::KeyK.pressed && tmpZoon.contains(Circle(posX - PLAYER_SPEED, posY, 40))) posX -= PLAYER_SPEED;
if(Input::KeyO.pressed && tmpZoon.contains(Circle(posX, posY - PLAYER_SPEED, 40))) posY -= PLAYER_SPEED;
if(Input::KeyL.pressed && tmpZoon.contains(Circle(posX, posY + PLAYER_SPEED, 40))) posY += PLAYER_SPEED;
}
ship = Circle(posX, 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();
};
12 changes: 6 additions & 6 deletions SpaceWars2/scenes/Game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
#include "Game.hpp"
#include "../Config.hpp"

#include "../functions/Player.hpp"

void Game::init() {
this->CicaR32 = Font(32, L"Cica"); // :ac:
m_data->count++;
Expand All @@ -11,15 +13,13 @@ void Game::init() {
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"));
}
2 changes: 2 additions & 0 deletions SpaceWars2/scenes/Opening.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ void Opening::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 Opening::update(){
Expand Down