-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgame.c
161 lines (141 loc) · 3.83 KB
/
game.c
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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
#include <raylib.h>
#include <math.h>
#include <tmx.h>
#include "game.h"
#include "config.h"
#include "resourcesIdx.h"
#include "combat.h"
#include "items.h"
#include "screens.h"
#include "enemy.h"
#include "arena.h"
#include "include/canvas.h"
#include "load.h"
static Arena MainArena;
static ArenaPlayer MainPlayer;
static bool InBattle = false;
static bool Running = true;
bool IsRunning() {
return Running;
}
void SetRunning(bool running) {
Running = running;
}
bool IsInBattle() {
return InBattle;
}
void SetInBattle(bool inBattle) {
InBattle = inBattle;
}
void StartBattle(ArenaEnemy *enemy) {
ArenaConstructor(&MainArena, &MainPlayer, enemy);
PlayerConstructor(&MainPlayer);
InBattle = true;
SetActiveScreen(&battleMenu);
}
void StartPlaying(){
InBattle = false;
SetRunning(true);
SetActiveScreen(NULL);
}
void StartTutorial() {
InBattle = false;
SetActiveScreen(&TutorialCanvas);
}
void DoPlayerChoice(Choice choice) {
printf("Player choice: %d\n", choice);
selectPlayerAction(&MainArena, choice);
}
RoundResult UpdateGameActions() {
RoundResult result = {0, 0, 0, 0};
if (InBattle) {
UpdateArena(&MainArena, &result);
}
if (result.gameResult != 0) {
if (result.gameResult == 1) { // voltar para a tela do mapa e setar que o inimigo foi derrotado
printf("Player won!\n");
StartPlaying();
} else if (result.gameResult == 2) { // voltar para a tela do mapa e teletransportar para o inicio
printf("Player lost!\n");
ResetArena();
}
}
}
void ResetArena() {
InBattle = false;
SetActiveScreen(&mainMenu);
ArenaConstructor(&MainArena, &MainPlayer, NULL);
PlayerConstructor(&MainPlayer);
}
void PlayerControl(Rectangle *playerRect, tmx_map *map)
{
Rectangle auxu = *playerRect;
auxu.y -= 5;
Rectangle auxd = *playerRect;
auxd.y += 5;
Rectangle auxl = *playerRect;
auxl.x -= 5;
Rectangle auxr = *playerRect;
auxr.x += 5;
if (IsKeyDown(KEY_UP) && !CheckObjgr(map, &auxu, "Paredes"))
{
playerRect->y -= 4;
}
else if (IsKeyDown(KEY_UP) && CheckObjgr(map, &auxu, "Paredes"))
{
playerRect->y += 1;
}
if (IsKeyDown(KEY_DOWN) && !CheckObjgr(map, &auxd, "Paredes"))
{
playerRect->y += 4;
}
else if(IsKeyDown(KEY_DOWN) && CheckObjgr(map, &auxd, "Paredes"))
{
playerRect->y -= 1;
}
if (IsKeyDown(KEY_LEFT) && !CheckObjgr(map, &auxl, "Paredes"))
{
playerRect->x -= 4;
}
else if(IsKeyDown(KEY_LEFT) && CheckObjgr(map, &auxl, "Paredes"))
{
playerRect->x += 1;
}
if (IsKeyDown(KEY_RIGHT) && !CheckObjgr(map, &auxr, "Paredes"))
{
playerRect->x += 4;
}
else if(IsKeyDown(KEY_RIGHT) && CheckObjgr(map, &auxr, "Paredes"))
{
playerRect->x -= 1;
}
}
void EnvironmentControl(Rectangle *playerRect, tmx_map *map) {
if (!map || !playerRect)
return;
EnemyList *enemies = GetEnemies();
mapCanvas(map);
DrawCenteredTexture(*GetTexture(Texture_Player), playerRect->x, playerRect->y, WHITE);
if(CheckObjgr(map, playerRect, "Inimigos"))
{
printf("Enemy found!\n");
if(!EnemyDefeated(map, playerRect, enemies))
{
DrawText("Press E to interact", playerRect->x-10, playerRect->y-10, 20, WHITE);
if (IsKeyPressed(KEY_E))
{
SetActiveScreen(&FoundEnemyCanvas);
SetInBattle(true);
SetRunning(false);
}
}
else if(CheckObjgr(map, playerRect, "Portas"))
{
DrawText("Press E to enter", playerRect->x - 10, playerRect->y-10, 20, WHITE);
if (IsKeyPressed(KEY_E))
{
UpdateMap(map, playerRect);
}
}
}
}