Mercurial > molko
comparison libmlk-rpg/rpg/walksprite.h @ 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/walksprite.h@86b71e1f9dd5 |
children | 08ab73b32832 |
comparison
equal
deleted
inserted
replaced
242:4c24604efcab | 243:71b3b7036de7 |
---|---|
1 /* | |
2 * walksprite.h -- sprite designed for walking entities | |
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 #ifndef MOLKO_RPG_WALKSPRITE_H | |
20 #define MOLKO_RPG_WALKSPRITE_H | |
21 | |
22 /** | |
23 * \file walksprite.h | |
24 * \brief Sprite designed for walking entities. | |
25 * \ingroup drawing | |
26 */ | |
27 | |
28 struct sprite; | |
29 | |
30 /** | |
31 * \brief Sprite designed for walking entities. | |
32 * | |
33 * This structure works with sprite images that are defined as using the | |
34 * following conventions: | |
35 * | |
36 * ``` | |
37 * 7 0 1 | |
38 * ↖ ↑ ↗ | |
39 * 6 ← → 2 | |
40 * ↙ ↓ ↘ | |
41 * 5 4 3 | |
42 * ``` | |
43 * | |
44 * Where numbers define row in the sprite according to the character | |
45 * orientation. In other terms, your image sprite should look like this: | |
46 * | |
47 * ``` | |
48 * row columns in your image | |
49 * ---|--------------------- | |
50 * 0 | ↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑ | |
51 * 1 | ↗↗↗↗↗↗↗↗↗↗↗↗↗↗↗↗↗↗↗↗ | |
52 * 2 | →→→→→→→→→→→→→→→→→→→→ | |
53 * 3 | ↘↘↘↘↘↘↘↘↘↘↘↘↘↘↘↘↘↘↘↘ | |
54 * 4 | ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓ | |
55 * 5 | ↙↙↙↙↙↙↙↙↙↙↙↙↙↙↙↙↙↙↙↙ | |
56 * 6 | ←←←←←←←←←←←←←←←←←←←← | |
57 * 7 | ↖↖↖↖↖↖↖↖↖↖↖↖↖↖↖↖↖↖↖↖ | |
58 * ``` | |
59 */ | |
60 struct walksprite { | |
61 struct sprite *sprite; /*!< (+&) The sprite to use */ | |
62 unsigned int delay; /*!< (+) The delay between frames */ | |
63 unsigned int index; /*!< (-) Current column index */ | |
64 unsigned int elapsed; /*!< (-) Elapsed time since last frame */ | |
65 }; | |
66 | |
67 /** | |
68 * Initialize the walking sprite. | |
69 * | |
70 * \pre ws != NULL | |
71 * \pre sprite != NULL | |
72 * \param ws the walking sprite | |
73 * \param sprite the sprite to use | |
74 * \param delay the delay between sprites | |
75 */ | |
76 void | |
77 walksprite_init(struct walksprite *ws, struct sprite *sprite, unsigned int delay); | |
78 | |
79 /** | |
80 * Reset current column to inactive (aka no longer walking). | |
81 * | |
82 * \pre ws != NULL | |
83 * \param ws the walking sprite | |
84 */ | |
85 void | |
86 walksprite_reset(struct walksprite *ws); | |
87 | |
88 /** | |
89 * Update the walking sprite | |
90 * | |
91 * \pre ws != NULL | |
92 * \param ws the walking sprite | |
93 * \param ticks the number of milliseconds between last frame | |
94 */ | |
95 void | |
96 walksprite_update(struct walksprite *ws, unsigned int ticks); | |
97 | |
98 /** | |
99 * Draw the appropriate sprite cell to the screen according to the orientation | |
100 * given. | |
101 * | |
102 * \pre ws != NULL | |
103 * \pre orientation < 8 | |
104 * \param ws the walking sprite | |
105 * \param orientation the orientation (or the row between 0 and 7) | |
106 * \param x the x coordinate | |
107 * \param y the y coordinate | |
108 */ | |
109 void | |
110 walksprite_draw(const struct walksprite *ws, unsigned int orientation, int x, int y); | |
111 | |
112 #endif /* !MOLKO_RPG_WALKSPRITE_H */ |