ChatGPT & Euphoria
- Posted by Icy_Viking 4 weeks ago
- 745 views
Hi all, So I got bored and decided how ChatGPT would react to the question "Shoot a bullet in Euphoria programming language". Here is what it gave me.
-- Bullet class structure (using a sequence) sequence bullet = {0, 0, 5, 0} -- {x, y, speed, direction} -- Update function to move the bullet procedure update_bullet(sequence b) b[1] = b[1] + b[3] * cos(b[4]) -- x = x + speed * cos(direction) b[2] = b[2] + b[3] * sin(b[4]) -- y = y + speed * sin(direction) end procedure procedure shoot_bullet(sequence bullet) bullet[1] = 0 -- Start x position bullet[2] = 0 -- Start y position bullet[3] = 10 -- Bullet speed bullet[4] = 0 -- Direction in radians (0 = moving to the right) end procedure -- This procedure could be called in a loop to continuously update the bullet position update_bullet(bullet) -- A simple game loop while 1 do -- Check for user input (e.g., space bar to shoot) if keypressed() = ' ' then shoot_bullet(bullet) end if -- Update bullet's position update_bullet(bullet) -- If the bullet has gone off-screen, reset it if bullet[1] > screen_width then bullet = {0, 0, 5, 0} -- Reset bullet end if -- Draw the bullet (or just print for now) puts(1, "Bullet position: " & bullet[1] & ", " & bullet[2] & "\n") -- You would use your graphics library here for rendering the bullet on screen. -- Pause briefly to control game speed sleep(0.016) -- 60 frames per second end while
Also, it included a way to do it with Euphoria-GL, lol
include graphics.e -- Initialize window window_width = 800 window_height = 600 open_window(window_width, window_height, "Bullet Simulation") -- Main game loop while 1 do -- Clear screen and redraw the background clear_screen() -- Update bullet's position update_bullet(bullet) -- Draw the bullet (use a circle or small rectangle) draw_circle(bullet[1], bullet[2], 5) -- Show the updated screen update_screen() -- Check for key press if keypressed() = ' ' then shoot_bullet(bullet) end if -- Sleep briefly to control game speed sleep(0.016) end while
Collision test
-- Example target (a rectangle) sequence target = {400, 300, 50, 50} -- {x, y, width, height} -- Collision detection (bullet with target) if bullet[1] >= target[1] and bullet[1] <= target[1] + target[3] and bullet[2] >= target[2] and bullet[2] <= target[2] + target[4] then -- Bullet hit the target puts(1, "Bullet hit the target!\n") bullet = {0, 0, 5, 0} -- Reset bullet end if
I'm surprised how thorough the example was. With Euphoria being such a fringe language these days, I'm surprised.