-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBat.cpp
69 lines (62 loc) · 951 Bytes
/
Bat.cpp
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
// Copyright Milan Oberkirch
// <[email protected]>
#include <stdio.h>
#include <stdlib.h>
#include <curses.h>
#include "./Bat.h"
Bat::Bat()
{
_x = _y = 0;
_length = 1;
}
void Bat::Init(int x, int y, int yMin, int yMax, int length)
{
_x = x;
_y = y;
_yMin = yMin;
_yMax = yMax;
_length = length;
}
void Bat::Move(bool up)
{
// Delete the bat from screen
Erase();
if (up)
{
_y -= (_length / 2);
}
else
{
_y += (_length / 2);
}
// Draw the bat into the screen-buffer
Draw();
}
void Bat::Draw()
{
// draw a '|' to every position, that equals the bat-position
for (int i = _y; i < _length+_y; ++i)
{
if (i <= _yMax && i >= _yMin)
{
move(i, _x);
printw("|");
}
}
}
void Bat::Draw(int y)
{
_y = y;
Draw();
}
void Bat::Erase()
{
for (int i = _y; i < _length+_y; ++i)
{
if (i <= _yMax && i >= _yMin)
{
move(i, _x);
printw(" ");
}
}
}