This repository was archived by the owner on Feb 3, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
85 lines (68 loc) · 2.35 KB
/
main.cpp
File metadata and controls
85 lines (68 loc) · 2.35 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
#include <iostream>
#include "GameObject.h"
#include "Vector.h"
#include "Field.h"
#include "Input.h"
#include <windows.h>
#include "myconio.h"
#include <time.h>
using namespace std;
void hidecursor();
int main(){
Field field;
GameObject objPlayerLeft('#', Vector2d(2, 23, 0.3), 15, 2, true);
GameObject objBall('O', Vector2d(50, 23, 2), 1, 1, true);
GameObject objPlayerRight('#', Vector2d(95, 23, 0.3), 15, 2, true);
GameObject upperLine('=', Vector2d(0, 0, 0.0), 1, MAXX - 1, true);
GameObject downLine('=', Vector2d(0, MAXY - 1, 0.0), 1, MAXX - 1, true);
GameObject rightLine('|', Vector2d(MAXX - 1, 0, 0.0), MAXY, 1, true);
GameObject leftLine('|', Vector2d(0, 0, 0.0), MAXY, 1, true);
field.setObjectAtPosition(objPlayerLeft);
field.setObjectAtPosition(objBall);
field.setObjectAtPosition(objPlayerRight);
field.setObjectAtPosition(upperLine);
field.setObjectAtPosition(downLine);
field.setObjectAtPosition(rightLine);
field.setObjectAtPosition(leftLine);
field.printField();
//vec.print();
hidecursor();
//Demo
Input input;
Vector2d vecs[4] = {
Vector2d(-1, 1, 0.0),
Vector2d(1, -1, 0.0),
Vector2d(-1, -1, 0.0),
Vector2d(1, 1, 0.0)
};
int once = 0, idx;
while(1){
gotoxy(0, 0);
if(input.getStoredKey() == 42) break;
if (!once) {
srand(time(NULL));
idx = rand() % 4;
once = 1;
}
field.gameObjectMove(vecs[idx], objBall);
field.setObjectAtPosition(objBall);
if (input.getKey() == 'w') {
field.moveBigObject(Vector2d(0, -1, 0.0), objPlayerLeft);
field.setObjectAtPosition(objPlayerLeft);
}
if (input.getKey() == 's') {
field.moveBigObject(Vector2d(0, 1, 0.0), objPlayerLeft);
field.setObjectAtPosition(objPlayerLeft);
}
field.printField();
cout << endl << input.getKey() << " | Last: " << input.getLastKey() << " | Stored: " << input.getStoredKey() <<endl;
Sleep(10);
}
}
void hidecursor() {
HANDLE consoleHandle = GetStdHandle(STD_OUTPUT_HANDLE);
CONSOLE_CURSOR_INFO info;
info.dwSize = 100;
info.bVisible = FALSE;
SetConsoleCursorInfo(consoleHandle, &info);
}