Kräftig aufgeräumt. Kollisions- und Sprungtötungsphysik jetzt allein auf
[hackover2013-badge-firmware.git] / badge / jumpnrun / render.c
1 #include "render.h"
2
3 static badge_sprite const anim_sickle[JUMPNRUN_SHOT_FRAMES] = {
4 { 3, 3, (uint8_t const *) "\xab\x01" },
5 { 3, 3, (uint8_t const *) "\xee" }
6 };
7
8 static badge_sprite const anim_player[JUMPNRUN_PLAYER_FRAMES ] = {
9 { 5, 8, (uint8_t const *) "\x1c\xff\xfd\x04\x04" },
10 { 5, 8, (uint8_t const *) "\x1c\xff\x3d\xc4\x04" },
11 { 5, 8, (uint8_t const *) "\xdc\x3f\x1d\x24\xc4" },
12 { 5, 8, (uint8_t const *) "\x1c\xff\x3d\xc4\x04" }
13 };
14
15 vec2d jumpnrun_player_extents(void) { return (vec2d) { FIXED_INT_I(5), FIXED_INT_I(8) }; }
16
17 void jumpnrun_render_moveable (badge_framebuffer *fb, jumpnrun_game_state const *state, jumpnrun_moveable const *moveable, badge_sprite const *animation, vec2d sprite_offset) {
18 vec2d render_pos = vec2d_sub(moveable->hitbox.pos, sprite_offset);
19 badge_framebuffer_blt(fb,
20 fixed_point_cast_int(render_pos.x) - jumpnrun_screen_left(state),
21 fixed_point_cast_int(render_pos.y),
22 &animation[moveable->anim_frame],
23 (moveable->flags & JUMPNRUN_MOVEABLE_MIRRORED) ? BADGE_BLT_MIRRORED : 0);
24 }
25
26 void jumpnrun_render_player (badge_framebuffer *fb, jumpnrun_game_state const *state) {
27 jumpnrun_render_moveable(fb, state, &state->player.base, anim_player, (vec2d) { FIXED_INT(0), FIXED_INT(0) });
28 }
29
30 void jumpnrun_render_shot (badge_framebuffer *fb, jumpnrun_game_state const *state, jumpnrun_shot *shot ) {
31 /* show every position twice, because LCD switching time. This makes the shots more
32 * visible on the nokia lcds.
33 */
34 badge_framebuffer_blt(fb,
35 fixed_point_cast_int(shot->old_box.pos.x) - jumpnrun_screen_left(state),
36 fixed_point_cast_int(shot->old_box.pos.y),
37 &anim_sickle[shot->tick / JUMPNRUN_SHOT_TICKS_PER_FRAME],
38 fixed_point_lt(shot->inertia.x, FIXED_INT(0)) ? BADGE_BLT_MIRRORED : 0);
39 badge_framebuffer_blt(fb,
40 fixed_point_cast_int(shot->current_box.pos.x) - jumpnrun_screen_left(state),
41 fixed_point_cast_int(shot->current_box.pos.y),
42 &anim_sickle[shot->tick / JUMPNRUN_SHOT_TICKS_PER_FRAME],
43 fixed_point_lt(shot->inertia.x, FIXED_INT(0)) ? BADGE_BLT_MIRRORED : 0);
44
45 shot->old_box = shot->current_box;
46 }
47
48 void jumpnrun_render_enemy (badge_framebuffer *fb, jumpnrun_game_state const *state, jumpnrun_enemy const *enemy ) {
49 jumpnrun_render_moveable(fb, state, &enemy->base, enemy->type->animation_frames, enemy->type->hitbox.pos);
50 }
51
52 void jumpnrun_render_tile (badge_framebuffer *fb, jumpnrun_game_state const *state, jumpnrun_tile const *tile ) {
53 badge_framebuffer_blt(fb,
54 tile->pos.x * JUMPNRUN_TILE_PIXEL_WIDTH - jumpnrun_screen_left(state),
55 tile->pos.y * JUMPNRUN_TILE_PIXEL_HEIGHT,
56 &tile_type(tile)->sprite,
57 0);
58 }
59
60 void jumpnrun_render_item (badge_framebuffer *fb, jumpnrun_game_state const *state, jumpnrun_item const *item ) {
61 badge_framebuffer_blt(fb,
62 fixed_point_cast_int(item->pos.x) - jumpnrun_screen_left(state),
63 fixed_point_cast_int(item->pos.y),
64 &item->type->sprite,
65 0);
66 }
67
68 void jumpnrun_render_player_symbol(badge_framebuffer *fb, int8_t x, int8_t y) {
69 badge_framebuffer_blt(fb, x, y, &anim_player[0], 0);
70 }
71
72 void jumpnrun_render_key_symbol (badge_framebuffer *fb, int8_t x, int8_t y) {
73 badge_framebuffer_blt(fb, x, y, &jumpnrun_item_type_data[JUMPNRUN_ITEM_TYPE_KEY].sprite, 0);
74 }
This page took 0.072034 seconds and 5 git commands to generate.