Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
wrangling chatgpt to get it to write a more complex program - Spacewar!
#1
So the sky's the limit, right? Why not shoot for the moon, or at least Space! 
Here's what happend when I asked it to write Spacewar!

Code: (Select All)
Can you write a 2 player Spacewar! game in QB64 where the players are controlled with the keyboard, (player 1 controls are: up arrow = thrust, down arrow = warp, left arrow = rotate left, right arrow = rotate right, ENTER = fire; player 2 controls are: A = rotate left, D = rotate right, S = warp, W = thrust,  E = fire), and includes 2 additional computer controlled players, and 2 suns?
Sure! Here is a simple Spacewar! game in QB64 that allows two players to control their ships with the keyboard, and includes two additional computer-controlled players and two suns:

' Declare constants for the screen width and height
CONST SCREEN_WIDTH = 640
CONST SCREEN_HEIGHT = 480

' Declare constants for the player colors
CONST PLAYER_1_COLOR = 15
CONST PLAYER_2_COLOR = 11
CONST CPU_PLAYER_COLOR = 7

' Declare constants for the sun colors
CONST SUN_1_COLOR = 12
CONST SUN_2_COLOR = 14

' Declare constants for the player controls
CONST PLAYER_1_UP = 72
CONST PLAYER_1_DOWN = 80
CONST PLAYER_1_LEFT = 75
CONST PLAYER_1_RIGHT = 77
CONST PLAYER_1_FIRE = 13

CONST PLAYER_2_UP = 87
CONST PLAYER_2_DOWN = 83
CONST PLAYER_2_LEFT = 65
CONST PLAYER_2_RIGHT = 68
CONST PLAYER_2_FIRE = 69

' Declare constants for the game states
CONST GAME_STATE_INITIALIZING = 0
CONST GAME_STATE_PLAYING = 1
CONST GAME_STATE_PAUSED = 2
CONST GAME_STATE_OVER = 3

' Declare variables for the game state and the player scores
DIM GameState AS INTEGER
DIM Player1Score AS INTEGER
DIM Player2Score AS INTEGER

' Declare a type for the players
TYPE Player
    X AS SINGLE
    Y AS SINGLE
    Angle AS SINGLE
    Speed AS SINGLE
    RotationSpeed AS SINGLE
    Color AS INTEGER
    IsComputerControlled AS BOOLEAN
END TYPE

' Declare variables for the players
DIM Player1 AS Player
DIM Player2 AS Player
DIM CPUPlayer1 AS Player
DIM CPUPlayer2 AS Player

' Declare a type for the suns
TYPE Sun
    X AS SINGLE
    Y AS SINGLE
    Mass AS SINGLE
    Color AS INTEGER
END TYPE

' Declare variables for the suns
DIM Sun1 AS Sun
DIM Sun2 AS Sun

' Initialize the game
SUB InitializeGame
    ' Set the game state to initializing
    GameState = GAME_STATE_INITIALIZING

    ' Initialize the player scores
    Player1Score = 0
    Player2Score = 0

    ' Initialize player 1
    Player1.X = SCREEN_WIDTH / 4
    Player1.Y = SCREEN_HEIGHT / 2
    Player1.Angle = 0
    Player1.Speed = 0
    Player1.RotationSpeed = 0
    Player1.Color = PLAYER_1_COLOR
    Player1.IsComputerControlled = False

    ' Initialize player 2
    Player2.X = SCREEN_WIDTH * 3 / 4
    Player2.Y = SCREEN_HEIGHT / 2
    Player2.Angle = 180
    Player2.Speed = 0
    Player2.R

Wait! You're not done! What if we ask it to finish? We'll even say "please"!

Code: (Select All)
Would you please show the rest of the program?
Certainly! Here is the rest of the Spacewar! game in QB64 that allows two players to control their ships with the keyboard, and includes two additional computer-controlled players and two suns:

' Update the player's position and angle based on their speed and rotation speed
SUB UpdatePlayer(Player AS Player)
    ' Update the player's angle
    Player.Angle = Player.Angle + Player.RotationSpeed

    ' Keep the angle between 0 and 360 degrees
    IF Player.Angle < 0 THEN
        Player.Angle = Player.Angle + 360
    ELSEIF Player.Angle > 360 THEN
        Player.Angle = Player.Angle - 360
    END IF

    ' Calculate the player's new position based on their speed and angle
    Player.X = Player.X + Player.Speed * COS(Player.Angle)
    Player.Y = Player.Y + Player.Speed * SIN(Player.Angle)

    ' Keep the player within the screen bounds
    IF Player.X < 0 THEN
        Player.X = 0
    ELSEIF Player.X > SCREEN_WIDTH THEN
        Player.X = SCREEN_WIDTH
    END IF
    IF Player.Y < 0 THEN
        Player.Y = 0
    ELSEIF Player.Y > SCREEN_HEIGHT THEN
        Player.Y = SCREEN_HEIGHT
    END IF
END SUB

' Update the player's speed based on their thrust
SUB UpdatePlayerThrust(Player AS Player, IsThrusting AS BOOLEAN)
    ' If the player is thrusting, increase their speed
    IF IsThrusting THEN
        Player.Speed = Player.Speed + 0.1
    ' If the player is not thrusting, decrease their speed
    ELSE
        Player.Speed = Player.Speed - 0.1
    END IF

    ' Limit the player's speed
    IF Player.Speed < 0 THEN
        Player.Speed = 0
    ELSEIF Player.Speed > 5 THEN
        Player.Speed = 5
    END IF
END SUB

' Update the player's rotation speed based on their rotation
SUB UpdatePlayerRotation(Player AS Player, IsRotatingLeft AS BOOLEAN, IsRotatingRight AS BOOLEAN)
    ' If the player is rotating left, increase their rotation speed
    IF Is

OK, it remembered what we asked it, and sort of continued, but not where it left off! 
Shall we persevere? 

Code: (Select All)
Would you please show the rest of the program?
Certainly! Here is the rest of the Spacewar! game in QB64 that allows two players to control their ships with the keyboard, and includes two additional computer-controlled players and two suns:

' Update the computer-controlled players
SUB UpdateCPUPlayers
    ' Update player 1
    UpdateCPUPlayer(CPUPlayer1)

    ' Update player 2
    UpdateCPUPlayer(CPUPlayer2)
END SUB

' Update a computer-controlled player
SUB UpdateCPUPlayer(Player AS Player)
    ' Calculate the distance to player 1
    DX = Player1.X - Player.X
    DY = Player1.Y - Player.Y
    DistanceToPlayer1 = SQR(DX * DX + DY * DY)

    ' Calculate the distance to player 2
    DX = Player2.X - Player.X
    DY = Player2.Y - Player.Y
    DistanceToPlayer2 = SQR(DX * DX + DY * DY)

    ' Calculate the distance to the nearest sun
    DX = Sun1.X - Player.X
    DY = Sun1.Y - Player.Y
    DistanceToSun1 = SQR(DX * DX + DY * DY)
    DX = Sun2.X - Player.X
    DY = Sun2.Y - Player.Y
    DistanceToSun2 = SQR(DX * DX + DY * DY)
    If DistanceToSun1 < DistanceToSun2 Then
        DistanceToNearestSun = DistanceToSun1
    Else
        DistanceToNearestSun = DistanceToSun2
    End If

    ' If the player is far from the other players and the suns, move randomly
    If DistanceToPlayer1 > 100 And DistanceToPlayer2 > 100 And DistanceToNearestSun > 100 Then
        ' Choose a random angle and set the player's rotation speed
        TargetAngle = RND * 360
        If TargetAngle > Player.Angle Then
            Player.RotationSpeed = 0.5
        Else
            Player.RotationSpeed = -0.5
        End If
    ' If the player is close to a player, move towards them
    ElseIf DistanceToPlayer1 < DistanceToPlayer2 Then
        ' Calculate the angle to player 1 and set the player's rotation speed
        TargetAngle = ATN2(DY, DX) * 180 / PI
        If TargetAngle > Player.Angle Then
            Player.RotationSpeed = 0.5
        Else
            Player.RotationSpeed = -0.5
        End If
    Else
        ' Calculate the angle to player 2 and set the player's rotation speed
        TargetAngle = ATN2(DY, DX) * 180 / PI
        If TargetAngle > Player.Angle Then
            Player.RotationSpeed = 0.5
        Else

Don't leave me hanging, chatgpt! 

Code: (Select All)
Would you please show the rest of the program?
Certainly! Here is the rest of the Spacewar! game in QB64 that allows two players to control their ships with the keyboard, and includes two additional computer-controlled players and two suns:

' Update the player's speed based on the gravitational pull of the suns
SUB UpdatePlayerGravity(Player AS Player)
    ' Calculate the distance and angle to sun 1
    DX = Sun1.X - Player.X
    DY = Sun1.Y - Player.Y
    DistanceToSun1 = SQR(DX * DX + DY * DY)
    AngleToSun1 = ATN2(DY, DX) * 180 / PI

    ' Calculate the distance and angle to sun 2
    DX = Sun2.X - Player.X
    DY = Sun2.Y - Player.Y
    DistanceToSun2 = SQR(DX * DX + DY * DY)
    AngleToSun2 = ATN2(DY, DX) * 180 / PI

    ' Calculate the gravitational force from sun 1
    GravitationalForce1 = Sun1.Mass / DistanceToSun1
    ' Calculate the gravitational force from sun 2
    GravitationalForce2 = Sun2.Mass / DistanceToSun2

    ' Calculate the total gravitational force
    TotalGravitationalForce = GravitationalForce1 + GravitationalForce2

    ' Calculate the gravitational acceleration
    GravitationalAcceleration = TotalGravitationalForce / Player.Mass

    ' Calculate the gravitational speed
    GravitationalSpeed = GravitationalAcceleration * 0.1

    ' Calculate the new speed based on the gravitational speed
    NewSpeed = Player.Speed + GravitationalSpeed

    ' Limit the player's speed
    If NewSpeed < 0 Then
        NewSpeed = 0
    ElseIf NewSpeed > 5 Then
        NewSpeed = 5
    End If

    ' Set the player's speed
    Player.Speed = NewSpeed
END SUB

' Draw a player
SUB DrawPlayer(Player AS Player)
    ' Calculate the points of the triangle representing the player's ship
    X1 = Player.X + 5 * COS

Aye aye aye! It doesn't seem to always know how to (or want to) continue from where it left off, does it? 
What if we're more specific? 

Code: (Select All)
would you please show the full SUB UpdatePlayerRotation ?
Certainly! Here is the full UpdatePlayerRotation subroutine in the Spacewar! game in QB64 that allows two players to control their ships with the keyboard, and includes two additional computer-controlled players and two suns:

