clean up comments
This commit is contained in:
parent
926d3873e4
commit
daf638d060
101
main.c
101
main.c
@ -44,30 +44,22 @@ uint16_t goal_y = 0;
|
|||||||
uint16_t rng_tmp = 0;
|
uint16_t rng_tmp = 0;
|
||||||
uint16_t orient = 0;
|
uint16_t orient = 0;
|
||||||
uint16_t inputs_tmp = 0;
|
uint16_t inputs_tmp = 0;
|
||||||
|
|
||||||
struct Object *rendered;
|
struct Object *rendered;
|
||||||
struct Bullet *bullets;
|
struct Bullet *bullets;
|
||||||
char *playfield;
|
char *playfield;
|
||||||
|
|
||||||
|
|
||||||
int randomInt(int lower, int upper) {
|
int randomInt(int lower, int upper) {
|
||||||
return rand() % (upper - lower + 1) + lower;
|
return rand() % (upper - lower + 1) + lower;
|
||||||
}
|
}
|
||||||
|
|
||||||
void generate_maze(){
|
void generate_maze(){
|
||||||
//fill playfield with blank
|
//fill playfield with blank
|
||||||
for (uint16_t y = 0; y < SCR_Y; y++) {
|
for (uint16_t y = 0; y < SCR_Y; y++) {
|
||||||
for (uint16_t x = 0; x < SCR_X; x++) {
|
for (uint16_t x = 0; x < SCR_X; x++) {
|
||||||
//playfield[y][x] = blank_char;
|
|
||||||
//do it in one dimension
|
|
||||||
playfield[y*SCR_X + x] = blank_char;
|
playfield[y*SCR_X + x] = blank_char;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//fill every other row with walls
|
//fill every other row with walls
|
||||||
for (uint16_t y = 0; y < SCR_Y; y += 2) {
|
for (uint16_t y = 0; y < SCR_Y; y += 2) {
|
||||||
for (uint16_t x = 0; x < SCR_X; x++) {
|
for (uint16_t x = 0; x < SCR_X; x++) {
|
||||||
//playfield[y][x] = wall_char;
|
|
||||||
//do it in one dimension
|
|
||||||
playfield[y*SCR_X + x] = wall_char;
|
playfield[y*SCR_X + x] = wall_char;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -76,51 +68,43 @@ void generate_maze(){
|
|||||||
//punch holes in the walls depending on the SCR_X
|
//punch holes in the walls depending on the SCR_X
|
||||||
for (uint16_t ix = 0; ix < ((SCR_X-(SCR_X%Hole_Div))/Hole_Div); ix += 1) {
|
for (uint16_t ix = 0; ix < ((SCR_X-(SCR_X%Hole_Div))/Hole_Div); ix += 1) {
|
||||||
rng_tmp = randomInt(1, SCR_X);
|
rng_tmp = randomInt(1, SCR_X);
|
||||||
//playfield[y][rng_tmp] = blank_char;
|
|
||||||
//do it in one dimension
|
|
||||||
playfield[y*SCR_X + rng_tmp] = blank_char;
|
playfield[y*SCR_X + rng_tmp] = blank_char;
|
||||||
}
|
}
|
||||||
if (orient == 0) {
|
if (orient == 0) {
|
||||||
if(y == 0){
|
if(y == 0){
|
||||||
//playfield[y][rng_tmp] = goal_char;
|
|
||||||
//do it in one dimension
|
|
||||||
playfield[y*SCR_X + rng_tmp] = goal_char;
|
playfield[y*SCR_X + rng_tmp] = goal_char;
|
||||||
goal_x = rng_tmp;
|
goal_x = rng_tmp;
|
||||||
goal_y = y;
|
goal_y = y;
|
||||||
}
|
}
|
||||||
if (y == SCR_Y -1){
|
if (y == SCR_Y -1){
|
||||||
//playfield[y][rng_tmp] = player_char;
|
|
||||||
//do it in one dimension
|
|
||||||
playfield[y*SCR_X + rng_tmp] = player_char;
|
playfield[y*SCR_X + rng_tmp] = player_char;
|
||||||
player_x = rng_tmp;
|
player_x = rng_tmp;
|
||||||
player_y = y;
|
player_y = y;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if(y == SCR_Y -1){
|
if(y == SCR_Y -1){
|
||||||
//playfield[y][rng_tmp] = goal_char;
|
|
||||||
//do it in one dimension
|
|
||||||
playfield[y*SCR_X + rng_tmp] = goal_char;
|
playfield[y*SCR_X + rng_tmp] = goal_char;
|
||||||
goal_x = rng_tmp;
|
goal_x = rng_tmp;
|
||||||
goal_y = y;
|
goal_y = y;
|
||||||
}
|
}
|
||||||
if (y == 0){
|
if (y == 0){
|
||||||
//playfield[y][rng_tmp] = player_char;
|
|
||||||
//do it in one dimension
|
|
||||||
playfield[y*SCR_X + rng_tmp] = player_char;
|
playfield[y*SCR_X + rng_tmp] = player_char;
|
||||||
player_x = rng_tmp;
|
player_x = rng_tmp;
|
||||||
player_y = y;
|
player_y = y;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void render_maze(){
|
void render_maze(){
|
||||||
//fill rendered with blank
|
//fill rendered with blank
|
||||||
for (uint16_t y = 0; y < SCR_Y; y++) {
|
for (uint16_t y = 0; y < SCR_Y; y++) {
|
||||||
for (uint16_t x = 0; x < SCR_X; x++) {
|
for (uint16_t x = 0; x < SCR_X; x++) {
|
||||||
//rendered[y][x] = blank_char;
|
|
||||||
//do it in one dimension
|
|
||||||
rendered[y*SCR_X + x].letter = blank_char;
|
rendered[y*SCR_X + x].letter = blank_char;
|
||||||
rendered[y*SCR_X + x].color = blank_color;
|
rendered[y*SCR_X + x].color = blank_color;
|
||||||
rendered[y*SCR_X + x].x = x;
|
rendered[y*SCR_X + x].x = x;
|
||||||
@ -129,63 +113,46 @@ void render_maze(){
|
|||||||
}
|
}
|
||||||
for (uint16_t y = 0; y < SCR_Y; y++) {
|
for (uint16_t y = 0; y < SCR_Y; y++) {
|
||||||
for (uint16_t x = 0; x < SCR_X; x++) {
|
for (uint16_t x = 0; x < SCR_X; x++) {
|
||||||
//letter = playfield[y - 1][x- 1];
|
|
||||||
//do it in one dimension
|
|
||||||
letter = playfield[(y)*SCR_X + (x)];
|
letter = playfield[(y)*SCR_X + (x)];
|
||||||
//rendered[x][y].letter = letter;
|
|
||||||
//do it in one dimension
|
|
||||||
rendered[(y)*SCR_X + (x)].letter = letter;
|
rendered[(y)*SCR_X + (x)].letter = letter;
|
||||||
//rendered[x][y].x = x;
|
|
||||||
//do it in one dimension
|
|
||||||
rendered[(y)*SCR_X + (x)].x = x;
|
rendered[(y)*SCR_X + (x)].x = x;
|
||||||
//rendered[x][y].y = y;
|
|
||||||
//do it in one dimension
|
|
||||||
rendered[(y)*SCR_X + (x)].y = y;
|
rendered[(y)*SCR_X + (x)].y = y;
|
||||||
if (letter == goal_char){
|
if (letter == goal_char){
|
||||||
//rendered[x][y].color = goal_color;
|
|
||||||
//do it in one dimension
|
|
||||||
rendered[(y)*SCR_X + (x)].color = goal_color;
|
rendered[(y)*SCR_X + (x)].color = goal_color;
|
||||||
}
|
}
|
||||||
else if (letter == player_char){
|
else if (letter == player_char){
|
||||||
//rendered[x][y].color = player_color;
|
|
||||||
//do it in one dimension
|
|
||||||
rendered[(y)*SCR_X + (x)].color = player_color;
|
rendered[(y)*SCR_X + (x)].color = player_color;
|
||||||
}
|
}
|
||||||
else if (letter == blank_char){
|
else if (letter == blank_char){
|
||||||
//rendered[x][y].color = blank_color;
|
|
||||||
//do it in one dimension
|
|
||||||
rendered[(y)*SCR_X + (x)].color = blank_color;
|
rendered[(y)*SCR_X + (x)].color = blank_color;
|
||||||
}
|
}
|
||||||
else if (letter == wall_char){
|
else if (letter == wall_char){
|
||||||
//rendered[x][y].color = wall_color;
|
|
||||||
//do it in one dimension
|
|
||||||
rendered[(y)*SCR_X + (x)].color = wall_color;
|
rendered[(y)*SCR_X + (x)].color = wall_color;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void draw_maze(){
|
void draw_maze(){
|
||||||
//FILE *fp;
|
for (uint16_t y = 0; y < SCR_Y; y++) {
|
||||||
//fp = fopen("logx", "w");
|
|
||||||
for (uint16_t y = 0; y < SCR_Y; y++) {
|
|
||||||
for (uint16_t x = 0; x < SCR_X; x++) {
|
for (uint16_t x = 0; x < SCR_X; x++) {
|
||||||
//attron(COLOR_PAIR(rendered[x][y].color));
|
|
||||||
//do it in one dimension
|
|
||||||
attron(COLOR_PAIR(rendered[(y)*SCR_X + (x)].color));
|
attron(COLOR_PAIR(rendered[(y)*SCR_X + (x)].color));
|
||||||
//mvaddch(y, x, rendered[x][y].letter);
|
|
||||||
//do it in one dimension
|
|
||||||
mvaddch(y, x, rendered[(y)*SCR_X + (x)].letter);
|
mvaddch(y, x, rendered[(y)*SCR_X + (x)].letter);
|
||||||
//fprintf(fp, "%c, x:%d y:%d\n", rendered[(y)*SCR_X + (x)].letter, rendered[(y)*SCR_X + (x)].x, rendered[(y)*SCR_X + (x)].y);
|
|
||||||
//attroff(COLOR_PAIR(rendered[x][y].color));
|
|
||||||
//do it in one dimension
|
|
||||||
attroff(COLOR_PAIR(rendered[(y)*SCR_X + (x)].color));
|
attroff(COLOR_PAIR(rendered[(y)*SCR_X + (x)].color));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//fclose(fp);
|
refresh();
|
||||||
refresh();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void init(){
|
void init(){
|
||||||
initscr();
|
initscr();
|
||||||
//get screen size
|
//get screen size
|
||||||
@ -207,7 +174,6 @@ void init(){
|
|||||||
clear();
|
clear();
|
||||||
srand(time(NULL));
|
srand(time(NULL));
|
||||||
}
|
}
|
||||||
|
|
||||||
int keyinput(){
|
int keyinput(){
|
||||||
inchar = getch();
|
inchar = getch();
|
||||||
if (inchar == 'q'){
|
if (inchar == 'q'){
|
||||||
@ -216,12 +182,10 @@ int keyinput(){
|
|||||||
if (inchar == 'w'){
|
if (inchar == 'w'){
|
||||||
//if (playfield[player_y - 1][player_x] == blank_char){
|
//if (playfield[player_y - 1][player_x] == blank_char){
|
||||||
if (player_y > 0&&playfield[(player_y-1)*SCR_X + player_x] == blank_char){
|
if (player_y > 0&&playfield[(player_y-1)*SCR_X + player_x] == blank_char){
|
||||||
//playfield[player_y][player_x] = blank_char;
|
|
||||||
//do it in one dimension
|
|
||||||
playfield[(player_y)*SCR_X + player_x] = blank_char;
|
playfield[(player_y)*SCR_X + player_x] = blank_char;
|
||||||
player_y--;
|
player_y--;
|
||||||
//playfield[player_y][player_x] = player_char;
|
|
||||||
//do it in one dimension
|
|
||||||
playfield[(player_y)*SCR_X + player_x] = player_char;
|
playfield[(player_y)*SCR_X + player_x] = player_char;
|
||||||
//}else if (playfield[player_y - 1][player_x] == goal_char){
|
//}else if (playfield[player_y - 1][player_x] == goal_char){
|
||||||
}else if (playfield[(player_y-1)*SCR_X + player_x] == goal_char){
|
}else if (playfield[(player_y-1)*SCR_X + player_x] == goal_char){
|
||||||
@ -231,12 +195,10 @@ int keyinput(){
|
|||||||
if (inchar == 'a'){
|
if (inchar == 'a'){
|
||||||
//if (playfield[player_y][player_x - 1] == blank_char){
|
//if (playfield[player_y][player_x - 1] == blank_char){
|
||||||
if (player_x > 0 &&playfield[(player_y)*SCR_X + (player_x-1)] == blank_char){
|
if (player_x > 0 &&playfield[(player_y)*SCR_X + (player_x-1)] == blank_char){
|
||||||
//playfield[player_y][player_x] = blank_char;
|
|
||||||
//do it in one dimension
|
|
||||||
playfield[(player_y)*SCR_X + player_x] = blank_char;
|
playfield[(player_y)*SCR_X + player_x] = blank_char;
|
||||||
player_x--;
|
player_x--;
|
||||||
//playfield[player_y][player_x] = player_char;
|
|
||||||
//do it in one dimension
|
|
||||||
playfield[(player_y)*SCR_X + player_x] = player_char;
|
playfield[(player_y)*SCR_X + player_x] = player_char;
|
||||||
}
|
}
|
||||||
//else if (playfield[player_y][player_x - 1] == goal_char){
|
//else if (playfield[player_y][player_x - 1] == goal_char){
|
||||||
@ -247,11 +209,9 @@ int keyinput(){
|
|||||||
if (inchar == 's'){
|
if (inchar == 's'){
|
||||||
//if (playfield[player_y + 1][player_x] == blank_char){
|
//if (playfield[player_y + 1][player_x] == blank_char){
|
||||||
if (player_x < SCR_X - 1 &&playfield[(player_y+1)*SCR_X + player_x] == blank_char){
|
if (player_x < SCR_X - 1 &&playfield[(player_y+1)*SCR_X + player_x] == blank_char){
|
||||||
// playfield[player_y][player_x] = blank_char;
|
playfield[(player_y)*SCR_X + player_x] = blank_char;
|
||||||
playfield[(player_y)*SCR_X + player_x] = blank_char;
|
|
||||||
player_y++;
|
player_y++;
|
||||||
// playfield[player_y][player_x] = player_char;
|
playfield[(player_y)*SCR_X + player_x] = player_char;
|
||||||
playfield[(player_y)*SCR_X + player_x] = player_char;
|
|
||||||
// }else if (playfield[player_y + 1][player_x] == goal_char){
|
// }else if (playfield[player_y + 1][player_x] == goal_char){
|
||||||
}else if (playfield[(player_y+1)*SCR_X + player_x] == goal_char){
|
}else if (playfield[(player_y+1)*SCR_X + player_x] == goal_char){
|
||||||
return 2;
|
return 2;
|
||||||
@ -261,11 +221,9 @@ int keyinput(){
|
|||||||
if (inchar == 'd'){
|
if (inchar == 'd'){
|
||||||
// if (playfield[player_y][player_x + 1] == blank_char){
|
// if (playfield[player_y][player_x + 1] == blank_char){
|
||||||
if (player_x < SCR_X - 1 &&playfield[(player_y)*SCR_X + (player_x+1)] == blank_char){
|
if (player_x < SCR_X - 1 &&playfield[(player_y)*SCR_X + (player_x+1)] == blank_char){
|
||||||
//playfield[player_y][player_x] = blank_char;
|
playfield[(player_y)*SCR_X + player_x] = blank_char;
|
||||||
playfield[(player_y)*SCR_X + player_x] = blank_char;
|
|
||||||
player_x++;
|
player_x++;
|
||||||
//playfield[player_y][player_x] = player_char;
|
playfield[(player_y)*SCR_X + player_x] = player_char;
|
||||||
playfield[(player_y)*SCR_X + player_x] = player_char;
|
|
||||||
}
|
}
|
||||||
//else if (playfield[player_y][player_x + 1] == goal_char){
|
//else if (playfield[player_y][player_x + 1] == goal_char){
|
||||||
else if (playfield[(player_y)*SCR_X + (player_x+1)] == goal_char){
|
else if (playfield[(player_y)*SCR_X + (player_x+1)] == goal_char){
|
||||||
@ -273,7 +231,6 @@ int keyinput(){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char *argv[]){
|
int main(int argc, char *argv[]){
|
||||||
init();
|
init();
|
||||||
//parse the command line arguments for width and height
|
//parse the command line arguments for width and height
|
||||||
|
Loading…
Reference in New Issue
Block a user