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 it I 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 at The objects coming at it should be a tire, a fishshark reef coming out of the bottom of the screen, anything thing else you think will look good. Try your best to create the best graphics you can. For the game logic, it's all done except just make it go faster as you go on Please use what i've been using and try your best to explain it to me and paste the final code aswell. import pygame
import sys
import random
# Initialize Pygame
pygame.init
# Constants
WIDTH, HEIGHT
SUBMARINEWIDTH, SUBMARINEHEIGHT
OBSTACLEWIDTH, OBSTACLEHEIGHT
FPS
SUBMARINESPEED
# Colors
WHITE
BLUE
RED
# Game variables
submarinerect pygame.RectWIDTH SUBMARINEWIDTH HEIGHT SUBMARINEHEIGHT SUBMARINEWIDTH, SUBMARINEHEIGHT
obstaclerect pygame.RectWIDTH random.randint HEIGHT OBSTACLEHEIGHT OBSTACLEWIDTH, OBSTACLEHEIGHT
score
# Create the screen
screen pygame.display.setmodeWIDTH HEIGHT
pygame.display.setcaptionSubmarine Game"
# Fonts
font pygame.font.FontNone
# Functions
def drawsubmarine:
pygame.draw.rectscreen BLUE, submarinerect
def drawobstacle:
pygame.draw.rectscreen RED, obstaclerect
def drawscore:
scoretext font.renderScore: strscore True, WHITE
screen.blitscoretext,
# Game loop
clock pygame.time.Clock
while True:
for event in pygame.event.get:
if event.type pygame.QUIT:
pygame.quit
sysexit
keys pygame.key.getpressed
if keyspygameKUP and submarinerect.top :
submarinerect.y SUBMARINESPEED
if keyspygameKDOWN and submarinerect.bottom HEIGHT:
submarinerect.y SUBMARINESPEED
# Update obstacle position
obstaclerect.x
if obstaclerect.right :
obstaclerect.x WIDTH
obstaclerect.y random.randint HEIGHT 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