' Update the player's rotation speed based on their rotation
SUB UpdatePlayerRotation(Player AS Player, IsRotatingLeft AS BOOLEAN, IsRotatingRight AS BOOLEAN)
    ' If the player is rotating left, increase their rotation speed
    IF IsRotatingLeft THEN
        Player.RotationSpeed = Player.RotationSpeed + 0.5
    ' If the player is rotating right, decrease their rotation speed
    ELSEIF IsRotatingRight THEN
        Player.RotationSpeed = Player.RotationSpeed - 0.5
    ' If the player is not rotating, decrease their rotation speed
    ELSE
        Player.RotationSpeed = Player.RotationSpeed - 0.1
    END IF

    ' Limit the player's rotation speed
    IF Player.RotationSpeed < -2 THEN
        Player.RotationSpeed = -2
    ELSEIF Player.RotationSpeed > 2 THEN
        Player.RotationSpeed = 2
    END IF
END SUB
This subroutine updates the player's rotation speed based on whether they are rotating left, rotating right, or not rotating at all. If the player is rotating left, their rotation speed is increased. If the player is rotating right, their rotation speed is decreased. If the player is not rotating, their rotation speed is decreased. The rotation speed is limited to a maximum of 2 and a minimum of -2.

I hope this helps! Let me know if you have any questions or if you need further assistance.

Maybe being specific is the key? Let's try to get it to spit out the rest of "teh codez"! 

Code: (Select All)
Thank You. Would you please show the full SUB UpdateCPUPlayer ?
Certainly! Here is the full UpdateCPUPlayer subroutine in the Spacewar! game in QB64 that allows two players to control their ships with the keyboard, and includes two additional computer-controlled players and two suns:

' Update a computer-controlled player
SUB UpdateCPUPlayer(Player AS Player)
    ' Calculate the distance to player 1
    DX = Player1.X - Player.X
    DY = Player1.Y - Player.Y
    DistanceToPlayer1 = SQR(DX * DX + DY * DY)

    ' Calculate the distance to player 2
    DX = Player2.X - Player.X
    DY = Player2.Y - Player.Y
    DistanceToPlayer2 = SQR(DX * DX + DY * DY)

    ' Calculate the distance to the nearest sun
    DX = Sun1.X - Player.X
    DY = Sun1.Y - Player.Y
    DistanceToSun1 = SQR(DX * DX + DY * DY)
    DX = Sun2.X - Player.X
    DY = Sun2.Y - Player.Y
    DistanceToSun2 = SQR(DX * DX + DY * DY)
    If DistanceToSun1 < DistanceToSun2 Then
        DistanceToNearestSun = DistanceToSun1
    Else
        DistanceToNearestSun = DistanceToSun2
    End If

    ' If the

Argh. Why does it output in such small chunks?? How useless is that?! 
But we must see this thing through!

Code: (Select All)
would you please show the rest of the routine?
Certainly! Here is the rest of the UpdateCPUPlayer subroutine in the Spacewar! game in QB64 that allows two players to control their ships with the keyboard, and includes two additional computer-controlled players and two suns:

' If the player is far from the other players and the suns, move randomly
    If DistanceToPlayer1 > 100 And DistanceToPlayer2 > 100 And DistanceToNearestSun > 100 Then
        ' Choose a random angle and set the player's rotation speed
        TargetAngle = RND * 360
        If TargetAngle > Player.Angle Then
            Player.RotationSpeed = 0.5
        Else
            Player.RotationSpeed = -0.5
        End If
    ' If the player is close to a player, move towards them
    ElseIf DistanceToPlayer1 < DistanceToPlayer2 Then
        ' Calculate the angle to player 1 and set the player's rotation speed
        TargetAngle = ATN2(DY, DX) * 180 / PI
        If TargetAngle > Player.Angle Then
            Player.RotationSpeed = 0.5
        Else
            Player.RotationSpeed = -0.5
        End If
    Else
        ' Calculate the angle to player 2 and set the player's rotation speed
        TargetAngle = ATN2(DY, DX) * 180 / PI
        If TargetAngle > Player.Angle Then
            Player.RotationSpeed = 0.5
        Else
            Player.RotationSpeed = -0.5
        End If
    End If

    ' Set the player's thrust based on their distance to the nearest sun
    If DistanceToNearestSun < 50 Then
        Player.IsThrusting = False
    Else
        Player.IsThrusting = True
    End If
END SUB
This subroutine updates the position and angle of a computer-controlled player based on their distance to the other players and the suns. If the player is far from the other players and the suns, they choose a random angle and rotate towards it. If the player is close to a player, they move towards them. If the player is close to a sun, they stop thrusting.

I hope this helps! Let me know if you have any questions or if you need further assistance.

OK then! We'll keep soldiering on, then...
Maybe the "p" word isn't enough, let's also be sure to say "thank you"! 

Code: (Select All)
Thank you. Would you please show the full SUB DrawPlayer?
Certainly! Here is the full DrawPlayer subroutine in the Spacewar! game in QB64 that allows two players to control their ships with the keyboard, and includes two additional computer-controlled players and two suns:

' Draw a player
SUB DrawPlayer(Player AS Player)
    ' Calculate the points of the triangle representing the player's ship
    X1 = Player.X + 5 * COS(Player.Angle)
    Y1 = Player.Y + 5 * SIN(Player.Angle)
    X2 = Player.X + 5 * COS(Player.Angle + 120)
    Y2 = Player.Y + 5 * SIN(Player.Angle + 120)
    X3 = Player.X + 5 * COS(Player.Angle + 240)
    Y3 = Player.Y + 5 * SIN(Player.Angle + 240)

    ' Draw the triangle representing the player's ship
    LINE (X1, Y1)-(X2, Y2), Player.Color
    LINE (X2, Y2)-(X3, Y3), Player.Color
    LINE (X3, Y3)-(X1, Y1), Player.Color

    ' If the player is thrusting, draw a flame behind their ship
    If Player.IsThrusting Then
        LINE (X2, Y2)-(X2 + 2 * COS(Player.Angle + 180), Y2 + 2 * SIN(Player.Angle + 180)), Player.Color
        LINE (X3, Y3)-(X3 + 2 * COS(Player.Angle + 180), Y3 + 2 * SIN(Player.Angle + 180)), Player.Color
    End If
END SUB
This subroutine draws a triangle representing the player's ship and, if the player is thrusting, a flame behind their ship. The points of the triangle are calculated using the player's angle and the coordinates of the player's ship. The triangle is then drawn using the player's color. If the player is thrusting, two lines are drawn behind the triangle to represent the flame.

I hope this helps! Let me know if you have any questions or if you need further assistance.

And on...

Code: (Select All)
Thank you. Would you please show the rest of the program?
Certainly! Here is the rest of the Spacewar! game in QB64 that allows two players to control their ships with the keyboard, and includes two additional computer-controlled players and two suns:

' Initialize the players
Player1.X = 100
Player1.Y = 100
Player1.Angle = 0
Player1.RotationSpeed = 0
Player1.Speed = 0
Player1.IsThrusting = False
Player1.Mass = 10
Player1.Color = RGB(255, 0, 0)

Player2.X = 200
Player2.Y = 100
Player2.Angle = 0
Player2.RotationSpeed = 0
Player2.Speed = 0
Player2.IsThrusting = False
Player2.Mass = 10
Player2.Color = RGB(0, 255, 0)

CPUPlayer1.X = 100
CPUPlayer1.Y = 200
CPUPlayer1.Angle = 0
CPUPlayer1.RotationSpeed = 0
CPUPlayer1.Speed = 0
CPUPlayer1.IsThrusting = False
CPUPlayer1.Mass = 10
CPUPlayer1.Color = RGB(0, 0, 255)

CPUPlayer2.X = 200
CPUPlayer2.Y = 200
CPUPlayer2.Angle = 0
CPUPlayer2.RotationSpeed = 0
CPUPlayer2.Speed = 0
CPUPlayer2.IsThrusting = False
CPUPlayer2.Mass = 10
CPUPlayer2.Color = RGB(255, 255, 0)

' Initialize the suns
Sun1.X = 150
Sun1.Y = 150
Sun1.Mass = 1000
Sun2.X = 250
Sun2.Y = 150
Sun2.Mass = 1000

' Set the screen update rate
SCREEN UpdateRate(30)

' Set the window title
WINDOW Title$ = "Spacewar!"

' Set the window size
WINDOW Width = 320, Height = 240

DO
    ' Clear the screen
    CLS

    ' Update the players
    UpdatePlayerRotation(Player1, GetKeyState(VK_LEFT) AND 1, GetKeyState(VK_RIGHT) AND 1)
    UpdatePlayerRotation(Player2, GetKeyState(VK_A) AND 1, GetKeyState(VK_D) AND 1)
    UpdatePlayerThrust(Player1, GetKeyState(VK_UP) AND 1)
    UpdatePlayerThrust(Player2, GetKeyState(VK_W) AND 1)
    UpdatePlayerPosition(Player1)
    UpdatePlayerPosition(Player2)
    UpdateCPUPlayers
    UpdatePlayerGravity(Player1)
    UpdatePlayerGravity(Player2)
    UpdatePlayerGravity(CPUPlayer1)
    UpdatePlayerGravity(CPUPlayer2)

    ' Draw the players
    DrawPlayer(Player1)
    DrawPlayer(Player2)
    DrawPlayer(CPUPlayer1)
    DrawPlayer(CPUPlayer2)

    ' Draw the suns
    CIRCLE (Sun1.X, Sun1.Y), 10, RGB(255, 255, 0)
    CIRCLE (Sun2.X, Sun2.Y), 10, RGB(255, 255, 0)

    ' Check for player collisions
    If PlayerCollision(Player1, Player2) Then
        ' End the game

OK, now it's initializing values, this looks like the main (global) code. 
Can we get the rest out of this thing? 
What if we're specific about telling it to NOT STOP until it's DONE? 

