-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmultipla.c
70 lines (64 loc) · 1.93 KB
/
multipla.c
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
/* ************************************************************************** */
/* LE - / */
/* / */
/* multipla.c .:: .:/ . .:: */
/* +:+:+ +: +: +:+:+ */
/* By: cgarrot <[email protected]> +:+ +: +: +:+ */
/* #+# #+ #+ #+# */
/* Created: 2018/10/04 13:41:50 by cgarrot #+# ## ## #+# */
/* Updated: 2018/11/12 21:20:25 by cgarrot ### #+. /#+ ###.fr */
/* / */
/* / */
/* ************************************************************************** */
#include <curses.h>
int XPOS = 5;
int YPOS = 5;
char PLAYER = '@';
int userInput;
void Update()
{
switch(userInput)
{
case KEY_LEFT:
XPOS = XPOS - 1;
break;
case KEY_RIGHT:
XPOS = XPOS + 1;
break;
case KEY_UP:
YPOS = YPOS - 1;
break;
case KEY_DOWN:
YPOS = YPOS + 1;
break;
}
}
void Draw()
{
clear();
mvaddch(YPOS, XPOS, PLAYER);
refresh();
}
int main()
{
//Initialize ncurses
initscr(); //Tells it to make a terminal screen.
clear(); //Clears the screen.
noecho(); //When user types input, it doesn't appear on the screen.
cbreak(); //Typed character is immediately available.
keypad(stdscr, TRUE); //Standard screen.
curs_set(0); //Starts the cursor at (0,0).
mvaddch(YPOS, XPOS, PLAYER); //Draw '@' in the initial location.
refresh(); //Updates the screen to display the '@'.
while(true)
{
//Input()
userInput = getch();
Update();
Draw();
if (userInput == 'q')
break;
}
endwin(); //Closes the terminal screen.
return (0);
}