-
Notifications
You must be signed in to change notification settings - Fork 0
/
BrickLayer.d
executable file
·115 lines (108 loc) · 4.2 KB
/
BrickLayer.d
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
module BrickLayer;
private import Layer;
private import Actor;
private import Entity;
private import Brick;
private import Vector;
private import Sofu.Sofu;
private import Scene;
private import Graphics;
class BrickLayer : Layer
{
this(Scene scene)
{
super(scene);
}
Rect moveCollide(Actor actor, Vector2d velocity)
{
bit ondefloor = false;
Rect crect = actor.extent().move(velocity);
foreach(Entity entity; _entities) {
Brick brick = cast(Brick) entity;
if(brick) {
bit collide = false;
Rect over = brick.extent().overlaps(crect);
if(over) {
collide = true;
bit noturn = false;
if(over.height() * over.width() <= 4) {
noturn = true;
}
if(over.height() < over.width()) {
if(velocity.y() >= 0) {
if(crect.center().y() < brick.extent().center().y()) {
if(brick.type() == "solid" || brick.type() == "TopStone") {
crect = crect.moveToBottom(brick.extent().top());
ondefloor = true;
actor.setFloor(brick);
}
}
}
else {
if(crect.center().y() > brick.extent().center().y()) {
if(brick.type() == "solid") {
crect = crect.moveToTop(brick.extent().bottom());
actor.velocity(new Vector2d(actor.velocity().x(), 0));
}
if(brick.type() == "TopStone") {
actor.die();
}
}
}
}
else {
if(velocity.x() >= 0) {
if(crect.center().x() < brick.extent().center().x()) {
if(brick.type() == "solid") {
crect = crect.moveToRight(brick.extent().left());
if(!noturn)
{
actor.velocity(new Vector2d(0, actor.velocity().y()));
actor.heading(-1);
}
}
if(brick.type() == "TopStone") {
actor.die();
}
}
}
else {
if(crect.center().x() > brick.extent().center().x()) {
if(brick.type() == "solid") {
crect = crect.moveToLeft(brick.extent().right());
if(!noturn) {
actor.velocity(new Vector2d(0, actor.velocity().y()));
actor.heading(1);
}
}
if(brick.type() == "TopStone") {
actor.die();
}
}
}
}
}
if(collide) {
if(brick.type == "Jump") {
actor.jump();
}
if(brick.type == "Goal") {
actor.hitGoal();
}
}
}
}
if(!ondefloor) {
actor.setFloor(null);
}
return crect;
}
Sofu.List.List getEntities() {
Sofu.List.List list=new Sofu.List.List(0,0,"");
foreach(Entity entity; _entities) {
Brick brick = cast(Brick) entity;
list.appendElement(brick.getBrick());
}
return list;
}
}