-
Notifications
You must be signed in to change notification settings - Fork 0
/
game.c
102 lines (89 loc) · 2.48 KB
/
game.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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#include <gb/gb.h>
/* bloke was created in GameBoy Tile Designer, in 8x16 mode */
unsigned char bloke[] =
{
/* Tile 0 */
0x00,0x00,0x38,0x38,0x7C,0x44,0x7F,0x7F,
0x44,0x74,0x46,0x7C,0x40,0x78,0x24,0x3C,
/* Tile 1 */
0x18,0x3C,0x00,0x24,0x00,0x24,0x00,0x24,
0x00,0x24,0x00,0x36,0x00,0x00,0x00,0x00,
/* Tile 2 */
0x00,0x00,0x38,0x38,0x7C,0x44,0x7F,0x7F,
0x44,0x74,0x46,0x7C,0x40,0x78,0x24,0x3C,
/* Tile 3 */
0x18,0x3C,0x00,0x22,0x00,0x22,0x00,0x22,
0x00,0x23,0x00,0x30,0x00,0x00,0x00,0x00,
/* Tile 4 */
0x00,0x00,0x38,0x38,0x7C,0x44,0x7F,0x7F,
0x44,0x74,0x46,0x7C,0x40,0x78,0x24,0x3C,
/* Tile 5 */
0x18,0x3C,0x00,0x42,0x00,0x42,0x00,0x42,
0x00,0x42,0x00,0x63,0x00,0x00,0x00,0x00,
/* Tile 6 */
0x00,0x00,0x38,0x38,0x7C,0x44,0x7F,0x7F,
0x44,0x74,0x46,0x7C,0x40,0x78,0x24,0x3C,
/* Tile 7 */
0x18,0x3C,0x00,0x44,0x00,0x44,0x00,0x44,
0x00,0x64,0x00,0x06,0x00,0x00,0x00,0x00
};
void main()
{
int spr,x,y,old;
SPRITES_8x16;
set_sprite_data(0, 8, bloke);
set_sprite_tile(0,0);
set_sprite_tile(1,2);
set_sprite_tile(2,4);
set_sprite_tile(3,6);
spr=0; /* sprite number to start with */
x=15; /* x cordinate to start at */
y=75; /* y cordinate to start at */
old=0; /* the last sprite displayed */
move_sprite(spr,14,75); /* puts the first sprite on screen */
SHOW_SPRITES;
while(1) {
/* checks to see if joypad has been pressed and is equal to right,
if so increments x, then moves old sprite out of view then
places new sprite at x,y. Waits then saves the current sprite
number in old and increments spr.
Lastly checks to see if we have reached the end of the
animiation (which is 4 sprites long), if so resets spr to 0. */
if(joypad()==J_RIGHT) {
x++;
move_sprite(old,200,200);
move_sprite(spr,x,y);
delay(75);
old=spr;
spr++;
if(spr==4) spr=0;
}
if(joypad()==J_LEFT) {
x--;
move_sprite(old,200,200);
move_sprite(spr,x,y);
delay(75);
old=spr;
spr++;
if(spr==4) spr=0;
}
if(joypad()==J_UP) {
y--;
move_sprite(old,200,200);
move_sprite(spr,x,y);
delay(75);
old=spr;
spr++;
if(spr==4) spr=0;
}
if(joypad()==J_DOWN) {
y++;
move_sprite(old,200,200);
move_sprite(spr,x,y);
delay(75);
old=spr;
spr++;
if(spr==4) spr=0;
}
}
}