Source Code
import pygame
pygame.init()
space_width = 55
space_height = 40
win = pygame.display.set_mode((600, 400))
pygame.display.set_caption("hi")
playerimg = pygame.image.load('001-spaceship.png')
ply = pygame.transform.rotate(pygame.transform.scale(playerimg, (space_width, space_height)), 90)
print(win)
def draw_window(plyred):
win.fill((255, 0, 0))
win.blit(ply, (plyred.x, plyred.y))
pygame.display.update()
def main():
plyred = pygame.rect(100, 100, (space_width, space_height))
run = True
while run:
for event in pygame.event.get():
if event.type == pygame.QUIT:
run = False
plyred += 1
draw_window(plyred)
pygame.quit()
My code won't run and only shows a temporary black screen before crashing.
First of all, there are so many mistake on the code, anyway here, this should at least show you something:
Consideration and area where you should improve
Indentation, indentation, indentation, Python is one of the few Programming languages where it punishes you if you don't indent correctly (hopefully) and so are other Programmers if you don't do so, here ---> Indentation in Python
The Biggest issue was on the variable
plyred
, for of all is the ClassRect
and notrect
(which is a function from pygame.draw.rect) -----> Here your best friend Documentation :)Also, it was givin error because space_width, space_height was inside a tuple, so it should be
pygame.Rect(100, 100, space_width, space_height)
instead.You never call the
main
function, so one way is express it this way:if name == 'main': main()
Another is just call it as so at the end of the script:
**DOCUMENTATION What does if name == “main”: do?
Projects