Mercurial > molko
comparison libmlk-rpg/rpg/battle-state-lost.c @ 243:71b3b7036de7
misc: lot of cleanups,
- prefix libraries with libmlk,
- move assets from source directories closes #2520,
- prefix header guards closes #2519
author | David Demelier <markand@malikania.fr> |
---|---|
date | Sat, 28 Nov 2020 22:37:30 +0100 |
parents | librpg/rpg/battle-state-lost.c@76afe639fd72 |
children | 6367b976112d |
comparison
equal
deleted
inserted
replaced
242:4c24604efcab | 243:71b3b7036de7 |
---|---|
1 /* | |
2 * battle-state-lost.c -- battle state (lost) | |
3 * | |
4 * Copyright (c) 2020 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 "battle-state-closing.h" | |
31 #include "battle-state-victory.h" | |
32 #include "rpg_p.h" | |
33 | |
34 struct lost { | |
35 struct battle_state self; | |
36 struct message msg; | |
37 }; | |
38 | |
39 static void | |
40 handle(struct battle_state *st, struct battle *bt, const union event *ev) | |
41 { | |
42 (void)bt; | |
43 | |
44 struct lost *lost = st->data; | |
45 | |
46 message_handle(&lost->msg, ev); | |
47 } | |
48 | |
49 static bool | |
50 update(struct battle_state *st, struct battle *bt, unsigned int ticks) | |
51 { | |
52 (void)bt; | |
53 | |
54 struct lost *lost = st->data; | |
55 | |
56 if (message_update(&lost->msg, ticks)) | |
57 battle_state_closing(bt); | |
58 | |
59 return false; | |
60 } | |
61 | |
62 static void | |
63 draw(const struct battle_state *st, const struct battle *bt) | |
64 { | |
65 (void)bt; | |
66 | |
67 const struct lost *lost = st->data; | |
68 | |
69 message_draw(&lost->msg); | |
70 } | |
71 | |
72 void | |
73 battle_state_lost(struct battle *bt) | |
74 { | |
75 assert(bt); | |
76 | |
77 struct lost *lost; | |
78 | |
79 if (!(lost = alloc_new0(sizeof (*lost)))) | |
80 panic(); | |
81 | |
82 lost->self.data = lost; | |
83 lost->self.handle = handle; | |
84 lost->self.update = update; | |
85 lost->self.draw = draw; | |
86 | |
87 lost->msg.text[0] = _("You have been defeated..."); | |
88 lost->msg.theme = bt->theme; | |
89 lost->msg.flags = MESSAGE_FLAGS_AUTOMATIC | | |
90 MESSAGE_FLAGS_FADEIN | | |
91 MESSAGE_FLAGS_FADEOUT; | |
92 lost->msg.timeout = MESSAGE_TIMEOUT_DEFAULT; | |
93 lost->msg.delay = MESSAGE_DELAY_DEFAULT; | |
94 | |
95 message_start(&lost->msg); | |
96 message_query(&lost->msg, NULL, &lost->msg.h); | |
97 | |
98 lost->msg.w = window.w * 0.6; | |
99 lost->msg.y = window.h * 0.1; | |
100 lost->msg.x = (window.w - lost->msg.w) / 2; | |
101 | |
102 bt->status = BATTLE_STATUS_LOST; | |
103 battle_switch(bt, &lost->self); | |
104 | |
105 if (bt->music[2]) | |
106 music_play(bt->music[2], MUSIC_NONE, 0); | |
107 } |