-
Notifications
You must be signed in to change notification settings - Fork 0
/
graphics.c.save-failed
123 lines (88 loc) · 2.71 KB
/
graphics.c.save-failed
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
#include "graphics.h"
#include "raylib.h"
#include "Structs/Vec2.h"
#include "Structs/Circle.h"
#include "Structs/World.h"
#include "Structs/Enemy.h"
#include <stdio.h>
#define SCREEN_WIDTH 800
#define SCREEN_HEIGHT 600
void initGraphics() {
InitWindow(SCREEN_WIDTH, SCREEN_HEIGHT, "Hr.io");
SetTargetFPS(60);
cam = (Camera2D) { 0 };
cam.offset = (Vector2) { SCREEN_WIDTH / 2.0f, SCREEN_HEIGHT / 2.0f };
cam.zoom = 1.0f;
}
void drawWorld(World w) {
BeginDrawing();
switch (w.state) {
case PLAYING:
drawPlaying(w);
}
EndDrawing();
}
void drawPlaying(World w) {
int i;
cam.target = vec2ToVector2(w.player.position);
cam.zoom += (float)(GetMouseWheelMove() * 0.05f);
BeginMode2D(cam);
ClearBackground(RAYWHITE);
if (w.player.isAlive) {
Color c = VIOLET;
// Make poisoned balls flicker
int time = (int)(w.player.poisonTimeRemaining * 3);
if (time % 2 == 1) {
// "mix" the colors togehter
c = GetColor((ColorToInt(GREEN) + ColorToInt(c)) / 2);
}
drawCircle(w.player, c);
}
for (i = 0; i < NUM_ENEMIES; i++) {
if (w.enemies[i].ball.isAlive) {
Color c;
switch (w.enemies[i].elementalType) {
case EXPLOSIVE:
c = ORANGE;
break;
case POISONOUS:
c = GREEN;
break;
case NONE:
c = RED;
break;
}
// Make poisoned balls flicker
int time = (int)(w.enemies[i].ball.poisonTimeRemaining * 3);
if (time % 2 == 1) {
// "mix" the colors togehter
c = GetColor((ColorToInt(GREEN) + ColorToInt(c)) / 2);
}
drawCircle(w.enemies[i].ball, c);
}
}
for (i = 0; i < NUM_FOOD; i++) {
if (w.foods[i].isAlive) {
drawCircle(w.foods[i], YELLOW);
}
}
EndMode2D();
char mensagem[51];
sprintf(mensagem, "Score: %.1f", w.elapsedTime);
DrawText(mensagem, 0, 0, 52, BLACK);
}
void drawCircle(Ball b, Color c) {
DrawCircle(b.position.x, b.position.y, b.radius, c);
}
void endGraphics() {
CloseWindow();
}
int isGraphicsRunning() {
return !WindowShouldClose();
}
Vector2 vec2ToVector2(Vec2 v) {
Vector2 res;
res.x = v.x;
res.y = v.y;
return res;
}