A downloadable game

# Assicura il caricamento delle librerie grafiche di Windows Forms

Add-Type -AssemblyName System.Windows.Forms

Add-Type -AssemblyName System.Drawing

# 1. Definizione della Finestra di Gioco (GUI stile Retro 8-bit)

$Form = New-Object System.Windows.Forms.Form

$Form.Text = "PowerSpace Invaders 1980"

$Form.Size = New-Object System.Drawing.Size(600, 600)

$Form.StartPosition = "CenterScreen"

$Form.BackColor = [System.Drawing.Color]::Black

$Form.FormBorderStyle = "FixedSingle"

$Form.MaximizeBox = $false

# Variabili di Stato del Gioco

$Script:PlayerX = 270

$Script:PlayerY = 480

$Script:LaserActive = $false

$Script:LaserX = 0

$Script:LaserY = 0

$Script:AlienX = 50

$Script:AlienY = 50

$Script:AlienDirection = 5

$Script:Score = 0

$Script:GameOver = $false

# 2. Creazione del Player (Navicella - Rettangolo Verde Retro)

$Player = New-Object System.Windows.Forms.Label

$Player.Size = New-Object System.Drawing.Size(50, 20)

$Player.Location = New-Object System.Drawing.Point($Script:PlayerX, $Script:PlayerY)

$Player.BackColor = [System.Drawing.Color]::LimeGreen

$Form.Controls.Add($Player)

# 3. Creazione dell'Alieno (Rettangolo Rosso Retro)

$Alien = New-Object System.Windows.Forms.Label

$Alien.Size = New-Object System.Drawing.Size(40, 30)

$Alien.Location = New-Object System.Drawing.Point($Script:AlienX, $Script:AlienY)

$Alien.BackColor = [System.Drawing.Color]::Red

$Form.Controls.Add($Alien)

# 4. Creazione del Laser (Linea Gialla)

$Laser = New-Object System.Windows.Forms.Label

$Laser.Size = New-Object System.Drawing.Size(4, 15)

$Laser.BackColor = [System.Drawing.Color]::Yellow

$Laser.Visible = $false

$Form.Controls.Add($Laser)

# 5. Interfaccia Punteggio

$ScoreLabel = New-Object System.Windows.Forms.Label

$ScoreLabel.Size = New-Object System.Drawing.Size(200, 30)

$ScoreLabel.Location = New-Object System.Drawing.Point(10, 10)

$ScoreLabel.ForeColor = [System.Drawing.Color]::White

$ScoreLabel.Text = "SCORE: 0000"

$ScoreLabel.Font = New-Object System.Drawing.Font("Courier New", 14, [System.Drawing.FontStyle]::Bold)

$Form.Controls.Add($ScoreLabel)

# 6. Messaggio di Game Over (Invisibile all'inizio)

$GameOverLabel = New-Object System.Windows.Forms.Label

$GameOverLabel.Size = New-Object System.Drawing.Size(400, 50)

$GameOverLabel.Location = New-Object System.Drawing.Point(100, 250)

$GameOverLabel.ForeColor = [System.Drawing.Color]::Red

$GameOverLabel.Text = "GAME OVER"

$GameOverLabel.TextAlign = "MiddleCenter"

$GameOverLabel.Font = New-Object System.Drawing.Font("Courier New", 28, [System.Drawing.FontStyle]::Bold)

$GameOverLabel.Visible = $false

$Form.Controls.Add($GameOverLabel)

# 7. Ciclo di Gioco Principale (Timer)

$GameTimer = New-Object System.Windows.Forms.Timer

$GameTimer.Interval = 20 # ~50 FPS

$GameTimer.Add_Tick({

if ($Script:GameOver) { return }

# ---- MOVIMENTO ALIENO ----

$Script:AlienX += $Script:AlienDirection

if ($Script:AlienX -le 0 -or $Script:AlienX -ge 540) {

$Script:AlienDirection *= -1

$Script:AlienY += 25 # Scende di livello

}

$Alien.Location = New-Object System.Drawing.Point($Script:AlienX, $Script:AlienY)

# ---- MOVIMENTO LASER ----

if ($Script:LaserActive) {

$Script:LaserY -= 12

if ($Script:LaserY -lt 0) {

$Script:LaserActive = $false

$Laser.Visible = $false

} else {

$Laser.Location = New-Object System.Drawing.Point($Script:LaserX, $Script:LaserY)

# Controllo Collisione Laser -> Alieno

if ($Script:LaserX -ge $Script:AlienX -and $Script:LaserX -le ($Script:AlienX + 40) -and

$Script:LaserY -ge $Script:AlienY -and $Script:LaserY -le ($Script:AlienY + 30)) {

# Collisione! Resetta alieno e aumenta punteggio

$Script:Score += 100

$ScoreLabel.Text = "SCORE: " + $Script:Score.ToString("D4")

$Script:AlienY = 50

$Script:AlienX = Get-Random -Minimum 50 -Maximum 450

$Script:LaserActive = $false

$Laser.Visible = $false

}

}

}

# ---- CONDIZIONI DI GAME OVER ----

if ($Script:AlienY -ge ($Script:PlayerY - 20)) {

$Script:GameOver = $true

$GameOverLabel.Visible = $true

$GameTimer.Stop()

}

})

# 8. Gestione Input Tastiera (Comandi)

$Form.Add_KeyDown({

param($Sender, $EventArgs)

switch ($EventArgs.KeyCode) {

"Left" {

if ($Script:PlayerX -gt 10) { $Script:PlayerX -= 20 }

$Player.Location = New-Object System.Drawing.Point($Script:PlayerX, $Script:PlayerY)

}

"Right" {

if ($Script:PlayerX -lt 520) { $Script:PlayerX += 20 }

$Player.Location = New-Object System.Drawing.Point($Script:PlayerX, $Script:PlayerY)

}

"Space" {

if (-not $Script:LaserActive -and -not $Script:GameOver) {

$Script:LaserActive = $true

$Script:LaserX = $Script:PlayerX + 23 # Centro della navicella

$Script:LaserY = $Script:PlayerY - 15

$Laser.Location = New-Object System.Drawing.Point($Script:LaserX, $Script:LaserY)

$Laser.Visible = $true

}

}

}

})

# Avvia il gioco

$GameTimer.Start()

[System.Windows.Forms.Application]::Run($Form)

Published 9 days ago
StatusReleased
AuthorTttt89weee
GenreAdventure

Comments

Log in with itch.io to leave a comment.

is apowershell projec