/
lobby.c
95 lines (78 loc) · 1.64 KB
/
lobby.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
/* This file is part of punani-strike
* Copyright (c) 2011 Gianni Tedesco
* Released under the terms of GPLv3
*/
#include <punani/punani.h>
#include <punani/renderer.h>
#include <punani/tex.h>
#include "game-modes.h"
#include <SDL/SDL_keysym.h>
struct lobby {
renderer_t renderer;
texture_t splash;
};
static void *ctor(renderer_t r, void *common)
{
struct lobby *lobby = NULL;
lobby = calloc(1, sizeof(*lobby));
if ( NULL == lobby )
return NULL;
lobby->renderer = r;
lobby->splash = png_get_by_name("data/splash.png");
if ( NULL == lobby->splash )
goto out_free;
/* success */
goto out;
out_free:
free(lobby);
lobby = NULL;
out:
return lobby;
}
static void render(void *priv, float lerp)
{
struct lobby *lobby = priv;
unsigned int x, y, sx, sy;
renderer_t r = lobby->renderer;
prect_t dst;
renderer_render_2d(r);
renderer_clear_color(r, 0.0, 0.0, 0.0);
renderer_size(r, &x, &y);
sx = texture_width(lobby->splash);
sy = texture_height(lobby->splash);
dst.x = (x - sx) / 2;
dst.y = (y - sy) / 2;
dst.w = sx;
dst.h = sy;
renderer_blit(r, lobby->splash, NULL, &dst);
}
static void dtor(void *priv)
{
struct lobby *lobby = priv;
texture_put(lobby->splash);
free(lobby);
}
static void keypress(void *priv, int key, int down)
{
struct lobby *lobby = priv;
if ( !down )
return;
switch(key) {
case SDLK_SPACE:
case SDLK_KP_ENTER:
case SDLK_RETURN:
renderer_exit(lobby->renderer, GAME_MODE_COMPLETE);
break;
case SDLK_ESCAPE:
renderer_exit(lobby->renderer, GAME_MODE_QUIT);
break;
default:
break;
}
}
const struct game_ops lobby_ops = {
.ctor = ctor,
.dtor = dtor,
.render = render,
.keypress = keypress,
};