Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
charadon
Pong C
Commits
3e778ea5
Commit
3e778ea5
authored
Jun 08, 2022
by
Charadon
Browse files
Migrate to C++
parent
21b272f6
Pipeline
#6245
pending with stage
Changes
8
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
premake5.lua
View file @
3e778ea5
...
...
@@ -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
...
...
src/ball.c
→
src/ball.c
c
View file @
3e778ea5
#include
"pong.h"
#include
<SDL2/SDL_atomic.h>
void
ball
(
Rectangle
*
Player
,
Rectangle
*
Enemy
,
struct
Balls
*
Ball
,
int
*
PlayerScore
,
int
*
EnemyScore
)
{
...
...
src/enemy.c
→
src/enemy.c
c
View file @
3e778ea5
#include
"pong.h"
#include
<SDL2/SDL_atomic.h>
void
enemy
(
struct
Players
*
Enemy
,
struct
Balls
ball
)
{
if
(
Enemy
->
NextTick
<=
SDL_AtomicGet
(
&
Ticks
))
{
...
...
src/main.c
→
src/main.c
c
View file @
3e778ea5
#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
);
...
...
src/marathon.c
→
src/marathon.c
c
View file @
3e778ea5
...
...
@@ -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
;
...
...
src/pong.h
View file @
3e778ea5
...
...
@@ -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>
...
...
src/title.c
→
src/title.c
c
View file @
3e778ea5
...
...
@@ -2,8 +2,8 @@
static
void
settings
(
Camera2D
*
MainCamera
,
Mix_Music
*
TitleScreenMusic
)
{
bool
SettingsGoing
=
true
;
in
t
MusicBarY
=
50
;
in
t
SoundBarY
=
150
;
floa
t
MusicBarY
=
50
;
floa
t
SoundBarY
=
150
;
Rectangle
MouseCursor
=
{
0
,
0
,
1
,
1
...
...
@@ -41,7 +41,7 @@ static void settings(Camera2D *MainCamera, Mix_Music *TitleScreenMusic) {
};
//Screen Buttons
in
t
ScreenButtonLength
=
250
;
floa
t
ScreenButtonLength
=
250
;
Rectangle
ScreenButtons
[
3
]
=
{
{
95
,
242
,
ScreenButtonLength
,
42
},
{
95
,
284
,
ScreenButtonLength
,
42
},
...
...
src/versus.c
→
src/versus.c
c
View file @
3e778ea5
...
...
@@ -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.0
f
};
char
EnemyScore
[
50
];
char
PlayerScore
[
50
];
// Used later to display score on screen.
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment