Turn orders work, move selection works
Co-authored-by: sigonasr2 <sigonasr2@gmail.com>
This commit is contained in:
parent
32a9b54f1a
commit
4e7e6be7a8
@ -1,3 +1,3 @@
|
||||
build.sh:530634457ea9041267c05d4ced95eee1 -
|
||||
commit.sh:d03a46e721060c22ccb146e19d27e70a -
|
||||
web.sh:241ce74055952325f82f009b494df250 -
|
||||
web.sh:3dcc2fe7e036359eedd257a864e9a1e1 -
|
||||
|
Binary file not shown.
14
diff
Normal file
14
diff
Normal file
@ -0,0 +1,14 @@
|
||||
1114d1113
|
||||
< void SetFPSDisplay(bool display);
|
||||
1176,1177c1175
|
||||
< int nFrameCount = 0;
|
||||
< bool showFPS = true;
|
||||
---
|
||||
> int nFrameCount = 0;
|
||||
3203,3204d3200
|
||||
< void PixelGameEngine::SetFPSDisplay(bool display)
|
||||
< { showFPS=display; }
|
||||
3543c3539
|
||||
< std::string sTitle = "OneLoneCoder.com - Pixel Game Engine - " + sAppName + ((showFPS)?" - FPS: " + std::to_string(nFrameCount):"");
|
||||
---
|
||||
> std::string sTitle = "OneLoneCoder.com - Pixel Game Engine - " + sAppName + " - FPS: " + std::to_string(nFrameCount);
|
97
main.cpp
97
main.cpp
@ -1,46 +1,103 @@
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
// Collect the Balls Game
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
// Purpose of the game is to figure out how to program.
|
||||
// The goal of the game, is to simply to collect balls until a score or time limit has been reached.
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
// created by Rune; with massive help from sigonasr2 on Javidx9's One Lone Coder Discord server
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
#define OLC_PGE_APPLICATION
|
||||
#include "pixelGameEngine.h"
|
||||
#include <iostream>
|
||||
#include "pixelGameEngine.h" // use this for drawing stuff to screen
|
||||
|
||||
using namespace std;
|
||||
using namespace olc;
|
||||
|
||||
class Example : public olc::PixelGameEngine
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
// class
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
class BallGame : public olc::PixelGameEngine
|
||||
{
|
||||
public:
|
||||
Example()
|
||||
BallGame()
|
||||
{
|
||||
sAppName = "Example";
|
||||
sAppName = "Rectangle Collision";
|
||||
}
|
||||
|
||||
public:
|
||||
struct Rectangle{
|
||||
vd2d pos;
|
||||
vd2d size;
|
||||
};
|
||||
|
||||
vd2d pos = {0,0};
|
||||
|
||||
Rectangle r1 = {{64,64},{16,16}};
|
||||
Rectangle r3 = {{128,64},{16,16}};
|
||||
Rectangle r2 = {pos,{8,8}};
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
// Create stuff for game
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool OnUserCreate() override
|
||||
{
|
||||
SetPixelMode(olc::Pixel::ALPHA);
|
||||
ConsoleCaptureStdOut(true);
|
||||
// Called once at the start, so create things here
|
||||
for (int x = 0; x < ScreenWidth(); x++)
|
||||
for (int y = 0; y < ScreenHeight(); y++)
|
||||
Draw(x, y, olc::Pixel(rand() % 255, rand() % 255, rand()% 255));
|
||||
for (int x=0;x<50;x++) {
|
||||
for (int y=0;y<50;y++) {
|
||||
Draw(x, y, olc::Pixel(255, 0, 0, 128));
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
// main game function
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool OnUserUpdate(float fElapsedTime) override
|
||||
{
|
||||
// called once per frame
|
||||
|
||||
Clear(VERY_DARK_CYAN);
|
||||
|
||||
if (GetKey(A).bHeld) {
|
||||
r2.pos.x-=20*fElapsedTime;
|
||||
}
|
||||
if (GetKey(D).bHeld) {
|
||||
r2.pos.x+=20*fElapsedTime;
|
||||
}
|
||||
if (GetKey(W).bHeld) {
|
||||
r2.pos.y-=20*fElapsedTime;
|
||||
}
|
||||
if (GetKey(S).bHeld) {
|
||||
r2.pos.y+=20*fElapsedTime;
|
||||
}
|
||||
|
||||
if (Collision(r1,r2)) {
|
||||
FillRect(r1.pos,r1.size,YELLOW);
|
||||
} else {
|
||||
FillRect(r1.pos,r1.size,RED);
|
||||
}
|
||||
if (Collision(r3,r2)) {
|
||||
FillRect(r3.pos,r1.size,YELLOW);
|
||||
} else {
|
||||
FillRect(r3.pos,r1.size,GREEN);
|
||||
}
|
||||
FillRect(r2.pos,r2.size,BLUE);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Collision(Rectangle r1,Rectangle r2) {
|
||||
return abs(r1.pos.x-r2.pos.x)<r1.size.x&&abs(r1.pos.y-r2.pos.y)<r1.size.y;
|
||||
}
|
||||
bool Collision2(Rectangle r1,Rectangle r2) {
|
||||
return abs(r1.pos.x-r2.pos.x)<r1.size.x&&abs(r1.pos.y-r2.pos.y)<r1.size.y;
|
||||
}
|
||||
};
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
|
||||
int main()
|
||||
{
|
||||
Example demo;
|
||||
if (demo.Construct(256, 240, 4, 4))
|
||||
demo.Start();
|
||||
BallGame game;
|
||||
if (game.Construct(256, 240, 4, 4))
|
||||
game.Start();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
// END OF FILE
|
||||
//--------------------------------------------------------------------------------------------------
|
6191
olcPixelGameEngine.h
Normal file
6191
olcPixelGameEngine.h
Normal file
File diff suppressed because it is too large
Load Diff
@ -1111,6 +1111,7 @@ namespace olc
|
||||
std::string TextEntryGetString() const;
|
||||
int32_t TextEntryGetCursor() const;
|
||||
bool IsTextEntryEnabled() const;
|
||||
void SetFPSDisplay(bool display);
|
||||
|
||||
|
||||
|
||||
@ -1173,6 +1174,7 @@ namespace olc
|
||||
float fFrameTimer = 1.0f;
|
||||
float fLastElapsed = 0.0f;
|
||||
int nFrameCount = 0;
|
||||
bool showFPS = true;
|
||||
bool bSuspendTextureTransfer = false;
|
||||
Renderable fontRenderable;
|
||||
std::vector<LayerDesc> vLayers;
|
||||
@ -3198,6 +3200,8 @@ namespace olc
|
||||
|
||||
bool PixelGameEngine::IsTextEntryEnabled() const
|
||||
{ return bTextEntryEnable; }
|
||||
void PixelGameEngine::SetFPSDisplay(bool display)
|
||||
{ showFPS=display; }
|
||||
|
||||
|
||||
void PixelGameEngine::UpdateTextEntry()
|
||||
@ -3536,7 +3540,7 @@ namespace olc
|
||||
{
|
||||
nLastFPS = nFrameCount;
|
||||
fFrameTimer -= 1.0f;
|
||||
std::string sTitle = "OneLoneCoder.com - Pixel Game Engine - " + sAppName + " - FPS: " + std::to_string(nFrameCount);
|
||||
std::string sTitle = "OneLoneCoder.com - Pixel Game Engine - " + sAppName + ((showFPS)?" - FPS: " + std::to_string(nFrameCount):"");
|
||||
platform->SetWindowTitle(sTitle);
|
||||
nFrameCount = 0;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user