feat: draw map and player
This commit is contained in:
parent
30e3154a31
commit
a9fc1c3a74
92
src/main.c
92
src/main.c
@ -1,7 +1,95 @@
|
||||
|
||||
#include <stdio.h>
|
||||
// https://www.youtube.com/playlist?list=PLkTXsX7igf8erbWGYT4iSAhpnJLJ0Nk5G
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <ncurses.h>
|
||||
|
||||
typedef struct {
|
||||
int pos_x;
|
||||
int pos_y;
|
||||
} player_t;
|
||||
|
||||
player_t *player_malloc(void);
|
||||
void player_free(player_t *player);
|
||||
|
||||
int screen_setup(void);
|
||||
int screen_teardown(void);
|
||||
|
||||
int draw_map(void);
|
||||
int draw_player(player_t *player);
|
||||
|
||||
int main(void)
|
||||
{
|
||||
printf("Hello, World!\n");
|
||||
player_t *player = player_malloc();
|
||||
|
||||
screen_setup();
|
||||
|
||||
while (true)
|
||||
{
|
||||
draw_map();
|
||||
draw_player(player);
|
||||
refresh();
|
||||
|
||||
char key_pressed = getch();
|
||||
|
||||
if (key_pressed == 'q') {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
screen_teardown();
|
||||
|
||||
player_free(player);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int screen_setup(void)
|
||||
{
|
||||
initscr();
|
||||
noecho();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int screen_teardown(void)
|
||||
{
|
||||
endwin();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int draw_map(void)
|
||||
{
|
||||
int const pos_x = 0;
|
||||
int const pos_y = 0;
|
||||
|
||||
mvprintw(pos_y+0, pos_x, "--------");
|
||||
mvprintw(pos_y+1, pos_x, "|......|");
|
||||
mvprintw(pos_y+2, pos_x, "|......|");
|
||||
mvprintw(pos_y+3, pos_x, "|......|");
|
||||
mvprintw(pos_y+4, pos_x, "--------");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
player_t *player_malloc(void)
|
||||
{
|
||||
int const player_x = 1;
|
||||
int const player_y = 1;
|
||||
|
||||
player_t *player = (player_t*)malloc(sizeof(player_t));
|
||||
player->pos_x = player_x;
|
||||
player->pos_y = player_y;
|
||||
return player;
|
||||
}
|
||||
|
||||
void player_free(player_t *player)
|
||||
{
|
||||
free(player);
|
||||
}
|
||||
|
||||
int draw_player(player_t *player)
|
||||
{
|
||||
mvprintw(player->pos_y, player->pos_x, "@");
|
||||
return 0;
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user