forked from EliasFarhan/GBDev
-
Notifications
You must be signed in to change notification settings - Fork 0
/
game_screen.c
133 lines (112 loc) · 2.2 KB
/
game_screen.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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
/*
* game_screen.c
*
* Created on: 28 juil. 2014
* Author: efarhan
*/
#include <gb/gb.h>
#include <gb/drawing.h>
#include "game_screen.h"
#define MAP2D
#define MAX_SPRITES 1
#define SPRITE_SIZE 8
struct POS {
UBYTE x;
UBYTE y;
UBYTE dir;//0 right, 1 left, 2 up, 3 down
};
unsigned char test_sprite[] =
{
//up-left
0x01,0x01,0x1E,0x1F,0x20,0x3F,0x4F,0x70,
0x9F,0xE0,0xBF,0xC0,0xBF,0xC0,0xBF,0xC0,
//up-right
0x80,0x80,0x60,0xE0,0x10,0xF0,0xC8,0x38,
0xE6,0x1E,0xF1,0x0F,0xFD,0x03,0xFD,0x03,
//down-left
0xBF,0xC0,0xBF,0xC0,0xBF,0xC0,0x9F,0xE0,
0x4F,0x70,0x20,0x3F,0x1E,0x1F,0x01,0x01,
//down-right
0xFD,0x03,0xFD,0x03,0xF1,0x0F,0xE6,0x1E,
0xC8,0x38,0x10,0xF0,0x60,0xE0,0x80,0x80
};
UBYTE sprite_tile[] =
{
0, 1, 2, 3 /* direct North */
};
UBYTE keys;
UBYTE finish;
struct POS player_pos;
void manage_input() NONBANKED
{
#ifdef MAP2D
if (keys & J_DOWN)
if(player_pos.y != 144)
player_pos.y++;
if (keys & J_UP)
if(player_pos.y != SPRITE_SIZE+SPRITE_SIZE)
player_pos.y--;
#endif
if (keys & J_LEFT)
if(player_pos.x != SPRITE_SIZE)
player_pos.x--;
if (keys & J_RIGHT)
if(player_pos.x != 160-SPRITE_SIZE)
player_pos.x++;
if (keys & J_START)
finish = 1;
}
void set_sprite() NONBANKED
{
UBYTE i;
for (i = 0; i != 4; i++)
{
set_sprite_tile( i, sprite_tile[i] );
}
move_sprite( 0, player_pos.x, player_pos.y );
move_sprite( 1, player_pos.x+8, player_pos.y );
move_sprite( 2, player_pos.x, player_pos.y+8 );
move_sprite( 3, player_pos.x+8, player_pos.y+8 );
}
void game_screen() NONBANKED
{
init_screen();
finish = 0;
while(!finish)
{
wait_vbl_done();
keys = joypad();
manage_input();
set_sprite();
}
game_over();
}
void init_screen() NONBANKED
{
disable_interrupts();
HIDE_BKG;
HIDE_SPRITES;
HIDE_WIN;
DISPLAY_OFF;
set_sprite_data( 0, 4, test_sprite );
SPRITES_8x8;//TODO: why not 8x16?
//SHOW_BKG;
SHOW_SPRITES;
DISPLAY_ON;
enable_interrupts();
player_pos.x = SPRITE_SIZE;
player_pos.y = SPRITE_SIZE+SPRITE_SIZE;
set_sprite();
}
void game_over() NONBANKED
{
wait_vbl_done();
HIDE_SPRITES;
gotogxy(5, 5);
gprintf("GAME OVER");
DISPLAY_ON;
waitpad(J_A | J_B | J_START | J_SELECT);
waitpadup();
DISPLAY_OFF;
DISABLE_RAM_MBC1;
}