Quick question

Working on a SwinGame and want to share your progress? Post up a link to your game and let everyone know.

Quick question

Postby oodan on Tue Sep 13, 2011 8:44 pm

Hi I am doing Vbugs and im trying to add a bonus screen when i kill a certain amount of bugs but im not sure where i should add it to the Public Sub Main() can someone please help?
Here is the code:

Module GameLogic
Private listBugs As List(Of Bug)
Private level As Integer
Private GameTimer As Timer
Private PeneltyAt As Integer
Public BugsKilled As Integer
Public Score As Integer
Public Time As Integer
Public scorePenalty As Integer
Private bgNumber As Integer
Private bonusScore As Integer

Public Sub Bonus()



Select Case BugsKilled
Case 5
bonusScore = 100
Score = Score + bonusScore
BonusScreen()
Case 10
bonusScore = 500
Score = Score + bonusScore
BonusScreen()
Case 20
bonusScore = 1000
Score = Score + bonusScore
BonusScreen()
Case 30
bonusScore = 1500
Score = Score + bonusScore
BonusScreen()
Case 40
bonusScore = 2000
Score = Score + bonusScore
BonusScreen()
Case 50
bonusScore = 5000
Score = Score + bonusScore
BonusScreen()

End Select


End Sub
Public Sub BonusScreen()

Core.StopTimer(GameTimer)
Audio.PlaySoundEffect(GameSound("bonus"))
For i As Integer = 1 To 25
Graphics.FillRectangle(Color.FromArgb(5, 0, 0, 255), 0, 0, 800, 600)
Text.DrawText(BugsKilled & "Bugs Killed!! ", Color.Black, GameFont("bear"), 50, 200)
Text.DrawText("+ " & bonusScore, Color.Black, GameFont("cat_scratch"), 330, 300)
Core.RefreshScreen(25)
Core.ProcessEvents()
Next
Core.StartTimer(GameTimer)
End Sub
Public Sub Pause()
Audio.PlaySoundEffect(GameSound("pause"))
Core.PauseTimer(GameTimer)

Do
Graphics.FillRectangle(Color.FromArgb(5, 66, 66, 255), 0, 0, 800, 600)
Graphics.DrawBitmap(GameImage("instructions"), 50, 50)
Core.RefreshScreen(25)
Core.ProcessEvents()
Loop Until Input.WasKeyTyped(Keys.VK_P) Or
SwinGame.Core.WindowCloseRequested() = True
Core.ResumeTimer(GameTimer)

End Sub
Public Sub Penalty()
For i As Integer = 1 To 30

Audio.PlaySoundEffect(GameSound("Penalty"))
Text.DrawText("Too Slow!", Color.Green,
GameFont("comic"), 400, 300)
Text.DrawText("-" & scorePenalty, Color.Green,
GameFont("comic"), 400, 320)
Core.RefreshScreen(25)
Core.ProcessEvents()
Next



End Sub
Public Sub DrawLoser()
Audio.PlaySoundEffect(GameSound("gameover"))
Do

Graphics.ClearScreen(Color.White)
Text.DrawText("YOU", Color.Green,
GameFont("bear"), 300, 10)
Text.DrawText("LOOOOSE!", Color.Red,
GameFont("bear_huge"), 95, 125)
Text.DrawText("You Reached Level" & level,
Color.Green, GameFont("cat_scratch"), 245, 340)
Text.DrawText("And Killed " & BugsKilled & " bugs",
Color.Green, GameFont("cat_scratch"), 240, 400)
Text.DrawText("Press SPACE to play again",
Color.Green,
GameFont("cat_scratch"), 190, 480)
Text.DrawText("Score: " & Score, Color.Green,
GameFont("cat_scratch"), 300, 290)
Core.RefreshScreen(25)
Core.ProcessEvents()
Loop Until Input.WasKeyTyped(Keys.VK_SPACE) Or
SwinGame.Core.WindowCloseRequested = True
If Input.WasKeyTyped(Keys.VK_SPACE) Then
Score = 0
level = 1
LevelSetUp()
End If

