-
Notifications
You must be signed in to change notification settings - Fork 0
/
Fighter.h
135 lines (98 loc) · 3.38 KB
/
Fighter.h
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
#include <windows.h> // Header File For Windows
#include <gl.h> // Header File For The OpenGL32 Library
#include <glu.h> // Header File For The GLu32 Library
#include <glaux.h> // Header File For The Glaux Library
#include <cmath>
#include <fstream>
#include <texture.h>
#include <Model_3DS.h>
#include <3dTexture.h>
#include "Entity.h"
#include <iostream>
class Fighter:public Entity
{
public:
Camera fighterCamera;
float speed;
public: Fighter(){};
public:
Fighter(Camera c, float cSpeed) {
fighter = Model_3DS();
char data[] = "data/Fighter.3ds";
fighter.Load(data);
GLTexture muhammer;
muhammer.LoadBMP("data/Muhammer.bmp");
fighter.Materials[0].tex = muhammer;
speed = cSpeed;
fighterCamera = Camera();
fighterCamera = c;
fighterCamera.MoveUpward(-19);
fighterCamera.MoveForward(25);
fighter.pos.x = fighterCamera.Position.x;
fighter.pos.y = fighterCamera.Position.y;
fighter.pos.z = fighterCamera.Position.z;
}
void drawFighter() {
fighter.scale = 2;
glColor3f(0.6f,0.3f,0.7f);
fighter.Draw();
glColor3f(1,1,1);
}
void move(bool keys[], Camera c){
fighterCamera = c;
fighterCamera.MoveUpward(-19);
fighterCamera.MoveForward(25);
fighter.pos.x = fighterCamera.Position.x;
fighter.pos.y = fighterCamera.Position.y;
fighter.pos.z = fighterCamera.Position.z;
}
bool collisionOut (float x, float z, float width, float length, bool keys[], float offset) {
Camera newC = Camera();
newC = fighterCamera;
if (keys['W'])
newC.MoveForward(speed);
if (keys['S'])
newC.MoveForward(-speed);
if (keys['A'])
newC.MoveRight(-speed);
if (keys['D'])
newC.MoveRight(speed);
if (keys[VK_LEFT]) newC.RotateY(0.09); if (keys[VK_RIGHT]) newC.RotateY(-0.09);
if (keys[VK_UP]) newC.RotateX(-0.09); if (keys[VK_DOWN]) newC.RotateX(0.09);
bool outX = (newC.Position.x - offset > x+width/2) || (newC.Position.x + offset < x-width/2);
bool outZ = (newC.Position.z - offset > z+length/2) || (newC.Position.z + offset < z-length/2);
return outX || outZ;
}
bool collision (float x, float z, float width, float length, bool keys[], float offset) {
Camera newC = Camera();
newC = fighterCamera;
if (keys['W'])
newC.MoveForward(speed);
if (keys['S'])
newC.MoveForward(-speed);
if (keys['A'])
newC.MoveRight(-speed);
if (keys['D'])
newC.MoveRight(speed);
if (keys[VK_LEFT]) newC.RotateY(0.09); if (keys[VK_RIGHT]) newC.RotateY(-0.09);
if (keys[VK_UP]) newC.RotateX(-0.09); if (keys[VK_DOWN]) newC.RotateX(0.09);
return (newC.Position.x + offset < x+width/2) && (newC.Position.x - offset > x-width/2)
&& (newC.Position.z + offset < z+length/2) && (newC.Position.z - offset > z-length/2);
}
bool collisionCylinder (float x, float z, float r, bool keys[], float offset) {
Camera newC = Camera();
newC = fighterCamera;
if (keys['W'])
newC.MoveForward(speed);
if (keys['S'])
newC.MoveForward(-speed);
if (keys['A'])
newC.MoveRight(-speed);
if (keys['D'])
newC.MoveRight(speed);
if (keys[VK_LEFT]) newC.RotateY(0.09); if (keys[VK_RIGHT]) newC.RotateY(-0.09);
if (keys[VK_UP]) newC.RotateX(-0.09); if (keys[VK_DOWN]) newC.RotateX(0.09);
float dist = sqrt( (newC.Position.x - x)*(newC.Position.x - x) + (newC.Position.z - z)*(newC.Position.z - z));
return dist-offset > r;
}
};