-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscore.c
More file actions
47 lines (45 loc) · 1.15 KB
/
score.c
File metadata and controls
47 lines (45 loc) · 1.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
#include <time.h>
#include "raylib.h"
bool IsRoomCleared (Enemy enemies[32]){
bool roomIsCleared = true;
for (int i = 0; i < 32; i++)
{
if (enemies[i].health > 0)
{
roomIsCleared=false;
}
}
return roomIsCleared;
}
//https://www.desmos.com/calculator/oqzyr80y6h
int CalculateScore(int roomsCleared, int health, int maxHealth, float timeElapsed, int bossCleared){
int score = bossCleared + floor(1000*roomsCleared*(1+(health/maxHealth))/((timeElapsed+120)/60));
return score;
}
int UpdateHighScore(int score){
int previousScore = 0;
FILE *fptr;
fptr=fopen("highscore.txt","r");
if(fptr == NULL){
printf("does not exist");
}
else{
fscanf(fptr,"%d", &previousScore);
printf("read %d\n", previousScore);
fclose(fptr);
}
if(score > previousScore){
fptr=fopen("highscore.txt","w");
fprintf(fptr, "%d",score);
printf("%d > %d ",score,previousScore);
fclose(fptr);
return score;
}
else{
return previousScore;
}
}