End Sub
Public Sub DrawLevelIntro()
For i As Integer = 1 To 50
Graphics.ClearScreen(Color.Black)
Text.DrawText("level " & level, Color.Green,
GameFont("bear"), 180, 200)
Text.DrawText("Score: " & Score, Color.Green,
GameFont("cat_scratch"), 320, 300)
Core.RefreshScreen(25)
Core.ProcessEvents()
Next
End Sub

Public Function EndOfLevel() As Boolean
For Each mybug As Bug In listBugs
If mybug.IsAlive Then
Return False
End If
Next
Return True
End Function
Public Sub LevelSetUp()

Core.StopTimer(GameTimer)
For Each Bug As Bug In listBugs
Bug.CleanUp()
Next
listBugs.Clear()

For i As Integer = 1 To level * 2
listBugs.Add(New Bug)
Next

PeneltyAt = 10000 - 500 * (level - 1)

If PeneltyAt < 500 Then
PeneltyAt = 500
End If
Core.StartTimer(GameTimer)
End Sub

Public Sub DrawMouse()
Dim mousePoint As Point2D
'Replace mouse with a target
mousePoint = Input.GetMousePosition()
Graphics.DrawBitmapOnScreen(GameImage("target"), mousePoint.X, mousePoint.Y)
Input.ShowMouse(False)
End Sub
Public Sub ChangeVolume()
'Change volume with arrow keys
If Input.IsKeyPressed(Keys.VK_UP) = True Then
Audio.SetMusicVolume(Audio.MusicVolume + 0.01F)

End If
If Input.IsKeyPressed(Keys.VK_DOWN) = True Then
Audio.SetMusicVolume(Audio.MusicVolume - 0.01F)
End If
End Sub

Public Sub Main()
'Opens a new Graphics Window
Core.OpenGraphicsWindow("Game", 800, 600)

'Open Audio Device
Audio.OpenAudio()

'Load Resources
LoadResources()
Randomize()
listBugs = New List(Of Bug)

'Make levels
GameTimer = Core.CreateTimer()

level = 1
Score = 0
LevelSetUp()
DrawLevelIntro()

'Game Loop
Do

'Clears the Screen to White
SwinGame.Graphics.ClearScreen(Color.White)
Graphics.DrawBitmap(GameImage("background" & bgNumber), 0, 0)

Time = (PeneltyAt - Core.GetTimerTicks(GameTimer)) / 100


If Input.WasKeyTyped(Keys.VK_P) Then
Pause()
End If

For Each Bug As Bug In listBugs
Bug.Draw()
Bug.Update()

Next


If EndOfLevel() = True Then

level = level + 1
If bgNumber > 1 Then
bgNumber = 0
Else
bgNumber = bgNumber + 1
End If
LevelSetUp()
DrawLevelIntro()

End If

ChangeVolume()

DrawMouse()

'Display statuses
Text.DrawText("level: " & level, Color.Green,
GameFont("cat_scratch"), 320, 2)
Text.DrawText("time: " & Time, Color.Red,
GameFont("comic"), 2, 2)
Text.DrawText("bugs killed: " & BugsKilled, Color.Green,
GameFont("comic"), 2, 60)
Text.DrawText("Score : " & Score, Color.Green,
GameFont("comic"), 2, 30)


'Refreshes the Screen and Processes Input Events
Core.RefreshScreen()
Core.ProcessEvents()

If Time = 0 Then
scorePenalty = 100 * level
Score = Score - scorePenalty

Core.StopTimer(GameTimer)
Core.StartTimer(GameTimer)
Penalty()
DrawLoser()
BugsKilled = 0
bgNumber = 1
End If



Loop Until SwinGame.Core.WindowCloseRequested() = True

'Free Resources and Close Audio, to end the program.
FreeResources()

Audio.CloseAudio()
Music.Stop()
End Sub

End Module
oodan
Apprentice
 
Posts: 6
Joined: Fri Sep 09, 2011 8:15 pm

Re: Quick question

Postby dan3008 on Tue Sep 13, 2011 9:50 pm

