Skip to content

Commit

Permalink
Add score counter for endless + fix commandbar layout
Browse files Browse the repository at this point in the history
  • Loading branch information
Difegue committed Dec 1, 2023
1 parent 49b31f6 commit 90332e3
Show file tree
Hide file tree
Showing 27 changed files with 89 additions and 18 deletions.
1 change: 1 addition & 0 deletions LCDonald.Core/Games/AiAiBananaCatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ protected override void UpdateCore()
QueueSound(new LCDGameSound("../common/hit.ogg"));
_bananaPositions.Remove(banPos);
_bananasCollected++;
IncrementScore();
}
}

Expand Down
1 change: 1 addition & 0 deletions LCDonald.Core/Games/AmyRougeTennis.cs
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@ public override void CustomUpdate()
if (_ballPosition < 20 && _ballPosition != -1 && _aiResistance > 0 && _ballDirection)
{
_aiResistance--;
IncrementScore();
QueueSound(new LCDGameSound("hit.ogg"));
_ballDirection = false;

Expand Down
1 change: 1 addition & 0 deletions LCDonald.Core/Games/AmyRougeVolleyball.cs
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,7 @@ public override void CustomUpdate()
if (_ballPosition < 20 && _ballPosition != -1 && _aiResistance > 0 && _ballDirection)
{
_aiResistance--;
IncrementScore();
QueueSound(new LCDGameSound("hit_return.ogg"));
_ballDirection = false;

Expand Down
1 change: 1 addition & 0 deletions LCDonald.Core/Games/BigFishing.cs
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,7 @@ private void ReelUpAnimation()
PlayAnimation(reelAnimation);

_fishCaught++;
IncrementScore();
_hasLure = true;

_rodPosition = 0;
Expand Down
1 change: 1 addition & 0 deletions LCDonald.Core/Games/BillyGiantEgg.cs
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ protected override void UpdateCore()
if (horizontalPos == _billyPosition)
{
_fruitPositions.Remove(ringPos);
IncrementScore();

if (horizontalPos == 1 || horizontalPos == 2)
BlinkElement(GET_LEFT, 1);
Expand Down
1 change: 1 addition & 0 deletions LCDonald.Core/Games/CreamFlowerCatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ protected override void UpdateCore()
QueueSound(new LCDGameSound("../common/hit.ogg"));
_flowerPositions.Remove(fPos);
_flowersCollected++;
IncrementScore();
}
}

Expand Down
1 change: 1 addition & 0 deletions LCDonald.Core/Games/CreamFlowerCatch2005.cs
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ protected override void UpdateCore()
QueueSound(new LCDGameSound("hit.ogg"));
_flowerPositions.Remove(fPos);
_flowersCollected++;
IncrementScore();

// blink the matching hit bubble
switch (digit)
Expand Down
1 change: 1 addition & 0 deletions LCDonald.Core/Games/KnucklesBaseball.cs
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ public override void CustomUpdate()
if (digit == _knucklesPosition)
{
_ballsIntercepted++;
IncrementScore();
QueueSound(new LCDGameSound("../common/hit.ogg"));
}
else
Expand Down
1 change: 1 addition & 0 deletions LCDonald.Core/Games/KnucklesSoccer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ public override void CustomUpdate()
if (digit == _knucklesPosition)
{
_ballsIntercepted++;
IncrementScore();
QueueSound(new LCDGameSound("../common/hit.ogg"));
}
else
Expand Down
1 change: 1 addition & 0 deletions LCDonald.Core/Games/KnucklesTreasureHunt.cs
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,7 @@ protected override void UpdateCore()
if (IsInFrontOfEmerald(emerald) && _hasKnucklesMoved)
{
_emeraldsCollected++;
IncrementScore();
QueueSound(new LCDGameSound("emerald_get.ogg"));
_emeraldPositions.Remove(emerald);
}
Expand Down
3 changes: 2 additions & 1 deletion LCDonald.Core/Games/ShadowBasketball.cs
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,8 @@ protected override void UpdateCore()
{
QueueSound(new LCDGameSound("../common/hit.ogg"));
_goalsScored += 2;

IncrementScore();

// hack to make the ball unshootable for 2 cycles
_ballPosition = -10;
_ballHalfStep = true;
Expand Down
1 change: 1 addition & 0 deletions LCDonald.Core/Games/ShadowGrinder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ public override void CustomUpdate()
case 2:
QueueSound(new LCDGameSound("../common/hit.ogg"));
_gapsDodged++;
IncrementScore();
break;
}
}
Expand Down
3 changes: 2 additions & 1 deletion LCDonald.Core/Games/ShadowHockey.cs
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,8 @@ protected override void UpdateCore()
{
QueueSound(new LCDGameSound("score.ogg"));
_goalsScored++;

IncrementScore();

// hack to make the ball unshootable for 2 cycles
_ballPosition = -10;
_ballHalfStep = true;
Expand Down
1 change: 1 addition & 0 deletions LCDonald.Core/Games/SonicActionGame.cs
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ public override void CustomUpdate()
{
QueueSound(new LCDGameSound("../common/hit.ogg"));
_platformsDodged++;
IncrementScore();
}

if (_platformsHit == 5)
Expand Down
3 changes: 2 additions & 1 deletion LCDonald.Core/Games/SonicExtremeBoarding.cs
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,8 @@ protected override void UpdateCore()
_ringPosition = 0;
QueueSound(new LCDGameSound("ring_hit.ogg"));
_ringsCollected++;

IncrementScore();

// swap ring spawn point
_ringSpawn = _ringSpawn == 11 ? 17 : 11;
}
Expand Down
1 change: 1 addition & 0 deletions LCDonald.Core/Games/SonicSkateboard.cs
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ protected override void UpdateCore()
_ringPositions.Remove(ringPos);
QueueSound(new LCDGameSound("../common/hit.ogg"));
_ringsCollected++;
IncrementScore();
}
}
}
Expand Down
1 change: 1 addition & 0 deletions LCDonald.Core/Games/SonicSpeedway.cs
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ public override void CustomUpdate()
{
QueueSound(new LCDGameSound("../common/hit.ogg"));
_carRowsDodged++;
IncrementScore();
}

