-
Notifications
You must be signed in to change notification settings - Fork 0
/
title.cpp
84 lines (58 loc) · 1.39 KB
/
title.cpp
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
#include "title.h"
static void logic(void);
static void draw(void);
static void drawLogo(void);
static SDL_Texture* sdl2Texture;
static SDL_Texture* shooterTexture;
static int reveal = 0;
static int timeout;
void initTitle(void)
{
app.delegate.logic = logic;
app.delegate.draw = draw;
memset(app.keyboard, 0, sizeof(int) * MAX_KEYBOARD_KEYS);
sdl2Texture = loadTexture("gfx/sdl2.png");
shooterTexture = loadTexture("gfx/shooter.png");
timeout = FPS * 5;
}
static void logic(void)
{
doBackground();
doStarfield();
if (reveal < SCREEN_HEIGHT)
{
reveal++;
}
if (--timeout <= 0)
{
initHighscores();
}
if (app.keyboard[SDL_SCANCODE_LCTRL])
{
initStage();
}
}
static void draw(void)
{
drawBackground();
drawStarfield();
drawLogo();
drawText(SCREEN_WIDTH / 2, 430, 255, 255, 255, TEXT_CENTER, "MOVE WITH ARROW KEYS");
drawText(SCREEN_WIDTH / 2, 480, 255, 255, 255, TEXT_CENTER, "PRESS CTRL TO FIRE");
if (timeout % 40 < 20)
{
drawText(SCREEN_WIDTH / 2, 600, 255, 255, 255, TEXT_CENTER, "PRESS FIRE TO PLAY!");
}
}
static void drawLogo(void)
{
SDL_Rect r;
r.x = 0;
r.y = 0;
SDL_QueryTexture(sdl2Texture, NULL, NULL, &r.w, &r.h);
r.h = MIN(reveal, r.h);
blitRect(sdl2Texture, &r, (SCREEN_WIDTH / 2) - (r.w / 2), 100);
SDL_QueryTexture(shooterTexture, NULL, NULL, &r.w, &r.h);
r.h = MIN(reveal, r.h);
blitRect(shooterTexture, &r, (SCREEN_WIDTH / 2) - (r.w / 2), 250);
}