Skip to content

Commit

Permalink
Rebalancing and fixed framerate-dependency of main loop
Browse files Browse the repository at this point in the history
  • Loading branch information
Tau5 committed Aug 12, 2022
1 parent 302f3b0 commit 2e122dc
Show file tree
Hide file tree
Showing 6 changed files with 294 additions and 231 deletions.
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ MINGW= x86_64-w64-mingw32
all : $(OBJS)
$(CC) $(OBJS) $(COMPILER_FLAGS) $(LINKER_FLAGS) -o $(OBJ_NAME)

debug : $(OBJS)
$(CC) $(OBJS) -g $(LINKER_FLAGS) -o $(OBJ_NAME)
dist : all
mkdir -p build
cp -r installer build
Expand Down
10 changes: 5 additions & 5 deletions game.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@ void player_change_state() {
}

void make_random_cubi() {
std::random_device rd; // obtain a random number from hardware
static std::mt19937 eng(rd()); // seed the generator
std::uniform_int_distribution<> random_cubi_state(false, true); // define the range
std::random_device rd; // obtain a random number from hardware
static std::mt19937 eng(rd()); // seed the generator
std::uniform_int_distribution<> random_cubi_state(false, true); // define the range
std::uniform_int_distribution<> random_cubi_height((SCREEN_HEIGHT-SCREEN_HEIGHT/5*2)/4, (SCREEN_HEIGHT-SCREEN_HEIGHT/5*2)/2); // define the range
cubis_state.push_back(random_cubi_state(eng));
cubis_state.push_back(random_cubi_state(eng));
Cuby tempcubi;
tempcubi.set_size(ENEMY_WIDTH, random_cubi_height(eng));
tempcubi.set_sdl_color(cubis_color);
Expand Down Expand Up @@ -78,7 +78,7 @@ bool check_cubis() {
for(auto it = cubis.begin(); it != cubis.end(); ++it) {
auto i = std::distance(cubis.begin(), it);
auto target = &cubis[i];
if(target->get_rect().x-ENEMY_WIDTH < PLAYER_POSX-30 && target->get_rect().x-30 > PLAYER_POSX-ENEMY_WIDTH) {
if(target->get_rect().x-ENEMY_WIDTH < PLAYER_POSX-15 && target->get_rect().x-15 > PLAYER_POSX-ENEMY_WIDTH) {
if (cubis_state[i] == player_state) {
end = true;
}
Expand Down
2 changes: 1 addition & 1 deletion global.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ int INITIAL_SCREEN_WIDTH = 640;
int INITIAL_SCREEN_HEIGHT = 200;
int SCREEN_WIDTH = INITIAL_SCREEN_WIDTH;
int SCREEN_HEIGHT = INITIAL_SCREEN_HEIGHT;
const std::string HELP = "Version 2.0 Game of the Year Edition\nHELP\nIn CubiGrav your goal is to get the furthest without touching any obstacle.\nTo do this you can change your position from the roof to the ceiling using th Up and Down keys.";
const std::string HELP = "Version 3.0 Game of the Year, Press Edition\nHELP\nIn CubiGrav your goal is to get the furthest without touching any obstacle.\nTo do this you can change your position from the roof to the ceiling using th Up and Down keys.";
30 changes: 15 additions & 15 deletions highscore.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
#include <fstream>
#include <stdio.h>
#include <string>
using namespace std;
int key = HELP.size();
#include "global.hpp"
int key = HELP.size() + 30;

string enc(string inpString)
std::string enc(std::string inpString)
{
// Define XOR key
// Any character value will work
Expand All @@ -23,12 +23,12 @@ string enc(string inpString)
}

bool update_highscore(int points) {
ofstream filew;
ifstream filer;
std::ofstream filew;
std::ifstream filer;
int hspoints;
bool newfile = false;

filer.open("./highscores", ios::out);
filer.open("./highscores", std::ios::out);
bool hs = false; //This variable represents if the given points results in a new highscore or not
if (!filer.is_open()) {
filew.open("./highscores");
Expand All @@ -38,11 +38,11 @@ bool update_highscore(int points) {
filew.close();
}
if (!newfile) {
string output = "";
string line;
std::string output = "";
std::string line;

while (std::getline(filer, line)) {
hspoints = stoi(enc(line));
hspoints = std::stoi(enc(line));
}
}

Expand All @@ -52,7 +52,7 @@ bool update_highscore(int points) {
hs = false;
} else {
filew.open("./highscores");
string newpoints = to_string(points);
std::string newpoints = std::to_string(points);
filew << enc(newpoints);
filew.close();
hs = true;
Expand All @@ -64,11 +64,11 @@ bool update_highscore(int points) {
}

int get_highscore() {
ofstream filew;
ifstream filer;
std::ofstream filew;
std::ifstream filer;
int hspoints;
bool newfile = false;
filer.open("./highscores", ios::out);
filer.open("./highscores", std::ios::out);
if (!filer.is_open()) {
filew.open("./highscores");
filew << enc("0");
Expand All @@ -77,8 +77,8 @@ int get_highscore() {
filew.close();
}
if (!newfile) {
string output = "";
string line;
std::string output = "";
std::string line;

while (std::getline(filer, line)) {
hspoints = stoi(enc(line));
Expand Down
Loading

0 comments on commit 2e122dc

Please sign in to comment.