if (_carsHit == 5)
Expand Down
2 changes: 1 addition & 1 deletion LCDonald.Core/Games/TailsSkyAdventure.cs
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ protected override void UpdateCore()
QueueSound(new LCDGameSound("hit.ogg"));
_enemyPos = _projectilePos = -1;
_enemiesHit++;

IncrementScore();
}

// Move projectile forward
Expand Down
1 change: 1 addition & 0 deletions LCDonald.Core/Games/TailsSkyPatrol.cs
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ protected override void UpdateCore()
QueueSound(new LCDGameSound("../common/hit.ogg"));
_ringPositions.Remove(ringPos);
_ringsCollected++;
IncrementScore();
}
}

Expand Down
1 change: 1 addition & 0 deletions LCDonald.Core/Games/TailsSoccer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ public override void CustomUpdate()
if (digit == _tailsPosition)
{
_ballsIntercepted++;
IncrementScore();
QueueSound(new LCDGameSound("../common/hit.ogg"));
}
else
Expand Down
1 change: 1 addition & 0 deletions LCDonald.Core/Model/ILCDGame.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ public interface ILCDGame
event EventHandler Paused;
event EventHandler Resumed;
event EventHandler Stopped;
event EventHandler Scored;

}

Expand Down
3 changes: 3 additions & 0 deletions LCDonald.Core/Model/LCDGameBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public abstract class LCDGameBase : ILCDGame
public event EventHandler Paused;
public event EventHandler Resumed;
public event EventHandler Stopped;
public event EventHandler Scored;
#pragma warning restore CS8618

protected int _customUpdateSpeed = 100;
Expand Down Expand Up @@ -211,6 +212,8 @@ public void Stop()
Stopped?.Invoke(this, new EventArgs());
}

public void IncrementScore() => Scored?.Invoke(this, new EventArgs());

