Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Imports WMPLib
- ' Hey there, SubGenius here.
- ' So, Acid Bounce is my first try into GDI gaming and I have to admit, shit is interesting.
- ' Here are some informations about the game:
- '
- ' The game is seperate into 3 major parts.
- ' 1st is the input. We read what keyboard keys the user types into the keydown sub.
- ' Then it's the GameTime. A timer which makes the whole processing work. Update, check, move, etc.
- ' And last it's the GDI part where we take all the informations and give them shape.
- '
- ' The code is fully commented.
- ' Have fun playing :)
- '
- '
- ' Only3 is the best. <333 i luv u bby :* :*
- '
- Public Class frmMain
- #Region "Variables"
- 'System Variables
- Private WithEvents GameTimer As New Timer With {.Interval = 1}
- Private CenterScreenPoint As Point = New Point(Me.Width / 2, Me.Height / 2)
- Private RandomSeed As New Random
- Private MusicPlayer As New WindowsMediaPlayer ' I use media player so we can pause/change volume.
- Private TotalGameTicks As Integer = 0 'We use this as a time interval to spawn the walls
- 'Game Variables
- Private IsGameRunning As Boolean = False
- Private IsGameFinished As Boolean = False
- Private IsGamePaused As Boolean = False
- 'Game Score / Level
- Private Score As Long = 0
- Private LastGameScore As Long = 0
- Private BestScore As Long = 0
- Private Level As Integer = 1
- Private Gravity As Integer = 0 ' 0 is for top and 1 is for bottom
- 'CheatEngine Protection
- Private ScoreOffset As Integer = 0
- 'Game Objects
- Private PlayerBox As Rectangle
- Class Wall
- Friend TopWall As Rectangle
- Friend PassGap As Rectangle
- Friend BottomWall As Rectangle
- Friend PlayerIn As Boolean
- End Class
- Private SpawnedWalls As New List(Of Wall)
- 'Game Colors 'Caribbean green 'Electric Lime 'Jazzberry Jam 'Deep Sky Blue 'Piggy Pink 'Crimson
- Private GameColorsTable As Color() = {Color.FromArgb(0, 204, 153), Color.FromArgb(206, 255, 29), Color.FromArgb(202, 55, 103), Color.FromArgb(0, 191, 255), Color.FromArgb(253, 221, 230), Color.FromArgb(220, 20, 60)}
- Private PlayerBoxColor As Color
- 'Paint Objects
- Private NormalBrush As Brush = New SolidBrush(Color.FromArgb(32, 32, 39))
- Private NormalBorderBrush As Brush = New SolidBrush(Color.FromArgb(50, 50, 50))
- Private NormalTextFont As Font = New Font("Segoe UI Light", 15)
- Private SmallTextFont As Font = New Font("Segoe UI Light", 10, FontStyle.Bold)
- Private NormalTextColor As Color = Color.FromArgb(125, 125, 125)
- Private HighLightTextColor As Color = Color.FromArgb(0, 192, 192)
- #End Region
- Sub WindowLoad() Handles Me.Load
- Me.SetStyle(ControlStyles.AllPaintingInWmPaint, True) ' Stops the flickering when we update the graphics.
- 'Load Some music :)
- MusicPlayer.settings.autoStart = False
- MusicPlayer.URL = My.Application.Info.DirectoryPath + "\Data\Dj Rolando - Jaguar.mp3" 'Load the file
- MusicPlayer.settings.playCount = -1 'Loop forever
- MusicPlayer.settings.volume = 10 'Headphone users wont get a heart attack.
- 'Generate Cheat Engine offset.
- ScoreOffset = RandomSeed.Next(10, 100)
- 'Load the best score from the settings
- BestScore = My.Settings.BestScore * ScoreOffset
- End Sub
- Private Sub GameRun() Handles GameTimer.Tick
- TotalGameTicks += 1
- If IsGameRunning = True And IsGameFinished = False Then
- 'Move the box towards the gravity point.
- If Gravity = 0 Then PlayerBox.Y -= 3 Else PlayerBox.Y += 3
- 'Check if the box touches the top or bottom floors.
- If (PlayerBox.Y + PlayerBox.Height) >= ClientSize.Height Or PlayerBox.Y <= 0 Then
- IsGameRunning = False
- IsGameFinished = True
- MusicPlayer.controls.stop()
- GameTimer.Stop()
- SpawnedWalls.Clear()
- LastGameScore = Score
- If Score >= BestScore Then BestScore = Score
- My.Settings.BestScore = BestScore / ScoreOffset
- End If
- 'Spawn Walls
- If TotalGameTicks Mod 150 = 0 Then
- Dim TempWall As New Wall
- Dim PassGapHeight As Integer = RandomSeed.Next(60, Height - 180)
- TempWall.PassGap = New Rectangle(Width - 60, PassGapHeight, 60, 100)
- TempWall.TopWall = New Rectangle(Width - 60, 0, 60, PassGapHeight)
- TempWall.BottomWall = New Rectangle(Width - 60, PassGapHeight + 120, 60, Height - PassGapHeight)
- TempWall.PlayerIn = False
- SpawnedWalls.Add(TempWall)
- End If
- 'Move the walls
- For Each Wall In SpawnedWalls.ToArray
- If Wall.PassGap.X <= -60 Then
- SpawnedWalls.Remove(Wall)
- End If
- Wall.PassGap.X -= (2 + Level)
- Wall.TopWall.X -= (2 + Level)
- Wall.BottomWall.X -= (2 + Level)
- Next
- 'Check If player touches the walls.
- For Each Wall In SpawnedWalls.ToArray
- 'If the box touches the top or bottom wall, end the game.
- If PlayerBox.IntersectsWith(Wall.TopWall) Or PlayerBox.IntersectsWith(Wall.BottomWall) Then
- IsGameRunning = False
- IsGameFinished = True
- MusicPlayer.controls.stop()
- GameTimer.Stop()
- SpawnedWalls.Clear()
- LastGameScore = Score
- If Score >= BestScore Then BestScore = Score
- My.Settings.BestScore = CLng(BestScore / ScoreOffset)
- End If
- 'If the player goes into the gap.
- If PlayerBox.IntersectsWith(Wall.PassGap) And Wall.PlayerIn = False Then
- Wall.PlayerIn = True
- End If
- 'If the player was in the gap and now he left, give him some points.
- If Wall.PlayerIn = True Then
- If PlayerBox.IntersectsWith(Wall.PassGap) = False Then
- Score += ScoreOffset
- Wall.PlayerIn = False
- End If
- End If
- Next
- 'For every 30 points, make the game harder
- If Score / ScoreOffset <> 0 Then If ((Score / ScoreOffset) Mod 30 = 0) Then Level += 1
- End If
- If TotalGameTicks = 1000 Then TotalGameTicks = 0
- Invalidate() 'Paint our stuff.
- End Sub
- Private Sub frmMain_KeyDown(sender As Object, e As KeyEventArgs) Handles MyBase.KeyDown
- ' If the game state is not running.
- If IsGameRunning = False And IsGameFinished = False Then
- If e.KeyCode = Keys.Space Then 'If space is pressed start the game.
- GameTimer.Start()
- IsGameRunning = True
- IsGameFinished = False
- Score = 0
- Gravity = RandomSeed.Next(0, 2) 'Make the start Gravity random to bottom or top
- Level = 1
- 'Create the PlayerBox, and give it a random color.
- PlayerBox = New Rectangle(200, CenterScreenPoint.Y, 50, 50)
- PlayerBoxColor = GameColorsTable(RandomSeed.Next(0, 4))
- 'Play the BG music
- MusicPlayer.controls.play()
- End If
- 'If escape is pressed, exit game
- If e.KeyCode = Keys.Escape Then
- Application.Exit()
- End If
- Exit Sub
- End If
- 'If The game is running.
- If IsGameRunning = True And IsGamePaused = False Then
- If e.KeyCode = Keys.Space Then 'If space is pressed change the gravity.
- 'Toogle gravity
- If Gravity = 0 Then
- Gravity = 1
- PlayerBox.Y += 3
- Else
- Gravity = 0
- PlayerBox.Y -= 3
- End If
- End If
- 'If escape is pressed while game is running, pause the game.
- If e.KeyCode = Keys.Escape Then
- GameTimer.Stop()
- IsGamePaused = True
- MusicPlayer.controls.pause()
- Invalidate() 'Because we stoped the game timer we must update the game manualy
- End If
- Exit Sub
- End If
- 'If game is paused
- If IsGameRunning = True And IsGamePaused = True Then
- If e.KeyCode = Keys.Space Then 'If space is pressed, unpause the game
- IsGamePaused = False
- GameTimer.Start()
- MusicPlayer.controls.play()
- End If
- Exit Sub
- End If
- 'If the game is finished
- If IsGameRunning = False And IsGameFinished = True Then
- If e.KeyCode = Keys.Escape Then 'If space is pressed show the main menu.
- IsGameFinished = False
- Invalidate()
- End If
- End If
- End Sub
- Private Sub frmMain_Paint(sender As Object, e As PaintEventArgs) Handles MyBase.Paint
- With e.Graphics
- .CompositingQuality = Drawing2D.CompositingQuality.HighSpeed ' i have no idea
- .Clear(Color.FromArgb(22, 22, 29)) ' paint the background.
- 'Paint The Starting Screen Menu
- If IsGameRunning = False And IsGameFinished = False Then
- .FillRectangle(NormalBrush, 242, 180, 200, 100)
- .DrawString("Acid Bounce", NormalTextFont, New SolidBrush(HighLightTextColor), 288, 184)
- .DrawString("Press Space To Start", NormalTextFont, New SolidBrush(NormalTextColor), 254, 216)
- .DrawString("Press Escape to exit and save.", SmallTextFont, New SolidBrush(NormalTextColor), 253, 260)
- .DrawRectangle(New Pen(NormalBorderBrush), 241, 179, 201, 101)
- End If
- 'Paint The Paused Screen Menu
- If IsGameRunning = True And IsGamePaused = True Then
- .FillRectangle(NormalBrush, 242, 180, 200, 100)
- .DrawString("Acid Bounce", NormalTextFont, New SolidBrush(HighLightTextColor), 288, 184)
- .DrawString("Press Space To Resume", NormalTextFont, New SolidBrush(NormalTextColor), 239, 226)
- .DrawRectangle(New Pen(NormalBorderBrush), 241, 179, 201, 101)
- End If
- 'Paint The End Game Screen Menu
- If IsGameRunning = False And IsGameFinished = True Then
- .FillRectangle(NormalBrush, 242, 180, 200, 100)
- .DrawString("Acid Bounce", NormalTextFont, New SolidBrush(HighLightTextColor), 288, 184)
- .DrawString("Your Score: " & (Score / ScoreOffset).ToString, NormalTextFont, New SolidBrush(NormalTextColor), 265, 220)
- .DrawString("Press Escape to play again", SmallTextFont, New SolidBrush(NormalTextColor), 263, 260)
- .DrawRectangle(New Pen(NormalBorderBrush), 241, 179, 201, 101)
- End If
- 'Paint The Game
- If IsGameRunning = True And IsGamePaused = False Then
- 'Paint the PlayerBox
- .FillRectangle(New SolidBrush(PlayerBoxColor), PlayerBox)
- 'Draw The Gravity Icon
- If Gravity = 0 Then
- .DrawString("▲", NormalTextFont, New SolidBrush(Color.White), PlayerBox.X + ((PlayerBox.Width / 2)), PlayerBox.Y + ((PlayerBox.Height / 2)))
- Else
- .DrawString("▼", NormalTextFont, New SolidBrush(Color.White), PlayerBox.X + ((PlayerBox.Width / 2)), PlayerBox.Y + ((PlayerBox.Height / 2)))
- End If
- 'Draw Walls
- For Each Wall As Wall In SpawnedWalls
- Dim RandomWallColor As Color = GameColorsTable(RandomSeed.Next(0, 4))
- .FillRectangle(New SolidBrush(RandomWallColor), Wall.TopWall)
- .FillRectangle(New SolidBrush(RandomWallColor), Wall.BottomWall)
- Next
- 'Show the score on screen.
- If Score > BestScore Then 'If the current score is biggerst than the best, show current score as best.
- .DrawString("Score: " & (Score / ScoreOffset).ToString & " | Last Game: " & (LastGameScore / ScoreOffset).ToString & " | Best: " & (Score / ScoreOffset).ToString, SmallTextFont, New SolidBrush(NormalTextColor), 2, 2)
- Else
- .DrawString("Score: " & (Score / ScoreOffset).ToString & " | Last Game: " & (LastGameScore / ScoreOffset).ToString & " | Best: " & (BestScore / ScoreOffset).ToString, SmallTextFont, New SolidBrush(NormalTextColor), 2, 2)
- End If
- End If
- End With
- End Sub
- End Class
Advertisement
Add Comment
Please, Sign In to add comment