-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplayer.hpp
102 lines (68 loc) · 2.11 KB
/
player.hpp
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
#ifndef PLAYER_HPP
#define PLAYER_HPP
#include <ncurses.h>
#include "bullet.hpp"
class player
{
public:
void mv_player(void);
unsigned curr_y, curr_x;
unsigned *curr_y_ptr, *curr_x_ptr;
//bool is_player_collision(const int &curr_pos_bomb_y, const int &curr_pos_bomb_x);
unsigned live = 3;
};
void player::mv_player(void){
unsigned height_y , wide_x;
getmaxyx(stdscr, height_y, wide_x);
if(height_y < 20 || wide_x < 55){ // if the terminal window is to small
mvprintw(0,0, "Enlarge the terminal!");
refresh();
nodelay(stdscr, FALSE);
getch();
return; //quit the game
}
curr_y = height_y-3;
curr_x = wide_x/2;
curr_y_ptr = &curr_y;
curr_x_ptr = &curr_x;
mvaddch(curr_y, curr_x, 'X');
//refresh(); //the refresh will do the getch in the for loop
bullet std_bullet;
enemy std_enemy;
enemy *enemy_pointer = &std_enemy;
std_bullet.bullet_scrinit(height_y, wide_x, enemy_pointer);
std_enemy.set_enemy(wide_x, height_y, curr_y_ptr, curr_x_ptr);
for(int i;;){
std_bullet.bullet_func(curr_y, curr_x, false);
if(std_enemy.enemy_move())
return;
mvaddch(curr_y, curr_x, 'X');
refresh();
while((i = getch()) != ERR){
switch(i) {
case KEY_LEFT:
if(curr_x > 0){
mvaddch(curr_y, curr_x--, ' ');
mvaddch(curr_y, curr_x, 'X');
std_bullet.bullet_func(curr_y, curr_x, false);
break;
}
else
break;
case KEY_RIGHT:
if(curr_x+1 < wide_x){
mvaddch(curr_y, curr_x++, ' ');
mvaddch(curr_y, curr_x, 'X');
std_bullet.bullet_func(curr_y, curr_x, false);
break;
}
else
break;
case ' ':
std_bullet.bullet_func(curr_y, curr_x, true);
break;
}
}
}
}
#endif // PLAYER_HPP