Mercurial > repos > genjam1
comparison src/main.c @ 10:889227ec630c
cursor and input code added.
author | William Morgan <bill@mrgn.org> |
---|---|
date | Sun, 12 Jan 2014 16:13:49 -0800 |
parents | 3ed112d64b1b |
children | 1ee4a5c23c95 |
comparison
equal
deleted
inserted
replaced
9:5ec4707a3fd1 | 10:889227ec630c |
---|---|
1 #include <genesis.h> | 1 #include <genesis.h> |
2 #include "creep.h" | 2 #include "creep.h" |
3 | |
4 const u32 cursor_tiles[4*8] = { | |
5 0x21100000, // top left | |
6 0x10000000, | |
7 0x10000000, | |
8 0x00000000, | |
9 0x00000000, | |
10 0x00000000, | |
11 0x00000000, | |
12 0x00000000, | |
13 | |
14 0x00000000, // bottom left | |
15 0x00000000, | |
16 0x00000000, | |
17 0x00000000, | |
18 0x00000000, | |
19 0x10000000, | |
20 0x10000000, | |
21 0x21100000, | |
22 | |
23 0x00000112, // top right | |
24 0x00000001, | |
25 0x00000001, | |
26 0x00000000, | |
27 0x00000000, | |
28 0x00000000, | |
29 0x00000000, | |
30 0x00000000, | |
31 | |
32 0x00000000, // bottom right | |
33 0x00000000, | |
34 0x00000000, | |
35 0x00000000, | |
36 0x00000000, | |
37 0x00000001, | |
38 0x00000001, | |
39 0x00000112, | |
40 | |
41 }; | |
3 | 42 |
4 u16 tilemap[40*28]; | 43 u16 tilemap[40*28]; |
5 u16 countdown; | 44 u16 countdown; |
6 | 45 |
46 int cursor_x = 0; | |
47 int cursor_y = 0; | |
48 const int cursor_size_px = 2 * 8; // two tiles of 8 pixels each | |
49 | |
50 void joy_event_handler(u16 joy, u16 changed, u16 state) { | |
51 u16 went_down = changed & state; | |
52 if (went_down & BUTTON_UP) { | |
53 cursor_y -= cursor_size_px; | |
54 } | |
55 if (went_down & BUTTON_DOWN) { | |
56 cursor_y += cursor_size_px; | |
57 } | |
58 if (went_down & BUTTON_LEFT) { | |
59 cursor_x -= cursor_size_px; | |
60 } | |
61 if (went_down & BUTTON_RIGHT) { | |
62 cursor_x += cursor_size_px; | |
63 } | |
64 } | |
65 | |
7 int main(void) | 66 int main(void) |
8 { | 67 { |
68 JOY_init(); | |
69 JOY_setEventHandler(&joy_event_handler); | |
70 | |
71 u8 cursor_tile_index = 1; | |
72 VDP_loadTileData((const u32 *)cursor_tiles, cursor_tile_index, 4, 0); | |
73 | |
9 u16 i; | 74 u16 i; |
10 VDP_setPlanSize(64, 32); | 75 VDP_setPlanSize(64, 32); |
11 for (i = 6; i < 40*28; i += 4) | 76 for (i = 6; i < 40*28; i += 4) |
12 if ((i > 80 || i & 4) && (i < 40*26 || !(i & 4)) && i % 40 < 38) | 77 if ((i > 80 || i & 4) && (i < 40*26 || !(i & 4)) && i % 40 < 38) |
13 { | 78 { |
19 tilemap[39 + 13*40] = TILE_ATTR_FULL(1, 0, 0, 0, 'G' + TILE_FONTINDEX); | 84 tilemap[39 + 13*40] = TILE_ATTR_FULL(1, 0, 0, 0, 'G' + TILE_FONTINDEX); |
20 tilemap[38 + 14*40] = TILE_ATTR_FULL(1, 0, 0, 0, 'G' + TILE_FONTINDEX); | 85 tilemap[38 + 14*40] = TILE_ATTR_FULL(1, 0, 0, 0, 'G' + TILE_FONTINDEX); |
21 tilemap[39 + 14*40] = TILE_ATTR_FULL(1, 0, 0, 0, 'G' + TILE_FONTINDEX); | 86 tilemap[39 + 14*40] = TILE_ATTR_FULL(1, 0, 0, 0, 'G' + TILE_FONTINDEX); |
22 for (;;) | 87 for (;;) |
23 { | 88 { |
89 VDP_setSprite(0, cursor_x, cursor_y, SPRITE_SIZE(2,2), TILE_ATTR_FULL(PAL0, 1, 0, 0, cursor_tile_index), 0); | |
24 VDP_waitVSync(); | 90 VDP_waitVSync(); |
25 VDP_updateSprites(); | 91 VDP_updateSprites(); |
26 for (i = 0; i < 28; i++) | 92 for (i = 0; i < 28; i++) |
27 { | 93 { |
28 VDP_setTileMapRectByIndex(VDP_PLAN_B, tilemap + i*40, i*64, 40, 0); | 94 VDP_setTileMapRectByIndex(VDP_PLAN_B, tilemap + i*40, i*64, 40, 0); |