-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInteractiveGameObject.h
More file actions
206 lines (189 loc) · 4.39 KB
/
Copy pathInteractiveGameObject.h
File metadata and controls
206 lines (189 loc) · 4.39 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
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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
#pragma once
#include <wrl.h>
#include <Content\AnimatedTexture.h>
#include <SpriteBatch.h>
#include <DirectXMath.h>
#include <DirectXTK\Inc\SimpleMath.h>
#include "SpriteFont.h"
class InteractiveGameObject : public DrawableObject
{
public:
InteractiveGameObject::InteractiveGameObject(ID3D11ShaderResourceView* buttonSpriteSheet, DirectX::XMFLOAT2 positionIn, float scaleX, float scaleY) :
DrawableObject(buttonSpriteSheet, positionIn, scaleX, scaleY)
{
this->startPosition = positionIn;
direction = blockLeft = blockRight = blockTop = blockButtom = stand =
left = right = jumpFlag = blockTop = blockRight = blockLeft = false;
this->speed = 7;
force = 8;
x = y = 1;
}
void InteractiveGameObject::Draw(DirectX::SpriteBatch* batch)
{
updateBoundingRect();
if (direction)
animation->Draw(batch, position, DirectX::SpriteEffects::SpriteEffects_FlipHorizontally);
else
animation->Draw(batch, position);
}
void Update(float elapsed)
{
if (right && !blockRight)
position.x += (speed * scale.x);
else if (left && !blockLeft)
position.x -= (speed * scale.x);
if (jumpFlag)
{
position.y -= float((force / 2.0) * scale.y);
force--;
stand = false;
if (force == 8)
{
jumpFlag = false;
}
}
else if (stand) {}
else if (!stand)
position.y += force * scale.y;
updateBoundingRect();
animation->Update(elapsed);
left = right = stand = blockRight = blockTop = blockRight = blockLeft = false;
}
void move(float x, float y)
{
if (x > 0)
right = true;
else if (x < 0)
left = true;
if (!jumpFlag && y > 0 && stand)
{
jumpFlag = true;
force = gravity;
}
if (x > 0)
{
direction = false;
}
else if (x < 0)
{
direction = true;
}
}
void correctPersonPosition(float screenWidth, float screenHeight)
{
if (position.y > screenHeight)
{
position.y = -dimensions.y;
}
else if (position.y < -dimensions.y)
{
position.y = screenHeight;
}
if (getPosition().x > screenWidth)
{
position.x = -dimensions.x;
}
else if (getPosition().x < -dimensions.x)
{
position.x = screenWidth;
}
updateBoundingRect();
}
void colision(Windows::Foundation::Rect rect)
{
if (boundingRectangle.Right > rect.Left &&
boundingRectangle.Left < rect.Right &&
boundingRectangle.Bottom >= rect.Top &&
boundingRectangle.Top < rect.Top)
{
position.y = rect.Y - dimensions.y;
updateBoundingRect();
stand = true;
}
if (boundingRectangle.Bottom <= rect.Bottom + 1 &&
boundingRectangle.Bottom > rect.Top + 1 &&
boundingRectangle.Right >= rect.Left &&
boundingRectangle.Left < rect.Left
)
{
position.x = rect.X - dimensions.x;
updateBoundingRect();
blockRight = true;
direction = true;
}
if (boundingRectangle.Bottom <= rect.Bottom + 1 &&
boundingRectangle.Bottom > rect.Top + 1 &&
boundingRectangle.Left <= rect.Right &&
boundingRectangle.Right > rect.Right
)
{
position.x = rect.X + rect.Width;
updateBoundingRect();
blockLeft = true;
direction = false;
}
}
void colisionShot(Windows::Foundation::Rect rect)
{
if (boundingRectangle.Right > rect.Left &&
boundingRectangle.Left < rect.Right &&
boundingRectangle.Bottom >= rect.Top &&
boundingRectangle.Top < rect.Top)
{
position.y = rect.Y - dimensions.y;
updateBoundingRect();
stand = true;
}
}
void InteractiveGameObject::moveToStartPosition()
{
position = startPosition;
updateBoundingRect();
}
void setStartPosition(DirectX::XMINT2 position)
{
this->startPosition = DirectX::XMFLOAT2(position.x, position.y);
}
void setAndMoveToStartPosition(DirectX::XMINT2 position)
{
setStartPosition(position);
moveToStartPosition();
}
void jump()
{
this->force = this->gravity;
this->jumpFlag = true;
}
void reset()
{
position = startPosition;
updateBoundingRect();
}
void resize(float scaleX, float scaleY)
{
DrawableObject::resize(scaleX, scaleY);
//float tmpScaleX = scaleX / this->scale.x;
//float tmpScaleY = scaleY / this->scale.y;
//this->position.x *= tmpScaleX;
//this->position.y *= tmpScaleY;
//this->startPosition.x *= tmpScaleX;
//this->startPosition.y *= tmpScaleY;
//updateBoundingRect();
}
public:
bool right;
bool left;
int x;
int y;
bool direction; //0 lat, 1 right
int gravity = 15;
int force;
bool jumpFlag;
bool stand;
bool blockRight;
bool blockLeft;
bool blockTop;
bool blockButtom;
int speed;
DirectX::XMFLOAT2 startPosition;
};