-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
142 lines (100 loc) · 2.24 KB
/
main.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
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
// main.c
#include <stdio.h>
#include <curses.h>
#include <sys/time.h>
#include "cestypes.h"
static WINDOW *mainwin;
int offsety, offsetx;
World world;
void win_startup( void )
{
initscr( );
cbreak( );
noecho( );
curs_set( 0 );
nonl( );
offsety = ( LINES - NLINES ) / 2;
offsetx = ( COLS - NCOLS ) / 2;
mainwin = newwin( NLINES, NCOLS, offsety, offsetx );
nodelay( mainwin, TRUE );
keypad( mainwin, TRUE );
mousemask( BUTTON1_CLICKED, NULL );
return;
}
void win_shutdown( void )
{
delwin( mainwin );
endwin( );
mousemask( 0, NULL );
return;
}
void win_update( void )
{
wborder( mainwin, 0, 0, 0, 0, 0, 0, 0, 0 );
mvwprintw( mainwin, 1, 1, "CES" );
wrefresh( mainwin );
return;
}
void getInput( UserInput *input )
{
int c;
static MEVENT event;
c = wgetch( mainwin );
if ( c == KEY_MOUSE )
{
if ( c == KEY_MOUSE )
{
if ( getmouse( &event ) == OK )
{
if ( event.bstate & BUTTON1_CLICKED )
{
input->y = event.y - offsety;
input->x = event.x - offsetx;
input->mouse_active = 1;
}
}
}
}
else
{
input->key = (char)c;
input->key_active = 1;
}
}
unsigned long long getTimestamp( void )
{
struct timeval tv;
unsigned long long t1;
gettimeofday( &tv, NULL );
t1 = ( tv.tv_sec * 1000000 ) + tv.tv_usec;
return t1;
}
int main( int argc, char *argv[] )
{
UserInput input;
unsigned long long curTime;
input.key_active = input.mouse_active = 0;
initEntities( &world );
win_startup( );
win_update( );
// Create Entities
createPlayer( &world, 34, 10 );
createEnemy( &world, 6, 4 );
createEnemy( &world, 60, 4 );
createEnemy( &world, 6, 17 );
createEnemy( &world, 60, 17 );
curTime = getTimestamp( );
while ( 1 )
{
getInput( &input );
// Execute systems
SystemAttackFunction( &world, mainwin, &input );
SystemMovementFunction( &world, mainwin, &input );
SystemDisplayFunction( &world, mainwin );
wrefresh( mainwin );
while ( getTimestamp( ) < curTime + TIME_DELTA );
curTime += TIME_DELTA;
}
win_shutdown( );
return 0;
}