public void Update()
{
UpdateCore();
Expand Down
1 change: 1 addition & 0 deletions LCDonald/App.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
<Application.Resources>
<ResourceDictionary>
<x:Double x:Key="ContentDialogMaxWidth">848</x:Double>
<FontFamily x:Key="DSEG7">avares://LCDonald/Assets#DSEG7 Classic</FontFamily>
</ResourceDictionary>
</Application.Resources>

Expand Down
Binary file added LCDonald/Assets/DSEG7Classic-Italic.ttf
Binary file not shown.
24 changes: 23 additions & 1 deletion LCDonald/ViewModels/MainWindowViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,16 @@ partial void OnGameChanging(ILCDGame game)
Game.Paused -= Game_Paused;
Game.Resumed -= Game_Resumed;
Game.Stopped -= Game_Stopped;
Game.Scored -= Game_Scored;
}

game.Started += Game_Started;
game.Paused += Game_Paused;
game.Resumed += Game_Resumed;
game.Stopped += Game_Stopped;
game.Scored += Game_Scored;

IsEndless = false;
_currentInputs = game.GetAvailableInputs();
}

Expand All @@ -94,6 +97,12 @@ partial void OnAvailableViewsChanged(List<MAMEView> views)
[ObservableProperty]
private bool _isPaused;

[ObservableProperty]
private bool _isEndless;

[ObservableProperty]
private int _score;

[ObservableProperty]
[NotifyCanExecuteChangedFor(nameof(PauseGameCommand))]
[NotifyCanExecuteChangedFor(nameof(StopGameCommand))]
Expand All @@ -110,7 +119,10 @@ private void StartGame()
Game.Resume();
}
else if (!_isGameRunning)
{
IsEndless = false;
Game.Start();
}
}

[RelayCommand]
Expand All @@ -121,7 +133,11 @@ private void StartEndless()
Game.Resume();
}
else if (!_isGameRunning)
{
IsEndless = true;
Score = 0;
Game.Start(true);
}
}

[RelayCommand(CanExecute = "IsGameRunning")]
Expand Down Expand Up @@ -161,7 +177,13 @@ private void Game_Stopped(object? sender, EventArgs e)
IsGameRunning = false;
IsPaused = false;
});

}
private void Game_Scored(object? sender, EventArgs e)
{
if (IsEndless)
{
Score++;
}
}
}

Expand Down
50 changes: 37 additions & 13 deletions LCDonald/Views/MainView.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -189,9 +189,9 @@
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition MinWidth="32" Width="*" MaxWidth="400" />
<ColumnDefinition MinWidth="124" Width="*" />
<ColumnDefinition Width="268"/>
<ColumnDefinition MinWidth="32" Width="3*" MaxWidth="400" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>

<Border Grid.Row="0" Grid.Column="0" Margin="0,4,0,0"
Expand All @@ -204,12 +204,14 @@
<ContentControl Content="{Binding Game.Name}" Grid.Row="0" Grid.Column="0" MinWidth="128"
IsVisible="{Binding #NavView.DisplayMode, Converter={StaticResource MinimalDisplayModeConverter}}"
Margin="8,0" ContentTemplate="{StaticResource GameTitleTemplate}" />

<ui:CommandBarButton Grid.Row="0" Grid.Column="1" HorizontalAlignment="Right" Width="120" Margin="0,0,8,0"

<StackPanel Orientation="Horizontal" Grid.Row="0" Grid.Column="2" Margin="0,0,12,0" HorizontalAlignment="Right">

<ui:CommandBarButton Width="120" Margin="0,0,8,0"
IconSource="{Binding #LCDView.CurrentView, Mode=OneWay, Converter={StaticResource ViewIconConverter}}"
Label="{Binding #LCDView.CurrentView}"
ToolTip.Tip="Change View">
<ui:CommandBarButton.Flyout>
<ui:CommandBarButton.Flyout>
<Flyout>

<StackPanel Orientation="Vertical">
Expand Down Expand Up @@ -242,13 +244,26 @@
</ui:CommandBarButton.Flyout>
</ui:CommandBarButton>

<ui:CommandBarSeparator Grid.Row="0" Grid.Column="1" HorizontalAlignment="Right"/>
<ui:CommandBarSeparator />

