Questo sito utilizza cookies solo per scopi di autenticazione sul sito e nient'altro. Nessuna informazione personale viene tracciata. Leggi l'informativa sui cookies.
Username: Password: oppure
Game - MainForm.frm

MainForm.frm

Caricato da: Shutdown
Scarica il programma completo

  1. '--------------------------------'
  2. '  Game (c) 2006 Ciardo Niccolò  '
  3. '       Un gioco d'esempio       '
  4. ' mail to: mr.shutdown@gmail.com '
  5. '--------------------------------'
  6.  
  7. '----------------------'
  8. ' Variabili e Costanti '
  9. '----------------------'
  10.  
  11. Dim Game As Boolean ' Stato del gioco
  12. Dim GameOver As Boolean ' Game Over
  13. Dim Level As Integer ' Livello
  14. Dim Score As Integer ' Punteggio
  15. Dim Speed As Double ' Velocità di movimento della palla
  16. Dim BallDefXPos As Integer ' Ball Default X Position
  17. Dim BallDefYPos As Integer ' Ball Default Y Position
  18. Dim BallDefMove As Integer ' Ball Default Move
  19. Dim BallDefLeft As Boolean ' Ball Default Left
  20. Dim BallDefTop As Boolean ' Ball Default Top
  21. Dim BoardDefXPos As Integer ' Board Default X Position
  22. Dim BoardDefYPos As Integer ' Board Default Y Position
  23. Dim BoardDefMove As Integer ' Board Default Move
  24.  
  25. '----------------------'
  26. ' Procedure e Funzioni '
  27. '----------------------'
  28.  
  29. Sub NewGame()
  30.     Game = True
  31.     GameOver = False
  32.     Level = 1
  33.     Score = 0
  34.     Speed = 0
  35.     Ball.Left = BallDefXPos
  36.     Ball.Top = BallDefYPos
  37.     BallDefLeft = False
  38.     BallDefTop = True
  39.     BallDefMove = 80
  40.     Ball.Visible = True
  41.     Board.Left = BoardDefXPos
  42.     Board.Top = BoardDefYPos
  43.     Board.Visible = True
  44.     BoardDefMove = 200
  45.     MainForm.Caption = "Game"
  46. End Sub
  47.  
  48. Sub PauseGame()
  49.     If Game Then
  50.         Game = False
  51.         MainForm.Caption = MainForm.Caption + " - Pause"
  52.     Else
  53.         Game = True
  54.         MainForm.Caption = "Game"
  55.     End If
  56. End Sub
  57.  
  58. Sub MoveBall()
  59.     Select Case BallDefLeft
  60.         Case True
  61.             If (Ball.Left - BallDefMove) > (Space.ScaleLeft) Then
  62.                 Ball.Left = Ball.Left - BallDefMove
  63.                 BallDefLeft = True
  64.             Else
  65.                 BallDefLeft = False
  66.             End If
  67.         Case False
  68.             If (Ball.Left + BallDefMove) < (Space.ScaleWidth - Ball.Width) Then
  69.                 Ball.Left = Ball.Left + BallDefMove
  70.                 BallDefLeft = False
  71.             Else
  72.                 BallDefLeft = True
  73.             End If
  74.     End Select
  75.     Select Case BallDefTop
  76.         Case True
  77.             If (Ball.Top - BallDefMove) > (Space.ScaleTop) Then
  78.                 Ball.Top = Ball.Top - BallDefMove
  79.                 BallDefTop = True
  80.             Else
  81.                 BallDefTop = False
  82.             End If
  83.         Case False
  84.             If (Ball.Top + BallDefMove) < (Space.ScaleHeight - Ball.Height) Then
  85.                 Ball.Top = Ball.Top + BallDefMove
  86.                 BallDefTop = False
  87.             Else
  88.                 BallDefTop = True
  89.             End If
  90.     End Select
  91. End Sub
  92.  
  93. Sub MoveBoard(KeyCode As Integer)
  94.     Select Case KeyCode
  95.         Case vbKeyLeft
  96.             If (Board.Left - BoardDefMove) > (Space.ScaleLeft) Then
  97.                 Board.Left = Board.Left - BoardDefMove
  98.             End If
  99.         Case vbKeyRight
  100.             If (Board.Left + BoardDefMove) < (Space.ScaleWidth - Board.Width) Then
  101.                 Board.Left = Board.Left + BoardDefMove
  102.             End If
  103.     End Select
  104. End Sub
  105.  
  106. Sub CheckGame()
  107.     If ((Ball.Left <= (Board.Left + Board.Width)) And ((Ball.Left + Ball.Width) >= Board.Left)) And ((Ball.Top + Ball.Height) >= Board.Top) Then
  108.         BallDefTop = True
  109.         Score = Score + 10
  110.         Speed = Speed + 0.25
  111.         If Score = (Level * 100) Then
  112.             Level = Level + 1
  113.             BallDefMove = BallDefMove + Speed
  114.         End If
  115.     End If
  116.     If (Ball.Top + Ball.Height) > (Board.Top + Board.Height) Then
  117.         Game = False
  118.         GameOver = True
  119.         MainForm.Caption = MainForm.Caption + " - Game Over"
  120.     End If
  121. End Sub
  122.  
  123. '--------'
  124. ' Eventi '
  125. '--------'
  126.  
  127. Private Sub Form_Load()
  128.     Game = False
  129.     GameOver = False
  130.     Level = 1
  131.     Score = 0
  132.     Speed = 0
  133.     BallDefXPos = (Space.ScaleWidth / 2) - (Ball.Width / 2)
  134.     BallDefYPos = Ball.Top
  135.     BoardDefXPos = (Space.ScaleWidth / 2) - (Board.Width / 2)
  136.     BoardDefYPos = Board.Top
  137.     ScoreLabel.Caption = "Score: " & Score
  138.     LevelLabel.Caption = "Level: " & Level
  139. End Sub
  140.  
  141. Private Sub Clock_Timer()
  142.     If Game Then
  143.         Call MainForm.Refresh
  144.         Call MoveBall
  145.         Call CheckGame
  146.         ScoreLabel.Caption = "Score: " & Score
  147.         LevelLabel.Caption = "Level: " & Level
  148.     End If
  149. End Sub
  150.  
  151. Private Sub Space_KeyDown(KeyCode As Integer, Shift As Integer)
  152.     If (KeyCode = vbKeyP) And (GameOver = False) Then
  153.         Call PauseGame
  154.     End If
  155.     If Game Then
  156.         Call MoveBoard(KeyCode)
  157.     End If
  158. End Sub
  159.  
  160. Private Sub NewGameMenu_Click()
  161.     Call NewGame
  162. End Sub
  163.  
  164. Private Sub QuitMenu_Click()
  165.     End
  166. End Sub
  167.  
  168. Private Sub HowToMenu_Click()
  169.     If Game Then
  170.         Call PauseGame
  171.     End If
  172.     HowToForm.Show (vbModal)
  173. End Sub
  174.  
  175. Private Sub AboutMenu_Click()
  176.     If Game Then
  177.         Call PauseGame
  178.     End If
  179.     AboutForm.Show (vbModal)
  180. End Sub