Dieses Repository enthält Python-Dateien die im Rahmen des Wahlpflichtmoduls "Informationssysteme in der Medizintechnik" (Dozent: Prof. Dr. Oliver Hofmann) erstellt wurden und verwaltet deren Versionskontrolle.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Tag2_EigenesSpiel.py 1.8KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. import pygame
  2. def initScreen():
  3. global width, height, size
  4. width = 820
  5. height = 640
  6. size = (width, height)
  7. global red, black
  8. red = (255, 0, 0, 0)
  9. black = (0, 0, 0, 0)
  10. def initGame():
  11. global Rectangle
  12. Rectangle = initRectangle()
  13. global running
  14. running = False
  15. def initSign():
  16. global image, image_rect
  17. image = pygame.image.load("seehofer.png")
  18. image_rect = image.get_rect()
  19. class Rectangle(pygame.Rect):
  20. def __init__(self, x, y, width, height):
  21. self.x = x
  22. self.y = y
  23. self.width = width
  24. self.height = height
  25. self.speed_l = 0
  26. self.speed_r = 0
  27. def initRectangle():
  28. x = 0
  29. y = 620
  30. width = 100
  31. height = 20
  32. global My_Rect
  33. My_Rect = Rectangle(x, y, width, height)
  34. return My_Rect
  35. def input():
  36. for event in pygame.event.get():
  37. if event.type == pygame.QUIT:
  38. return False
  39. if event.type == pygame.KEYDOWN:
  40. if event.key == pygame.K_ESCAPE:
  41. return False
  42. if event.key == pygame.K_LEFT:
  43. My_Rect.speed_l = 1
  44. if event.key == pygame.K_RIGHT:
  45. My_Rect.speed_r = 1
  46. if event.type == pygame.KEYUP:
  47. Rectangle.speed_left = 0
  48. Rectangle.speed_right = 0
  49. return True
  50. def update():
  51. if(0 <= Rectangle.x < width):
  52. Rectangle.x += My_Rect.speed_r * 3
  53. Rectangle.x += My_Rect.speed_l * 3
  54. image_rect.x = 100
  55. image_rect.y = 50
  56. def draw():
  57. screen.fill(black)
  58. screen.blit(image, image_rect)
  59. pygame.draw.rect(screen, red, Rectangle)
  60. pygame.display.flip()
  61. # --------- Start of Main-Code ------------
  62. running = False
  63. pygame.init()
  64. initScreen()
  65. initGame()
  66. initSign()
  67. screen = pygame.display.set_mode(size)
  68. running = True
  69. while running == True:
  70. running = input()
  71. update()
  72. draw()