Skip to content

Instantly share code, notes, and snippets.

@Nafmo2

Nafmo2/Main.cpp

Last active Feb 8, 2018
Embed
What would you like to do?
Thread Through ver 0.3(完成版)
// 製作者 @Nafmo2
// Siv3Dを使用。
// 5日クオリティーのため雑に仕上げたところ多数。
// 無告知で編集・削除されることがあります。ご了承ください
// 無断利用はご遠慮ください。
#include "Main.h"
#define NAD 300
#define BMAX 1000
int mode = 1;
int m_R = 80;
bool Nga = true;
const String Title = L"Thread Through", ver = L"0.3";
void Menu() {
FontAsset(L"Title")(Title).drawCenter(30);
Circle B1 = Circle(320, 300, m_R);
Circle B2 = Circle(120, 300, 80);
Circle B3 = Circle(520, 300, 80);
B1.draw(Palette::Aqua);
B2.draw(Palette::Hotpink);
B3.draw(Palette::Limegreen);
FontAsset(L"ver").draw(L"ver:" + ver, 530, 125, Palette::White);
FontAsset(L"sel")(L"Play").drawCenter(B1.center, Palette::Black);
FontAsset(L"sel")(L"quit").drawCenter(B2.center, Palette::Black);
FontAsset(L"sel")(L"Rank").drawCenter(B3.center, Palette::Black);
if (B1.mouseOver) {
if (85 > m_R)m_R++;
}
else {
if (80 < m_R)m_R--;
}
if (B1.leftClicked) {
mode = 2;
}
if (B2.leftClicked) {
System::Exit();
}
if (B3.leftClicked) {
mode = 3;
}
}
void Main()
{
FontAsset::Register(L"Title", 50, Typeface::Black);
FontAsset::Register(L"sel", 30, Typeface::Default);
FontAsset::Register(L"ver", 15, Typeface::Default);
const Font font(20);
const Font Resl(30);
const Font Lar(50);
const Font Foo(40);
const Font Out1(30, Typeface::Bold, FontStyle::Outline);
const Font Out2(22, Typeface::Bold, FontStyle::Outline);
Out1.changeOutlineStyle(TextOutlineStyle(Palette::Orange, Palette::Black, 2.0));
Out2.changeOutlineStyle(TextOutlineStyle(Palette::Yellowgreen, Palette::Black, 2.0));
Window::SetTitle(Title + L" ver" + ver);
Graphics::SetBackground(Color::Color(0x393939));
Player P;
Ball bal[BMAX];
int Time = 0;
int Score = -1;
std::queue<int> Des;
bool fir = true;
int pc = 0;
RW(-1);
Stopwatch stopwatch(true);
DynamicTexture texturePause;
while (System::Update())
{
//if (stopwatch.isPaused())
//{
// if (ScreenCapture::HasNewFrame())
// {
// texturePause.fill(ScreenCapture::GetFrame().gaussianBlurred(16, 16));
// }
// if (Input::KeyP.clicked)
// {
// stopwatch.resume();
// }
// texturePause.draw(AlphaF(0.5));
// RoundRect(Rect(300, 200).setCenter(Window::Center()), 20).draw(ColorF(0.2, 0.6, 0.8, 0.8));
// font(L"PAUSE").drawCenter(Window::Center());
//}else {
switch (mode) {
case 1:
Score = -1;
Nga = true;
Menu();
//if (!KinectV2::IsAvailable()) {
//// font(L"Can't use Kinect").draw(0,0,Palette::Gold);
//}
break;
case 2:
Nga = false;
//--------------------admin--------------------
//if (Input::KeyF9.pressed) { Time += NAD; Ad = true; }
//if (Input::KeyP.clicked){
// ScreenCapture::Request();
// stopwatch.pause();
// pc = 30;
//}
//---------------------------------------------
Circle Player(P.GetX(), P.GetY(), 5);
if (fir) {
P.Init();
for (int i = 0; i < BMAX; i++) {
bal[i].Init();
}
Score = -1;
Time = 0;
P.Init();
pc = 0;
Lar(L"Please L-Click").drawCenter(240);
font(L"押してから1秒後に始まります").drawCenter(380);
if (Input::KeySpace.clicked | Input::MouseL.clicked)fir = false;
continue;
}
if (P.Alive()) {
if (pc > 60) {
//Admin if (Input::KeyR.clicked) { P.Init(); Ad = true; }
if (Time % 60 == 0) {
for (int i = 0, cnt = 0; cnt < 3 + Time / NAD; i++) {
if (!bal[i].NF()) {
bal[i].set(640 + Random(0, 400), Random(1, 480), double((Time + Random(10, 100)) % 360));
cnt++;
}
}
}
for (int i = 0; i < BMAX; i++) {
if (bal[i].NF()) {
bal[i].Phy();
}
}
P.D.push_back(std::make_pair(P.GetX(), P.GetY()));
P.UpK();
P.Phy(Input::MouseL.pressed || Input::KeySpace.pressed);
Time++;
}
else {
P.D.push_back(std::make_pair(P.GetX(), P.GetY()));
P.UpK();
pc++;
}
//Admin(当たり判定無効)
bool NoAt = true/*!(Input::KeyF8.pressed)*/;
//if (!NoAt)Ad = true;
//font(NoAt).draw(0, 440);
for (int i = 0; i < BMAX; i++) {
//1行目:三平方 二行目:画面外 3行目:当たり判定を消すためのAdminフラグ
//P.Gor()はGameOver関数。
if ((std::pow(P.GetX() - bal[i].GetX(), 2) + std::pow(P.GetY() - bal[i].GetY(), 2) < std::pow(15, 2) && bal[i].NF() ||
P.GetY() < 0 || P.GetY() > 480)
&& NoAt) {
P.Gor();
}
}
}
else {
if (Score == -1)Score = Time;
if (Input::KeyS.clicked) {
RW(Score);
P.Init();
for (int i = 0; i < BMAX; i++) {
bal[i].Init();
}
Score = -1;
Time = 0;
pc = 0;
}
if (Input::KeyEnter.pressed) {
mode = 3;
}
}
//--------------------描画------------------------------
for (int i = 0; i < BMAX; i++) {
if (bal[i].NF())Circle(bal[i].GetX(), bal[i].GetY(), 10).draw(HSV(bal[i].Col, 0.65, 1.0));
}
Player.draw(Color(52, 152, 219));
font(L"Level:", Time / NAD, L" Score:", Time).draw(0, 0, Palette::Lightgreen);
font(L"HighScore:", HighScore).draw(400, 0, Palette::Lightblue);
Line(0, 0, 640, 0).draw(10, Palette::Red);
Line(0, 480, 640, 480).draw(10, Palette::Red);
if (!P.Alive()) {
Out1(L"Your Score is ", Score).draw(50, 100);
Out2(L"Retry:Press S-Key! Exit:Press Enter").drawCenter(Window::Height() / 2);
Out2(L"Press T:Tweet Result").drawCenter(370);
if (Input::KeyT.clicked) {
Twitter::OpenTweetWindow(L"#ThreadThrough ver " + ver + L" を プレイしました!\nYour Score is " + Format(Score));
}
}
//---------------------------------------------------
break;
case 3:
if (!fir) {
RW(Score);
fir = true;
}
TextReader Read(L"ranking.txt", unspecified);
if (Score != -1)Resl(L"Your Score is ", Score).draw(25, 10, Palette::Lightgreen);
if (HighScore == Score)font(L"(Highest!!)").draw(450, 17.5, Palette::Orange);
Foo(L"Score Ranking!").drawCenter(80, Palette::Aqua, 1.0);
if (Score != -1)font(L"Retry:Press S-Key! Exit:Press Enter").drawCenter(420, Palette::Lightyellow, 1.0);
else font(L"Click to Menu").drawCenter(420, Palette::Lightyellow, 1.0);
if ((Input::KeyS.clicked | Input::MouseL.clicked) && !Nga) {
P.Init();
for (int i = 0; i < BMAX; i++) {
bal[i].Init();
}
Score = -1;
Time = 0;
pc = 0;
mode = 2;
}
if (Input::MouseR.clicked || Input::KeyEnter.clicked || Nga&&Input::MouseL.clicked) { m_R = 80; mode = 1; }
for (int i = 1; i <= 5; i++) {
String st;
Read.readLine(st);
font(i, L":", st).drawCenter(110 + i * 50);
}
break;
}
//}
}
}
#pragma once
#include <list>
#include <Siv3D.hpp>
#include <queue>
#include <cmath>
#include <iostream>
#include <fstream>
#include <algorithm>
#include <string>
#include <cstdlib>
__int64 HighScore;
bool Ad=false;
class Player {
private:
double x, y;
double a,g;
bool alv;
double dx;
public:
std::list<std::pair<double,double>> D;
void Init() {
x = 100;
y = 240;
dx = 0;
a = 0.75;
g = 0.30;
alv = true;
D.clear();
}
Player() {
Init();
}
bool Alive() {
return alv;
}
double GetX() {
return x;
}
double GetY() {
return y;
}
//時期の重力がかかった移動関数
//Tは上方向に行くキーが押されたか
//dxは速度 gは重力 aは加速度です。
void Phy(bool T) {
y += dx;
dx += g;
if (T) {
dx -= a;
}
}
void Gor() {
alv = false;
}
//軌跡の描画関数
void UpK() {
//外にはみ出た数
int pot = 0;
for (auto &s : D) {
//はみ出ていなければ座標を減らして弾を描画。はみ出ていたら、カウントを増やす。
if (0 < s.first) {
s.first -= 4;
Circle(s.first, s.second, 4).draw(Palette::Aqua);
}
else pot++;
}
//はみ出た数だけpopする。
//(先に入れた要素が先に画面外に出るはずなので)
for (int i = 0; i < pot; i++)D.pop_front();
}
};
class Ball {
private:
double x, y;
double g, speed;
double dx;
bool flag;
public:
double Col;
void Init() {
x = 100;
y = 100;
dx = 0;
speed = 5;
flag = false;
}
Ball () {
Init();
}
//飛んでいるかどうかのフラグを返す
bool NF() {
return flag;
}
void set(int a,int b,double c) {
x = a;
y = b;
Col = c;
flag = true;
}
double GetX() {
return x;
}
double GetY() {
return y;
}
//今回は横にしか飛ばさないのでspeedだけx座標を引く。
//はみ出たら飛んでいるかどうかのフラグをfalseに
void Phy() {
x -= speed;
if (x < 0)flag = false;
}
};
//スコアを記録するためにファイル入出力するところ
long long int RW(int x) {
if (Ad)return HighScore;//Admin機能を使ったら弾く
std::fstream fs, fe;
long long int S[10];
fs.open("ranking.txt", std::ios::in);
//開けなかった場合 100~60までを書き込んだファイルを作る。
if (!fs.is_open()) {
fs.close();
std::fstream fw; fw.open("ranking.txt", std::ios::out | std::ios::trunc);
for (int i = 0; i < 5; i++)fw << 100 - i * 10 << std::endl;
fw.close();
fs.open("ranking.txt", std::ios::in);
}
for (int i = 0; i < 5; i++)fs >> S[i];
S[5] = x;
//得点順にソート
std::sort(S, S + 6);
fs.close();
fe.open("ranking.txt", std::ios::out | std::ios::trunc);
for (int i = 0; i<5; i++)fe << S[5 - i] << std::endl;
fe << std::endl;
fe.close();
HighScore = S[5];
return HighScore;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment