Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
J
jumpNrun
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
wise2023_jumpnrun
jumpNrun
Commits
4b316438
Commit
4b316438
authored
1 year ago
by
Michael
Browse files
Options
Downloads
Patches
Plain Diff
added comments and explanations to gameLoop.c
parent
6e2b1ade
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
gameLoop.c
+18
-2
18 additions, 2 deletions
gameLoop.c
with
18 additions
and
2 deletions
gameLoop.c
+
18
−
2
View file @
4b316438
...
...
@@ -5,11 +5,15 @@ SDL_Rect *player;
int
playerscore
;
int
playerhighscore
;
//V: enum vehicle exists with 4 correct themes, Renderer exists
//N: renderer still exists, all objects are still exist or have been correctly removed
//E: game has been played for one round, which was at least 16ms long
void
gameLoop
(
enum
vehicle
theme
,
SDL_Renderer
*
renderer
)
{
SDL_Event
e
;
int
speed
=
0
;
// Character wird in der Mitte des vorletzten Feldes gestartet
SDL_Rect
character
=
{
.
x
=
420
,
.
y
=
810
,
...
...
@@ -22,23 +26,30 @@ void gameLoop(enum vehicle theme,SDL_Renderer* renderer) {
playerscore
=
0
;
playerhighscore
=
0
;
//start_game prevents game start before player input has been received
bool
start_game
=
false
;
//ends game if game over criteria have been met
bool
end_game
=
false
;
//used to implement rows and allows to remove rows out of view
struct
LinkedList
*
map
=
init_map
(
theme
);
//every at least 16ms this loop is called
while
(
!
end_game
)
{
//prevents overlap of menu and game
SDL_RenderClear
(
renderer
);
//used to standardize time to at least 16ms per tick
Uint32
start_time
=
SDL_GetTicks
();
while
(
SDL_PollEvent
(
&
e
))
{
switch
(
e
.
type
){
// if user closes window exit frees all used space
case
SDL_QUIT
:
exit
(
0
);
// any key input starts game and takes player input
case
SDL_KEYDOWN
:
start_game
=
true
;
jump
(
e
.
key
.
keysym
.
scancode
);
...
...
@@ -70,17 +81,22 @@ void gameLoop(enum vehicle theme,SDL_Renderer* renderer) {
//Position des Spielers wird aktualisiert und gezeichnet
update_character
(
speed
,
renderer
);
//Der aktuelle Score wird oben rechts angezeigt
paste_score
(
renderer
);
//Hier wird der aktuelle Stand des Spiels dem Spieler angezeigt
SDL_RenderPresent
(
renderer
);
// Spiel bekommt eine feste Aktuallisierungsrate von ~60 fps
// Tick dauert mindestens 16ms
Uint32
end_time
=
SDL_GetTicks
();
while
(
end_time
-
start_time
<
16
)
{
end_time
=
SDL_GetTicks
();
}
}
//Wenn das Spiel game over ist schreiben wir den aktuellen Score in die score.txt
write_table
(
theme
);
//wir löschen die map
free_map
(
map
);
return
;
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment