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
|
using System;
using GameEngine;
namespace SpaceInvaders {
class GameLogic : GameObject {
public override void Update() {
if (Input.KeyPressed(ConsoleKey.Escape)) {
Environment.Exit(0);
}
}
}
class Bullet : GameObject {
int moveTimer = 10;
public override void Start() {
Tag = "Projectile";
Scale = 1;
Sprite = new char[1, 1] { { '\u2588' } };
}
public override void Update() {
moveTimer--;
if (moveTimer <= 0) {
yPos = yPos - 1;
moveTimer = 10;
}
if (yPos <= 0) {
isDead = true;
}
}
public override void LateUpdate(Frame thisFrame) {
for (int i = 0; i < Parent.GameObjects.Count; i++) {
GameObject other = Parent.GameObjects[i];
if (other.Tag == "Enemy") {
int x1 = other.xPos;
int x2 = other.xPos + other.Sprite.GetLength(1);
int y1 = other.yPos;
int y2 = other.yPos + other.Sprite.GetLength(0);
if (x1 <= xPos && xPos <= x2 && y1 <= yPos && yPos <= y2) {
other.isDead = true;
isDead = true;
}
}
if (other.Tag == "Obstacle") {
int x1 = other.xPos;
int x2 = other.xPos + other.Sprite.GetLength(1);
int y1 = other.yPos;
int y2 = other.yPos + other.Sprite.GetLength(0);
if (x1 <= xPos && xPos <= x2 && y1 <= yPos && yPos <= y2) {
isDead = true;
}
}
}
}
}
class Player : GameObject {
public override void Start() {
Tag = "Player";
Sprite = new char[4, 9] {
{'\0', '\0', '\0', '\0', '\u2588', '\0', '\0', '\0', '\0'},
{'\0', '\0', '\0', '\0', '\u2588', '\0', '\0', '\0', '\0'},
{'\u2588', '\u2588', '\u2588', '\u2588', '\u2588', '\u2588', '\u2588', '\u2588', '\u2588'},
{'\u2588', '\u2588', '\u2588', '\u2588', '\u2588', '\u2588', '\u2588', '\u2588', '\u2588'}
};
}
public override void Update() {
if (Input.KeyPressed(ConsoleKey.RightArrow)) {
xPos = xPos + 2;
}
if (Input.KeyPressed(ConsoleKey.LeftArrow)) {
xPos = xPos - 2;
}
if (Input.KeyPressed(ConsoleKey.Spacebar)) {
GameObject tmpBullet = new Bullet();
tmpBullet.Parent = Parent;
tmpBullet.xPos = xPos + 8;
tmpBullet.yPos = yPos - 1;
tmpBullet.Start();
Parent.GameObjects.Add(tmpBullet);
}
}
}
class Obstacle : GameObject {
public override void Start() {
Tag = "Obstacle";
Scale = 4;
Sprite = new char[2, 5] {
{'\u2588', '\u2588', '\u2588', '\u2588', '\u2588'},
{'\u2588', '\0', '\0', '\0', '\u2588'}
};
}
}
class Monster : GameObject {
public override void Start() {
Tag = "Enemy";
xPos = 10;
yPos = 10;
Scale = 1;
Sprite = new char[8, 11] {
{'\0', '\0', '\u2588', '\0', '\0', '\0', '\0', '\0', '\u2588', '\0', '\0'},
{'\0', '\0', '\0', '\u2588', '\0', '\0', '\0', '\u2588', '\0', '\0', '\0'},
{'\0', '\0', '\u2588', '\u2588', '\u2588', '\u2588', '\u2588', '\u2588', '\u2588', '\0', '\0'},
{'\0', '\u2588', '\u2588', '\0', '\u2588', '\u2588', '\u2588', '\0', '\u2588', '\u2588', '\0'},
{'\u2588', '\u2588', '\u2588', '\u2588', '\u2588', '\u2588', '\u2588', '\u2588', '\u2588', '\u2588', '\u2588'},
{'\u2588', '\0', '\u2588', '\u2588', '\u2588', '\u2588', '\u2588', '\u2588', '\u2588', '\0', '\u2588'},
{'\u2588', '\0', '\u2588', '\0', '\0', '\0', '\0', '\0', '\u2588', '\0', '\u2588'},
{'\0', '\0', '\0', '\u2588', '\u2588', '\0', '\u2588', '\u2588', '\0', '\0', '\0'}
};
}
public override void Update() {
}
}
}
|