Code: (Select All)
Thank you. Would you please show the rest of the program? Don't stop until you have shown the whole thing.
Certainly! Here is the rest of the Spacewar! game in QB64 that allows two players to control their ships with the keyboard, and includes two additional computer-controlled players and two suns:

        ' End the game
        EXIT DO
    End If
    If PlayerCollision(Player1, CPUPlayer1) Then
        ' End the game
        EXIT DO
    End If
    If PlayerCollision(Player1, CPUPlayer2) Then
        ' End the game
        EXIT DO
    End If
    If PlayerCollision(Player2, CPUPlayer1) Then
        ' End the game
        EXIT DO
    End If
    If PlayerCollision(Player2, CPUPlayer2) Then
        ' End the game
        EXIT DO
    End If

    ' Check for player and sun collisions
    If PlayerSunCollision(Player1, Sun1) Then
        ' End the game
        EXIT DO
    End If
    If PlayerSunCollision(Player1, Sun2) Then
        ' End the game
        EXIT DO
    End If
    If PlayerSunCollision(Player2, Sun1) Then
        ' End the game
        EXIT DO
    End If
    If PlayerSunCollision(Player2, Sun2) Then
        ' End the game
        EXIT DO
    End If
    If PlayerSunCollision(CPUPlayer1, Sun1) Then
        ' End the game
        EXIT DO
    End If
    If PlayerSunCollision(CPUPlayer1, Sun2) Then
        ' End the game
        EXIT DO
    End If
    If PlayerSunCollision(CPUPlayer2, Sun1) Then
        ' End the game
        EXIT DO
    End If
    If PlayerSunCollision(CPUPlayer2, Sun2) Then
        ' End the game
        EXIT DO
    End If

    ' Check for player shots
    If GetKeyState(VK_RETURN) AND 1 Then
        Player1.Shots.AddNew
        Player1.Shots(Player1.Shots.Count).X = Player1.X + 5 * COS(Player1.Angle)
        Player1.Shots(Player1.Shots.Count).Y = Player1.Y + 5 * SIN(Player1.Angle)
        Player1.Shots(Player1.Shots.Count).Angle = Player1.Angle
    End If
    If GetKeyState(VK_E) AND 1 Then
        Player2.Shots.AddNew
        Player2.Shots(Player2.Shots.Count).X = Player2.X + 5 * COS(Player2.Angle)
        Player2.Shots(Player2.Shots.Count).Y =

A lot good that did! 
Well, we've made it this far, let's see just how much more it will take to get the whole program! 

Code: (Select All)
Thank you. Would you please show the rest of the program?
Certainly! Here is the rest of the Spacewar! game in QB64 that allows two players to control their ships with the keyboard, and includes two additional computer-controlled players and two suns:

Player2.Shots(Player2.Shots.Count).Angle = Player2.Angle
    End If

    ' Update and draw the player shots
    For i = 0 To Player1.Shots.Count - 1
        UpdateShot(Player1.Shots(i))
        DrawShot(Player1.Shots(i))
    Next
    For i = 0 To Player2.Shots.Count - 1
        UpdateShot(Player2.Shots(i))
        DrawShot(Player2.Shots(i))
    Next

    ' Check for shot and player collisions
    For i = 0 To Player1.Shots.Count - 1
        If ShotPlayerCollision(Player1.Shots(i), Player2) Then
            ' End the game
            EXIT DO
        End If
        If ShotPlayerCollision(Player1.Shots(i), CPUPlayer1) Then
            ' End the game
            EXIT DO
        End If
        If ShotPlayerCollision(Player1.Shots(i), CPUPlayer2) Then
            ' End the game
            EXIT DO
        End If
    Next
    For i = 0 To Player2.Shots.Count - 1
        If ShotPlayerCollision(Player2.Shots(i), Player1) Then
            ' End the game
            EXIT DO
        End If
        If ShotPlayerCollision(Player2.Shots(i), CPUPlayer1) Then
            ' End the game
            EXIT DO
        End If
        If ShotPlayerCollision(Player2.Shots(i), CPUPlayer2) Then
            ' End the game
            EXIT DO
        End If
    Next

    ' Check for shot and sun collisions
    For i = 0 To Player1.Shots.Count - 1
        If

If... if what you nincompoop?!?!?! 
Let's not lose our temper, now. 
We must stay calm, cool, and collected! 
After all, there has to be at least one adult in the room!

Code: (Select All)
Thank you. Would you please show the rest of the program? Don't stop until you have shown the whole thing.
Certainly! Here is the rest of the Spacewar! game in QB64 that allows two players to control their ships with the keyboard, and includes two additional computer-controlled players and two suns:

ShotSunCollision(Player1.Shots(i), Sun1) Then
            Player1.Shots.Remove(i)
        End If
        If ShotSunCollision(Player1.Shots(i), Sun2) Then
            Player1.Shots.Remove(i)
        End If
    Next
    For i = 0 To Player2.Shots.Count - 1
        If ShotSunCollision(Player2.Shots(i), Sun1) Then
            Player2.Shots.Remove(i)
        End If
        If ShotSunCollision(Player2.Shots(i), Sun2) Then
            Player2.Shots.Remove(i)
        End If
    Next

    ' Update the screen
    SCREEN Update

LOOP
This is the main game loop that updates and draws the players, suns, and shots, and checks for collisions between them. The game ends when any two players collide, a player collides with a sun, or a shot hits a player or sun.

I hope this helps! Let me know if you have any questions or if you need further assistance.

Is it done? I've just about reached the end of my rope. 
Can we just have it email the thing to us? 
(After all, they have you give an email address when you sign up for a free account.)
Only one way to find out... 

Code: (Select All)
can you email me the entire program listing at my account's email address?
I'm sorry, but I am not able to send emails as I am just a text-based AI program. I do not have the ability to access or send emails. However, I can provide you with the full listing of the Spacewar! game in QB64 that allows two players to control their ships with the keyboard, and includes two additional computer-controlled players and two suns.

Here is the full listing of the program:

' Struct to represent a player
TYPE Player
    X AS SINGLE
    Y AS SINGLE
    Angle AS SINGLE
    RotationSpeed AS SINGLE
    Speed AS SINGLE
    IsThrusting AS BOOLEAN
    Mass AS SINGLE
    Color AS LONG
    Shots AS Collection
END TYPE

' Struct to represent a shot
TYPE Shot
    X AS SINGLE
    Y AS SINGLE
    Angle AS SINGLE
    Speed AS SINGLE
    Color AS LONG
END TYPE

' Struct to represent a sun
TYPE Sun
    X AS SINGLE
    Y AS SINGLE
    Mass AS SINGLE
END TYPE

' Declare the players and suns
DIM Player1 AS Player
DIM Player2 AS Player
DIM CPUPlayer1 AS Player
DIM CPUPlayer2 AS Player
DIM Sun1 AS Sun
DIM Sun2 AS Sun

' Function to calculate the distance between two players
FUNCTION DistanceToPlayer(Player1 AS Player, Player2 AS Player) AS SINGLE
    DistanceToPlayer = SQR((Player1.X

Guess not... But wait, is it starting over? 
We've seen the Player and Sun UDTs already, but we haven't seen this Shot UDT before! 
That's new - what gives?? Can we coax some more out of it? 

Code: (Select All)
go on
Certainly! Here is the rest of the Spacewar! game in QB64 that allows two players to control their ships with the keyboard, and includes two additional computer-controlled players and two suns:

- Player2.X) ^ 2 + (Player1.Y - Player2.Y) ^ 2)
END FUNCTION

' Function to check for a collision between two players
FUNCTION PlayerCollision(Player1 AS Player, Player2 AS Player) AS BOOLEAN
    If DistanceToPlayer(Player1, Player2) < 10 Then
        PlayerCollision = True
    Else
        PlayerCollision = False
    End If
END FUNCTION

' Function to check for a collision between a player and a sun
FUNCTION PlayerSunCollision(Player AS Player, Sun AS Sun) AS BOOLEAN
    If DistanceToPlayer(Player, Sun) < 10 Then
        PlayerSunCollision = True
    Else
        PlayerSunCollision = False
    End If
END FUNCTION

' Function to check for a collision between a shot and a player
FUNCTION ShotPlayerCollision(Shot AS Shot, Player AS Player) AS BOOLEAN
    If DistanceToPlayer(Shot, Player) < 5 Then
        ShotPlayerCollision = True
    Else
        ShotPlayerCollision = False
    End If
END FUNCTION

' Function to check for a collision between a shot and a sun
FUNCTION ShotSunCollision(Shot AS Shot, Sun AS Sun) AS BOOLEAN
    If DistanceToPlayer(Shot, Sun) < 5 Then
        ShotSunCollision = True
    Else
        ShotSunCollision = False
    End If
END FUNCTION

' Update a player's rotation
SUB UpdatePlayerRotation(Player AS Player, LeftKey AS BOOLEAN, RightKey AS BOOLEAN)
    If LeftKey Then
        Player.RotationSpeed = Player.RotationSpeed - 0.1
    ElseIf RightKey Then
        Player.RotationSpeed = Player.RotationSpeed + 0.1
    Else
        Player.RotationSpeed = Player.RotationSpeed * 0.9
    End If
    Player.Angle = Player.Angle + Player

Mmmmmkay, so is there an end to this? 
We'll continue, as long as our sanity holds out!

Code: (Select All)
do continue
Certainly! Here is the rest of the Spacewar! game in QB64 that allows two players to control their ships with the keyboard, and includes two additional computer-controlled players and two suns:

'.RotationSpeed
END SUB

' Update a player's thrust
SUB UpdatePlayerThrust(Player AS Player, UpKey AS BOOLEAN)
    If UpKey Then
        Player.IsThrusting = True
        Player.Speed = Player.Speed + 0.1
    Else
        Player.IsThrusting = False
    End If
END SUB

' Update a player's position based on their speed and angle
SUB UpdatePlayerPosition(Player AS Player)
    Player.X = Player.X + Player.Speed * COS(Player.Angle)
    Player.Y = Player.Y + Player.Speed * SIN(Player.Angle)
END SUB

' Update the computer-controlled players
SUB UpdateCPUPlayers
    CPUPlayer1.Angle = ATN2(Player1.Y - CPUPlayer1.Y, Player1.X - CPUPlayer1.X)
    CPUPlayer1.Speed = CPUPlayer1.Speed + 0.1
    CPUPlayer1.X = CPUPlayer1.X + CPUPlayer1.Speed * COS(CPUPlayer1.Angle)
    CPUPlayer1.Y = CPUPlayer1.Y + CPUPlayer1.Speed * SIN(CPUPlayer1.Angle)
    CPUPlayer2.Angle = ATN2(Player2.Y - CPUPlayer2.Y, Player2.X - CPUPlayer2.X)
    CPUPlayer2.Speed = CPUPlayer2.Speed + 0.1
    CPUPlayer2.X = CPUPlayer2.X + CPUPlayer2.Speed * COS(CPUPlayer2.Angle)
    CPUPlayer2.Y = CPUPlayer2.Y + CPUPlayer2.Speed * SIN(CPUPlayer2.Angle)
END SUB

