Question: I need help improving my code. It's a basic game where an object avoids stuff coming at it . I need to improve the graphics
I need help improving my code. It's a basic game where an object avoids stuff coming at itI need to improve the graphics using the same method I have been using to draw, I can't load an image. A submarine is the main object that will be avoiding stuff coming atThe objects coming at it should be a tire, a fishshark anything thing else you think will look good. Try your best to create the best graphics you can. The game logic is all good. Take your time drawing it it should look realistic, change the background to blue for water. I want the tire to actually look like a tire and not just a red blob. A submarine is hard to draw but use a draw a yellow sideways oval and a gray pipe sticking out the top. Google a submarine to imagine what it looks like. Draw a fish so you actually know its a fish not just a gray block. Im really emphasizing how important it is to take your time, this will take time and if you try to rush it it will come out bad. As realistic as possible using pygame.draw and using different shapes if you can.
import sys
import random
# Initialize Pygame
pygame.init
# Constants
WIDTH, HEIGHT
SUBMARINEWIDTH, SUBMARINEHEIGHT
OBSTACLEWIDTH, OBSTACLEHEIGHT
FPS
SUBMARINESPEED
# Colors
WHITE
BLUE
RED
# Game variables
submarinerect pygameRectWIDTH SUBMARINEWIDTH HEIGHT SUBMARINEHEIGHT SUBMARINEWIDTH, SUBMARINEHEIGHT
obstaclerect pygameRectWIDTHrandomrandintHEIGHT OBSTACLEHEIGHTOBSTACLEWIDTH, OBSTACLEHEIGHT
score
# Create the screen
screen pygamedisplay.setmodeWIDTHHEIGHT
pygame.display.setcaptionSubmarine Game"
# Fonts
font pygamefont.FontNone
# Functions
def drawsubmarine:
pygame.draw.rectscreenBLUE submarinerect
def drawobstacle:
pygame.draw.rectscreenRED obstaclerect
def drawscore:
scoretext fontrenderScore: strscoreTrue WHITE
screen.blitscoretext,
# Game loop
clock pygametime.Clock
while True:
for event in pygame.event.get:
if event.type pygameQUIT:
pygame.quit
sysexit
keys pygamekey.getpressed
if keyspygameKUPand submarinerect.top :
submarinerect.y SUBMARINESPEED
if keyspygameKDOWNand submarinerect.bottom HEIGHT:
submarinerect.y SUBMARINESPEED
# Update obstacle position
obstaclerect.x
if obstaclerect.right :
obstaclerect.x WIDTH
obstaclerect.y randomrandintHEIGHT OBSTACLEHEIGHT
score
# Check for collisions
if submarinerect.colliderectobstaclerect:
printGame Over!"
pygame.quit
sysexit
# Draw everything
screen.fillWHITE
drawsubmarine
drawobstacle
drawscore
# Update display
pygame.display.flip
# Cap the frame rate
clock.tickFPS
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