Technically you can call it anywhere in the loop, Personaly, I'd call it just before the core.refreshscreen myself. If you want to email me the project I'll take a closer look, and reconfirm

pieman_purple@hotmail.co.uk


Hope that helps


dan

PS its easyer to read if you put youre code in code brackets
Code: Select all
[code][/code]
just for future refreance
dan3008
Journeyman
 
Posts: 43
Joined: Sat Nov 27, 2010 1:57 pm

Re: Quick question

Postby acain on Wed Sep 14, 2011 8:53 am

Sounds like a good extension. Remember that you will need to ensure that they only get the bonus once.

Let us know how it goes.
Cheers,

Andrew Cain
----------
Swinburne University of Technology
Lecturer of Software Development in PSD
User avatar
acain
Site Admin
 
Posts: 252
Joined: Wed Dec 05, 2007 2:35 pm
Location: Swinburne University - Hawthorn - Melbourne

Re: Quick question

Postby oodan on Wed Sep 14, 2011 4:04 pm

Hi dan
I cant send you the project because its over 25MB and my hotmail wont let me send it
oodan
Apprentice
 
Posts: 6
Joined: Fri Sep 09, 2011 8:15 pm

Re: Quick question

Postby dan3008 on Wed Sep 14, 2011 8:51 pm

ah, I can see why the would be a problem, Should have seen that comeing lol.

Ok, Look at somewhere like megaupload, And host it and email me the download link, I'll take a proper look.
dan3008
Journeyman
 
Posts: 43
Joined: Sat Nov 27, 2010 1:57 pm

Re: Quick question

Postby dan3008 on Sun Sep 18, 2011 2:19 am

Well, After 5 min playing with the code, I can get the bonus screen to display. However, Its repeeting every frame. I'm just working on sorting it.
Personaly, I'd add one to the kill count each time its displayed, and then take it into account everywhere else.
I've modified the code, And I'll post the link to redownload it for you once i've checked it

acain
can you think of a better way? Otherwise, nevermind?
dan3008
Journeyman
 
Posts: 43
Joined: Sat Nov 27, 2010 1:57 pm

Re: Quick question

Postby dan3008 on Sun Sep 18, 2011 2:50 am

http://www.mediafire.com/?jaqas1j916i9a8d

There we go

Works really well, However, I would ither slow the bugs or give the gamer longer, Its a little to hard to early im my oppinion
dan3008
Journeyman
 
Posts: 43
Joined: Sat Nov 27, 2010 1:57 pm

Re: Quick question

Postby acain on Sun Sep 18, 2011 8:22 am

You could keep a bonus given at value...

So something like...

Code: Select all
if bonus given at < bugs killed and bugs killed = 10 then
    ... give bonus
    Bonus given at = bugs killed
End if
Cheers,

Andrew Cain
----------
Swinburne University of Technology
Lecturer of Software Development in PSD
User avatar
acain
Site Admin
 
Posts: 252
Joined: Wed Dec 05, 2007 2:35 pm
Location: Swinburne University - Hawthorn - Melbourne

Re: Quick question

Postby dan3008 on Mon Sep 19, 2011 1:29 am

ah yes, i didnt think of doing it thatway lol
That is as easy if not easyer than mine, ah well, Both work to the same final effect.
dan3008
Journeyman
 
Posts: 43
Joined: Sat Nov 27, 2010 1:57 pm

Re: Quick question

Postby oodan on Sat Sep 24, 2011 10:54 am

Thanks for your help guys, it works really well! :)
oodan
Apprentice
 
Posts: 6
Joined: Fri Sep 09, 2011 8:15 pm

Re: Quick question

Postby dan3008 on Sun Sep 25, 2011 4:09 am

:) youre more than welcome. I must say, I do like the idea of a bonus screen.

I strognly recomend that others take a look at this code and have a play with bonus screens. Well done Oodan, brilliant work.
dan3008
Journeyman
 
Posts: 43
Joined: Sat Nov 27, 2010 1:57 pm


Return to Projects

Who is online

Users browsing this forum: No registered users and 1 guest

cron