generated from sigonasr2/CPlusPlusProjectTemplate
Implement star field
Co-authored-by: sigonasr2 <sigonasr2@gmail.com>
This commit is contained in:
parent
b246dac938
commit
58a89798d7
@ -1,4 +1,4 @@
|
|||||||
#Compiles the entire program then runs it, producing an executable. If the "test" argument is included, will try and run tests too (in the test folder)
|
#Compiles the entire program then runs it, producing an executable. If the "test" argument is included, will try and run tests too (in the test folder). If the "full" argument is included, it will recopmile the PixelGameEngine (should it change)
|
||||||
#C++
|
#C++
|
||||||
printf "Running program...\n\n\n"
|
printf "Running program...\n\n\n"
|
||||||
output=$(dpkg -l | grep libx11-dev)
|
output=$(dpkg -l | grep libx11-dev)
|
||||||
@ -6,16 +6,28 @@ if [[ -z $output ]]
|
|||||||
then
|
then
|
||||||
sudo apt install libx11-dev libpulse-dev mesa-common-dev libpng-dev
|
sudo apt install libx11-dev libpulse-dev mesa-common-dev libpng-dev
|
||||||
fi
|
fi
|
||||||
|
if [ ! -f "pixelGameEngine.o" ]
|
||||||
|
then
|
||||||
|
printf "Pixel Game Engine compile object missing. Compiling for the first time..."
|
||||||
|
g++ -c pixelGameEngine.cpp
|
||||||
|
fi
|
||||||
if [ "$1" = "test" ]
|
if [ "$1" = "test" ]
|
||||||
then
|
then
|
||||||
printf "Running tests...\n"
|
printf "Running tests...\n"
|
||||||
echo "#define TEST_SUITE" > ./test/test.h
|
echo "#define TEST_SUITE" > ./test/test.h
|
||||||
if g++ $(find . -type f -name "*.cpp") ${CUSTOM_PARAMS} -o ${PROJECT_NAME}; then
|
if g++ $(find . -type f -name "*.cpp" -not -name "pixelGameEngine.cpp") pixelGameEngine.o ${CUSTOM_PARAMS} -o ${PROJECT_NAME}; then
|
||||||
|
./${PROJECT_NAME} "$@"
|
||||||
|
fi
|
||||||
|
elif [ "$1" = "full" ]
|
||||||
|
then
|
||||||
|
echo "" > ./test/test.h
|
||||||
|
g++ -c pixelGameEngine.cpp
|
||||||
|
if g++ $(find . -type f -name "*.cpp" -not -path "./test/*" -not -name "pixelGameEngine.cpp") pixelGameEngine.o ${CUSTOM_PARAMS} -o ${PROJECT_NAME}; then
|
||||||
./${PROJECT_NAME} "$@"
|
./${PROJECT_NAME} "$@"
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
echo "" > ./test/test.h
|
echo "" > ./test/test.h
|
||||||
if g++ $(find . -type f -name "*.cpp" -not -path "./test/*") ${CUSTOM_PARAMS} -o ${PROJECT_NAME}; then
|
if g++ $(find . -type f -name "*.cpp" -not -path "./test/*" -not -name "pixelGameEngine.cpp") pixelGameEngine.o ${CUSTOM_PARAMS} -o ${PROJECT_NAME}; then
|
||||||
./${PROJECT_NAME} "$@"
|
./${PROJECT_NAME} "$@"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
build.sh:d5e4e98a6f677aa0a9759ba0afb2fb77 -
|
build.sh:f7da5b6f54c56658f5410e0df797b5a7 -
|
||||||
commit.sh:d03a46e721060c22ccb146e19d27e70a -
|
commit.sh:d03a46e721060c22ccb146e19d27e70a -
|
||||||
debug.sh:849488515cab075948653c15eec4177b -
|
debug.sh:849488515cab075948653c15eec4177b -
|
||||||
lines.sh:3b907786f7fc9204025993016c9080de -
|
lines.sh:3b907786f7fc9204025993016c9080de -
|
||||||
release.sh:6a96fb84ba64ed60d31be436ec069f05 -
|
release.sh:0ab321c3fa2f1a1b2f03b1aec3bce816 -
|
||||||
temp:d41d8cd98f00b204e9800998ecf8427e -
|
temp:d41d8cd98f00b204e9800998ecf8427e -
|
||||||
web.sh:b982212b88b80a59ad607b47d2ff3e94 -
|
web.sh:e317e1d492d00517a0ac0e460239daa0 -
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
#Creates a release build that focuses on high runtime performance.
|
#Creates a release build that focuses on high runtime performance. Use "full" argument to completely rebuild PGE.
|
||||||
#C++
|
#C++
|
||||||
printf "Running program...\n\n\n"
|
printf "Running program...\n\n\n"
|
||||||
output=$(dpkg -l | grep libx11-dev)
|
output=$(dpkg -l | grep libx11-dev)
|
||||||
@ -6,7 +6,15 @@ if [[ -z $output ]]
|
|||||||
then
|
then
|
||||||
sudo apt install libx11-dev libpulse-dev mesa-common-dev libpng-dev
|
sudo apt install libx11-dev libpulse-dev mesa-common-dev libpng-dev
|
||||||
fi
|
fi
|
||||||
if g++ $(find . -type f -name "*.cpp" -not -path "./test/*") ${CUSTOM_PARAMS} -O3 -s -DNDEBUG -o ${PROJECT_NAME}; then
|
if [ "$1" == "full" ]; then
|
||||||
|
rm "pixelGameEngine.o"
|
||||||
|
fi
|
||||||
|
if [ ! -f "pixelGameEngine.o" ]
|
||||||
|
then
|
||||||
|
printf "Pixel Game Engine compile object missing. Compiling for the first time..."
|
||||||
|
g++ -c pixelGameEngine.cpp
|
||||||
|
fi
|
||||||
|
if g++ $(find . -type f -name "*.cpp" -not -path "./test/*" -not -name "pixelGameEngine.cpp") pixelGameEngine.o ${CUSTOM_PARAMS} -o ${PROJECT_NAME}; then
|
||||||
./${PROJECT_NAME} "$@"
|
./${PROJECT_NAME} "$@"
|
||||||
fi
|
fi
|
||||||
printf "\n\n"
|
printf "\n\n"
|
||||||
|
@ -1,23 +1,30 @@
|
|||||||
#Compiles emscripten instance of this project for the web.
|
#Compiles emscripten instance of this project for the web. Use "full" argument if your PGE has to be completely rebuilt. Use "headless" argument for a headless version.
|
||||||
#C++
|
#C++
|
||||||
output=$(dpkg -l | grep libx11-dev)
|
output=$(dpkg -l | grep libx11-dev)
|
||||||
if [[ -z $output ]]
|
if [[ -z $output ]]
|
||||||
then
|
then
|
||||||
sudo apt install libx11-dev libpulse-dev mesa-common-dev libpng-dev
|
sudo apt install libx11-dev libpulse-dev mesa-common-dev libpng-dev
|
||||||
fi
|
fi
|
||||||
|
if [[ "$1" == "full" || "$2" == "full" ]]; then
|
||||||
|
rm "pixelGameEngine_wasm.o"
|
||||||
|
fi
|
||||||
|
if [ ! -f "pixelGameEngine_wasm.o" ]
|
||||||
|
then
|
||||||
|
printf "Pixel Game Engine compile object missing. Compiling for the first time..."
|
||||||
|
em++ -std=c++17 -O2 -s ALLOW_MEMORY_GROWTH=1 -s MAX_WEBGL_VERSION=2 -s MIN_WEBGL_VERSION=2 -s USE_SDL_MIXER=2 -s USE_LIBPNG=1 -c pixelGameEngine.cpp -o pixelGameEngine_wasm.o
|
||||||
|
fi
|
||||||
if [ -d "assets" ]; then
|
if [ -d "assets" ]; then
|
||||||
em++ -std=c++17 -O2 -s ALLOW_MEMORY_GROWTH=1 -s MAX_WEBGL_VERSION=2 -s MIN_WEBGL_VERSION=2 -s USE_SDL_MIXER=2 -s USE_LIBPNG=1 $(find . -type f -name "*.cpp" -not -path "./test/*") -o ${PROJECT_NAME}.html -I pixelGameEngine.h --preload-file ./assets
|
em++ -std=c++17 -O2 -s ALLOW_MEMORY_GROWTH=1 -s MAX_WEBGL_VERSION=2 -s MIN_WEBGL_VERSION=2 -s USE_SDL_MIXER=2 -s USE_LIBPNG=1 $(find . -type f -name "*.cpp" -not -path "./test/*" -not -name "pixelGameEngine.cpp") pixelGameEngine_wasm.o -o ${PROJECT_NAME}.html --preload-file ./assets
|
||||||
else
|
else
|
||||||
em++ -std=c++17 -O2 -s ALLOW_MEMORY_GROWTH=1 -s MAX_WEBGL_VERSION=2 -s MIN_WEBGL_VERSION=2 -s USE_SDL_MIXER=2 -s USE_LIBPNG=1 $(find . -type f -name "*.cpp" -not -path "./test/*") -o ${PROJECT_NAME}.html -I pixelGameEngine.h
|
em++ -std=c++17 -O2 -s ALLOW_MEMORY_GROWTH=1 -s MAX_WEBGL_VERSION=2 -s MIN_WEBGL_VERSION=2 -s USE_SDL_MIXER=2 -s USE_LIBPNG=1 $(find . -type f -name "*.cpp" -not -path "./test/*" -not -name "pixelGameEngine.cpp") pixelGameEngine_wasm.o -o ${PROJECT_NAME}.html
|
||||||
fi
|
fi
|
||||||
|
|
||||||
cp buildtemplate.html ${PROJECT_NAME}.html
|
cp buildtemplate.html ${PROJECT_NAME}.html
|
||||||
sed -i "s/_REPLACEME_/$PROJECT_NAME.js/" ${PROJECT_NAME}.html
|
sed -i "s/_REPLACEME_/$PROJECT_NAME.js/" ${PROJECT_NAME}.html
|
||||||
|
|
||||||
if [ "$1" == "headless" ]; then
|
if [[ "$1" == "headless" || "$2" == "headless" ]]; then
|
||||||
echo "Running as headless web server"
|
echo "Running as headless web server"
|
||||||
emrun --no_browser ${PROJECT_NAME}.html
|
emrun --no_browser ${PROJECT_NAME}.html
|
||||||
else
|
else
|
||||||
emrun --serve_after_close ${PROJECT_NAME}.html
|
emrun --serve_after_close ${PROJECT_NAME}.html
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
Binary file not shown.
3
Meteos.h
3
Meteos.h
@ -4,6 +4,7 @@
|
|||||||
#include "Board.h"
|
#include "Board.h"
|
||||||
#include <random>
|
#include <random>
|
||||||
#include "ComboOverlay.h"
|
#include "ComboOverlay.h"
|
||||||
|
#include "Star.h"
|
||||||
|
|
||||||
class Meteos : public olc::PixelGameEngine{
|
class Meteos : public olc::PixelGameEngine{
|
||||||
public:
|
public:
|
||||||
@ -28,6 +29,7 @@ class Meteos : public olc::PixelGameEngine{
|
|||||||
bool gameCanRun=true;
|
bool gameCanRun=true;
|
||||||
std::map<std::string,Renderable> SPRITES;
|
std::map<std::string,Renderable> SPRITES;
|
||||||
std::vector<ComboOverlay>comboDisplayList;
|
std::vector<ComboOverlay>comboDisplayList;
|
||||||
|
std::vector<Star>starField;
|
||||||
int score=0;
|
int score=0;
|
||||||
int displayTargetScore=0; //While technically the displayed score should be what the score actually is, if we're showing how many points we earn for a combo we want to delay adding it to our actual score display for flair and show a side bonus counter.
|
int displayTargetScore=0; //While technically the displayed score should be what the score actually is, if we're showing how many points we earn for a combo we want to delay adding it to our actual score display for flair and show a side bonus counter.
|
||||||
int displayScore=0;
|
int displayScore=0;
|
||||||
@ -46,5 +48,6 @@ class Meteos : public olc::PixelGameEngine{
|
|||||||
void handleWarningLevels(float fElapsedTime);
|
void handleWarningLevels(float fElapsedTime);
|
||||||
void validateSelectedBlock();
|
void validateSelectedBlock();
|
||||||
void handleComboAnimations();
|
void handleComboAnimations();
|
||||||
|
void updateScoreDisplay(float fElapsedTime);
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
29
Star.cpp
Normal file
29
Star.cpp
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
#include "pixelGameEngine.h"
|
||||||
|
#include "Meteos.h"
|
||||||
|
|
||||||
|
extern Meteos*game;
|
||||||
|
|
||||||
|
void Star::Update(){
|
||||||
|
pos+=spd;
|
||||||
|
if (pos.x<0){
|
||||||
|
pos.x+=game->ScreenWidth();
|
||||||
|
}
|
||||||
|
if (pos.x>game->ScreenWidth()){
|
||||||
|
pos.x-=game->ScreenWidth();
|
||||||
|
}
|
||||||
|
if (pos.y<0){
|
||||||
|
pos.y+=game->ScreenHeight();
|
||||||
|
}
|
||||||
|
if (pos.y>game->ScreenHeight()){
|
||||||
|
pos.y-=game->ScreenHeight();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (flickerTimer++>=flickerRate){
|
||||||
|
flickerTimer=0;
|
||||||
|
brightness={redDistribution(game->gen),greenDistribution(game->gen),blueDistribution(game->gen)};
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
void Star::Draw(){
|
||||||
|
game->FillRectDecal(pos,size,brightness);
|
||||||
|
};
|
23
Star.h
Normal file
23
Star.h
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
#include "pixelGameEngine.h"
|
||||||
|
#include <random>
|
||||||
|
|
||||||
|
class Star{
|
||||||
|
vf2d pos;
|
||||||
|
vf2d spd;
|
||||||
|
vf2d size={1,1};
|
||||||
|
Pixel minBrightness;
|
||||||
|
Pixel maxBrightness;
|
||||||
|
Pixel brightness=minBrightness;
|
||||||
|
int flickerRate=10; //Number of frames between each flicker.
|
||||||
|
int flickerTimer=0;
|
||||||
|
std::uniform_int_distribution<uint8_t>redDistribution,greenDistribution,blueDistribution;
|
||||||
|
public:
|
||||||
|
Star(vf2d pos,vf2d spd,Pixel minBrightness,Pixel maxBrightness)
|
||||||
|
:pos(pos),spd(spd),minBrightness(minBrightness),maxBrightness(maxBrightness){
|
||||||
|
redDistribution=std::uniform_int_distribution<uint8_t>(minBrightness.r,maxBrightness.r);
|
||||||
|
greenDistribution=std::uniform_int_distribution<uint8_t>(minBrightness.g,maxBrightness.g);
|
||||||
|
blueDistribution=std::uniform_int_distribution<uint8_t>(minBrightness.b,maxBrightness.b);
|
||||||
|
}
|
||||||
|
void Update();
|
||||||
|
void Draw();
|
||||||
|
};
|
30
main.cpp
30
main.cpp
@ -1,5 +1,3 @@
|
|||||||
#define OLC_PGE_APPLICATION
|
|
||||||
#include "pixelGameEngine.h"
|
|
||||||
#include <random>
|
#include <random>
|
||||||
#include "gameDefines.h"
|
#include "gameDefines.h"
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
@ -889,14 +887,7 @@ void Meteos::handleComboAnimations(){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Meteos::updateGame(float fElapsedTime){
|
void Meteos::updateScoreDisplay(float fElapsedTime){
|
||||||
spawnBlocks(fElapsedTime);
|
|
||||||
handleBlockGravity(fElapsedTime);
|
|
||||||
matchBlocks();
|
|
||||||
cleanupBlocks();
|
|
||||||
handleWarningLevels(fElapsedTime);
|
|
||||||
validateSelectedBlock();
|
|
||||||
handleComboAnimations();
|
|
||||||
if (blocksInAttackQueue){
|
if (blocksInAttackQueue){
|
||||||
lastBlockLaunched+=fElapsedTime;
|
lastBlockLaunched+=fElapsedTime;
|
||||||
if (lastBlockLaunched>=blockLaunchWaitPeriod){
|
if (lastBlockLaunched>=blockLaunchWaitPeriod){
|
||||||
@ -941,8 +932,25 @@ void Meteos::updateGame(float fElapsedTime){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Meteos::updateGame(float fElapsedTime){
|
||||||
|
spawnBlocks(fElapsedTime);
|
||||||
|
handleBlockGravity(fElapsedTime);
|
||||||
|
matchBlocks();
|
||||||
|
cleanupBlocks();
|
||||||
|
handleWarningLevels(fElapsedTime);
|
||||||
|
validateSelectedBlock();
|
||||||
|
handleComboAnimations();
|
||||||
|
updateScoreDisplay(fElapsedTime);
|
||||||
|
for (Star s:starField){
|
||||||
|
s.Update();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void Meteos::drawGame(float fElapsedTime,bool debugView){
|
void Meteos::drawGame(float fElapsedTime,bool debugView){
|
||||||
Clear(Pixel(32,32,255));
|
Clear(VERY_DARK_BLUE);
|
||||||
|
for (Star s:starField){
|
||||||
|
s.Draw();
|
||||||
|
}
|
||||||
for (int x=-1;x<=gameBoard.boardSize.x;x++){
|
for (int x=-1;x<=gameBoard.boardSize.x;x++){
|
||||||
for (int y=0;y<=gameBoard.boardSize.y;y++){
|
for (int y=0;y<=gameBoard.boardSize.y;y++){
|
||||||
if (x==-1||x==10||y==14){
|
if (x==-1||x==10||y==14){
|
||||||
|
3
pixelGameEngine.cpp
Normal file
3
pixelGameEngine.cpp
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
#define OLC_PGE_HEADLESS
|
||||||
|
#define OLC_PGE_APPLICATION
|
||||||
|
#include "pixelGameEngine.h"
|
File diff suppressed because it is too large
Load Diff
BIN
pixelGameEngine.o
Normal file
BIN
pixelGameEngine.o
Normal file
Binary file not shown.
2
sig
2
sig
@ -3,7 +3,7 @@ export AUTO_UPDATE=true
|
|||||||
source utils/define.sh
|
source utils/define.sh
|
||||||
|
|
||||||
define PROJECT_NAME "C++ProjectTemplate"
|
define PROJECT_NAME "C++ProjectTemplate"
|
||||||
define CUSTOM_PARAMS "-std=c++17 -lX11 -lGL -lpthread -lpng -lstdc++fs -lpulse -lpulse-simple -I/usr/include/lua5.3"
|
define CUSTOM_PARAMS "-std=c++17 -lX11 -lpthread -lpng -lstdc++fs -lGL -lpulse -lpulse-simple -I/usr/include/lua5.3"
|
||||||
define LANGUAGE "C++"
|
define LANGUAGE "C++"
|
||||||
|
|
||||||
source utils/main.sh
|
source utils/main.sh
|
||||||
|
Loading…
x
Reference in New Issue
Block a user