[PyGame] Shapes dont respond to keyboard input - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: Game Development (https://python-forum.io/forum-11.html) +--- Thread: [PyGame] Shapes dont respond to keyboard input (/thread-35871.html) |
Shapes dont respond to keyboard input - Mechanicalpixelz - Dec-25-2021 i try to make a break block type of game but the button line doesnt move left or right, i ve been trying for 2 days this is what i made so far import pygame from pygame.locals import * pygame.init() pygame.display.init() Red = (255,0,0) black = (0,0,0) yellow = (255,255,0) aqua = (0,255,255) w_h = [720, 720] LEFT = 'left' screen = pygame.display.set_mode((w_h)) pygame.display.set_caption("tetris clone") screen.fill(Red) pygame.draw.rect(screen, black, [25, 20, 100, 25]) pygame.draw.rect(screen, black, [245, 700, 150, 25]) draw = pygame.draw.circle(screen, yellow, (300, 400), 15, 0) while True: for event in pygame.event.get(): if event.type == pygame.QUIT: pygame.quit() if event.type == pygame.K_LEFT: move = event.pos LEFT pygame.display.flip()also i how do i make the ball fall and when the ball hits the button line it will bounce at the walls?thanks! RE: Shapes dont respond to keyboard input - Mechanicalpixelz - Dec-25-2021 (Dec-25-2021, 02:38 AM)Mechanicalpixelz Wrote: i try to make a break block type of game but the buttom line doesnt move left or right, i ve been trying for 2 days this is what i made so far RE: Shapes dont respond to keyboard input - BashBedlam - Dec-25-2021 You animate things in pygame by changing it's co-ordinates, redrawing the background and then redrawing everything in the foreground. This will animate the lower paddle. You can take it from here... Right? import pygame from pygame.locals import * pygame.init() pygame.display.init() Red = (255,0,0) black = (0,0,0) yellow = (255,255,0) aqua = (0,255,255) w_h = [720, 720] LEFT = 'left' screen = pygame.display.set_mode((w_h)) pygame.display.set_caption("tetris clone") screen.fill(Red) pygame.draw.rect(screen, black, [25, 20, 100, 25]) pygame.draw.rect(screen, black, [245, 700, 150, 25]) draw = pygame.draw.circle(screen, yellow, (300, 400), 15, 0) rect_x = 340 while True: for event in pygame.event.get(): if event.type == pygame.QUIT: pygame.quit() keys = pygame.key.get_pressed () # This is where we change the x co-ordinate if keys [pygame.K_LEFT]: rect_x -= 1 elif keys [pygame.K_RIGHT]: rect_x += 1 screen.fill(Red) pygame.draw.rect(screen, black, [25, 20, 100, 25]) draw = pygame.draw.circle(screen, yellow, (300, 400), 15, 0) # This is where we change to the updated x co-ordinate pygame.draw.rect(screen, black, [rect_x, 700, 100, 25]) pygame.display.flip() RE: Shapes dont respond to keyboard input - Mechanicalpixelz - Dec-25-2021 yes thank you! If only i had made an account sooner and asked here! |