' Update a player's position based on the gravity of the suns
SUB UpdatePlayerGravity(Player AS Player)
    Dim GravityForce As Single
    GravityForce = (Sun1.Mass

And again...

Code: (Select All)
more, please (continue listing the rest of the program)
Certainly! Here is the rest of the Spacewar! game in QB64 that allows two players to control their ships with the keyboard, and includes two additional computer-controlled players and two suns:

* Player.Mass) / DistanceToPlayer(Player, Sun1) ^ 2
    Player.X = Player.X + GravityForce * (Sun1.X - Player.X) / DistanceToPlayer(Player, Sun1)
    Player.Y = Player.Y + GravityForce * (Sun1.Y - Player.Y) / DistanceToPlayer(Player, Sun1)
    GravityForce = (Sun2.Mass * Player.Mass) / DistanceToPlayer(Player, Sun2) ^ 2
    Player.X = Player.X + GravityForce * (Sun2.X - Player.X) / DistanceToPlayer(Player, Sun2)
    Player.Y = Player.Y + GravityForce * (Sun2.Y - Player.Y) / DistanceToPlayer(Player, Sun2)
END SUB

' Update a shot's position based on its speed and angle
SUB UpdateShot(Shot AS Shot)
    Shot.X = Shot.X + Shot.Speed * COS(Shot.Angle)
    Shot.Y = Shot.Y + Shot.Speed * SIN(Shot.Angle)
END SUB

' Draw a player
SUB DrawPlayer(Player AS Player)
    SCREEN(Player.X, Player.Y) = Player.Color
    SCREEN(Player.X + 5 * COS(Player.Angle), Player.Y + 5 * SIN(Player.Angle)) = Player.Color
    SCREEN(Player.X + 5 * COS(Player.Angle + 1.5), Player.Y + 5 * SIN(Player.Angle + 1.5)) = Player.Color
    SCREEN(Player.X + 5 * COS(Player.Angle - 1.5), Player.Y + 5 * SIN(Player.Angle - 1.5)) = Player.Color
    If Player.IsThrusting Then
        SCREEN(Player.X + 5 * COS(Player.Angle + 1.5), Player.Y + 5 * SIN(Player.Angle + 1.5)) = RGB(255, 0, 0)
        SCREEN(Player.X + 5 * COS(Player.Angle - 1.5), Player.Y + 5 * SIN(Player.Angle - 1.5)) = RGB(255, 0, 0)
    End If
END SUB

' Draw a shot
SUB DrawShot(Shot AS Shot)
    SCREEN(Shot.X, Shot.Y) = Shot.Color
END SUB

' Initialize the game
SCREEN Initialize
SCREEN SetRes 800, 600
SCREEN SetTitle "Spacewar!"

' Set the player properties
Player1.X = 400
Player1.Y = 300
Player1.Angle = 0
Player1.RotationSpeed = 0
Player1.Speed = 0
Player1.IsThrusting = False
Player1.Mass = 1
Player1.Color = RGB(255, 255, 0)
Set Player1.Shots = New Collection

Player2.X = 400

...aaaaand again...!

Code: (Select All)
continue listing the rest of the program please
Certainly! Here is the rest of the Spacewar! game in QB64 that allows two players to control their ships with the keyboard, and includes two additional computer-controlled players and two suns:

Player2.Y = 300
Player2.Angle = 0
Player2.RotationSpeed = 0
Player2.Speed = 0
Player2.IsThrusting = False
Player2.Mass = 1
Player2.Color = RGB(0, 255, 255)
Set Player2.Shots = New Collection

CPUPlayer1.X = 100
CPUPlayer1.Y = 100
CPUPlayer1.Angle = 0
CPUPlayer1.RotationSpeed = 0
CPUPlayer1.Speed = 0
CPUPlayer1.IsThrusting = False
CPUPlayer1.Mass = 1
CPUPlayer1.Color = RGB(255, 0, 255)
Set CPUPlayer1.Shots = New Collection

CPUPlayer2.X = 700
CPUPlayer2.Y = 500
CPUPlayer2.Angle = 0
CPUPlayer2.RotationSpeed = 0
CPUPlayer2.Speed = 0
CPUPlayer2.IsThrusting = False
CPUPlayer2.Mass = 1
CPUPlayer2.Color = RGB(0, 255, 0)
Set CPUPlayer2.Shots = New Collection

' Set the sun properties
Sun1.X = 100
Sun1.Y = 500
Sun1.Mass = 100

Sun2.X = 700
Sun2.Y = 100
Sun2.Mass = 100

' Main game loop
DO
    ' Clear the screen
    SCREEN Cls

    ' Draw the suns
    SCREEN(Sun1.X, Sun1.Y) = RGB(255, 255, 0)
    SCREEN(Sun2.X, Sun2.Y) = RGB(255, 255, 0)

    ' Check for player and sun collisions
    If PlayerSunCollision(Player1, Sun1) Or PlayerSunCollision(Player1, Sun2) Then
        ' End the game
        EXIT DO
    End If
    If PlayerSunCollision(Player2, Sun1) Or PlayerSunCollision(Player2, Sun2) Then
        ' End the game
        EXIT DO
    End If
    If PlayerSunCollision(CPUPlayer1, Sun1) Or PlayerSunCollision(CPUPlayer1, Sun2) Then
        ' End the game
        EXIT DO
    End If
    If PlayerSunCollision(CPUPlayer2, Sun1) Or PlayerSunCollision(CPUPlayer2, Sun2) Then
        ' End the game
        EXIT DO
    End If

    ' Check for player collisions
    If PlayerCollision(Player

Don't stop now! We're so close! (yeah, right)

Code: (Select All)
keep listing the rest of the program
Certainly! Here is the rest of the Spacewar! game in QB64 that allows two players to control their ships with the keyboard, and includes two additional computer-controlled players and two suns:

, Player2) Or PlayerCollision(Player1, CPUPlayer1) Or PlayerCollision(Player1, CPUPlayer2) Then
        ' End the game
        EXIT DO
    End If
    If PlayerCollision(Player2, CPUPlayer1) Or PlayerCollision(Player2, CPUPlayer2) Then
        ' End the game
        EXIT DO
    End If

    ' Check for shot and player collisions
    For i = 0 To Player1.Shots.Count - 1
        If ShotPlayerCollision(Player1.Shots(i), Player2) Then
            Player1.Shots.Remove(i)
        End If
        If ShotPlayerCollision(Player1.Shots(i), CPUPlayer1) Then
            Player1.Shots.Remove(i)
        End If
        If ShotPlayerCollision(Player1.Shots(i), CPUPlayer2) Then
            Player1.Shots.Remove(i)
        End If
    Next
    For i = 0 To Player2.Shots.Count - 1
        If ShotPlayerCollision(Player2.Shots(i), Player1) Then
            Player2.Shots.Remove(i)
        End If
        If ShotPlayerCollision(Player2.Shots(i), CPUPlayer1) Then
            Player2.Shots.Remove(i)
        End If
        If ShotPlayerCollision(Player2.Shots(i), CPUPlayer2) Then
            Player2.Shots.Remove(i)
        End If
    Next
    For i = 0 To CPUPlayer1.Shots.Count - 1
        If ShotPlayerCollision(CPUPlayer1.Shots(i), Player1) Then
            CPUPlayer1.

I can't wait to piece this all together, and see what this hunk of burnin' love hath wrought!

Code: (Select All)
please keep going and list the rest
Certainly! Here is the rest of the Spacewar! game in QB64 that allows two players to control their ships with the keyboard, and includes two additional computer-controlled players and two suns:

Shots.Remove(i)
        End If
        If ShotPlayerCollision(CPUPlayer1.Shots(i), Player2) Then
            CPUPlayer1.Shots.Remove(i)
        End If
        If ShotPlayerCollision(CPUPlayer1.Shots(i), CPUPlayer2) Then
            CPUPlayer1.Shots.Remove(i)
        End If
    Next
    For i = 0 To CPUPlayer2.Shots.Count - 1
        If ShotPlayerCollision(CPUPlayer2.Shots(i), Player1) Then
            CPUPlayer2.Shots.Remove(i)
        End If
        If ShotPlayerCollision(CPUPlayer2.Shots(i), Player2) Then
            CPUPlayer2.Shots.Remove(i)
        End If
        If ShotPlayerCollision(CPUPlayer2.Shots(i), CPUPlayer1) Then
            CPUPlayer2.Shots.Remove(i)
        End If
    Next

    ' Check for shot and sun collisions
    For i = 0 To Player1.Shots.Count - 1
        If ShotSunCollision(Player1.Shots(i), Sun1) Or ShotSunCollision(Player1.Shots(i), Sun2) Then
            Player1.Shots.Remove(i)
        End If
    Next
    For i = 0 To Player2.Shots.Count - 1
        If ShotSunCollision(Player2.Shots(i), Sun1) Or ShotSunCollision(Player2.Shots(i), Sun2) Then
            Player2.Shots.Remove(i)
        End If
    Next
    For i = 0 To CPUPlayer1.Shots.Count - 1
        If ShotSunCollision(CPUPlayer1.Shots(i), Sun1) Or ShotSunCollision(CPUPlayer1.Shots(i), Sun2) Then
            CPUPlayer1.Shots.Remove(i)
        End If
    Next
    For i = 0 To CPUPlayer2.Shots.Count - 1
        If ShotSunCollision(CPUPlayer2.Shots(i), Sun1) Or ShotSunCollision(CPUPlayer2.Shots(i), Sun2) Then
            CPUPlayer2.Shots.Remove(i)
        End If
    Next

    ' Update the player rotations
    UpdatePlayerRotation Player1, KEY(37), KEY(39)
    UpdatePlayerRotation Player2, KEY(65), KEY(68)

    ' Update the player thrusts
    UpdatePlayerThrust Player1, KEY(38)
    Update

