-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_game.cpp
More file actions
91 lines (77 loc) · 1.34 KB
/
test_game.cpp
File metadata and controls
91 lines (77 loc) · 1.34 KB
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
#include "test_game.h"
#include "coord.h"
using cursen::Coord;
//PUBLIC
TestGame::TestGame()
:
screen_w_(screen_width()),
screen_h_(screen_height())
{
win_ = create_window(screen_w_, screen_h_);
pos_ = {screen_w_/2, screen_h_/2};
}
//PRIVATE
void TestGame::input()
{
input_ = get_input();
}
void TestGame::update()
{
switch(input_)
{
case kQuit: {
stop();
break;
}
case kUp: {
pos_.y -= kYStep;
break;
}
case kDown: {
pos_.y += kYStep;
break;
}
case kLeft: {
pos_.x -= kXStep;
break;
}
case kRight: {
pos_.x += kXStep;
break;
}
}
//wrap our x position
if( pos_.x > (screen_w_ - 1) ) {
pos_.x = 0;
}
else if( pos_.x < 0 ) {
pos_.x = screen_w_ - 1;
}
//wrap our y position
if( pos_.y > (screen_h_ - 1) ) {
pos_.y = 0;
}
else if( pos_.y < 0 ) {
pos_.y = screen_h_ - 1;
}
}
void TestGame::render()
{
//clear the screen
win_->clear();
//draw our cube to the buffer
Coord cursor = pos_;
win_->move_cursor(cursor);
win_->add_ch(kSprite);
cursor.x += 1;
win_->move_cursor(cursor);
win_->add_ch(kSprite);
cursor.y += 1;
win_->move_cursor(cursor);
win_->add_ch(kSprite);
cursor.x -= 1;
win_->move_cursor(cursor);
win_->add_ch(kSprite);
//push buffer onto screen
win_->refresh();
}