I try to print a square for use as a hitbox because the collision detection doesn't work on images. But when I try to draw a test square in setup it doesn't appear. I have tried moving the command, and changing it but nothing worked. And that is only for the square. The images appear and move perfectly. I am pretty sure it has something to do with the sprites because without them everything works perfectly.
import pygame
import sys
pygame.init()
fps = 30
fpsclock=pygame.time.Clock()
window = pygame.display.set_mode((600, 600))
x = 275
y = 375
BulletX = x + 10
BulletY = y - 15
color = (250,210,240)
ship_img = pygame.image.load('spaceship.png')
ship = pygame.transform.scale(ship_img,(32,32))
bullet_img = pygame.image.load('bullet (2).png')
bullet = pygame.transform.scale(bullet_img,(12,12))
# main application loop
run = True
while run:
# limit frames per second
fpsclock.tick(fps)
# event loop
for event in pygame.event.get():
if event.type == pygame.QUIT:
run = False
key_input = pygame.key.get_pressed() #key inputs
if key_input[pygame.K_LEFT]:
x -= 5
if key_input[pygame.K_RIGHT]:
x += 5
# clear the display
window.fill(0)
window.blit(ship,(x,y))
pygame.draw.rect(window,color,pygame.rect(200,200,30,30))
window.blit(bullet,(BulletX,BulletY))
BulletY = BulletY - 20
if(BulletY <= -10):
BulletY = y - 10
BulletX = x + 10
# update the display
pygame.display.flip()
pygame.quit()
exit()
The only problem with your code is a lowercase 'r' instead of of uppercase one. Change the appropriate line to:
pygame.draw.rect(window, color, pygame.Rect(200,200,30,30) )
and have fun implementing the collision.