Browse Source

Add a ground to the screen

master
Elis Axelsson 4 years ago
parent
commit
b82ac8512f
  1. 11
      watersteal.py

11
watersteal.py

@ -12,6 +12,7 @@ speed = [1, 1]
# Define colors
black = 0, 0, 0
white = 255, 255, 255
green = 0, 255, 0
# Set up screen
screen = pygame.display.set_mode(size)
@ -20,6 +21,11 @@ screen = pygame.display.set_mode(size)
ball = pygame.image.load("ball.bmp")
ballrect = ball.get_rect()
# Define ground
ground = pygame.Surface((width, height / 4))
ground.fill(green)
groundrect = pygame.Rect(0, (height / 4 * 3), width, (height / 4))
while True:
# Handle events
for event in pygame.event.get():
@ -39,12 +45,15 @@ while True:
# Direct ball movement
if ballrect.left < 0 or ballrect.right > width:
speed[0] = -speed[0]
if ballrect.top < 0 or ballrect.bottom > height:
if ballrect.top < 0 or ballrect.bottom > (height / 4 * 3):
speed[1] = -speed[1]
# Fill screen buffer with black color
screen.fill(black)
# Draw ground on buffer
screen.blit(ground, groundrect)
# Draw ball on buffer
screen.blit(ball, ballrect)

Loading…
Cancel
Save