Quoted By:
Why won't my fucking sprite move when I press the UP key?
import pygame, sys
from pygame.locals import *
#import os
ht = 288-5
x, y = 360/2, ht
pygame.init()
screen = pygame.display.set_mode((640, 360), 0, 32)
pygame.display.set_caption('Shitty game')
screen.fill((135, 206, 235))
screen.blit(pygame.image.load('floor.jpg'),(0,288))
screen.blit(pygame.image.load('sun.png'),(355,30))
pygame.draw.lines(screen, (255, 255, 255), False, [(0, ht), (640, ht)], 8)
pl = pygame.sprite.Sprite() # create sprite
pl.image = pygame.image.load("player.png").convert_alpha() # load ball image
pl.rect = pl.image.get_rect() # use image extent values
pl.rect.topleft = [x, y] # put the ball in the top left corner
screen.blit(pl.image, pl.rect)
pl.rect = pl.image.get_rect()
cont = 1
while cont:
pygame.display.flip()
for event in pygame.event.get():
if event.type == QUIT:
cont = 0
if event.type == KEYDOWN:
if event.key == K_UP:
pl.rect.y = pl.rect.y - 5
pygame.time.delay(100)
import pygame, sys
from pygame.locals import *
#import os
ht = 288-5
x, y = 360/2, ht
pygame.init()
screen = pygame.display.set_mode((640, 360), 0, 32)
pygame.display.set_caption('Shitty game')
screen.fill((135, 206, 235))
screen.blit(pygame.image.load('floor.jpg'),(0,288))
screen.blit(pygame.image.load('sun.png'),(355,30))
pygame.draw.lines(screen, (255, 255, 255), False, [(0, ht), (640, ht)], 8)
pl = pygame.sprite.Sprite() # create sprite
pl.image = pygame.image.load("player.png").convert_alpha() # load ball image
pl.rect = pl.image.get_rect() # use image extent values
pl.rect.topleft = [x, y] # put the ball in the top left corner
screen.blit(pl.image, pl.rect)
pl.rect = pl.image.get_rect()
cont = 1
while cont:
pygame.display.flip()
for event in pygame.event.get():
if event.type == QUIT:
cont = 0
if event.type == KEYDOWN:
if event.key == K_UP:
pl.rect.y = pl.rect.y - 5
pygame.time.delay(100)