-
Notifications
You must be signed in to change notification settings - Fork 13
/
huge_sprite.c
84 lines (68 loc) · 1.35 KB
/
huge_sprite.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
// # Huge Sprite
// <div style="text-align: center"><img src="screenshot.png" alt="" /></div>
//
// Render a huge 40x64 sprite that can be moved around with the D-pad.
//
// ## Source
#include <gb/gb.h>
#include <types.h>
#include "sprite.h"
#include "bg.h"
#define SPR_WIDTH 8
#define SPR_HEIGHT 5
#define TOTAL_SPR SPR_WIDTH * SPR_HEIGHT
UINT8 x = 64;
UINT8 y = 96;
void render_huge_sprite() {
UINT8 i, j;
UINT8 sprite_index;
set_sprite_tile(0, 1);
for(i = 0; i < SPR_WIDTH; ++i) {
for(j = 0; j < SPR_HEIGHT; ++j) {
sprite_index = i * SPR_HEIGHT + j;
set_sprite_tile(sprite_index, sprite_index);
move_sprite(sprite_index, x + (j * 8), y + (i * 8));
}
}
}
void load_background() {
set_bkg_data(0, 2, bg_tile_data);
set_bkg_tiles(0, 0, 20, 18, bg_map_data);
}
void move_huge_sprite(UINT8 nx, UINT8 ny) {
UINT8 i, lx, ly;
lx = 0;
ly = 0;
for(i = 0; i < 40; i++) {
if(lx == 40) {
lx = 0;
ly += 8;
}
move_sprite(i, nx + lx, ny + ly);
lx += 8;
}
}
void move_right() {
move_huge_sprite(++x, y);
}
void move_left() {
move_huge_sprite(--x, y);
}
void main() {
SPRITES_8x8;
set_sprite_data(0, 40, sprite_tile_data);
render_huge_sprite();
load_background();
SHOW_SPRITES;
SHOW_BKG;
while(1) {
wait_vbl_done();
if(joypad() & J_RIGHT) {
move_right();
}
if(joypad() & J_LEFT) {
move_left();
}
delay(10);
}
}