An attempt at a small fishing game - Delsus - 04-20-2025
I tried to recreate the Stardew Valley fishing mini-game in QB64, with moderate success. Please let me know what you think!
Code: (Select All)
_Title "Fishing Game - Stardew Valley Style by Delsus"
Screen _NewImage(1920, 1080, 32): Randomize Timer
Const TIMER_BAR_WIDTH = 100: Const TIMER_BAR_HEIGHT = 600: Const FISHING_BAR_WIDTH = 400
Const FISHING_BAR_HEIGHT = 600: Const FISH_SIZE = 60: Const CATCH_RECT_BASE_HEIGHT = 150
Dim Shared gameState As Integer ' 0=waiting, 1=fishing, 2=catching, 3=caught, 4=missed
Dim Shared fishY As Single: Dim Shared fishDirection As Single
Dim Shared fishSpeed As Single: Dim Shared catchRectY As Single
Dim Shared catchRectSpeed As Single: Dim Shared catchRectHeight As Single
Dim Shared catchProgress As Single: Dim Shared timerProgress As Single
Dim Shared score As Integer: Dim Shared difficulty As Integer
Dim Shared spacePressed As Integer: Dim Shared itemCaught As String
Call InitializeGame
Do
Cls
Select Case gameState
Case 0
If _KeyDown(32) Then ' Space key
gameState = 1
timerProgress = 100
End If
Case 1
timerProgress = timerProgress - 0.2
If timerProgress <= 0 Then
gameState = 0
End If
If Rnd < 0.015 Then
gameState = 2
Call SetupCatch
End If
Case 2
If _KeyDown(32) Then 'Space key
catchRectSpeed = -6 ' Move up when space pressed
Else
catchRectSpeed = 4 ' Fall down when space released
End If
' Move catching rectangle
catchRectY = catchRectY + catchRectSpeed
If catchRectY < 0 Then catchRectY = 0
If catchRectY > FISHING_BAR_HEIGHT - catchRectHeight Then
catchRectY = FISHING_BAR_HEIGHT - catchRectHeight
End If
' Move fish (more erratic movement)
fishY = fishY + fishDirection * fishSpeed
If fishY < 0 Or fishY > FISHING_BAR_HEIGHT - FISH_SIZE Then
fishDirection = -fishDirection * (0.7 + Rnd * 0.6)
fishY = fishY + fishDirection * fishSpeed
End If
' Random direction changes
If Rnd < 0.04 Then
fishDirection = (Rnd * 2) - 1
fishSpeed = 3 + difficulty + Rnd * 2
End If
' Check if fish is in catching rectangle
If fishY + FISH_SIZE / 2 >= catchRectY And fishY + FISH_SIZE / 2 <= catchRectY + catchRectHeight Then
catchProgress = catchProgress + 0.5
If catchProgress >= 100 Then
gameState = 3 ' Caught
score = score + difficulty * 10
If Rnd < 0.7 Then
itemCaught = "Fish"
ElseIf Rnd < 0.9 Then
itemCaught = "Treasure"
Else
itemCaught = "Junk"
End If
End If
Else
catchProgress = catchProgress - 0.3
If catchProgress < 0 Then catchProgress = 0
End If
timerProgress = timerProgress - 0.8
If timerProgress <= 0 Then
gameState = 4 ' Missed
End If
End Select
Select Case gameState
Case 0
Call DrawWaitingScreen
Case 1
Call DrawFishingScreen
Case 2
Call DrawCatchingScreen
Case 3
Call DrawCaughtScreen
Case 4
Call DrawMissedScreen
End Select
_PrintString (50, 50), "Score: " + Str$(score)
_PrintString (50, 100), "Difficulty: " + Str$(difficulty)
_Display
_Limit 60
If (gameState = 3 Or gameState = 4) And _KeyDown(32) Then
gameState = 0
timerProgress = 0
End If
Loop Until _KeyDown(27)
Sub InitializeGame
gameState = 0: score = 0: difficulty = 1
End Sub
Sub SetupCatch
fishY = FISHING_BAR_HEIGHT / 2: fishDirection = (Rnd * 2) - 1: fishSpeed = 3 + difficulty
catchRectY = FISHING_BAR_HEIGHT / 2
catchRectSpeed = 4 ' Start moving down
catchRectHeight = CATCH_RECT_BASE_HEIGHT - (difficulty * 15)
If catchRectHeight < 60 Then catchRectHeight = 60
catchProgress = 0
timerProgress = TIMER_BAR_HEIGHT
If score > 0 And score Mod 30 = 0 Then
difficulty = difficulty + 1
End If
End Sub
Sub DrawWaitingScreen
Line (0, 300)-(1920, 1080), _RGB(30, 144, 255), BF
Line (960, 100)-(960, 300), _RGB(139, 69, 19): Circle (960, 300), 10, _RGB(139, 69, 19)
_PrintString (860, 200), "Press SPACE to cast your line!": _PrintString (860, 250), "Try to catch fish when they bite!"
End Sub
Sub DrawFishingScreen
Line (0, 300)-(1920, 1080), _RGB(30, 144, 255), BF
Line (960, 100)-(960, 300), _RGB(139, 69, 19): Circle (960, 300), 10, _RGB(139, 69, 19)
Line (960, 300)-(1000, 500), _RGB(200, 200, 200): Circle (1000, 500), 15, _RGB(200, 200, 200)
Line (400, 200)-(400 + TIMER_BAR_WIDTH, 200 + timerProgress), _RGB(255, 0, 0), BF
Line (400, 200)-(400 + TIMER_BAR_WIDTH, 200 + TIMER_BAR_HEIGHT), _RGB(100, 100, 100), B
' Draw waiting message
_PrintString (900, 250), "Waiting for a bite..."
End Sub
Sub DrawCatchingScreen
Line (400, 200)-(400 + TIMER_BAR_WIDTH, 200 + TIMER_BAR_HEIGHT), _RGB(100, 100, 100), B
Line (400, 200)-(400 + TIMER_BAR_WIDTH, 200 + timerProgress), _RGB(255, 0, 0), BF
Line (1120, 200)-(1120 + FISHING_BAR_WIDTH, 200 + FISHING_BAR_HEIGHT), _RGB(50, 50, 50), B
Line (1120, 200)-(1120 + FISHING_BAR_WIDTH, 200 + FISHING_BAR_HEIGHT), _RGB(30, 144, 255), BF
For y = catchRectY To catchRectY + catchRectHeight Step 4
Line (1120, 200 + y)-(1120 + FISHING_BAR_WIDTH, 200 + y + 2), _RGB(0, 255, 0), BF
Next
Call DrawFish(1120 + FISHING_BAR_WIDTH / 2 - FISH_SIZE / 2, 200 + fishY, FISH_SIZE)
Line (800, 200)-(800 + 100, 200 + 20), _RGB(100, 100, 100), B
Line (800, 200)-(800 + catchProgress, 200 + 20), _RGB(0, 200, 0), BF
_PrintString (800, 230), "Catch: " + Str$(Int(catchProgress)) + "%"
_PrintString (800, 750), "HOLD SPACE to lift the green box"
_PrintString (800, 800), "Keep fish in box to fill catch meter!"
End Sub
Sub DrawCaughtScreen
_PrintString (860, 250), "You caught: " + itemCaught + "!"
_PrintString (860, 300), "Score: " + Str$(score)
_PrintString (860, 350), "Press SPACE to fish again"
Select Case itemCaught
Case "Fish"
Call DrawFish(930, 400, 120)
_PrintString (930, 540), "Fish (+" + Str$(difficulty * 10) + ")"
Case "Treasure"
Line (930, 400)-(1050, 520), _RGB(255, 215, 0), BF
Circle (960, 460), 20, _RGB(255, 255, 0)
Paint (960, 460), _RGB(255, 255, 0), _RGB(255, 255, 0)
_PrintString (930, 540), "Treasure! (+" + Str$(difficulty * 10) + ")"
Case "Junk"
Line (950, 420)-(1030, 500), _RGB(139, 137, 137), BF
Line (950, 420)-(930, 450), _RGB(139, 137, 137)
Line (1030, 420)-(1050, 450), _RGB(139, 137, 137)
_PrintString (930, 540), "Old Boot (+0)"
End Select
End Sub
Sub DrawMissedScreen
_PrintString (860, 250), "The fish got away!": _PrintString (860, 300), "Score: " + Str$(score): _PrintString (860, 350), "Press SPACE to try again"
Circle (960, 400), 50, _RGB(255, 255, 0): Paint (960, 400), _RGB(255, 255, 0), _RGB(255, 255, 0)
Circle (940, 380), 10, _RGB(0, 0, 0): Paint (940, 380), _RGB(0, 0, 0), _RGB(0, 0, 0)
Circle (980, 380), 10, _RGB(0, 0, 0): Paint (980, 380), _RGB(0, 0, 0), _RGB(0, 0, 0)
Line (940, 430)-(980, 430), _RGB(0, 0, 0)
End Sub
Sub DrawFish (x, y, size)
For i = 0 To size Step 2
radius = Sin(_Pi(i / size)) * (size / 3)
Line (x + i, y + size / 2 - radius)-(x + i, y + size / 2 + radius), _RGB(255, 165, 0)
Next
Line (x + size, y + size / 2)-(x + size + size / 3, y + size / 4), _RGB(255, 140, 0)
Line (x + size, y + size / 2)-(x + size + size / 3, y + 3 * size / 4), _RGB(255, 140, 0)
Circle (x + size / 3, y + size / 3), size / 10, _RGB(0, 0, 0)
Paint (x + size / 3, y + size / 3), _RGB(0, 0, 0), _RGB(0, 0, 0)
Line (x + size / 2, y + size / 2)-(x + size / 2 + size / 4, y + size / 4), _RGB(255, 140, 0)
Line (x + size / 2, y + size / 2)-(x + size / 2 + size / 4, y + 3 * size / 4), _RGB(255, 140, 0)
End Sub
RE: An attempt at a small fishing game - bplus - 04-20-2025
Your screen dimensions are way bigger than mine but _Fullscreen overcomes that except for distortions.
So the object is to keep green net over the fish as it helicopters up and down unlike any fish I've known must be from a different see 
Well I think I figured out the game without instructions +1 for that! Thankyou
|