Skip to content

Instantly share code, notes, and snippets.

@ChunChunMorning
Created September 20, 2017 11:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ChunChunMorning/c3e8fc6eea8bcffcd2ca7ea8228a329a to your computer and use it in GitHub Desktop.
Save ChunChunMorning/c3e8fc6eea8bcffcd2ca7ea8228a329a to your computer and use it in GitHub Desktop.
10時間ゲームジャム テーマ「格闘」
# include <Siv3D.hpp>
# include <HamFramework.hpp>
void Main()
{
Window::SetTitle(L"Dum Dum Fighting");
Graphics::SetBackground(Palette::Skyblue);
ScalableWindow::Setup();
const Font font(40);
const Texture textureP1(L"asachun.png");
const Texture textureP2(L"nisechun.png");
int32 stopwatch = 0;
const auto playerSize = 150.0;
const auto speed = 3.0;
double posP1 = 100;
double posP2 = 540;
int32 vitalityP1 = 100;
int32 vitalityP2 = 100;
double pointP1 = 50;
double pointP2 = 50;
bool squatP1 = false;
bool squatP2 = false;
int32 rigorP1 = 0;
int32 rigorP2 = 0;
int32 winceP1 = 0;
int32 winceP2 = 0;
while (System::Update())
{
if (vitalityP1 <= 0 || vitalityP2 <= 0)
{
stopwatch += 1;
}
if (stopwatch > 300)
{
posP1 = 100;
posP2 = 540;
vitalityP1 = 100;
vitalityP2 = 100;
pointP1 = 50;
pointP2 = 50;
squatP1 = false;
squatP2 = false;
rigorP1 = 0;
rigorP2 = 0;
winceP1 = 0;
winceP2 = 0;
System::ResetFrameCount();
stopwatch = 0;
}
rigorP1 = Max(0, rigorP1 - 1);
rigorP2 = Max(0, rigorP2 - 1);
winceP1 = Max(0, winceP1 - 1);
winceP2 = Max(0, winceP2 - 1);
if (vitalityP1 > 0 && rigorP1 <= 0)
{
if (Gamepad(1).povLeft.pressed)
{
posP1 -= speed;
}
if (Gamepad(1).povRight.pressed)
{
posP1 += speed;
}
}
if (vitalityP2 > 0 && rigorP2 <= 0)
{
if (Gamepad(0).povLeft.pressed)
{
posP2 -= speed;
}
if (Gamepad(0).povRight.pressed)
{
posP2 += speed;
}
}
const auto previousP1 = posP1;
posP1 = Clamp(posP1, playerSize / 2, posP2 - playerSize);
posP2 = Clamp(posP2, previousP1 + playerSize, 640.0 - playerSize / 2);
const auto healthP1 = vitalityP1 > 0 && rigorP1 <= 0 && winceP1 <= 0;
const auto healthP2 = vitalityP2 > 0 && rigorP2 <= 0 && winceP2 <= 0;
const auto feintP1 = healthP1 && Gamepad(1).button(2).pressed && pointP1 > 0;
const auto feintP2 = healthP2 && Gamepad(0).button(1).pressed && pointP2 > 0;
if (feintP1)
{
pointP1 = Max(0.0, pointP1 - 0.05);
}
if (feintP2)
{
pointP2 = Max(0.0, pointP2 - 0.05);
}
if (rigorP1 <= 0)
{
const auto squat = (Gamepad(1).button(0) | Gamepad(1).povBackward).pressed;
if (squat != squatP1 && !Gamepad(1).button(2).pressed)
{
pointP1 = Min(100.0, pointP1 + 0.5);
}
squatP1 = squat;
}
if (rigorP2 <= 0)
{
const auto squat = (Gamepad(0).button(0) | Gamepad(0).povBackward).pressed;
if (squat != squatP2 && !Gamepad(0).button(1).pressed)
{
pointP2 = Min(100.0, pointP2 + 0.5);
}
squatP2 = squat;
}
if (healthP1 && Gamepad(1).button(1).clicked)
{
const auto point = pointP1 * 0.25;
rigorP1 = 30;
pointP1 -= point;
if (Abs(posP1 - posP2) < 170 && squatP1 == squatP2)
{
vitalityP2 = Max(0, vitalityP2 - Max(5, static_cast<int32>(point)));
winceP2 = 30;
rigorP2 = 0;
}
}
if (healthP2 && Gamepad(0).button(2).clicked)
{
const auto point = pointP2 * 0.25;
rigorP2 = 30;
pointP2 -= point;
if (Abs(posP1 - posP2) < 170 && squatP1 == squatP2)
{
vitalityP1 = Max(0, vitalityP1 - Max(5, static_cast<int32>(point)));
winceP1 = 30;
rigorP1 = 0;
}
}
{
const auto wt = ScalableWindow::CreateTransformer();
const auto flush = ColorF(Math::Sin(System::FrameCount()), 0, 0);
Rect(0, 450, 640, 480).draw(Palette::Saddlebrown);
if (squatP1)
{
RectF(posP1 - playerSize / 2, 450 - playerSize / 2, playerSize, playerSize / 2)(textureP1)
.draw((winceP1 > 0 || vitalityP1 <= 0) ? flush : Palette::White);
}
else
{
RectF(posP1 - playerSize / 2, 450 - playerSize, playerSize, playerSize)(textureP1)
.draw((winceP1 > 0 || vitalityP1 <= 0) ? flush : Palette::White);
}
if (squatP2)
{
RectF(posP2 - playerSize / 2, 450 - playerSize / 2, playerSize, playerSize / 2)(textureP2)
.draw((winceP2 > 0 || vitalityP2 <= 0) ? flush : Palette::White);
}
else
{
RectF(posP2 - playerSize / 2, 450 - playerSize, playerSize, playerSize)(textureP2)
.draw((winceP2 > 0 || vitalityP2 <= 0) ? flush : Palette::White);
}
if (rigorP1 > 0 || feintP1)
{
Circle(posP1 + 70, squatP1 ? 430 : 380, 25).draw(Palette::Red).scaled(0.7).drawFrame(5, 0, Palette::White);
}
if (rigorP2 > 0 || feintP2)
{
Circle(posP2 - 70, squatP2 ? 430 : 380, 25).draw(Palette::Blue).scaled(0.7).drawFrame(5, 0, Palette::White);
}
Rect(10, 10, 300, 50).draw(Palette::Red);
Rect(10, 10, 3 * vitalityP1, 50).draw(Palette::Green);
Rect(10, 60, 300, 20).draw(Palette::Gray);
RectF(10, 60, 3 * pointP1, 20).draw(Palette::Orange);
Rect(330, 10, 300, 50).draw(Palette::Red);
Rect(330 + 3 * (100 - vitalityP2), 10, 3 * vitalityP2, 50).draw(Palette::Green);
Rect(330, 60, 300, 20).draw(Palette::Gray);
RectF(330 + 3 * (100 - pointP2), 60, 3 * pointP2, 20).draw(Palette::Orange);
if (vitalityP1 <= 0 && vitalityP2 <= 0)
{
const auto x = (Window::BaseWidth() - font(L"Draw ...").region().w) / 2;
font(L"Draw ...").draw(x, 150);
}
if (vitalityP2 <= 0)
{
const auto x = (Window::BaseWidth() - font(L"Winner P1 Asachun !").region().w) / 2;
font(L"Winner P1 Asachun !").draw(x, 150);
}
else if (vitalityP1 <= 0)
{
const auto x = (Window::BaseWidth() - font(L"Winner P2 Nisechun !").region().w) / 2;
font(L"Winner P2 Nisechun !").draw(x, 150);
}
else
{
const auto x = (Window::BaseWidth() - font(L"Fight !!!").region().w) / 2;
font(L"Fight !!!").draw(x, 150, Color(Palette::White, Max(0, 255 - 3 * System::FrameCount())));
}
}
ScalableWindow::DrawBlackBars(Color(27));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment