comparison src/libmlk-rpg/rpg/battle-state-lost.c @ 320:8f9937403749

misc: improve loading of data
author David Demelier <markand@malikania.fr>
date Fri, 01 Oct 2021 20:30:00 +0200
parents libmlk-rpg/rpg/battle-state-lost.c@d01e83210ca2
children 460c78706989
comparison
equal deleted inserted replaced
319:b843eef4cc35 320:8f9937403749
1 /*
2 * battle-state-lost.c -- battle state (lost)
3 *
4 * Copyright (c) 2020-2021 David Demelier <markand@malikania.fr>
5 *
6 * Permission to use, copy, modify, and/or distribute this software for any
7 * purpose with or without fee is hereby granted, provided that the above
8 * copyright notice and this permission notice appear in all copies.
9 *
10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 */
18
19 #include <assert.h>
20
21 #include <core/alloc.h>
22 #include <core/music.h>
23 #include <core/panic.h>
24 #include <core/window.h>
25
26 #include <rpg/message.h>
27
28 #include "battle.h"
29 #include "battle-state.h"
30 #include "rpg_p.h"
31
32 struct lost {
33 struct battle_state self;
34 struct message msg;
35 };
36
37 static void
38 handle(struct battle_state *st, struct battle *bt, const union event *ev)
39 {
40 (void)bt;
41
42 struct lost *lost = st->data;
43
44 message_handle(&lost->msg, ev);
45 }
46
47 static int
48 update(struct battle_state *st, struct battle *bt, unsigned int ticks)
49 {
50 (void)bt;
51
52 struct lost *lost = st->data;
53
54 if (message_update(&lost->msg, ticks))
55 battle_state_closing(bt);
56
57 return 0;
58 }
59
60 static void
61 draw(const struct battle_state *st, const struct battle *bt)
62 {
63 (void)bt;
64
65 const struct lost *lost = st->data;
66
67 message_draw(&lost->msg);
68 }
69
70 void
71 battle_state_lost(struct battle *bt)
72 {
73 assert(bt);
74
75 struct lost *lost;
76
77 if (!(lost = alloc_new0(sizeof (*lost))))
78 panic();
79
80 lost->self.data = lost;
81 lost->self.handle = handle;
82 lost->self.update = update;
83 lost->self.draw = draw;
84
85 lost->msg.text[0] = _("You have been defeated...");
86 lost->msg.theme = bt->theme;
87 lost->msg.flags = MESSAGE_FLAGS_AUTOMATIC |
88 MESSAGE_FLAGS_FADEIN |
89 MESSAGE_FLAGS_FADEOUT;
90 lost->msg.timeout = MESSAGE_TIMEOUT_DEFAULT;
91 lost->msg.delay = MESSAGE_DELAY_DEFAULT;
92
93 message_start(&lost->msg);
94 message_query(&lost->msg, NULL, &lost->msg.h);
95
96 lost->msg.w = window.w * 0.6;
97 lost->msg.y = window.h * 0.1;
98 lost->msg.x = (window.w - lost->msg.w) / 2;
99
100 bt->status = BATTLE_STATUS_LOST;
101 battle_switch(bt, &lost->self);
102
103 if (bt->music[2])
104 music_play(bt->music[2], MUSIC_NONE, 0);
105 }