From f83080b7100f42f569306469ce53e70c23ed9582 Mon Sep 17 00:00:00 2001 From: Maximilian Date: Tue, 30 Oct 2018 11:38:07 +0100 Subject: [PATCH] Include --- .idea/Pong2.iml | 11 ++++ .idea/misc.xml | 7 +++ .idea/modules.xml | 8 +++ .idea/vcs.xml | 6 ++ main.py | 140 ++++++++++++++++++++++++++++++++++++++++++++++ ohm.png | Bin 0 -> 1772 bytes 6 files changed, 172 insertions(+) create mode 100644 .idea/Pong2.iml create mode 100644 .idea/misc.xml create mode 100644 .idea/modules.xml create mode 100644 .idea/vcs.xml create mode 100644 main.py create mode 100644 ohm.png diff --git a/.idea/Pong2.iml b/.idea/Pong2.iml new file mode 100644 index 0000000..6711606 --- /dev/null +++ b/.idea/Pong2.iml @@ -0,0 +1,11 @@ + + + + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..8656114 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,7 @@ + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..0323285 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/main.py b/main.py new file mode 100644 index 0000000..936801d --- /dev/null +++ b/main.py @@ -0,0 +1,140 @@ +import pygame +import time + + +# Initialisierung der Spieldaten +def init(): + global width, height, size, black, red + global image, image_rect + global speed_image + global speed_balken + global balken + global text, text_rect + speed_image=[1,1] + speed_balken=[0,0] + width=320 + height=240 + size= (width,height) + + black=(0,0,0) + red=(255,0,0) + white=(255,255,255) + + image=pygame.image.load("ohm.png") + image_rect=image.get_rect() + balken=initbalken() + + font=pygame.font.Font(None,28) + text= font.render('Game Over', 1, white) + text_rect =text.get_rect() + textinit(text_rect) + +def textinit(text_rect): + text_rect.centerx=width/2 + text_rect.centery=height/2 + +def initbalken(): + global x_balken + global y_balken + x_balken=25 + y_balken=200 + width = 50 + height = 20 + return pygame.Rect(x_balken,y_balken,width,height) + + +def input(): + pygame.display.set_caption('PONG!') + for event in pygame.event.get(): + if event.type ==pygame.KEYDOWN: + if event.key==pygame.K_ESCAPE: + return False + + return True + +def update(): + image_rect.x=100 + image_rect.y=50 + +def draw_game(): + + screen.fill(black) + screen.blit(image, image_rect) + pygame.draw.rect(screen, red, balken) + pygame.display.flip() + + +def draw_gameover(): + image_rect.bottom=0 + screen.fill(black) + screen.blit(text, text_rect) + pygame.display.flip() + time.sleep(2) + + +def movement_image(): + + + #prüft ob Image links o. rechts am Rand kollidiert + + if image_rect.left < 0 or image_rect.right > width: + speed_image[0] = -speed_image[0] + + #prüft ob Image oben am Rand kollidiert + + if image_rect.top <0: + speed_image[1] = - speed_image[1] + + #prüft ob Kollidierung der Rechtecke stattfindet + + if pygame.Rect.colliderect(image_rect,balken): + speed_image[1] = - speed_image[1] + + +def movement_balken(): + + speed_balken[0]=0 + + keys=pygame.key.get_pressed() + + if keys[pygame.K_a]: + speed_balken[0]= -1 + + if keys[pygame.K_d]: + speed_balken[0]= 1 + + + if balken.left == 0: + balken.left=1 + + if balken.right == width: + balken.right = width -1 + + return + + + + +pygame.init() +init() +screen=pygame.display.set_mode(size) + +running = True + +while running: + running =input() + image_rect = image_rect.move(speed_image) + balken=balken.move(speed_balken) + movement_image() + movement_balken() + + + if image_rect.bottom < (height-1): + draw_game() + + else: + running= False + + time.sleep(0.01) + +draw_gameover() \ No newline at end of file diff --git a/ohm.png b/ohm.png new file mode 100644 index 0000000000000000000000000000000000000000..bd4d2758cb2bba4b17156e507ced8b56a89d3b7f GIT binary patch literal 1772 zcmV%uN;cU)jt^NIP>-&FeYyX2U7+35NOTB`74~{<)j{NOGLjicLROnEQQGn$VD(P2~xx>C&@_i;Ocb^2PD8T~<0Jkm0l2OP*_X~@8CVmsi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