-
Notifications
You must be signed in to change notification settings - Fork 0
/
myLib.h
184 lines (159 loc) · 4.62 KB
/
myLib.h
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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
#ifndef MYLIB_H
#define MYLIB_H
#include <stdio.h>
#include <stdlib.h>
#define BUTTONS *(unsigned int *)0x4000130 //memory location of buttons values
#define SCANLINECOUNTER *(volatile unsigned short *)0x4000006
//Buttons
#define BUTTON_A (1<<0)
#define BUTTON_B (1<<1)
#define BUTTON_SELECT (1<<2)
#define BUTTON_START (1<<3)
#define BUTTON_RIGHT (1<<4)
#define BUTTON_LEFT (1<<5)
#define BUTTON_UP (1<<6)
#define BUTTON_DOWN (1<<7)
#define BUTTON_R (1<<8)
#define BUTTON_L (1<<9)
#define KEY_DOWN_NOW(key) (~(BUTTONS) & key)//returns true (non 0) if button is down
//Graphics
#define REG_DISPCTL *(unsigned short *)0x4000000
#define MODE3 3
#define BG2_ENABLE (1<<10)
//Colors
#define BLACK 0x0000
#define WHITE 0x7fff
#define RED 31
#define GREEN (31<<5)
#define YELLOW (31<<5 | 31)
#define BLUE (31<< 10)
#define RGB(r, g, b) ((r) | ((g)<<5) | ((b)<<10))
//Display
#define WIDTH 239
#define HEIGHT 159
#define OFFSET(r, c, width) (((r)*(width)) + (c))
//DMA
#define DMA ((volatile DMA_CONTROLLER *) 0x040000B0)
// DMA channels
#define DMA_CHANNEL_0 0
#define DMA_CHANNEL_1 1
#define DMA_CHANNEL_2 2
#define DMA_CHANNEL_3 3
//DMA Destination Settings
#define DMA_DESTINATION_INCREMENT (0 << 21)//default
#define DMA_DESTINATION_DECREMENT (1 << 21)
#define DMA_DESTINATION_FIXED (2 << 21)
#define DMA_DESTINATION_RESET (3 << 21)
//DMA Source Settings
#define DMA_SOURCE_INCREMENT (0 << 23)//default
#define DMA_SOURCE_DECREMENT (1 << 23)
#define DMA_SOURCE_FIXED (2 << 23)
//Activates DMA
#define DMA_ON (1 << 31)
typedef struct OBJECT{
int row;
int col;
int xDir;
int yDir;
int oldRow;
int oldCol;
int health;
int isBoss;
} OBJECT;
typedef struct
{
const volatile void *src;
const volatile void *dst;
unsigned int cnt;
} DMA_CONTROLLER;
//main.c methods and vars
void delay(int n);
void delay(int n);
void waitForVblank();
void updateScore();
void resetVars();
extern int score;
extern int lost;
extern int timer;
extern int spawnRate;
extern int gameInProgress;
extern char scoreMsg[40];
extern char levelMsg[40];
extern unsigned short *videoBuffer;
//zombie methods and vars
void updateDirections();
void moveZombies();
void killZombie(int index);
void damageZombie(int i);
void spawnZombie();
void killPlayer();
void correctCollision();
void borderCheck(int i);
void zombieCollision(int i);
void drawZombies();
int horizontalCollision(int row, int col, int xDir, int size);
int verticalCollision(int row, int col, int xDir, int size);
extern OBJECT zombies[15];
extern const int max;
extern const int zSpeed;
extern const int zSize;
extern const int bossZSize;
extern int numZoms;
extern int level;
extern int levelCounter;
//player methods and vars
void updatePlayer();
void movePlayer();
void shoot(int i);
void moveBullets();
void bulletHit(int index);
void drawPlayer();
void drawBullets();
void bulletCollisions();
int dirToX(int d);
int dirToY(int d);
void killBullet(int i, int size);
void debug();
void debugSpawn();
void debugKill();
void updateBullets();
extern int row;
extern int col;
extern int xDir;
extern int yDir;
extern const int playerSpeed;
extern const int pSize;
extern OBJECT bullets[15];
//graphics methods and vars
void drawBackground();
void drawMenu();
void drawZombieBlock(int row, int col);
void drawBossZombieBlock(int row, int col);
void drawSoldier(int row, int col, int dir);
void setPixel(int row, int col, unsigned short color);
void drawString(int row, int col, char str[], unsigned short color);
void drawRect(int row, int col, int height, int width, unsigned short color);
void drawRectIMG(int row, int col, int height, int width, const unsigned short *color);
void drawChar(int row, int col, char ch, unsigned short color);
void gameOver();
void drawImage(int row, int col, int width, int height, const unsigned short* image);
void clearObj(int r, int c, int size);
void drawStringFast(int row, int col, char str[]);
void drawCharFast(int row, int col, char ch);
void setStringColor(unsigned short color);
extern const unsigned short soldierN_data[49];
extern const unsigned short soldierNE_data[49];
extern const unsigned short soldierE_data[49];
extern const unsigned short soldierSE_data[49];
extern const unsigned short soldierS_data[49];
extern const unsigned short soldierSW_data[49];
extern const unsigned short soldierW_data[49];
extern const unsigned short soldierNW_data[49];
extern const unsigned short zombie_data[36];
extern const unsigned short zomBoss_data[64];
extern const unsigned char fontdata_6x8[12288];
extern unsigned short colorFont[12288];
extern const unsigned short menu_data[36000];
extern const unsigned short background_data[38400+(10*240)];
extern const unsigned short gameOver_data[36000];
#endif