-
Notifications
You must be signed in to change notification settings - Fork 0
/
GameObj.h
121 lines (112 loc) · 3.63 KB
/
GameObj.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
#pragma once
#include "Task.h"
//----------------------------------------------------------------------
//とりあえずいろんな構造体
//----------------------------------------------------------------------
struct HITCIRCLE
{
float x,y;
float radius;
};
struct HITLINE
{
float x1,y1;
float x2,y2;
float length;
float argument;
};
struct HITRECT
{
float rect_width, rect_height;
};
struct HITSLOPERECT
{
float x1,y1;
float x2,y2;
float x3,y3;
float x4,y4;
float argument;
};
//----------------------------------------------------------------------
//ゲームオブジェクトクラス(あらゆるオブジェクトの基底クラス)
//----------------------------------------------------------------------
class CGameObj : public CTask
{
public:
float X, Y;
float Width, Height;
HITRECT m_hit;
HITLINE line;
float hit_radius;
CGameObj(CTaskList* task_list, float x, float y, float w, float h, float r, float hit_w, float hit_h)
:CTask(task_list), X(x), Y(y), Width(w), Height(h), hit_radius(r)
{
m_hit.rect_width =hit_w;
m_hit.rect_height =hit_h;
}
//当たり判定処理用関数(trueで当たってる
bool HitRect(CGameObj *obj)
{
return
X -m_hit.rect_width/2 < obj->X +obj->m_hit.rect_width/2 &&
X +m_hit.rect_width/2 > obj->X -obj->m_hit.rect_width/2 &&
Y -m_hit.rect_height/2 < obj->Y +obj->m_hit.rect_height/2 &&
Y +m_hit.rect_height/2 > obj->Y -obj->m_hit.rect_height/2;
}
bool HitRect(CGameObj *obj, HITRECT *hit)
{
return
X -hit->rect_width/2 < obj->X +obj->m_hit.rect_width/2 &&
X +hit->rect_width/2 > obj->X -obj->m_hit.rect_width/2 &&
Y -hit->rect_height/2 < obj->Y +obj->m_hit.rect_height/2 &&
Y +hit->rect_height/2 > obj->Y -obj->m_hit.rect_height/2;
}
bool HitCircle(CGameObj *obj)
{
return
pow(obj->X-X,2)+pow(obj->Y-Y,2) < pow(obj->hit_radius+hit_radius,2);
}
bool HitCircle(CGameObj *obj, float x, float y, float radius)
{
return
pow(obj->X-x,2)+pow(obj->Y-y,2) < pow(obj->hit_radius+radius,2);
}
bool HitCircleToLine(CGameObj *obj)
{
//P =(X,Y)
//A =(obj->line.x1,obj->line.y1)
//B =(obj->line.x2,obj->line.y2)
//vectorA =(X-obj->line.x1,Y-obj->line.y1) |A|=√((X-obj->line.x1)*(X-obj->line.x1)+(Y-obj->line.y1)*(Y-obj->line.y1))
//vectorB =(X-obj->line.x2,Y-obj->line.y2) |B|=√((X-obj->line.x2)*(X-obj->line.x2)+(Y-obj->line.y2)*(Y-obj->line.y2))
//vectorS =(obj->line.x2-obj->line.x1,obj->line.y2-obj->line.y1)
//|S| =obj->line.length
//|A×S| =|(X-obj->line.x1)*(obj->line.y2-obj->line.y1)-(Y-obj->line.y1)*(obj->line.x2-obj->line.x1)|
//d =|A×S|/|S| =((X-obj->line.x1)*(obj->line.y2-obj->line.y1)-(Y-obj->line.y1)*(obj->line.x2-obj->line.x1))/obj->line.length
//A・S =(X-obj->line.x1)*(obj->line.x2-obj->line.x1)+(Y-obj->line.y1)*(obj->line.y2-obj->line.y1)
//B・S =(X-obj->line.x2)*(obj->line.x2-obj->line.x1)+(Y-obj->line.y2)*(obj->line.y2-obj->line.y1)
if((hit_radius+2.0f) < abs(((X-obj->line.x1)*(obj->line.y2-obj->line.y1)-(Y-obj->line.y1)*(obj->line.x2-obj->line.x1))/obj->line.length))
{
return false;
}
else if(((X-obj->line.x1)*(obj->line.x2-obj->line.x1)+(Y-obj->line.y1)*(obj->line.y2-obj->line.y1))
*((X-obj->line.x2)*(obj->line.x2-obj->line.x1)+(Y-obj->line.y2)*(obj->line.y2-obj->line.y1))<=0)
{
return true;
}
else if((hit_radius+2.0f)*(hit_radius+2.0f) > ((X-obj->line.x1)*(X-obj->line.x1)+(Y-obj->line.y1)*(Y-obj->line.y1)) ||
(hit_radius+2.0f)*(hit_radius+2.0f) > ((X-obj->line.x2)*(X-obj->line.x2)+(Y-obj->line.y2)*(Y-obj->line.y2)))
{
return true;
}
else
{
return false;
}
}
/*bool HitCircleToLine(CGameObj *obj, float x, float y, float radius)
{
}*/
//継承先でオーバーライドすること
virtual bool Move() { return true; }
virtual void Draw() {}
};