I must be a glutton for punishment!
(and you too, gentle reader, if you're still following along!)

Code: (Select All)
please list the rest
Certainly! Here is the rest of the Spacewar! game in QB64 that allows two players to control their ships with the keyboard, and includes two additional computer-controlled players and two suns:

PlayerThrust Player2, KEY(87)

    ' Update the players' positions
    UpdatePlayerPosition Player1
    UpdatePlayerPosition Player2
    UpdateCPUPlayers

    ' Update the players' positions based on gravity
    UpdatePlayerGravity Player1
    UpdatePlayerGravity Player2
    UpdatePlayerGravity CPUPlayer1
    UpdatePlayerGravity CPUPlayer2

    ' Update the shots' positions
    For i = 0 To Player1.Shots.Count - 1
        UpdateShot Player1.Shots(i)
    Next
    For i = 0 To Player2.Shots.Count - 1
        UpdateShot Player2.Shots(i)
    Next
    For i = 0 To CPUPlayer1.Shots.Count - 1
        UpdateShot CPUPlayer1.Shots(i)
    Next
    For i = 0 To CPUPlayer2.Shots.Count - 1
        UpdateShot CPUPlayer2.Shots(i)
    Next

    ' Draw the players
    DrawPlayer Player1
    DrawPlayer Player2
    DrawPlayer CPUPlayer1
    DrawPlayer CPUPlayer2

    ' Draw the shots
    For i = 0 To Player1.Shots.Count - 1
        DrawShot Player1.Shots(i)
    Next
    For i = 0 To Player2.Shots.Count - 1
        DrawShot Player2.Shots(i)
    Next
    For i = 0 To CPUPlayer1.Shots.Count - 1
        DrawShot CPUPlayer1.Shots(i)
    Next
    For i = 0 To CPUPlayer2.Shots.Count - 1
        DrawShot CPUPlayer2.Shots(i)
    Next

    ' Check for player firing
    If KEY(13) Then
        Dim Shot As Shot
        Shot.X = Player1.X + 5 * COS(Player1.Angle)
        Shot.Y = Player1.Y + 5 * SIN(Player1.Angle

Will it ever end??? 

Code: (Select All)
please list the rest
Certainly! Here is the rest of the Spacewar! game in QB64 that allows two players to control their ships with the keyboard, and includes two additional computer-controlled players and two suns:

Shot.Angle = Player1.Angle
Shot.Speed = 5
Shot.Color = RGB(255, 255, 255)
Player1.Shots.Add Shot
    End If
    If KEY(69) Then
        Dim Shot As Shot
        Shot.X = Player2.X + 5 * COS(Player2.Angle)
        Shot.Y = Player2.Y + 5 * SIN(Player2.Angle)
        Shot.Angle = Player2.Angle
        Shot.Speed = 5
        Shot.Color = RGB(255, 255, 255)
        Player2.Shots.Add Shot
    End If

    ' Update the screen
    SCREEN Update
LOOP

' End the game
SCREEN Close
I hope this helps! Let me know if you have any questions or need further assistance.

ChatGPT Dec 15 Version. Free Research Preview. Our goal is to make AI systems more natural and safe to interact with. Your feedback will help us improve.

You hope this helps! 
Oh it helped, all right! 
Helped me straight to the looney bin!

Up next, let's try to piece this bad boy together!
Reply
#2
Well here it is, the whole she-bang. 

Evidently when I asked it to email the program, and it listed that code, the second listing did things slightly differently than the first. However, each version had things the other was missing, so I merged them. There were places where the same thing was done slightly differently, and I had to use my best judgment / guess which version of the code to go with. Wherever I wasn't entirely sure, I also included the 2nd version commented out, just in case. To facilitate merging & de-duping, I changed the order of the subs/functions to be alphabetic, just to make them easy to find. 

This is a total hack, but all the code is here, and with some editing it should work. Some issues are easy to fix - for example chatgpt doesn't seem to realize that there is no native Boolean in QB64, so we just change "boolean" to "integer" and make constants for TRUE and FALSE. Some not so trivial, for example there is no such thing as a Collection in QB64! That, and maybe some other things, will have to be reworked. 

But for a general skeleton of a Spacewar! game, it's probably decent. If anyone wants to try to make this bad boy live, have at it! :-D

Code: (Select All)
' Spacewar! the classic game, which we tried to have chatgpt program for us...
'
' >Can you write a 2 player Spacewar! game in QB64 where the players are
' >controlled with the keyboard, (player 1 controls are: up arrow = thrust, down
' >arrow = warp, left arrow = rotate left, right arrow = rotate right, ENTER =
' >fire; player 2 controls are: A = rotate left, D = rotate right, S = warp, W =
' >thrust,  E = fire), and includes 2 additional computer controlled players, and
' >2 suns?
' Sure! Here is a simple Spacewar! game in QB64 that allows two players to
' control their ships with the keyboard, and includes two additional
' computer-controlled players and two suns:

' Declare constants for the screen width and height
CONST SCREEN_WIDTH = 640
CONST SCREEN_HEIGHT = 480

' Declare constants for the player colors
CONST PLAYER_1_COLOR = 15
CONST PLAYER_2_COLOR = 11
CONST CPU_PLAYER_COLOR = 7

' Declare constants for the sun colors
CONST SUN_1_COLOR = 12
CONST SUN_2_COLOR = 14

' Declare constants for the player controls
CONST PLAYER_1_UP = 72
CONST PLAYER_1_DOWN = 80
CONST PLAYER_1_LEFT = 75
CONST PLAYER_1_RIGHT = 77
CONST PLAYER_1_FIRE = 13

CONST PLAYER_2_UP = 87
CONST PLAYER_2_DOWN = 83
CONST PLAYER_2_LEFT = 65
CONST PLAYER_2_RIGHT = 68
CONST PLAYER_2_FIRE = 69

' Declare constants for the game states
CONST GAME_STATE_INITIALIZING = 0
CONST GAME_STATE_PLAYING = 1
CONST GAME_STATE_PAUSED = 2
CONST GAME_STATE_OVER = 3

' Declare variables for the game state and the player scores
DIM GameState AS INTEGER
DIM Player1Score AS INTEGER
DIM Player2Score AS INTEGER

' Declare a type for the players
' Struct to represent a player
TYPE Player
    X AS SINGLE
    Y AS SINGLE
    Angle AS SINGLE
    Speed AS SINGLE
    RotationSpeed AS SINGLE
    IsThrusting AS integer ' BOOLEAN
    Mass AS SINGLE
    'Color AS INTEGER
    Color AS LONG
    Shots AS Collection
    IsComputerControlled AS BOOLEAN
END TYPE

' Struct to represent a shot
TYPE Shot
    X AS SINGLE
    Y AS SINGLE
    Angle AS SINGLE
    Speed AS SINGLE
    Color AS LONG
END TYPE

' Declare a type for the suns
' Struct to represent a sun
TYPE Sun
    X AS SINGLE
    Y AS SINGLE
    Mass AS SINGLE
    Color AS INTEGER
END TYPE

' Declare variables for the players
DIM Player1 AS Player
DIM Player2 AS Player
DIM CPUPlayer1 AS Player
DIM CPUPlayer2 AS Player

' Declare variables for the suns
DIM Sun1 AS Sun
DIM Sun2 AS Sun

' ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

' Initialize the game
SCREEN Initialize

' Set the screen update rate
SCREEN UpdateRate(30)

' Set the window title
'WINDOW Title$ = "Spacewar!"
SCREEN SetTitle "Spacewar!"

' Set the window size
'WINDOW Width = 320, Height = 240
SCREEN SetRes 800, 600

' ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

' Initialize the players
' Set the player properties

Player1.X = 100
Player1.Y = 100
Player1.Angle = 0
Player1.RotationSpeed = 0
Player1.Speed = 0
Player1.IsThrusting = False
Player1.Mass = 10
Player1.Color = RGB(255, 0, 0)
'Player1.X = 400
'Player1.Y = 300
'Player1.Angle = 0
'Player1.RotationSpeed = 0
'Player1.Speed = 0
'Player1.IsThrusting = False
'Player1.Mass = 1
'Player1.Color = RGB(255, 255, 0)
'Set Player1.Shots = New Collection

Player2.X = 200
Player2.Y = 100
Player2.Angle = 0
Player2.RotationSpeed = 0
Player2.Speed = 0
Player2.IsThrusting = False
Player2.Mass = 10
Player2.Color = RGB(0, 255, 0)
'Player2.X = 400
'Player2.Y = 300
'Player2.Angle = 0
'Player2.RotationSpeed = 0
'Player2.Speed = 0
'Player2.IsThrusting = False
'Player2.Mass = 1
'Player2.Color = RGB(0, 255, 255)
'Set Player2.Shots = New Collection

CPUPlayer1.X = 100
CPUPlayer1.Y = 200
CPUPlayer1.Angle = 0
CPUPlayer1.RotationSpeed = 0
CPUPlayer1.Speed = 0
CPUPlayer1.IsThrusting = False
CPUPlayer1.Mass = 10
CPUPlayer1.Color = RGB(0, 0, 255)
'CPUPlayer1.X = 100
'CPUPlayer1.Y = 100
'CPUPlayer1.Angle = 0
'CPUPlayer1.RotationSpeed = 0
'CPUPlayer1.Speed = 0
'CPUPlayer1.IsThrusting = False
'CPUPlayer1.Mass = 1
'CPUPlayer1.Color = RGB(255, 0, 255)
'Set CPUPlayer1.Shots = New Collection

CPUPlayer2.X = 200
CPUPlayer2.Y = 200
CPUPlayer2.Angle = 0
CPUPlayer2.RotationSpeed = 0
CPUPlayer2.Speed = 0
CPUPlayer2.IsThrusting = False
CPUPlayer2.Mass = 10
CPUPlayer2.Color = RGB(255, 255, 0)
'CPUPlayer2.X = 700
'CPUPlayer2.Y = 500
'CPUPlayer2.Angle = 0
'CPUPlayer2.RotationSpeed = 0
'CPUPlayer2.Speed = 0
'CPUPlayer2.IsThrusting = False
'CPUPlayer2.Mass = 1
'CPUPlayer2.Color = RGB(0, 255, 0)
'Set CPUPlayer2.Shots = New Collection

' Initialize the suns
' Set the sun properties
Sun1.X = 150
Sun1.Y = 150
Sun1.Mass = 1000
'Sun1.X = 100
'Sun1.Y = 500
'Sun1.Mass = 100

Sun2.X = 250
Sun2.Y = 150
Sun2.Mass = 1000
'Sun2.X = 700
'Sun2.Y = 100
'Sun2.Mass = 100

' This is the main game loop that updates and draws the players, suns, and shots,
' and checks for collisions between them. The game ends when any two players
' collide, a player collides with a sun, or a shot hits a player or sun.

' Main game loop
DO
    ' ================================================================================================================================================================
    ' Clear the screen
    CLS
    'SCREEN Cls

    ' ================================================================================================================================================================
    ' Update the players

    ' Update the player rotations
    UpdatePlayerRotation Player1, KEY(37), KEY(39)
    UpdatePlayerRotation Player2, KEY(65), KEY(68)
    'UpdatePlayerRotation(Player1, GetKeyState(VK_LEFT) AND 1, GetKeyState(VK_RIGHT) AND 1)
    'UpdatePlayerRotation(Player2, GetKeyState(VK_A) AND 1, GetKeyState(VK_D) AND 1)

    ' Update the player thrusts
    UpdatePlayerThrust Player1, KEY(38)
    UpdatePlayerThrust Player2, KEY(87)
    'UpdatePlayerThrust(Player1, GetKeyState(VK_UP) AND 1)
    'UpdatePlayerThrust(Player2, GetKeyState(VK_W) AND 1)

    ' Update the players' positions
    UpdatePlayerPosition Player1
    'UpdatePlayerPosition(Player1)
    UpdatePlayerPosition Player2
    'UpdatePlayerPosition(Player2)
    UpdateCPUPlayers

    ' Update the players' positions based on gravity
    UpdatePlayerGravity Player1
    'UpdatePlayerGravity(Player1)
    UpdatePlayerGravity Player2
    'UpdatePlayerGravity(Player2)
    UpdatePlayerGravity CPUPlayer1
    'UpdatePlayerGravity(CPUPlayer1)
    UpdatePlayerGravity CPUPlayer2
    'UpdatePlayerGravity(CPUPlayer2)

    ' Check for player firing
    If KEY(13) Then
        Dim Shot As Shot
        Shot.X = Player1.X + 5 * COS(Player1.Angle)
        Shot.Y = Player1.Y + 5 * SIN(Player1.Angle
        Shot.Angle = Player1.Angle
        Shot.Speed = 5
        Shot.Color = RGB(255, 255, 255)
        Player1.Shots.Add Shot
    End If
    If KEY(69) Then
        Dim Shot As Shot
        Shot.X = Player2.X + 5 * COS(Player2.Angle)
        Shot.Y = Player2.Y + 5 * SIN(Player2.Angle)
        Shot.Angle = Player2.Angle
        Shot.Speed = 5
        Shot.Color = RGB(255, 255, 255)
        Player2.Shots.Add Shot
    End If

    ' ================================================================================================================================================================
    ' Draw the players
    DrawPlayer(Player1)
    DrawPlayer(Player2)
    DrawPlayer(CPUPlayer1)
    DrawPlayer(CPUPlayer2)

    ' ================================================================================================================================================================
    ' Draw the suns
    CIRCLE (Sun1.X, Sun1.Y), 10, RGB(255, 255, 0)
    CIRCLE (Sun2.X, Sun2.Y), 10, RGB(255, 255, 0)
    'SCREEN(Sun1.X, Sun1.Y) = RGB(255, 255, 0)
    'SCREEN(Sun2.X, Sun2.Y) = RGB(255, 255, 0)

    ' ================================================================================================================================================================
    ' Check for player collisions
    If PlayerCollision(Player1, Player2) Then
        ' End the game
        EXIT DO
    End If
    If PlayerCollision(Player1, CPUPlayer1) Then
        ' End the game
        EXIT DO
    End If
    If PlayerCollision(Player1, CPUPlayer2) Then
        ' End the game
        EXIT DO
    End If
    If PlayerCollision(Player2, CPUPlayer1) Then
        ' End the game
        EXIT DO
    End If
    If PlayerCollision(Player2, CPUPlayer2) Then
        ' End the game
        EXIT DO
    End If

    '' Check for player collisions
    'If PlayerCollision(Player1, Player2) Or PlayerCollision(Player1, CPUPlayer1) Or PlayerCollision(Player1, CPUPlayer2) Then
    '    ' End the game
    '    EXIT DO
    'End If
    'If PlayerCollision(Player2, CPUPlayer1) Or PlayerCollision(Player2, CPUPlayer2) Then
    '    ' End the game
    '    EXIT DO
    'End If





    ' ================================================================================================================================================================
    ' Check for player and sun collisions
    If PlayerSunCollision(Player1, Sun1) Or PlayerSunCollision(Player1, Sun2) Then
        ' End the game
        EXIT DO
    End If
    If PlayerSunCollision(Player2, Sun1) Or PlayerSunCollision(Player2, Sun2) Then
        ' End the game
        EXIT DO
    End If
    If PlayerSunCollision(CPUPlayer1, Sun1) Or PlayerSunCollision(CPUPlayer1, Sun2) Then
        ' End the game
        EXIT DO
    End If
    If PlayerSunCollision(CPUPlayer2, Sun1) Or PlayerSunCollision(CPUPlayer2, Sun2) Then
        ' End the game
        EXIT DO
    End If
    'If PlayerSunCollision(Player1, Sun1) Then
    '    ' End the game
    '    EXIT DO
    'End If
    'If PlayerSunCollision(Player1, Sun2) Then
    '    ' End the game
    '    EXIT DO
    'End If
    'If PlayerSunCollision(Player2, Sun1) Then
    '    ' End the game
    '    EXIT DO
    'End If
    'If PlayerSunCollision(Player2, Sun2) Then
    '    ' End the game
    '    EXIT DO
    'End If
    'If PlayerSunCollision(CPUPlayer1, Sun1) Then
    '    ' End the game
    '    EXIT DO
    'End If
    'If PlayerSunCollision(CPUPlayer1, Sun2) Then
    '    ' End the game
    '    EXIT DO
    'End If
    'If PlayerSunCollision(CPUPlayer2, Sun1) Then
    '    ' End the game
    '    EXIT DO
    'End If
    'If PlayerSunCollision(CPUPlayer2, Sun2) Then
    '    ' End the game
    '    EXIT DO
    'End If

    ' ================================================================================================================================================================
    ' Check for player shots
    If GetKeyState(VK_RETURN) AND 1 Then
        Player1.Shots.AddNew
        Player1.Shots(Player1.Shots.Count).X = Player1.X + 5 * COS(Player1.Angle)
        Player1.Shots(Player1.Shots.Count).Y = Player1.Y + 5 * SIN(Player1.Angle)
        Player1.Shots(Player1.Shots.Count).Angle = Player1.Angle
    End If
    If GetKeyState(VK_E) AND 1 Then
        Player2.Shots.AddNew
        Player2.Shots(Player2.Shots.Count).X = Player2.X + 5 * COS(Player2.Angle)
        Player2.Shots(Player2.Shots.Count).Y = ???
        Player2.Shots(Player2.Shots.Count).Angle = Player2.Angle
    End If

    ' ================================================================================================================================================================
    ' Update and draw the player shots
    'For i = 0 To Player1.Shots.Count - 1
    '    UpdateShot(Player1.Shots(i))
    '    DrawShot(Player1.Shots(i))
    'Next
    'For i = 0 To Player2.Shots.Count - 1
    '    UpdateShot(Player2.Shots(i))
    '    DrawShot(Player2.Shots(i))
    'Next

    ' Update the shots' positions
    For i = 0 To Player1.Shots.Count - 1
        UpdateShot Player1.Shots(i)
    Next
    For i = 0 To Player2.Shots.Count - 1
        UpdateShot Player2.Shots(i)
    Next
    For i = 0 To CPUPlayer1.Shots.Count - 1
        UpdateShot CPUPlayer1.Shots(i)
    Next
    For i = 0 To CPUPlayer2.Shots.Count - 1
        UpdateShot CPUPlayer2.Shots(i)
    Next

    ' Draw the shots
    For i = 0 To Player1.Shots.Count - 1
        DrawShot Player1.Shots(i)
    Next
    For i = 0 To Player2.Shots.Count - 1
        DrawShot Player2.Shots(i)
    Next
    For i = 0 To CPUPlayer1.Shots.Count - 1
        DrawShot CPUPlayer1.Shots(i)
    Next
    For i = 0 To CPUPlayer2.Shots.Count - 1
        DrawShot CPUPlayer2.Shots(i)
    Next

    ' ================================================================================================================================================================
    ' Check for shot and player collisions

    ' check for player 1
    For i = 0 To Player1.Shots.Count - 1
        If ShotPlayerCollision(Player1.Shots(i), Player2) Then
            'Player1.Shots.Remove(i)

            ' End the game
            EXIT DO
        End If
        If ShotPlayerCollision(Player1.Shots(i), CPUPlayer1) Then
            'Player1.Shots.Remove(i)

            ' End the game
            EXIT DO
        End If
        If ShotPlayerCollision(Player1.Shots(i), CPUPlayer2) Then
            'Player1.Shots.Remove(i)

            ' End the game
            EXIT DO
        End If
    Next

    ' check for player 2
    For i = 0 To Player2.Shots.Count - 1
        If ShotPlayerCollision(Player2.Shots(i), Player1) Then
            'Player2.Shots.Remove(i)

            ' End the game
            EXIT DO
        End If
        If ShotPlayerCollision(Player2.Shots(i), CPUPlayer1) Then
            'Player2.Shots.Remove(i)

            ' End the game
            EXIT DO
        End If
        If ShotPlayerCollision(Player2.Shots(i), CPUPlayer2) Then
            'Player2.Shots.Remove(i)

            ' End the game
            EXIT DO
        End If
    Next

    'check cpu player 1
    For i = 0 To CPUPlayer1.Shots.Count - 1
        If ShotSunCollision(CPUPlayer1.Shots(i), Sun1) Or ShotSunCollision(CPUPlayer1.Shots(i), Sun2) Then
            CPUPlayer1.Shots.Remove(i)
        End If
    Next
    ''*** REDUNDANT? ***
    'For i = 0 To CPUPlayer1.Shots.Count - 1
    '    If ShotPlayerCollision(CPUPlayer1.Shots(i), Player1) Then
    '        CPUPlayer1.Shots.Remove(i)
    '    End If
    '    If ShotPlayerCollision(CPUPlayer1.Shots(i), Player2) Then
    '        CPUPlayer1.Shots.Remove(i)
    '    End If
    '    If ShotPlayerCollision(CPUPlayer1.Shots(i), CPUPlayer2) Then
    '        CPUPlayer1.Shots.Remove(i)
    '    End If
    'Next

    'check cpu player 2
    For i = 0 To CPUPlayer2.Shots.Count - 1
        If ShotSunCollision(CPUPlayer2.Shots(i), Sun1) Or ShotSunCollision(CPUPlayer2.Shots(i), Sun2) Then
            CPUPlayer2.Shots.Remove(i)
        End If
    Next
    ''*** REDUNDANT? ***
    'For i = 0 To CPUPlayer2.Shots.Count - 1
    '    If ShotPlayerCollision(CPUPlayer2.Shots(i), Player1) Then
    '        CPUPlayer2.Shots.Remove(i)
    '    End If
    '    If ShotPlayerCollision(CPUPlayer2.Shots(i), Player2) Then
    '        CPUPlayer2.Shots.Remove(i)
    '    End If
    '    If ShotPlayerCollision(CPUPlayer2.Shots(i), CPUPlayer1) Then
    '        CPUPlayer2.Shots.Remove(i)
    '    End If
    'Next


    ' Check for shot and sun collisions
    For i = 0 To Player1.Shots.Count - 1
        If ShotSunCollision(Player1.Shots(i), Sun1) Or ShotSunCollision(Player1.Shots(i), Sun2) Then
            Player1.Shots.Remove(i)
        End If
        'If ShotSunCollision(Player1.Shots(i), Sun1) Then
        '    Player1.Shots.Remove(i)
        'End If
        'If ShotSunCollision(Player1.Shots(i), Sun2) Then
        '    Player1.Shots.Remove(i)
        'End If
    Next
    For i = 0 To Player2.Shots.Count - 1
        If ShotSunCollision(Player2.Shots(i), Sun1) Or ShotSunCollision(Player2.Shots(i), Sun2) Then
            Player2.Shots.Remove(i)
        End If
        'If ShotSunCollision(Player2.Shots(i), Sun1) Then
        '    Player2.Shots.Remove(i)
        'End If
        'If ShotSunCollision(Player2.Shots(i), Sun2) Then
        '    Player2.Shots.Remove(i)
        'End If
    Next

    ' Update the screen
    SCREEN Update

LOOP

' End the game
SCREEN Close

System

' ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

' Function to calculate the distance between two players
FUNCTION DistanceToPlayer(Player1 AS Player, Player2 AS Player) AS SINGLE
    DistanceToPlayer = SQR((Player1.X - Player2.X) ^ 2 + (Player1.Y - Player2.Y) ^ 2)
END FUNCTION ' DistanceToPlayer

' ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

' This subroutine draws a triangle representing the player's ship and, if the
' player is thrusting, a flame behind their ship. The points of the triangle are
' calculated using the player's angle and the coordinates of the player's ship.
' The triangle is then drawn using the player's color. If the player is
' thrusting, two lines are drawn behind the triangle to represent the flame.
SUB DrawPlayer(Player AS Player)
    ' Calculate the points of the triangle representing the player's ship
    X1 = Player.X + 5 * COS(Player.Angle)
    Y1 = Player.Y + 5 * SIN(Player.Angle)
    X2 = Player.X + 5 * COS(Player.Angle + 120)
    Y2 = Player.Y + 5 * SIN(Player.Angle + 120)
    X3 = Player.X + 5 * COS(Player.Angle + 240)
    Y3 = Player.Y + 5 * SIN(Player.Angle + 240)

    ' Draw the triangle representing the player's ship
    LINE (X1, Y1)-(X2, Y2), Player.Color
    LINE (X2, Y2)-(X3, Y3), Player.Color
    LINE (X3, Y3)-(X1, Y1), Player.Color

    ' If the player is thrusting, draw a flame behind their ship
    If Player.IsThrusting Then
        LINE (X2, Y2)-(X2 + 2 * COS(Player.Angle + 180), Y2 + 2 * SIN(Player.Angle + 180)), Player.Color
        LINE (X3, Y3)-(X3 + 2 * COS(Player.Angle + 180), Y3 + 2 * SIN(Player.Angle + 180)), Player.Color
    End If
END SUB ' DrawPlayer

' ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
'
'' Draw a player
'SUB DrawPlayer(Player AS Player)
'    SCREEN(Player.X, Player.Y) = Player.Color
'    SCREEN(Player.X + 5 * COS(Player.Angle), Player.Y + 5 * SIN(Player.Angle)) = Player.Color
'    SCREEN(Player.X + 5 * COS(Player.Angle + 1.5), Player.Y + 5 * SIN(Player.Angle + 1.5)) = Player.Color
'    SCREEN(Player.X + 5 * COS(Player.Angle - 1.5), Player.Y + 5 * SIN(Player.Angle - 1.5)) = Player.Color
'    If Player.IsThrusting Then
'        SCREEN(Player.X + 5 * COS(Player.Angle + 1.5), Player.Y + 5 * SIN(Player.Angle + 1.5)) = RGB(255, 0, 0)
'        SCREEN(Player.X + 5 * COS(Player.Angle - 1.5), Player.Y + 5 * SIN(Player.Angle - 1.5)) = RGB(255, 0, 0)
'    End If
'END SUB

' ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

' Draw a shot
SUB DrawShot(Shot AS Shot)
    SCREEN(Shot.X, Shot.Y) = Shot.Color
END SUB ' DrawShot

' ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
' Initialize the game
SUB InitializeGame
    ' Set the game state to initializing
    GameState = GAME_STATE_INITIALIZING

    ' Initialize the player scores
    Player1Score = 0
    Player2Score = 0

    ' Initialize player 1
    Player1.X = SCREEN_WIDTH / 4
    Player1.Y = SCREEN_HEIGHT / 2
    Player1.Angle = 0
    Player1.Speed = 0
    Player1.RotationSpeed = 0
    Player1.Color = PLAYER_1_COLOR
    Player1.IsComputerControlled = False

    ' Initialize player 2
    Player2.X = SCREEN_WIDTH * 3 / 4
    Player2.Y = SCREEN_HEIGHT / 2
    Player2.Angle = 180
    Player2.Speed = 0
    Player2.R
    ???
END SUB ' InitializeGame

' ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
' Function to check for a collision between two players
FUNCTION PlayerCollision(Player1 AS Player, Player2 AS Player) AS BOOLEAN
    If DistanceToPlayer(Player1, Player2) < 10 Then
        PlayerCollision = True
    Else
        PlayerCollision = False
    End If
END FUNCTION ' PlayerCollision

' ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
' Function to check for a collision between a player and a sun
FUNCTION PlayerSunCollision(Player AS Player, Sun AS Sun) AS BOOLEAN
    If DistanceToPlayer(Player, Sun) < 10 Then
        PlayerSunCollision = True
    Else
        PlayerSunCollision = False
    End If
END FUNCTION ' PlayerSunCollision

' ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
' Function to check for a collision between a shot and a player
FUNCTION ShotPlayerCollision(Shot AS Shot, Player AS Player) AS BOOLEAN
    If DistanceToPlayer(Shot, Player) < 5 Then
        ShotPlayerCollision = True
    Else
        ShotPlayerCollision = False
    End If
END FUNCTION ' ShotPlayerCollision

' ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
' Function to check for a collision between a shot and a sun
FUNCTION ShotSunCollision(Shot AS Shot, Sun AS Sun) AS BOOLEAN
    If DistanceToPlayer(Shot, Sun) < 5 Then
        ShotSunCollision = True
    Else
        ShotSunCollision = False
    End If
END FUNCTION ' ShotSunCollision

' ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

' Update a computer-controlled player
' This subroutine updates the position and angle of a computer-controlled player
' based on their distance to the other players and the suns. If the player is far
' from the other players and the suns, they choose a random angle and rotate
' towards it. If the player is close to a player, they move towards them. If the
' player is close to a sun, they stop thrusting.
SUB UpdateCPUPlayer(Player AS Player)
    ' Calculate the distance to player 1
    DX = Player1.X - Player.X
    DY = Player1.Y - Player.Y
    DistanceToPlayer1 = SQR(DX * DX + DY * DY)

    ' Calculate the distance to player 2
    DX = Player2.X - Player.X
    DY = Player2.Y - Player.Y
    DistanceToPlayer2 = SQR(DX * DX + DY * DY)

    ' Calculate the distance to the nearest sun
    DX = Sun1.X - Player.X
    DY = Sun1.Y - Player.Y
    DistanceToSun1 = SQR(DX * DX + DY * DY)
    DX = Sun2.X - Player.X
    DY = Sun2.Y - Player.Y
    DistanceToSun2 = SQR(DX * DX + DY * DY)
    If DistanceToSun1 < DistanceToSun2 Then
        DistanceToNearestSun = DistanceToSun1
    Else
        DistanceToNearestSun = DistanceToSun2
    End If

    ' If the player is far from the other players and the suns, move randomly
    If DistanceToPlayer1 > 100 And DistanceToPlayer2 > 100 And DistanceToNearestSun > 100 Then
        ' Choose a random angle and set the player's rotation speed
        TargetAngle = RND * 360
        If TargetAngle > Player.Angle Then
            Player.RotationSpeed = 0.5
        Else
            Player.RotationSpeed = -0.5
        End If
    ' If the player is close to a player, move towards them
    ElseIf DistanceToPlayer1 < DistanceToPlayer2 Then
        ' Calculate the angle to player 1 and set the player's rotation speed
        TargetAngle = ATN2(DY, DX) * 180 / PI
        If TargetAngle > Player.Angle Then
            Player.RotationSpeed = 0.5
        Else
            Player.RotationSpeed = -0.5
        End If
    Else
        ' Calculate the angle to player 2 and set the player's rotation speed
        TargetAngle = ATN2(DY, DX) * 180 / PI
        If TargetAngle > Player.Angle Then
            Player.RotationSpeed = 0.5
        Else
            Player.RotationSpeed = -0.5
        End If
    End If

    ' Set the player's thrust based on their distance to the nearest sun
    If DistanceToNearestSun < 50 Then
        Player.IsThrusting = False
    Else
        Player.IsThrusting = True
    End If
END SUB ' UpdateCPUPlayer

' ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

' Update the computer-controlled players
SUB UpdateCPUPlayers
    ' Update player 1
    UpdateCPUPlayer(CPUPlayer1)

    ' Update player 2
    UpdateCPUPlayer(CPUPlayer2)
END SUB ' UpdateCPUPlayers

' ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
'' Update the computer-controlled players
'SUB UpdateCPUPlayers
'    CPUPlayer1.Angle = ATN2(Player1.Y - CPUPlayer1.Y, Player1.X - CPUPlayer1.X)
'    CPUPlayer1.Speed = CPUPlayer1.Speed + 0.1
'    CPUPlayer1.X = CPUPlayer1.X + CPUPlayer1.Speed * COS(CPUPlayer1.Angle)
'    CPUPlayer1.Y = CPUPlayer1.Y + CPUPlayer1.Speed * SIN(CPUPlayer1.Angle)
'    CPUPlayer2.Angle = ATN2(Player2.Y - CPUPlayer2.Y, Player2.X - CPUPlayer2.X)
'    CPUPlayer2.Speed = CPUPlayer2.Speed + 0.1
'    CPUPlayer2.X = CPUPlayer2.X + CPUPlayer2.Speed * COS(CPUPlayer2.Angle)
'    CPUPlayer2.Y = CPUPlayer2.Y + CPUPlayer2.Speed * SIN(CPUPlayer2.Angle)
'END SUB

' ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

' Update the player's position and angle based on their speed and rotation speed
SUB UpdatePlayer(Player AS Player)
    ' Update the player's angle
    Player.Angle = Player.Angle + Player.RotationSpeed

    ' Keep the angle between 0 and 360 degrees
    IF Player.Angle < 0 THEN
        Player.Angle = Player.Angle + 360
    ELSEIF Player.Angle > 360 THEN
        Player.Angle = Player.Angle - 360
    END IF

    ' Calculate the player's new position based on their speed and angle
    Player.X = Player.X + Player.Speed * COS(Player.Angle)
    Player.Y = Player.Y + Player.Speed * SIN(Player.Angle)

    ' Keep the player within the screen bounds
    IF Player.X < 0 THEN
        Player.X = 0
    ELSEIF Player.X > SCREEN_WIDTH THEN
        Player.X = SCREEN_WIDTH
    END IF
    IF Player.Y < 0 THEN
        Player.Y = 0
    ELSEIF Player.Y > SCREEN_HEIGHT THEN
        Player.Y = SCREEN_HEIGHT
    END IF
END SUB ' UpdatePlayer

' ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

' Update the player's speed based on the gravitational pull of the suns
SUB UpdatePlayerGravity(Player AS Player)
    ' Calculate the distance and angle to sun 1
    DX = Sun1.X - Player.X
    DY = Sun1.Y - Player.Y
    DistanceToSun1 = SQR(DX * DX + DY * DY)
    AngleToSun1 = ATN2(DY, DX) * 180 / PI

    ' Calculate the distance and angle to sun 2
    DX = Sun2.X - Player.X
    DY = Sun2.Y - Player.Y
    DistanceToSun2 = SQR(DX * DX + DY * DY)
    AngleToSun2 = ATN2(DY, DX) * 180 / PI

    ' Calculate the gravitational force from sun 1
    GravitationalForce1 = Sun1.Mass / DistanceToSun1
    ' Calculate the gravitational force from sun 2
    GravitationalForce2 = Sun2.Mass / DistanceToSun2

    ' Calculate the total gravitational force
    TotalGravitationalForce = GravitationalForce1 + GravitationalForce2

    ' Calculate the gravitational acceleration
    GravitationalAcceleration = TotalGravitationalForce / Player.Mass

    ' Calculate the gravitational speed
    GravitationalSpeed = GravitationalAcceleration * 0.1

    ' Calculate the new speed based on the gravitational speed
    NewSpeed = Player.Speed + GravitationalSpeed

    ' Limit the player's speed
    If NewSpeed < 0 Then
        NewSpeed = 0
    ElseIf NewSpeed > 5 Then
        NewSpeed = 5
    End If

    ' Set the player's speed
    Player.Speed = NewSpeed
END SUB ' UpdatePlayerGravity

' ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
'
'' Update a player's position based on the gravity of the suns
'SUB UpdatePlayerGravity(Player AS Player)
'    Dim GravityForce As Single
'    GravityForce = (Sun1.Mass???
'???
'
'* Player.Mass) / DistanceToPlayer(Player, Sun1) ^ 2
'    Player.X = Player.X + GravityForce * (Sun1.X - Player.X) / DistanceToPlayer(Player, Sun1)
'    Player.Y = Player.Y + GravityForce * (Sun1.Y - Player.Y) / DistanceToPlayer(Player, Sun1)
'    GravityForce = (Sun2.Mass * Player.Mass) / DistanceToPlayer(Player, Sun2) ^ 2
'    Player.X = Player.X + GravityForce * (Sun2.X - Player.X) / DistanceToPlayer(Player, Sun2)
'    Player.Y = Player.Y + GravityForce * (Sun2.Y - Player.Y) / DistanceToPlayer(Player, Sun2)
'END SUB ' UpdatePlayerGravity

' ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

' Update a player's position based on their speed and angle
SUB UpdatePlayerPosition(Player AS Player)
    Player.X = Player.X + Player.Speed * COS(Player.Angle)
    Player.Y = Player.Y + Player.Speed * SIN(Player.Angle)
END SUB ' UpdatePlayerPosition

' ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

' Update the player's rotation speed based on their rotation
' This subroutine updates the player's rotation speed based on whether they are
' rotating left, rotating right, or not rotating at all. If the player is
' rotating left, their rotation speed is increased. If the player is rotating
' right, their rotation speed is decreased. If the player is not rotating, their
' rotation speed is decreased. The rotation speed is limited to a maximum of 2
' and a minimum of -2.
SUB UpdatePlayerRotation(Player AS Player, IsRotatingLeft AS BOOLEAN, IsRotatingRight AS BOOLEAN)
    ' If the player is rotating left, increase their rotation speed
    IF IsRotatingLeft THEN
        Player.RotationSpeed = Player.RotationSpeed + 0.5
    ' If the player is rotating right, decrease their rotation speed
    ELSEIF IsRotatingRight THEN
        Player.RotationSpeed = Player.RotationSpeed - 0.5
    ' If the player is not rotating, decrease their rotation speed
    ELSE
        Player.RotationSpeed = Player.RotationSpeed - 0.1
    END IF

    ' Limit the player's rotation speed
    IF Player.RotationSpeed < -2 THEN
        Player.RotationSpeed = -2
    ELSEIF Player.RotationSpeed > 2 THEN
        Player.RotationSpeed = 2
    END IF
END SUB ' UpdatePlayerRotation

'' ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
'' Update a player's rotation
'SUB UpdatePlayerRotation(Player AS Player, LeftKey AS BOOLEAN, RightKey AS BOOLEAN)
'    If LeftKey Then
'        Player.RotationSpeed = Player.RotationSpeed - 0.1
'    ElseIf RightKey Then
'        Player.RotationSpeed = Player.RotationSpeed + 0.1
'    Else
'        Player.RotationSpeed = Player.RotationSpeed * 0.9
'    End If
'    Player.Angle = Player.Angle + Player
'...
'
''.RotationSpeed
'END SUB ' UpdatePlayerRotation

' ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

' Update the player's speed based on their thrust
SUB UpdatePlayerThrust(Player AS Player, IsThrusting AS BOOLEAN)
    ' If the player is thrusting, increase their speed
    IF IsThrusting THEN
        Player.Speed = Player.Speed + 0.1
    ' If the player is not thrusting, decrease their speed
    ELSE
        Player.Speed = Player.Speed - 0.1
    END IF

    ' Limit the player's speed
    IF Player.Speed < 0 THEN
        Player.Speed = 0
    ELSEIF Player.Speed > 5 THEN
        Player.Speed = 5
    END IF
END SUB ' UpdatePlayerThrust

' ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
'' Update a player's thrust
'SUB UpdatePlayerThrust(Player AS Player, UpKey AS BOOLEAN)
'    If UpKey Then
'        Player.IsThrusting = True
'        Player.Speed = Player.Speed + 0.1
'    Else
'        Player.IsThrusting = False
'    End If
'END SUB

' ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

' Update a shot's position based on its speed and angle
SUB UpdateShot(Shot AS Shot)
    Shot.X = Shot.X + Shot.Speed * COS(Shot.Angle)
    Shot.Y = Shot.Y + Shot.Speed * SIN(Shot.Angle)
END SUB ' UpdateShot
Reply
#3
You have amazing patience to interact with ChatGPT like that!
Reply
#4
(12-17-2022, 04:25 AM)ChiaPet Wrote: You have amazing patience to interact with ChatGPT like that!

It's not something I would do every day! 
I was just genuinely curious to see what it would take to coax a whole program out of that thing! 
And I think the operative word here is coax - you really have to be an "AI whisperer" to get it to spit out the whole of what it generates!
Reply
#5
I spent a while in a chat with it developing a set of adventure guidelines and ancillary materials for an RPG campaign and while it is all far from gold it is relatively coherent and useful (for it's purpose) given the limited input I gave it. I spent about an hour and got hundreds of lines of useful notes and ideas, along with things like riddles, songs, and poems, stuff I wouldn't usually spend my own time developing for a game but the AI is able to spill out and elaborate on with ease after learning the rules and conditions for the situation at hand.   

As for programming with it I realized you could get it to fake it is a interpreter and you can feed it code and pseudo-code and get results or commentary on the code snippet/function you entered.   

you can type:
 "for x = 1 to 10: print x: next x "
and ask it to explain and demonstrate output for the code.

I found it does a better job with html5 than it does QB64 but it is verbose as heck and sometime loses track of what it is doing.
Reply
#6
(12-17-2022, 04:35 PM)James D Jarvis Wrote: I spent a while in a chat with it developing a set of adventure guidelines and ancillary materials for an RPG campaign and while it is all far from gold it is relatively coherent and useful (for it's purpose) given the limited input I gave it. I spent about an hour and got hundreds of lines of useful notes and ideas, along with things like riddles, songs, and poems, stuff I wouldn't usually spend my own time developing for a game but the AI is able to spill out and elaborate on with ease after learning the rules and conditions for the situation at hand.   

As for programming with it I realized you could get it to fake it is a interpreter and you can feed it code and pseudo-code and get results or commentary on the code snippet/function you entered.   

you can type:
 "for x = 1 to 10: print x: next x "
and ask it to explain and demonstrate output for the code.

I found it does a better job with html5 than it does QB64 but it is verbose as heck and sometime loses track of what it is doing.

That's interesting that you use it for role playing or D&D, I wonder if it could be taught to be a dungeon master!
Reply
#7
It'll accept any text as input so you can feed it data and a situation. It may be able to serve as a referee of sorts if the rules are established for how to do that in the input text.     I fed it back data it created yesterday and asked it to consider it all and give me an overview of the materials ad it was able to do so and then continue creating new materials as prompted. 

I'll give it a shot and see if it can serve as an online DM.
Reply
#8
So I tried out using chatGBT as an online DM and it didn't work poorly in respect to what it generated. The servers are definitely overworked and busy because of all the press of this amazing tool so the session was cut short but showed it could function in such a role.  

I posted the session over on my gaming blog:  Aeons & Augauries: chatGBT as online GM. (aeonsnaugauries.blogspot.com)
Reply
#9
(12-17-2022, 07:02 PM)James D Jarvis Wrote: So I tried out using chatGBT as an online DM and it didn't work poorly in respect to what it generated. The servers are definitely overworked and busy because of all the press of this amazing tool so the session was cut short but showed it could function in such a role.  

I posted the session over on my gaming blog:  Aeons & Augauries: chatGBT as online GM. (aeonsnaugauries.blogspot.com)

That's cool, I'll check out your blog!
Reply




Users browsing this thread: 3 Guest(s)