-
Notifications
You must be signed in to change notification settings - Fork 0
/
MapObject.cs
85 lines (69 loc) · 2.69 KB
/
MapObject.cs
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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Breakout_for_C_Sharp
{
class MapObject
{
int x; //ブロックの座標
int y; //ブロックの座標
const int mapObjectHeight = 15; //ブロックの高さ
const int mapObjectWidth = 40; //ブロックの横幅
NatureObject natureObject; //オブジェクトの性質
public MapObject()
{
}
public int getX()
{
return this.x;
}
public void setX(int x)
{
this.x = x;
}
public int getY()
{
return this.y;
}
public void setY(int y)
{
this.y = y;
}
public NatureObject getNatureObject()
{
return this.natureObject;
}
public void setNatureObject(NatureObject natureObject)
{
this.natureObject = natureObject;
}
//ボールがブロックに衝突しているかをチェックする
public void ballCollisionCheck(ref Ball ball)
{
bool collisionFlag = false; //trueならブロックとボールは衝突している
if (NatureObject.OBJ_BLOCK == this.natureObject) {
//ボールの座標がブロックの矩形に重なっていないかをチェックする
//ボールのX座標がオブジェクトの矩形より大きく、ボールのX座標が矩形のX座標の幅よりも小さい場合、
//または矩形のX座標がボールのX座標よりも大きく、かつ、矩形のX座標よりもボールのX座標がボールの横幅よりも大きい場合、
//かつ、ボールのY座標が矩形のY座標よりも大きく、ボールのY座標が矩形のY座標の高さよりも大きい場合、
//または矩形のY座標がボールのY座標よりも大きく、さらに矩形のY座標よりもボールのY座標がボールの縦幅よりも大きい場合、
if (((ball.getX() > this.x) && (ball.getX() < (this.x + MapObject.mapObjectWidth)) ||
(this.x > ball.getX()) && (this.x < (ball.getX() + ball.getBallWidth()))) &&
((ball.getY() > this.y) && (ball.getY() < (this.y + MapObject.mapObjectHeight)) ||
(this.y > ball.getY()) && (this.y < (ball.getY() + ball.getBallHeight()))))
{
//ブロックの矩形と座標が重なっていたら、ボールを反射させる
double angle = ball.getAngle();
ball.setAngle(-angle);
collisionFlag = true;
}
//ブロックを消去する
if (collisionFlag == true) {
natureObject = NatureObject.OBJ_SPACE;
}
}
return;
}
}
}