-
Notifications
You must be signed in to change notification settings - Fork 0
/
gamemodeEndless.c
89 lines (69 loc) · 2.22 KB
/
gamemodeEndless.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
#include <jo/jo.h>
#include "global_defines.h"
#include "background.h"
#include "model.h"
#include "player.h"
#include "npc.h"
#include "musicHandler.h"
#include "gamemode.h"
#include "gamemodeEndless.h"
// -------------------------------------
// Internal
// -------------------------------------
/* Score spent on changing level */
static int Currentlevel;
/* Score spent on changing level */
static int LevelChangeSpentScore;
/* Current spawn timer */
static int SpawnTimer;
/* Next spawn delay */
static int NextSpawn;
// -------------------------------------
// Public
// -------------------------------------
void GmStartEndless(const GamemodeData * data)
{
Currentlevel = 0;
LevelChangeSpentScore = 0;
SpawnTimer = 0;
NextSpawn = 40;
BackgroundSetColorShift(BackgroundBlueSky);
MusicSetCurrent(LVL1_MUSIC, true);
}
GamemodeTickResult GmTickEndless(const GamemodeData * data)
{
int levelPrice = (6000 * data->PlayerCount) + (1000 * data->PlayerCount);
if (data->CurrentScore - (LevelChangeSpentScore + levelPrice) >=0)
{
LevelChangeSpentScore = LevelChangeSpentScore + levelPrice;
int color = jo_random((int)BackgroundCrimsonSky) - 1;
color = JO_MIN(color, (int)BackgroundBlackSky);
int music = JO_MIN(color, LVL_MUSIC_CNT - 1);
music = JO_MAX(music, 0);
BackgroundSetColorShift(color);
MusicSetCurrent(LVL1_MUSIC + color, true);
Currentlevel++;
}
int stage = Currentlevel;
int stageColor = JO_MIN(stage, (int)BackgroundBlackSky);
SpawnTimer++;
if (NextSpawn < SpawnTimer && data->TickCount >= 350)
{
int spawnCount = jo_random(2 + MIN(stageColor, 3));
for (int i = 0; i < spawnCount; i++)
{
jo_pos2D_fixed pos = {NPC_SPAWN_X, jo_int2fixed((jo_random(10) - 5) << 4)};
int toSpawn = jo_random(5) - 1;
NpcCreate(JO_MAX(toSpawn, 0), &pos);
int expectedSpawn = jo_random(50 - stageColor);
int limitedSpawn = 40 - (stageColor * 4);
NextSpawn = 40 + JO_MAX(expectedSpawn, limitedSpawn);
SpawnTimer = 0;
}
}
return GmTickResultNone;
}
void GmEndEndless(const GamemodeData * data)
{
return;
}