import pygame
import sys
def main():
x=375
y=400
y_velocity = 0
acceleration = 0.1
bg_color=(183,255,183)
shape_color=(0,255,255)
x_minus = None
pygame.init()
DISPLAY = pygame.display.set_mode((800,800))
icon = pygame.image.load("assets/firedash.ico")
pygame.display.set_caption("pygame window")
pygame.display.set_icon(icon)
DISPLAY.fill(bg_color)
pygame.display.update()
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
sys.exit()
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_SPACE:
y_velocity+=-5
cube = pygame.draw.rect(DISPLAY,shape_color,(x,y,50,50))
y+= y_velocity
y_velocity+=acceleration
if x_minus == None:
x+=-2
if x_minus == False:
x+=2
if x_minus == True:
x+=-2
if y > 800:
y_velocity = -abs(y_velocity)
if x < 0:
x*=-1
x_minus = False
if x > 750:
x*=-1
x_minus = True
pygame.time.delay(10)
pygame.display.update()
DISPLAY.fill(bg_color)
main()
Hi can someone tell me why my code isnt working well ? If i run it my cube will go to the left (which is what i want) and if it bump the left side it will bounce, and go to the right side but when it touches the right side the cube just disappear.. anyone has an idea on how to fix it ?