<TextBlock FontFamily="{StaticResource DSEG7}" Margin="4,0" HorizontalAlignment="Left"
IsVisible="{Binding IsEndless, Mode=OneWay}" Width="80"
Text="{Binding Score, StringFormat=\{0:000\}}" FontSize="32" VerticalAlignment="Center"/>

<ui:CommandBarButton IconSource="Play" Label="Play" ToolTip.Tip="Play" Command="{Binding StartGameCommand}"
IsVisible="{Binding !IsGameRunning, Mode=OneWay}"/>
<ui:CommandBarButton IconSource="RepeatAll" Label="ENDLESS" ToolTip.Tip="Play (ENDLESS Mode)" Command="{Binding StartEndlessCommand}"
IsVisible="{Binding !IsGameRunning, Mode=OneWay}"/>

<StackPanel IsVisible="{Binding IsGameRunning, Mode=OneWay}" Orientation="Horizontal">
<ui:CommandBarButton IconSource="Play" Label="Resume" ToolTip.Tip="Resume" Command="{Binding StartGameCommand}"
IsVisible="{Binding IsPaused, Mode=OneWay}"/>
<ui:CommandBarButton IconSource="Pause" Label="Pause" ToolTip.Tip="Pause" Command="{Binding PauseGameCommand}"
IsVisible="{Binding !IsPaused, Mode=OneWay}"/>
<ui:CommandBarButton IconSource="Stop" Label="Stop" ToolTip.Tip="Stop" Command="{Binding StopGameCommand}"
IsVisible="True"/>
</StackPanel>

<StackPanel Orientation="Horizontal" Grid.Row="0" Grid.Column="2" Margin="0,0,12,0">
<ui:CommandBarButton IconSource="RepeatAll" Label="ENDLESS" ToolTip.Tip="Play" Command="{Binding StartEndlessCommand}"/>
<ui:CommandBarButton IconSource="Play" Label="Play" ToolTip.Tip="Play" Command="{Binding StartGameCommand}"/>
<ui:CommandBarButton IconSource="Pause" Label="Pause" ToolTip.Tip="Pause" Command="{Binding PauseGameCommand}"/>
<ui:CommandBarButton IconSource="Stop" Label="Stop" ToolTip.Tip="Stop" Command="{Binding StopGameCommand}"/>
<ui:CommandBarSeparator />
<ui:CommandBarButton IconSource="Keyboard" Label="Controls" ToolTip.Tip="Controls">
<ui:CommandBarButton.Flyout>
Expand Down Expand Up @@ -285,9 +300,18 @@
<Border HorizontalAlignment="Stretch" VerticalAlignment="Stretch"
CornerRadius="{StaticResource ControlCornerRadius}"
Grid.Row="1" Grid.ColumnSpan="3" Margin="0,8,0,0"
IsVisible="{Binding !IsEndless, Mode=OneWay}"
ClipToBounds="True">
<Image Source="avares://LCDonald/Assets/bg_1.jpg"
Stretch="UniformToFill" Opacity="0.2"/>
Stretch="UniformToFill" Opacity="0.2"/>
</Border>
<Border HorizontalAlignment="Stretch" VerticalAlignment="Stretch"
CornerRadius="{StaticResource ControlCornerRadius}"
Grid.Row="1" Grid.ColumnSpan="3" Margin="0,8,0,0"
IsVisible="{Binding IsEndless, Mode=OneWay}"
ClipToBounds="True">
<Image Source="avares://LCDonald/Assets/bg_2.jpg"
Stretch="UniformToFill" Opacity="0.2"/>
</Border>

<controls:AvaloniaLCDView x:Name="LCDView" Grid.Row="1" Grid.ColumnSpan="3" Margin="0,8,0,0" Focusable="True"
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ Feel free to look at the [issues](https://github.com/Difegue/LCDonald/issues) if
* [AvaloniaUI](http://avaloniaui.net/)-based frontend, runs on Windows/Mac/Linux -- Backend is pure .NET and can run on (mostly)anything!

All scanned/photographied materials in this repository are ©️SEGA, 2004/2005/2006.
This uses the [DSEG 7-segment font.](https://www.keshikan.net/fonts-e.html)

## Build instructions

Expand Down

0 comments on commit 90332e3

Please sign in to comment.