Include a launch.json and tasks.json example files
Co-authored-by: sigonasr2 <sigonasr2@gmail.com>
This commit is contained in:
parent
4e7e6be7a8
commit
8651ee65cf
Binary file not shown.
BIN
dirtblock.png
Normal file
BIN
dirtblock.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 35 KiB |
67
main.cpp
67
main.cpp
@ -1,94 +1,35 @@
|
|||||||
//--------------------------------------------------------------------------------------------------
|
|
||||||
// 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 <iostream>
|
#include <iostream>
|
||||||
#include "pixelGameEngine.h" // use this for drawing stuff to screen
|
#include "pixelGameEngine.h" // use this for drawing stuff to screen
|
||||||
|
|
||||||
using namespace olc;
|
using namespace olc;
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
|
||||||
// class
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
|
||||||
class BallGame : public olc::PixelGameEngine
|
class BallGame : public olc::PixelGameEngine
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
BallGame()
|
BallGame()
|
||||||
{
|
{
|
||||||
sAppName = "Rectangle Collision";
|
sAppName = "Example";
|
||||||
}
|
}
|
||||||
|
|
||||||
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
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
|
||||||
// main game function
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
|
||||||
bool OnUserUpdate(float fElapsedTime) override
|
bool OnUserUpdate(float fElapsedTime) override
|
||||||
{
|
{
|
||||||
|
for (int i=0;i<ScreenWidth();i++) {
|
||||||
Clear(VERY_DARK_CYAN);
|
for (int j=0;j<ScreenHeight();j++) {
|
||||||
|
Draw({i,j},Pixel(rand()%255,rand()%255,rand()%255));
|
||||||
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()
|
||||||
{
|
{
|
||||||
BallGame game;
|
BallGame game;
|
||||||
|
6191
olcPixelGameEngine.h
6191
olcPixelGameEngine.h
File diff suppressed because it is too large
Load Diff
Loading…
x
Reference in New Issue
Block a user