'--------------------------------'
' Game (c) 2006 Ciardo Niccolò '
' Un gioco d'esempio '
' mail to: mr.shutdown@gmail.com '
'--------------------------------'
'----------------------'
' Variabili e Costanti '
'----------------------'
Dim Game As Boolean ' Stato del gioco
Dim GameOver As Boolean ' Game Over
Dim Level As Integer ' Livello
Dim Score As Integer ' Punteggio
Dim Speed As Double ' Velocità di movimento della palla
Dim BallDefXPos As Integer ' Ball Default X Position
Dim BallDefYPos As Integer ' Ball Default Y Position
Dim BallDefMove As Integer ' Ball Default Move
Dim BallDefLeft As Boolean ' Ball Default Left
Dim BallDefTop As Boolean ' Ball Default Top
Dim BoardDefXPos As Integer ' Board Default X Position
Dim BoardDefYPos As Integer ' Board Default Y Position
Dim BoardDefMove As Integer ' Board Default Move
'----------------------'
' Procedure e Funzioni '
'----------------------'
Sub NewGame()
Game = True
GameOver = False
Level = 1
Score = 0
Speed = 0
Ball.Left = BallDefXPos
Ball.Top = BallDefYPos
BallDefLeft = False
BallDefTop = True
BallDefMove = 80
Ball.Visible = True
Board.Left = BoardDefXPos
Board.Top = BoardDefYPos
Board.Visible = True
BoardDefMove = 200
MainForm.Caption = "Game"
End Sub
Sub PauseGame()
If Game Then
Game = False
MainForm.Caption = MainForm.Caption + " - Pause"
Else
Game = True
MainForm.Caption = "Game"
End If
End Sub
Sub MoveBall()
Select Case BallDefLeft
Case True
If (Ball.Left - BallDefMove) > (Space.ScaleLeft) Then
Ball.Left = Ball.Left - BallDefMove
BallDefLeft = True
Else
BallDefLeft = False
End If
Case False
If (Ball.Left + BallDefMove) < (Space.ScaleWidth - Ball.Width) Then
Ball.Left = Ball.Left + BallDefMove
BallDefLeft = False
Else
BallDefLeft = True
End If
End Select
Select Case BallDefTop
Case True
If (Ball.Top - BallDefMove) > (Space.ScaleTop) Then
Ball.Top = Ball.Top - BallDefMove
BallDefTop = True
Else
BallDefTop = False
End If
Case False
If (Ball.Top + BallDefMove) < (Space.ScaleHeight - Ball.Height) Then
Ball.Top = Ball.Top + BallDefMove
BallDefTop = False
Else
BallDefTop = True
End If
End Select
End Sub
Sub MoveBoard(KeyCode As Integer)
Select Case KeyCode
Case vbKeyLeft
If (Board.Left - BoardDefMove) > (Space.ScaleLeft) Then
Board.Left = Board.Left - BoardDefMove
End If
Case vbKeyRight
If (Board.Left + BoardDefMove) < (Space.ScaleWidth - Board.Width) Then
Board.Left = Board.Left + BoardDefMove
End If
End Select
End Sub
Sub CheckGame()
If ((Ball.Left <= (Board.Left + Board.Width)) And ((Ball.Left + Ball.Width) >= Board.Left)) And ((Ball.Top + Ball.Height) >= Board.Top) Then
BallDefTop = True
Score = Score + 10
Speed = Speed + 0.25
If Score = (Level * 100) Then
Level = Level + 1
BallDefMove = BallDefMove + Speed
End If
End If
If (Ball.Top + Ball.Height) > (Board.Top + Board.Height) Then
Game = False
GameOver = True
MainForm.Caption = MainForm.Caption + " - Game Over"
End If
End Sub
'--------'
' Eventi '
'--------'
Private Sub Form_Load()
Game = False
GameOver = False
Level = 1
Score = 0
Speed = 0
BallDefXPos = (Space.ScaleWidth / 2) - (Ball.Width / 2)
BallDefYPos = Ball.Top
BoardDefXPos = (Space.ScaleWidth / 2) - (Board.Width / 2)
BoardDefYPos = Board.Top
ScoreLabel.Caption = "Score: " & Score
LevelLabel.Caption = "Level: " & Level
End Sub
Private Sub Clock_Timer()
If Game Then
Call MainForm.Refresh
Call MoveBall
Call CheckGame
ScoreLabel.Caption = "Score: " & Score
LevelLabel.Caption = "Level: " & Level
End If
End Sub
Private Sub Space_KeyDown(KeyCode As Integer, Shift As Integer)
If (KeyCode = vbKeyP) And (GameOver = False) Then
Call PauseGame
End If
If Game Then
Call MoveBoard(KeyCode)
End If
End Sub
Private Sub NewGameMenu_Click()
Call NewGame
End Sub
Private Sub QuitMenu_Click()
End
End Sub
Private Sub HowToMenu_Click()
If Game Then
Call PauseGame
End If
HowToForm.Show (vbModal)
End Sub
Private Sub AboutMenu_Click()
If Game Then
Call PauseGame
End If
AboutForm.Show (vbModal)
End Sub