aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJakob Stendahl <jakob.stendahl@outlook.com>2017-11-13 11:28:10 +0100
committerJakob Stendahl <jakob.stendahl@outlook.com>2017-11-13 11:28:10 +0100
commitbd7e7336fffaa373365d587e933809239ae4dd47 (patch)
tree01bfe025f5bba2c456ceb4d7c76a2af1a89f6c09
parent563ea1e795d4d683aca889e72fa5f43f3f612763 (diff)
downloadSpace-Invaders-CS-Console-bd7e7336fffaa373365d587e933809239ae4dd47.tar.gz
Space-Invaders-CS-Console-bd7e7336fffaa373365d587e933809239ae4dd47.zip
[a] Two new monsters
-rw-r--r--Space Invaders/GameEngine/Graphics.cs3
-rw-r--r--Space Invaders/GameObjects.cs188
2 files changed, 184 insertions, 7 deletions
diff --git a/Space Invaders/GameEngine/Graphics.cs b/Space Invaders/GameEngine/Graphics.cs
index 1c15199..b27b419 100644
--- a/Space Invaders/GameEngine/Graphics.cs
+++ b/Space Invaders/GameEngine/Graphics.cs
@@ -33,8 +33,7 @@ namespace GameEngine {
public void DrawFrame(Frame newFrame) {
/* Method that draws all changes from last frame to the screen */
FrameNum++;
- //Console.Clear();
- //Console.SetCursorPosition(0, 0);
+
for (int y = 0; y < _consoleBuffer.GetLength(0); y++) {
for (int x = 0; x < _consoleBuffer.GetLength(1); x++) {
diff --git a/Space Invaders/GameObjects.cs b/Space Invaders/GameObjects.cs
index 9f1db1d..5eae067 100644
--- a/Space Invaders/GameObjects.cs
+++ b/Space Invaders/GameObjects.cs
@@ -7,12 +7,26 @@ namespace SpaceInvaders {
public override void Start() {
for (int i = 0; i < 12; i++) {
- GameObject monster = new Monster();
+ GameObject monster = new SmallInvader();
monster.Parent = Parent;
monster.xPos = i * 35 + 90;
monster.yPos = 20;
Parent.GameObjects.Add(monster);
}
+ for (int i = 0; i < 12; i++) {
+ GameObject monster = new MediumInvader();
+ monster.Parent = Parent;
+ monster.xPos = i * 35 + 87;
+ monster.yPos = 30;
+ Parent.GameObjects.Add(monster);
+ }
+ for (int i = 0; i < 12; i++) {
+ GameObject monster = new SmallInvader();
+ monster.Parent = Parent;
+ monster.xPos = i * 35 + 90;
+ monster.yPos = 40;
+ Parent.GameObjects.Add(monster);
+ }
}
public override void Update() {
@@ -141,12 +155,12 @@ namespace SpaceInvaders {
public override void Update() {
if (Input.KeyPressed(ConsoleKey.RightArrow)) {
- xPos = xPos + 2;
+ xPos = xPos + 8;
}
if (Input.KeyPressed(ConsoleKey.LeftArrow)) {
- xPos = xPos - 2;
+ xPos = xPos - 8;
}
if (Input.KeyPressed(ConsoleKey.Spacebar)) {
@@ -202,7 +216,7 @@ namespace SpaceInvaders {
}
- class Monster : GameObject {
+ class SmallInvader : GameObject {
private int _shootTimer = 400000;
private int _moveTimer = 400;
@@ -217,7 +231,90 @@ namespace SpaceInvaders {
_shootTimer = Parent.Rand.Next(1500, 3500);
- Sprite = new char[8, 11] {
+ Sprite = new char[8, 8] {
+ {'\0', '\0', '\0', '\u2588', '\u2588', '\0', '\0', '\0'},
+ {'\0', '\0', '\u2588', '\u2588', '\u2588', '\u2588', '\0', '\0'},
+ {'\0', '\u2588', '\u2588', '\u2588', '\u2588', '\u2588', '\u2588', '\0'},
+ {'\u2588', '\u2588', '\0', '\u2588', '\u2588', '\0', '\u2588', '\u2588'},
+ {'\u2588', '\u2588', '\u2588', '\u2588', '\u2588', '\u2588', '\u2588', '\u2588'},
+ {'\0', '\0', '\u2588', '\0', '\0', '\u2588', '\0', '\0'},
+ {'\0', '\u2588', '\0', '\u2588', '\u2588', '\0', '\u2588', '\0'},
+ {'\u2588', '\0', '\u2588', '\0', '\0', '\u2588', '\0', '\u2588'}
+ };
+
+ }
+
+ public override void Update() {
+
+ if (_moveTimer <= 0) {
+ _moveTimer = 400;
+ if (_currStep >= _UBound) {
+ _currStep = 0;
+ _movingRight = !_movingRight;
+
+ if (_movingRight) {
+ yPos = yPos + 8;
+ }
+ }
+
+ if (_movingRight) {
+ xPos = xPos + 5;
+ }
+ else {
+ xPos = xPos - 5;
+ }
+
+ _currStep++;
+ }
+ _moveTimer--;
+
+ }
+
+ public override void LateUpdate(Frame thisFrame) {
+ if (_shootTimer <= 0) {
+ _shootTimer = Parent.Rand.Next(1500, 3500); ;
+ MonsterBullet bullet = new MonsterBullet();
+ bullet.Parent = Parent;
+ bullet.xPos = xPos + 10;
+ bullet.yPos = yPos + Sprite.GetLength(0) + 1;
+ bullet.Start();
+ Parent.GameObjects.Add(bullet);
+ }
+ _shootTimer--;
+ }
+
+ }
+
+ class MediumInvader : GameObject {
+
+ private int _shootTimer = 400000;
+ private int _moveTimer = 400;
+
+ private bool _movingRight = true;
+ private int _UBound = 20;
+ private int _currStep = 10;
+ private char[,] handsUp;
+ private char[,] handsDown;
+ private bool handsIsUp = false;
+
+ public override void Start() {
+ Tag = "Enemy";
+ Scale = 1;
+
+ _shootTimer = Parent.Rand.Next(1500, 3500);
+
+ handsUp = 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'},
+ {'\u2588', '\0', '\u2588', '\u2588', '\u2588', '\u2588', '\u2588', '\u2588', '\u2588', '\0', '\u2588'},
+ {'\u2588', '\u2588', '\u2588', '\0', '\u2588', '\u2588', '\u2588', '\0', '\u2588', '\u2588', '\u2588'},
+ {'\u2588', '\u2588', '\u2588', '\u2588', '\u2588', '\u2588', '\u2588', '\u2588', '\u2588', '\u2588', '\u2588'},
+ {'\0', '\0', '\u2588', '\u2588', '\u2588', '\u2588', '\u2588', '\u2588', '\u2588', '\0', '\0'},
+ {'\0', '\0', '\u2588', '\0', '\0', '\0', '\0', '\0', '\u2588', '\0', '\0'},
+ {'\0', '\0', '\0', '\u2588', '\u2588', '\0', '\u2588', '\u2588', '\0', '\0', '\0'}
+ };
+
+ handsDown = 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'},
@@ -228,6 +325,8 @@ namespace SpaceInvaders {
{'\0', '\0', '\0', '\u2588', '\u2588', '\0', '\u2588', '\u2588', '\0', '\0', '\0'}
};
+ Sprite = handsDown;
+
}
public override void Update() {
@@ -250,6 +349,85 @@ namespace SpaceInvaders {
xPos = xPos - 5;
}
+ if (handsIsUp) {
+ handsIsUp = false;
+ Sprite = handsDown;
+ } else {
+ handsIsUp = true;
+ Sprite = handsUp;
+ }
+
+ _currStep++;
+ }
+ _moveTimer--;
+
+ }
+
+ public override void LateUpdate(Frame thisFrame) {
+ if (_shootTimer <= 0) {
+ _shootTimer = Parent.Rand.Next(1500, 3500); ;
+ MonsterBullet bullet = new MonsterBullet();
+ bullet.Parent = Parent;
+ bullet.xPos = xPos + 10;
+ bullet.yPos = yPos + Sprite.GetLength(0) + 1;
+ bullet.Start();
+ Parent.GameObjects.Add(bullet);
+ }
+ _shootTimer--;
+ }
+
+ }
+
+ class LargeInvader : GameObject {
+
+ private int _shootTimer = 400000;
+ private int _moveTimer = 400;
+
+ private bool _movingRight = true;
+ private int _UBound = 20;
+ private int _currStep = 10;
+
+ public override void Start() {
+ throw new NotImplementedException();
+
+ Tag = "Enemy";
+ Scale = 1;
+
+ _shootTimer = Parent.Rand.Next(1500, 3500);
+
+ 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() {
+
+ if (_moveTimer <= 0) {
+ _moveTimer = 400;
+ if (_currStep >= _UBound) {
+ _currStep = 0;
+ _movingRight = !_movingRight;
+
+ if (_movingRight) {
+ yPos = yPos + 8;
+ }
+ }
+
+ if (_movingRight) {
+ xPos = xPos + 5;
+ }
+ else {
+ xPos = xPos - 5;
+ }
+
_currStep++;
}
_moveTimer--;