parent
32a9b54f1a
commit
4e7e6be7a8
@ -1,3 +1,3 @@ |
|||||||
build.sh:530634457ea9041267c05d4ced95eee1 - |
build.sh:530634457ea9041267c05d4ced95eee1 - |
||||||
commit.sh:d03a46e721060c22ccb146e19d27e70a - |
commit.sh:d03a46e721060c22ccb146e19d27e70a - |
||||||
web.sh:241ce74055952325f82f009b494df250 - |
web.sh:3dcc2fe7e036359eedd257a864e9a1e1 - |
||||||
|
Binary file not shown.
@ -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); |
@ -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 |
#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: |
public: |
||||||
Example() |
BallGame() |
||||||
{ |
{ |
||||||
sAppName = "Example"; |
sAppName = "Rectangle Collision"; |
||||||
} |
} |
||||||
|
|
||||||
public: |
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 |
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; |
return true; |
||||||
} |
} |
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
// main game function
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
bool OnUserUpdate(float fElapsedTime) override |
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; |
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() |
int main() |
||||||
{ |
{ |
||||||
Example demo; |
BallGame game; |
||||||
if (demo.Construct(256, 240, 4, 4)) |
if (game.Construct(256, 240, 4, 4)) |
||||||
demo.Start(); |
game.Start(); |
||||||
|
|
||||||
return 0; |
return 0; |
||||||
} |
} |
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
// END OF FILE
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in new issue