12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091 |
- import pygame
-
- def initScreen():
- global width, height, size
- width = 820
- height = 640
- size = (width, height)
-
- global red, black
- red = (255, 0, 0, 0)
- black = (0, 0, 0, 0)
-
- def initGame():
- global Rectangle
- Rectangle = initRectangle()
- global running
- running = False
-
- def initSign():
- global image, image_rect
- image = pygame.image.load("seehofer.png")
- image_rect = image.get_rect()
-
- class Rectangle(pygame.Rect):
- def __init__(self, x, y, width, height):
- self.x = x
- self.y = y
- self.width = width
- self.height = height
-
- self.speed_l = 0
- self.speed_r = 0
-
- def initRectangle():
- x = 0
- y = 620
- width = 100
- height = 20
-
- global My_Rect
- My_Rect = Rectangle(x, y, width, height)
- return My_Rect
-
- def input():
- for event in pygame.event.get():
- if event.type == pygame.QUIT:
- return False
- if event.type == pygame.KEYDOWN:
- if event.key == pygame.K_ESCAPE:
- return False
- if event.key == pygame.K_LEFT:
- My_Rect.speed_l = 1
- if event.key == pygame.K_RIGHT:
- My_Rect.speed_r = 1
- if event.type == pygame.KEYUP:
- Rectangle.speed_left = 0
- Rectangle.speed_right = 0
-
- return True
-
- def update():
- if(0 <= Rectangle.x < width):
- Rectangle.x += My_Rect.speed_r * 3
- Rectangle.x += My_Rect.speed_l * 3
-
- image_rect.x = 100
- image_rect.y = 50
-
- def draw():
- screen.fill(black)
- screen.blit(image, image_rect)
- pygame.draw.rect(screen, red, Rectangle)
- pygame.display.flip()
-
-
- # --------- Start of Main-Code ------------
- running = False
-
- pygame.init()
- initScreen()
- initGame()
- initSign()
- screen = pygame.display.set_mode(size)
-
- running = True
-
-
- while running == True:
- running = input()
- update()
- draw()
|