-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathst_gameplay.c
129 lines (103 loc) · 2.65 KB
/
st_gameplay.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
#include "st_gameplay.h"
#include <stdio.h>
#include <math.h>
#include <ncurses.h>
#include <stdlib.h>
#include "const.h"
#include "ui.h"
#include "input.h"
#include "states.h"
#include "encounters.h"
#include "audio.h"
#include "rd_chad.h"
float encounter_timer = 0;
float income_timer = 0;
static void draw_ui(float delta) {
ui_draw_border();
ui_draw_debug(delta);
attron(COLOR_PAIR(PAIR_GREEN));
move(HEIGHT - BOTTOM_PANEL_HEIGHT, 1);
hline('-', WIDTH - 2);
move(HEIGHT - BOTTOM_PANEL_HEIGHT + 2, 2);
move(1, WIDTH - RIGHT_PANEL_WIDTH - 2);
vline('|', HEIGHT - BOTTOM_PANEL_HEIGHT);
attroff(COLOR_PAIR(PAIR_GREEN));
}
void st_gameplay_enter(game_t *game)
{
clear();
encounter_timer = 0;
income_timer = 0;
if (audio_music_current() != MUSIC_BG_BROKEN)
{
audio_music_play(MUSIC_BG_BROKEN);
}
}
static void add_int(int val)
{
char buffer[32];
snprintf(buffer, 32, "%d", val);
addstr(buffer);
}
void st_gameplay_run(game_t *game, float delta)
{
draw_ui(delta);
rd_chad(delta);
attron(COLOR_PAIR(PAIR_GREEN));
move(2, WIDTH - RIGHT_PANEL_WIDTH + 2);
addstr("POSITIVE ENERGY");
move(5, WIDTH - RIGHT_PANEL_WIDTH + 2);
addstr("POWER");
move(8, WIDTH - RIGHT_PANEL_WIDTH + 2);
addstr("GOOD VIBES");
move(11, WIDTH - RIGHT_PANEL_WIDTH + 2);
addstr("BAD VIBES");
attroff(COLOR_PAIR(PAIR_GREEN));
attron(COLOR_PAIR(PAIR_YELLOW));
move(3, WIDTH - RIGHT_PANEL_WIDTH + 2);
add_int(game->energy);
move(6, WIDTH - RIGHT_PANEL_WIDTH + 2);
add_int(game->power);
move(9, WIDTH - RIGHT_PANEL_WIDTH + 2);
add_int(game->good_vibes);
move(12, WIDTH - RIGHT_PANEL_WIDTH + 2);
add_int(game->bad_vibes);
attroff(COLOR_PAIR(PAIR_YELLOW));
ui_draw_help();
encounter_timer += delta;
income_timer += delta;
if (game->bad_vibes < 0)
{
game->bad_vibes = 0;
}
if (income_timer > 3 * 1000000)
{
game->energy += game->good_vibes;
game->good_vibes -= game->bad_vibes;
game->power += game->energy / 2;
income_timer = 0;
ui_clear_sprite(WIDTH - RIGHT_PANEL_WIDTH + 2, 2, 16, 16);
}
if (encounter_timer > 4 * 1000000)
{
encounter_t *enc = get_random_encounter();
game->encounter = enc;
sm_set_state(STATE_ENCOUNTER);
}
if (game->energy > 30 || game->energy < -30)
{
sm_set_state(STATE_SCORE);
}
if (CURR_KEY == (int) 'A')
{
game->good_vibes += 2;
game->energy += 2;
}
if (CURR_KEY == KEY_BACKSPACE)
{
sm_set_state(STATE_MENU);
}
}
void st_gameplay_exit(game_t *game)
{
}