Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
QB64 GPT now available
#2
Here is some code that it wrote when I asked for a game. Doesn't work, but it is syntactically correct and does compile:

Code: (Select All)
DECLARE SUB InitializeGame ()
DECLARE SUB HandleInput ()
DECLARE SUB UpdateGame ()
DECLARE SUB RenderGame ()
DECLARE SUB CheckPlatformCollision ()
DECLARE SUB CreatePlatforms ()
DECLARE SUB CreateEnemies ()
DECLARE SUB UpdateEnemies ()
DECLARE SUB CheckEnemyCollision ()

Const SCREEN_WIDTH = 800
Const SCREEN_HEIGHT = 600

Type Platform
    x As Single
    y As Single
    width As Single
    height As Single
End Type

Type Enemy
    x As Single
    y As Single
    width As Single
    height As Single
    velX As Single
End Type

Dim Shared playerX As Single, playerY As Single
Dim Shared playerVelX As Single, playerVelY As Single
Dim Shared gravity As Single
Dim Shared isJumping As Integer
Dim Shared platforms(10) As Platform
Dim Shared enemies(5) As Enemy

Screen _NewImage(SCREEN_WIDTH, SCREEN_HEIGHT, 32)
InitializeGame

Do
    HandleInput
    UpdateGame
    RenderGame
    _Limit 60
Loop Until InKey$ = Chr$(27) ' Esc key to exit

Sub InitializeGame
    playerX = SCREEN_WIDTH / 2
    playerY = SCREEN_HEIGHT - 50
    playerVelX = 0
    playerVelY = 0
    gravity = 0.5
    isJumping = 0
    CreatePlatforms
    CreateEnemies
End Sub

Sub HandleInput
    playerVelX = 0
    If _KeyDown(203) Then playerVelX = -5 ' Left arrow key
    If _KeyDown(205) Then playerVelX = 5 ' Right arrow key
    If _KeyDown(57) And isJumping = 0 Then ' Space bar
        playerVelY = -10
        isJumping = 1
    End If
End Sub

Sub UpdateGame
    playerY = playerY + playerVelY
    playerX = playerX + playerVelX
    playerVelY = playerVelY + gravity

    ' Simulate ground
    If playerY >= SCREEN_HEIGHT - 50 Then
        playerY = SCREEN_HEIGHT - 50
        playerVelY = 0
        isJumping = 0
    End If

    ' Check collision with platforms
    CheckPlatformCollision

    ' Update enemies
    UpdateEnemies

    ' Check collision with enemies
    CheckEnemyCollision
End Sub

Sub CheckPlatformCollision
    For i = 0 To 9
        If playerX + 10 > platforms(i).x And playerX < platforms(i).x + platforms(i).width Then
            If playerY + 10 > platforms(i).y And playerY < platforms(i).y + platforms(i).height Then
                playerY = platforms(i).y - 10
                playerVelY = 0
                isJumping = 0
            End If
        End If
    Next
End Sub

Sub CreatePlatforms
    For i = 0 To 9
        platforms(i).x = Rnd * (SCREEN_WIDTH - 100)
        platforms(i).y = Rnd * (SCREEN_HEIGHT - 200)
        platforms(i).width = 100
        platforms(i).height = 10
    Next
End Sub

Sub CreateEnemies
    For i = 0 To 4
        enemies(i).x = Rnd * (SCREEN_WIDTH - 50)
        enemies(i).y = Rnd * (SCREEN_HEIGHT - 50)
        enemies(i).width = 30
        enemies(i).height = 30
        enemies(i).velX = 2 * (Rnd - 0.5)
    Next
End Sub

Sub UpdateEnemies
    For i = 0 To 4
        enemies(i).x = enemies(i).x + enemies(i).velX
        If enemies(i).x < 0 Or enemies(i).x > SCREEN_WIDTH - enemies(i).width Then
            enemies(i).velX = -enemies(i).velX
        End If
    Next
End Sub

Sub CheckEnemyCollision
    For i = 0 To 4
        If playerX + 10 > enemies(i).x And playerX < enemies(i).x + enemies(i).width Then
            If playerY + 10 > enemies(i).y And playerY < enemies(i).y + enemies(i).height Then
                ' Game over or reduce player health
                Print "Game Over!"
                Sleep
                End
            End If
        End If
    Next
End Sub

Sub RenderGame
    Cls
    _PrintString (playerX, playerY), "O"
    For i = 0 To 9
        Line (platforms(i).x, platforms(i).y)-(platforms(i).x + platforms(i).width, platforms(i).y + platforms(i).height), _RGB(0, 255, 0), BF
    Next
    For i = 0 To 4
        Line (enemies(i).x, enemies(i).y)-(enemies(i).x + enemies(i).width, enemies(i).y + enemies(i).height), _RGB(255, 0, 0), BF
    Next
    _Display
End Sub
   

When I adjusted the arrow key controls to A, D, and space bar it actually worked. It ain't the prettiest, but it does work.
Tread on those who tread on you

Reply


Messages In This Thread
QB64 GPT now available - by SpriggsySpriggs - 05-17-2024, 05:08 PM
RE: QB64 GPT now available - by SpriggsySpriggs - 05-17-2024, 05:25 PM
RE: QB64 GPT now available - by bplus - 05-18-2024, 01:24 AM
RE: QB64 GPT now available - by SpriggsySpriggs - 05-18-2024, 03:50 PM
RE: QB64 GPT now available - by grymmjack - 05-18-2024, 04:11 PM
RE: QB64 GPT now available - by SpriggsySpriggs - 05-18-2024, 09:42 PM



Users browsing this thread: 1 Guest(s)