Schrift fest in Firmware eingebacken, damit die auch funktioniert, wenn auf dem
[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 static badge_sprite const anim_splosion[JUMPNRUN_SPLOSION_FRAMES] = {
16 { 7, 5, (uint8_t const *) "\x00\x28\xa0\x00" },
17 { 7, 5, (uint8_t const *) "\x51\x29\xa0\x54\x04" },
18 { 7, 5, (uint8_t const *) "\x51\x01\x00\x54\x04" },
19 { 7, 5, (uint8_t const *) "\x11\x00\x00\x40\x04" }
20 };
21
22 vec2d jumpnrun_player_extents(void) { return (vec2d) { FIXED_INT_I(5), FIXED_INT_I(8) }; }
23
24 void jumpnrun_render_moveable (badge_framebuffer *fb, jumpnrun_game_state const *state, jumpnrun_moveable const *moveable, badge_sprite const *animation, vec2d sprite_offset) {
25 vec2d render_pos = vec2d_sub(moveable->hitbox.pos, sprite_offset);
26 badge_framebuffer_blt(fb,
27 fixed_point_cast_int(render_pos.x) - jumpnrun_screen_left(state),
28 fixed_point_cast_int(render_pos.y),
29 &animation[moveable->anim_frame],
30 (moveable->flags & JUMPNRUN_MOVEABLE_MIRRORED) ? BADGE_BLT_MIRRORED : 0);
31 }
32
33 void jumpnrun_render_player (badge_framebuffer *fb, jumpnrun_game_state const *state) {
34 jumpnrun_render_moveable(fb, state, &state->player.base, anim_player, (vec2d) { FIXED_INT(0), FIXED_INT(0) });
35 }
36
37 void jumpnrun_render_shot (badge_framebuffer *fb, jumpnrun_game_state const *state, jumpnrun_shot *shot ) {
38 /* show every position twice, because LCD switching time. This makes the shots more
39 * visible on the nokia lcds.
40 */
41 badge_framebuffer_blt(fb,
42 fixed_point_cast_int(shot->old_box.pos.x) - jumpnrun_screen_left(state),
43 fixed_point_cast_int(shot->old_box.pos.y),
44 &anim_sickle[shot->tick / JUMPNRUN_SHOT_TICKS_PER_FRAME],
45 fixed_point_lt(shot->inertia.x, FIXED_INT(0)) ? BADGE_BLT_MIRRORED : 0);
46 badge_framebuffer_blt(fb,
47 fixed_point_cast_int(shot->current_box.pos.x) - jumpnrun_screen_left(state),
48 fixed_point_cast_int(shot->current_box.pos.y),
49 &anim_sickle[shot->tick / JUMPNRUN_SHOT_TICKS_PER_FRAME],
50 fixed_point_lt(shot->inertia.x, FIXED_INT(0)) ? BADGE_BLT_MIRRORED : 0);
51
52 shot->old_box = shot->current_box;
53 }
54
55 void jumpnrun_render_enemy (badge_framebuffer *fb, jumpnrun_game_state const *state, jumpnrun_enemy const *enemy ) {
56 jumpnrun_render_moveable(fb, state, &enemy->base, enemy->type->animation_frames, enemy->type->hitbox.pos);
57 }
58
59 void jumpnrun_render_tile (badge_framebuffer *fb, jumpnrun_game_state const *state, jumpnrun_tile const *tile ) {
60 badge_framebuffer_blt(fb,
61 tile->pos.x * JUMPNRUN_TILE_PIXEL_WIDTH - jumpnrun_screen_left(state),
62 tile->pos.y * JUMPNRUN_TILE_PIXEL_HEIGHT,
63 &tile_type(tile)->sprite,
64 0);
65 }
66
67 void jumpnrun_render_item (badge_framebuffer *fb, jumpnrun_game_state const *state, jumpnrun_item const *item ) {
68 badge_framebuffer_blt(fb,
69 fixed_point_cast_int(item->pos.x) - jumpnrun_screen_left(state),
70 fixed_point_cast_int(item->pos.y),
71 &item->type->sprite,
72 0);
73 }
74
75 void jumpnrun_render_splosion (badge_framebuffer *fb, jumpnrun_game_state const *state, jumpnrun_moveable const *moveable) {
76 badge_sprite const *sprite = &anim_splosion[moveable->tick_minor / JUMPNRUN_SPLOSION_TICKS_PER_FRAME];
77 vec2d sprite_offset = {
78 fixed_point_div(fixed_point_sub(FIXED_INT(sprite->width ), rectangle_width (&moveable->hitbox)), FIXED_INT(2)),
79 fixed_point_div(fixed_point_sub(FIXED_INT(sprite->height), rectangle_height(&moveable->hitbox)), FIXED_INT(2))
80 };
81 vec2d render_pos = vec2d_sub(moveable->hitbox.pos, sprite_offset);
82
83 badge_framebuffer_blt(fb,
84 fixed_point_cast_int(render_pos.x) - jumpnrun_screen_left(state),
85 fixed_point_cast_int(render_pos.y),
86 sprite, 0);
87 }
88
89 void jumpnrun_render_player_symbol(badge_framebuffer *fb, int8_t x, int8_t y) {
90 badge_framebuffer_blt(fb, x, y, &anim_player[0], 0);
91 }
92
93 void jumpnrun_render_key_symbol (badge_framebuffer *fb, int8_t x, int8_t y) {
94 badge_framebuffer_blt(fb, x, y, &jumpnrun_item_type_data[JUMPNRUN_ITEM_TYPE_KEY].sprite, 0);
95 }
This page took 0.077464 seconds and 5 git commands to generate.