Browse Source

Include

master
Maximilian 6 years ago
parent
commit
f83080b710
6 changed files with 172 additions and 0 deletions
  1. 11
    0
      .idea/Pong2.iml
  2. 7
    0
      .idea/misc.xml
  3. 8
    0
      .idea/modules.xml
  4. 6
    0
      .idea/vcs.xml
  5. 140
    0
      main.py
  6. BIN
      ohm.png

+ 11
- 0
.idea/Pong2.iml View File

@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="PYTHON_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$" />
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
<component name="TestRunnerService">
<option name="PROJECT_TEST_RUNNER" value="Unittests" />
</component>
</module>

+ 7
- 0
.idea/misc.xml View File

@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="JavaScriptSettings">
<option name="languageLevel" value="ES6" />
</component>
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.7" project-jdk-type="Python SDK" />
</project>

+ 8
- 0
.idea/modules.xml View File

@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/Pong2.iml" filepath="$PROJECT_DIR$/.idea/Pong2.iml" />
</modules>
</component>
</project>

+ 6
- 0
.idea/vcs.xml View File

@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>

+ 140
- 0
main.py View File

@@ -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()

BIN
ohm.png View File


Loading…
Cancel
Save