Skip to content

Commit

Permalink
shmupdates
Browse files Browse the repository at this point in the history
  • Loading branch information
ZacharyPatten committed Sep 30, 2023
1 parent 0c14f9d commit 630916f
Show file tree
Hide file tree
Showing 15 changed files with 1,313 additions and 52 deletions.
20 changes: 20 additions & 0 deletions .github/workflows/Shmup Build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: Shmup Build
on:
push:
paths:
- 'Projects/Shmup/**'
- '!**.md'
pull_request:
paths:
- 'Projects/Shmup/**'
- '!**.md'
workflow_dispatch:
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-dotnet@v3
with:
dotnet-version: 7.0.x
- run: dotnet build "Projects\Shmup\Shmup.csproj" --configuration Release
10 changes: 10 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -472,5 +472,15 @@
"console": "externalTerminal",
"stopAtEntry": false,
},
{
"name": "Shmup",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "Build Shmup",
"program": "${workspaceFolder}/Projects/Shmup/bin/Debug/Shmup.dll",
"cwd": "${workspaceFolder}/Projects/Shmup/bin/Debug",
"console": "externalTerminal",
"stopAtEntry": false,
},
],
}
13 changes: 13 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -613,6 +613,19 @@
],
"problemMatcher": "$msCompile",
},
{
"label": "Build Shmup",
"command": "dotnet",
"type": "process",
"args":
[
"build",
"${workspaceFolder}/Projects/Shmup/Shmup.csproj",
"/property:GenerateFullPaths=true",
"/consoleloggerparameters:NoSummary",
],
"problemMatcher": "$msCompile",
},
{
"label": "Build Solution",
"command": "dotnet",
Expand Down
16 changes: 14 additions & 2 deletions Projects/Shmup/Enemies/Helicopter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,23 @@ namespace Shmup.Enemies;

internal class Helicopter : IEnemy
{
public static int scorePerKill = 100;
public int Health = 70;
public float X;
public float Y;
public float XVelocity;
public float YVelocity;

Check warning on line 13 in Projects/Shmup/Enemies/Helicopter.cs

View workflow job for this annotation

GitHub Actions / build

Field 'Helicopter.YVelocity' is never assigned to, and will always have its default value 0

Check warning on line 13 in Projects/Shmup/Enemies/Helicopter.cs

View workflow job for this annotation

GitHub Actions / build

Field 'Helicopter.YVelocity' is never assigned to, and will always have its default value 0

Check warning on line 13 in Projects/Shmup/Enemies/Helicopter.cs

View workflow job for this annotation

GitHub Actions / build

Field 'Helicopter.YVelocity' is never assigned to, and will always have its default value 0

Check warning on line 13 in Projects/Shmup/Enemies/Helicopter.cs

View workflow job for this annotation

GitHub Actions / build

Field 'Helicopter.YVelocity' is never assigned to, and will always have its default value 0
private int Frame;
private string[] Sprite = Random.Shared.Next(2) is 0 ? spriteA : spriteB;

static string[] spriteA =
static readonly string[] spriteA =
{
@" ~~~~~+~~~~~",
@"'\===<[_]L) ",
@" -'-`- ",
};

static string[] spriteB =
static readonly string[] spriteB =
{
@" -----+-----",
@"*\===<[_]L) ",
Expand Down Expand Up @@ -82,4 +84,14 @@ public bool IsOutOfBounds()
XVelocity >= 0 && X > Program.gameWidth + XMax ||
YVelocity >= 0 && Y > Program.gameHeight + YMax;
}

public void Shot()
{
Health--;
if (Health <= 0)
{
Program.enemies.Remove(this);
Program.score += scorePerKill;
}
}
}
2 changes: 2 additions & 0 deletions Projects/Shmup/Enemies/IEnemy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

internal interface IEnemy
{
public void Shot();

public void Render();

public void Update();
Expand Down
20 changes: 16 additions & 4 deletions Projects/Shmup/Enemies/Tank.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,34 +5,36 @@ namespace Shmup.Enemies;

internal class Tank : IEnemy
{
public static int scorePerKill = 20;
public int Health = 20;
public float X;
public float Y;
public float XVelocity;

Check warning on line 12 in Projects/Shmup/Enemies/Tank.cs

View workflow job for this annotation

GitHub Actions / build

Field 'Tank.XVelocity' is never assigned to, and will always have its default value 0

Check warning on line 12 in Projects/Shmup/Enemies/Tank.cs

View workflow job for this annotation

GitHub Actions / build

Field 'Tank.XVelocity' is never assigned to, and will always have its default value 0

Check warning on line 12 in Projects/Shmup/Enemies/Tank.cs

View workflow job for this annotation

GitHub Actions / build

Field 'Tank.XVelocity' is never assigned to, and will always have its default value 0

Check warning on line 12 in Projects/Shmup/Enemies/Tank.cs

View workflow job for this annotation

GitHub Actions / build

Field 'Tank.XVelocity' is never assigned to, and will always have its default value 0
public float YVelocity;
private string[] Sprite;

Check warning on line 14 in Projects/Shmup/Enemies/Tank.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable field 'Sprite' must contain a non-null value when exiting constructor. Consider declaring the field as nullable.

Check warning on line 14 in Projects/Shmup/Enemies/Tank.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable field 'Sprite' must contain a non-null value when exiting constructor. Consider declaring the field as nullable.

Check warning on line 14 in Projects/Shmup/Enemies/Tank.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable field 'Sprite' must contain a non-null value when exiting constructor. Consider declaring the field as nullable.

Check warning on line 14 in Projects/Shmup/Enemies/Tank.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable field 'Sprite' must contain a non-null value when exiting constructor. Consider declaring the field as nullable.

static string[] spriteDown =
static readonly string[] spriteDown =
{
@" ___ ",
@"|_O_|",
@"[ooo]",
};

static string[] spriteUp =
static readonly string[] spriteUp =
{
@" _^_ ",
@"|___|",
@"[ooo]",
};

static string[] spriteLeft =
static readonly string[] spriteLeft =
{
@" __ ",
@"=|__|",
@"[ooo]",
};

static string[] spriteRight =
static readonly string[] spriteRight =
{
@" __ ",
@"|__|=",
Expand Down Expand Up @@ -96,4 +98,14 @@ public bool IsOutOfBounds()
XVelocity >= 0 && X > Program.gameWidth + XMax ||
YVelocity >= 0 && Y > Program.gameHeight + YMax;
}

public void Shot()
{
Health--;
if (Health <= 0)
{
Program.enemies.Remove(this);
Program.score += scorePerKill;
}
}
}
14 changes: 13 additions & 1 deletion Projects/Shmup/Enemies/UFO1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@ namespace Shmup.Enemies;

internal class UFO1 : IEnemy
{
public static int scorePerKill = 10;
public int Health = 10;
public float X;
public float Y;
public float XVelocity = 1f / 8f;
public float YVelocity = 1f / 8f;
private static string[] Sprite =
private static readonly string[] Sprite =
{
@" _!_ ",
@"(_o_)",
Expand Down Expand Up @@ -80,4 +82,14 @@ public bool IsOutOfBounds()
XVelocity >= 0 && X > Program.gameWidth + XMax ||
YVelocity >= 0 && Y > Program.gameHeight + YMax;
}

public void Shot()
{
Health--;
if (Health <= 0)
{
Program.enemies.Remove(this);
Program.score += scorePerKill;
}
}
}
14 changes: 13 additions & 1 deletion Projects/Shmup/Enemies/UFO2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@ namespace Shmup.Enemies;

internal class UFO2 : IEnemy
{
public static int scorePerKill = 80;
public int Health = 50;
public float X;
public float Y;
public int UpdatesSinceTeleport;
public int TeleportFrequency = 360;

private static string[] Sprite =
private static readonly string[] Sprite =
{
@" _!_ ",
@" /_O_\ ",
Expand Down Expand Up @@ -78,4 +80,14 @@ public bool IsOutOfBounds()
Y > 0 &&
Y < Program.gameHeight);
}

public void Shot()
{
Health--;
if (Health <= 0)
{
Program.enemies.Remove(this);
Program.score += scorePerKill;
}
}
}
108 changes: 99 additions & 9 deletions Projects/Shmup/Player.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ internal enum States
public float Y;
public States State;

static string[] neutral =
static readonly string[] Sprite =
{
@" ╱‾╲ ",
@" ╱╱‾╲╲ ",
Expand All @@ -27,26 +27,116 @@ internal enum States
@"╲_╱───╲_╱",
};

const int neutralOffsetX = -4;
const int neutralOffsetY = -2;
static readonly string[] SpriteUp =
{
@" ╱‾╲ ",
@" ╱╱‾╲╲ ",
@" ╱'╲O╱'╲ ",
@"╱ / ‾ \ ╲",
@"╲_╱───╲_╱",
@"/V\ /V\",
};

static readonly string[] SpriteDown =
{
@" ╱‾╲ ",
@" ╱╱‾╲╲ ",
@"-╱'╲O╱'╲-",
@"╱-/ ‾ \-╲",
@"╲_╱───╲_╱",
};

static readonly string[] SpriteLeft =
{
@" ╱╲ ",
@" ╱‾╲╲ ",
@" ╱╲O╱'╲ ",
@"╱/ ‾ \ ╲",
@"╲╱───╲_╱",
};

static readonly string[] SpriteRight =
{
@" ╱╲ ",
@" ╱╱‾╲ ",
@" ╱'╲O╱╲ ",
@"╱ / ‾ \╲",
@"╲_╱───╲╱",
};

static readonly string[] SpriteUpLeft =
{
@" ╱╲ ",
@" ╱‾╲╲ ",
@" ╱╲O╱'╲ ",
@"╱/ ‾ \ ╲",
@"╲╱───╲_╱",
@"/\ /V\",
};

static readonly string[] SpriteUpRight =
{
@" ╱╲ ",
@" ╱╱‾╲ ",
@" ╱'╲O╱╲ ",
@"╱ / ‾ \╲",
@"╲_╱───╲╱",
@"/V\ /\",
};

static readonly string[] SpriteDownLeft =
{
@" ╱╲ ",
@" ╱‾╲╲ ",
@"-╱╲O╱'╲-",
@"-/ ‾ \-╲",
@"╲╱───╲_╱",
};

static readonly string[] SpriteDownRight =
{
@" ╱╲ ",
@" ╱╱‾╲ ",
@"-╱'╲O╱╲-",
@"╱-/ ‾ \-",
@"╲_╱───╲╱",
};

public void Render()
{
for (int y = 0; y < neutral.Length; y++)
var (sprite, offset) = GetSpriteAndOffset();
for (int y = 0; y < sprite.Length; y++)
{
int yo = (int)Y + y + neutralOffsetY;
int yi = neutral.Length - y - 1;
int yo = (int)Y + y + offset.Y;
int yi = sprite.Length - y - 1;
if (yo >= 0 && yo < Program.frameBuffer.GetLength(1))
{
for (int x = 0; x < neutral[y].Length; x++)
for (int x = 0; x < sprite[y].Length; x++)
{
int xo = (int)X + x + neutralOffsetX;
int xo = (int)X + x + offset.X;
if (xo >= 0 && xo < Program.frameBuffer.GetLength(0))
{
Program.frameBuffer[xo, yo] = neutral[yi][x];
Program.frameBuffer[xo, yo] = sprite[yi][x];
}
}
}
}
}

internal (string[] Sprite, (int X, int Y) offset) GetSpriteAndOffset()
{
return State switch
{
States.None => (Sprite, (-4, -2)),
States.Up => (SpriteUp, (-4, -3)),
States.Down => (SpriteDown, (-4, -2)),
States.Left => (SpriteLeft, (-3, -2)),
States.Right => (SpriteRight, (-4, -2)),
States.Up | States.Left => (SpriteUpLeft, (-3, -3)),
States.Up | States.Right => (SpriteUpRight, (-4, -3)),
States.Down | States.Left => (SpriteDownLeft, (-3, -2)),
States.Down | States.Right => (SpriteDownRight, (-4, -2)),
_ => throw new NotImplementedException(),
};
}
}
Loading

0 comments on commit 630916f

Please sign in to comment.