Commit 3e778ea5 authored by Charadon's avatar Charadon
Browse files

Migrate to C++

parent 21b272f6
Pipeline #6245 pending with stage
......@@ -97,8 +97,9 @@ project("Pong")
}
kind("WindowedApp")
language("C")
files {"src/*.c", "src/*.h", }
language("C++")
cppdialect "C++11"
files {"src/*.cc", "src/*.hpp", }
--libdirs {"/usr/local/lib", "/usr/pkg/lib", "/usr/X11R7/include"}
-- Prefix Option
......
#include "pong.h"
#include <SDL2/SDL_atomic.h>
void ball(Rectangle *Player, Rectangle *Enemy, struct Balls *Ball, int *PlayerScore, int *EnemyScore) {
......
#include "pong.h"
#include <SDL2/SDL_atomic.h>
void enemy(struct Players *Enemy, struct Balls ball) {
if (Enemy->NextTick <= SDL_AtomicGet(&Ticks)) {
......
#include "pong.h"
#include <SDL2/SDL_thread.h>
#include <raylib.h>
int Difficulty = 1;
......@@ -18,10 +19,10 @@ void set_screen_mode() {
ClearWindowState(FLAG_WINDOW_TOPMOST);
ClearWindowState(FLAG_WINDOW_UNDECORATED);
ClearWindowState(FLAG_FULLSCREEN_MODE);
int Timeout = SDL_AtomicGet(&Ticks)+300; //Set the timeout for 5 seconds.
switch(GlobalSettings.Fullscreen) {
case 1: //Real Fullscreen is fickle as fuck. So it needs a timeout.
SetWindowSize(GetMonitorWidth(GetCurrentMonitor()), GetMonitorHeight(GetCurrentMonitor()));
int Timeout = SDL_AtomicGet(&Ticks)+300; //Set the timeout for 5 seconds.
while(GetScreenHeight() != GetMonitorHeight(GetCurrentMonitor())) {
BeginDrawing();
EndDrawing();
......@@ -47,7 +48,7 @@ void set_screen_mode() {
return;
}
static int internal_clock() {
static int internal_clock(void*) {
const struct timespec Delay = {
0, 16666666
};
......@@ -59,7 +60,7 @@ static int internal_clock() {
return(0);
}
static int audio() {
static int audio(void*) {
int i;
Mix_Init(0);
Mix_OpenAudio(48000, MIX_DEFAULT_FORMAT, 2, 1024);
......@@ -163,7 +164,7 @@ int main(int argc, char *argv[]) {
//Threading
AudioQueueBeingModified = SDL_CreateMutex();
SDL_AtomicSet(&Ticks, 0);
SDL_Thread *InternalClock = SDL_CreateThread(internal_clock, "Internal Clock", NULL);
SDL_Thread *InternalClock = SDL_CreateThread(internal_clock, "Internal Clock", (void*) NULL);
SDL_Thread *AudioThread = SDL_CreateThread(audio, "Audio", NULL);
SDL_AtomicSet(&AudioInitializing, 0);
......
......@@ -28,8 +28,8 @@ void marathon_main() {
char PlayerScore[50]; // Used later to display score on screen.
// Set Collision Boxes
Player.HitBox = (Rectangle){80, Player.Y, 5, PaddleSprite.height};
Ball.HitBox = (Rectangle){Ball.X, Ball.Y, BallSprite.width, BallSprite.height};
Player.HitBox = (Rectangle){80, Player.Y, 5, (float)PaddleSprite.height};
Ball.HitBox = (Rectangle){Ball.X, Ball.Y, (float)BallSprite.width, (float)BallSprite.height};
// Init Camera
Camera2D MainCamera;
......
......@@ -10,12 +10,10 @@
#include <SDL2/SDL_mutex.h>
#include <SDL2/SDL_thread.h>
#include "sounds.h"
#include <stdatomic.h>
#include <stdio.h>
#include <time.h>
#include <unistd.h>
#include <time.h>
#include <stdatomic.h>
#include <setjmp.h>
#include <string.h>
......
......@@ -2,8 +2,8 @@
static void settings(Camera2D *MainCamera, Mix_Music *TitleScreenMusic) {
bool SettingsGoing = true;
int MusicBarY = 50;
int SoundBarY = 150;
float MusicBarY = 50;
float SoundBarY = 150;
Rectangle MouseCursor = {
0,0,1,1
......@@ -41,7 +41,7 @@ static void settings(Camera2D *MainCamera, Mix_Music *TitleScreenMusic) {
};
//Screen Buttons
int ScreenButtonLength = 250;
float ScreenButtonLength = 250;
Rectangle ScreenButtons[3] = {
{95, 242, ScreenButtonLength, 42},
{95, 284, ScreenButtonLength, 42},
......
......@@ -35,9 +35,9 @@ void versus_main() {
Texture2D BallSprite = LoadTexture("resources/ball.png");
// Set Collision Boxes
Player.HitBox = (Rectangle){80, Player.Y, 5, PaddleSprite.height};
Enemy.HitBox = (Rectangle){1200, Enemy.Y, 5, PaddleSprite.height};
Ball.HitBox = (Rectangle){Ball.X, Ball.Y, BallSprite.width, BallSprite.height};
Player.HitBox = (Rectangle){80, Player.Y, 5, (float)PaddleSprite.height};
Enemy.HitBox = (Rectangle){1200, Enemy.Y, 5, (float)PaddleSprite.height};
Ball.HitBox = (Rectangle){Ball.X, Ball.Y, (float)BallSprite.width, (float)BallSprite.height};
Enemy.BallDetector = (Rectangle){0, Enemy.Y+120, 1280, PaddleSprite.height/5.0f};
char EnemyScore[50];
char PlayerScore[50]; // Used later to display score on screen.
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment