functions/outdated/Start-MiniGameFireworkOld.ps1
|
function Start-MiniGameFireworkOld { <# .SYNOPSIS [OUDATED VERSION] of the fireworks in the Terminal A function for creating fireworks in the Terminal. .DESCRIPTION A function for creating fireworks in the Terminal. Shoots fireworks in random intervalls. May not work correctly at times. Mainly just testing capabillities of Powershell Terminal. .OUTPUTS *..* *_\/_* '.\'/.' *..* -= o =- .'/.\'. ' = o = . . ^ . ^ .EXAMPLE Start Fireworks with cure hearts only: PS> Start-Fireworks hearts .LINK #> [CmdletBinding( )] param ( [Parameter( Position = 0 )] [System.String] [ValidateSet( 'hearts', 'normal' )] $FireworkType, [Parameter( Position = 1, Mandatory = $false )] [ValidateRange(1, 50)] $FireworkLaunchIntervall = 20, [Parameter( Position = 2, Mandatory = $false )] [ValidateRange(1, 1000)] [System.Int32] $TickIntervall = 5 ) $fireworkExplosionColors = @( "`e[91m", # BRIGTH RED FOREGROUND "`e[92m", # BRIGTH GREEN FOREGROUND "`e[93m", # BRIGTH YELLOW FOREGROUND "`e[94m", # BRIGTH BLUE FOREGROUND "`e[95m", # BRIGTH MAGENTA FOREGROUND "`e[96m" # BRIGTH CYAN FOREGROUND # "`e[97m" # BRIGTH WHITE FOREGROUND ) $fireworkExplosionTypes = $null if ($FireWorkType -IEQ 'hearts') { $fireworkExplosionColors = @( "`e[91m", # BRIGTH RED FOREGROUND "`e[95m" # BRIGTH MAGENTA FOREGROUND ) $fireworkExplosionTypes = (Import-PowerShellDataFile -Path "$PSScriptRoot/../assets/data/fireworks.hearts.psd1").fire_works } else { $fireworkExplosionTypes = (Import-PowerShellDataFile -Path "$PSScriptRoot/../assets/data/fireworks.normal.psd1").fire_works } # The configurations for this game $Configuration = @{ RequiredGameHeight = 15 RequiredGameWidth = 40 # Objects get drawn in that order. Following objects will potentially hide previous objects. GameObjects = [ordered]@{ Fireworks = [PSCustomObject[]]@( @{ position = [System.Numerics.Vector2]::new( 50, 12 ) velocity = [System.Numerics.Vector2]::new(0, -0.2) canvas = @( '.', '^' ) explosionHeight = 7 } ) Fireworks_Explosions = [PSCustomObject[]]@() Fireworks_staticText = [PSCustomObject]@{ position = [System.Numerics.Vector2]::new(1, 0) canvas = @( "Explosions:" ) } Fireworks_count = [PSCustomObject]@{ position = [System.Numerics.Vector2]::new(13, 0) canvas = @( "00" ) current = 0 } } onEveryTickDo = { param($GameObects, $GameWidth, $GameHeight) # Generate new fireworks at random intervals between 0 and 50 ticks. if ((Get-Random -Minimum 0 -Maximum $FireworkLaunchIntervall) -EQ 0) { $GameObects['Fireworks'] += [PSCustomObject]@{ position = [System.Numerics.Vector2]::new( (Get-Random -Minimum 10 -Maximum ($GameWidth - 10)), $GameHeight - 2 ) velocity = [System.Numerics.Vector2]::new(0, -0.2) canvas = @( '.', '^' ) explosionHeight = Get-Random -Minimum 4 -Maximum ($GameHeight - 7) } } # Redraw the count of explosions on every tick. if ($GameObects['Fireworks_count'].current -NE $GameObects['Fireworks_Explosions'].Count) { $GameObects['Fireworks_count'].redrawMark = $true $GameObects['Fireworks_count'].current = $GameObects['Fireworks_Explosions'].Count $GameObects['Fireworks_count'].canvas[0] = $($GameObects['Fireworks_Explosions'].Count) } # Update the fireworks to explode on a certain height. foreach ($firework in $GameObects['Fireworks']) { if ([System.Math]::Round($firework.position.y) -LT $firework.explosionHeight) { $firework.isDead = $true $randomColor = Get-Random -Minimum 0 -Maximum ($fireworkExplosionColors.Count) $randomExplosion = Get-Random -Minimum 0 -Maximum ($fireworkExplosionTypes.Count) $fireworkColor = $fireworkExplosionColors | Select-Object -Skip $randomColor -First 1 $fireworkType = $fireworkExplosionTypes | Select-Object -Skip $randomExplosion -First 1 $GameObects['Fireworks_Explosions'] += [PSCustomObject]@{ position = [System.Numerics.Vector2]::new( ($firework.position.x - $fireworkType[0][0].Length / 2), $firework.position.y #+ $fireworkType.Count / 2 ) stageTime = 0 maxStageTime = 20 currentStage = $fireworkType.Count - 1 stages = $fireworkType canvas = $fireworkType | Select-Object -Last 1 colorcodes = $fireworkColor } } } # Update the explosions on every tick. foreach ($explosion in $GameObects['Fireworks_Explosions']) { $explosion.stageTime += 1 if ($explosion.stageTime -GT $explosion.maxStageTime) { $explosion.stageTime = 0 $explosion.currentStage -= 1 if ($explosion.currentStage -LT 0) { $explosion.isDead = $true } else { $explosion.redrawMark = $true $explosion.canvas = $explosion.stages[$explosion.currentStage] } } } } onExitScreen = { param($object, $GameObjects, $didExitLeft, $didExitRigth, $didExitUp, $didExitDown) if ($didExitUp -AND $object.ParentName -EQ 'Fireworks') { $object.isDead = $true } } onKeyEvent = { param($KeyEvent, $GameObects) } onCollision = { param($collider, $participants) } } # Start a generic gameloop with the configurations for this game. Start-MiniGameLoop @Configuration -TickIntervall $TickIntervall } |