renamed types and constants
This commit is contained in:
@@ -16,7 +16,7 @@ int main(int argc, char** argv) {
|
||||
}
|
||||
|
||||
// get text properties
|
||||
struct text msg = scan_str(argv[1]);
|
||||
TimText_t msg = scan_str(argv[1]);
|
||||
|
||||
while (tim_run(0)) {
|
||||
// calculate size of message box
|
||||
@@ -41,7 +41,7 @@ int main(int argc, char** argv) {
|
||||
}
|
||||
|
||||
// return with 1 when q or esc is pressed
|
||||
if (is_key_press('q') || is_key_press(ESCAPE_KEY)) {
|
||||
if (is_key_press('q') || is_key_press(TimKey_Escape)) {
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#include "../tim.h" // one header, no lib
|
||||
int main(void) { //
|
||||
#include "../tim.h"
|
||||
|
||||
int main(void) {
|
||||
while (tim_run(0)) { // event loop
|
||||
scope (A, A, 24, 8) { // centered 24x8 scope
|
||||
uint64_t c = 0x0a060f; // three colors
|
||||
@@ -9,7 +10,7 @@ int main(void) { //
|
||||
return 0; // exit on button click
|
||||
if (is_key_press('q')) // ctrl-c is masked
|
||||
return 0; // exit on 'q' press
|
||||
} //
|
||||
} // atexit cleanup
|
||||
}
|
||||
} //TODO: remove atexit cleanup
|
||||
}
|
||||
|
||||
|
||||
@@ -63,12 +63,12 @@ static void game(void) {
|
||||
}
|
||||
|
||||
// draw
|
||||
if (tim.event.type == DRAW_EVENT) {
|
||||
if (tim.event.type == TimEvent_Draw) {
|
||||
// food
|
||||
draw_chr(cell(" ", 0, 0xc5), snek.food.x * 2 + 0, snek.food.y);
|
||||
draw_chr(cell(" ", 0, 0xc5), snek.food.x * 2 + 1, snek.food.y);
|
||||
// snek
|
||||
struct cell s = cell(" ", 0, 0);
|
||||
TimCell_t s = cell(" ", 0, 0);
|
||||
for (int i = 0; i < snek.len; i++) {
|
||||
s.bg = (i / 2) % 2 ? 0xe3 : 0xea;
|
||||
int x = snek.body[i].x * 2;
|
||||
@@ -81,13 +81,13 @@ static void game(void) {
|
||||
// user input
|
||||
if (tim.event.type == KEY_EVENT) {
|
||||
int key = tim.event.key;
|
||||
if ((key == RIGHT_KEY || key == 'd') && snek.look.x != -1) {
|
||||
if ((key == TimKey_Right || key == 'd') && snek.look.x != -1) {
|
||||
snek.look = (point){{1, 0}};
|
||||
} else if ((key == LEFT_KEY || key == 'a') && snek.look.x != 1) {
|
||||
} else if ((key == TimKey_Left || key == 'a') && snek.look.x != 1) {
|
||||
snek.look = (point){{-1, 0}};
|
||||
} else if ((key == DOWN_KEY || key == 's') && snek.look.y != -1) {
|
||||
} else if ((key == TimKey_Down || key == 's') && snek.look.y != -1) {
|
||||
snek.look = (point){{0, 1}};
|
||||
} else if ((key == UP_KEY || key == 'w') && snek.look.y != 1) {
|
||||
} else if ((key == TimKey_Up || key == 'w') && snek.look.y != 1) {
|
||||
snek.look = (point){{0, -1}};
|
||||
}
|
||||
}
|
||||
@@ -98,13 +98,13 @@ static void menu(void) {
|
||||
char* lbl = snek.state == OVER ? "GAME OVER" : "SNEK - THE GAME";
|
||||
char* btn = snek.state == PAUSE ? "Resume" : "Play";
|
||||
label(lbl, A, 0, A, A, BTN);
|
||||
if (button(btn, A, 2, 20, 5, BTN) || is_key_press(ENTER_KEY)) {
|
||||
if (button(btn, A, 2, 20, 5, BTN) || is_key_press(TimKey_Enter)) {
|
||||
if (snek.state != PAUSE) {
|
||||
start();
|
||||
}
|
||||
snek.state = RUN;
|
||||
}
|
||||
if (button("Exit", A, 8, 20, 5, BTN) || is_key_press(ESCAPE_KEY)) {
|
||||
if (button("Exit", A, 8, 20, 5, BTN) || is_key_press(TimKey_Escape)) {
|
||||
exit(0);
|
||||
}
|
||||
}
|
||||
@@ -113,7 +113,7 @@ static void menu(void) {
|
||||
int main(void) {
|
||||
// draw every 10 ms
|
||||
while (tim_run(10)) {
|
||||
struct cell bg = cell(" ", 0, BG);
|
||||
TimCell_t bg = cell(" ", 0, BG);
|
||||
draw_lot(bg, 0, 0, tim.w, tim.h);
|
||||
|
||||
if (snek.state == RUN) {
|
||||
@@ -122,7 +122,7 @@ int main(void) {
|
||||
menu();
|
||||
}
|
||||
|
||||
if (is_key_press(ESCAPE_KEY)) {
|
||||
if (is_key_press(TimKey_Escape)) {
|
||||
snek.state = PAUSE;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user