1

Python Help!

Captain_Hd_ 8/8/16 7:15 am
557
8/9/2016 8:39 am
So I'm making a simply game in pygame and python. But I've ran into an error. Basically when I run the game, all that's meant to happen so far is for a rocket to be infront of a blue background. But instead, I get a black background with nothing on it... Until I close out of it. When I close out of the game for a split second I see a blue background and part of my ship in the bottom left hand corner. Any fixes?

CODE :
Click to reveal
import pygame

pygame.init()

display_width = 800
display_height = 600

black = (0,0,0)
white = (255,255,255)
blue = (0,57,230)

gameDisplay = pygame.display.set_mode((display_width,display_height))
pygame.display.set_caption('Random Name Game...')
clock = pygame.time.Clock()

carImg = pygame.image.load('ship.png')

def car(x,y):
gameDisplay.blit(carImg,(x,y))

x = (display_width * 0.45)
y = (display_height * 0.8)



dead = False

while not dead:

for event in pygame.event.get():
if event.type == pygame.QUIT:
dead = True

gameDisplay.fill(blue)
car(x,y)

pygame.display.update()
clock.tick(60)

pygame.quit()
quit()


I don't get any errors in the run script either.
Posted by
Captain_Hd_
Level 4 : Apprentice Explorer
6

  Have something to say?

JoinSign in

6

anonpmc1793855
08/09/2016 8:03 am
Level 8 : Apprentice Miner
[deleted]
1
Captain_Hd_
08/09/2016 8:39 am
Level 4 : Apprentice Explorer
Oh np at all, I just assumed you knew python. Thanks for helping tho
1
anonpmc1793855
08/08/2016 7:57 am
Level 8 : Apprentice Miner
[deleted]
1
Captain_Hd_
08/09/2016 5:26 am
Level 4 : Apprentice Explorer
Ok yeah that worked :p I had a few command lines in a loop and stuff. Thanks

One more question though, I thought my ship was too big, so I resized it in paint.net and saved it as sprite (It's a png file). It's on my desktop, which is where my script is also saved. But when I do: carImg = pygame.image.load('sprite.png') it says:
Traceback (most recent call last):
File "C:\Users\My_Username\Desktop\pythongame.py", line 17, in <module>
carImg = pygame.image.load('sprite.png')
pygame.error: Couldn't open sprite.png
1
NewSuperMario
08/09/2016 6:49 am
Level 26 : Expert Dragonborn
I thought "True" and "False" were spelled with the first letter uppercase though? Or did it change in Python 3?
1
Captain_Hd_
08/09/2016 7:38 am
Level 4 : Apprentice Explorer
Nop, True and False have to be capitalized. But he was right in saying that I had some lines in the wrong place.
1

Welcome