85 lines
2.3 KiB
Python
85 lines
2.3 KiB
Python
import pygame
|
|
|
|
pygame.init()
|
|
screen = pygame.display.set_mode((640,480))
|
|
pygame.display.set_caption("Testgame")
|
|
|
|
WEISS = ( 255, 255, 255)
|
|
active = True
|
|
|
|
clock = pygame.time.Clock()
|
|
|
|
|
|
Testobjekt = {"name":"testobjekt",
|
|
"posx":0,
|
|
"posy":0
|
|
}
|
|
|
|
# Definieren der Variablen
|
|
ballpos_x = 10
|
|
ballpos_y = 10
|
|
|
|
class GameObjekt():
|
|
__name = str()
|
|
__pos_x = int()
|
|
__pos_y = int()
|
|
__rectobjekt = pygame.Rect
|
|
|
|
def __init__(self, name:str, posx:int, posy:int, *rect:pygame.Rect) -> None:
|
|
self.__name = name
|
|
self.__pos_x = posx
|
|
self.__pos_y = posy
|
|
self.__rectobjekt = rect
|
|
pass
|
|
|
|
def move(self, x):
|
|
MOVE_SPEED = 5
|
|
#self.__rectobjekt.x += MOVE_SPEED
|
|
print(self.__rectobjekt)
|
|
|
|
|
|
background = pygame.Surface((640,480)) #Erstellt eine Obfläche mit der Größe des Fensters
|
|
rect2 = pygame.draw.rect(background,(0,255,255),(20,20,40,40))
|
|
|
|
rect1 = pygame.draw.ellipse(screen, (0,0,0), [ballpos_x, ballpos_y, 20, 20])
|
|
Player = GameObjekt("Test", 0,0,rect1)
|
|
|
|
|
|
#Fenster-Hauptschleife
|
|
while active == True:
|
|
for event in pygame.event.get():
|
|
if (event.type == pygame.QUIT):
|
|
print("Programm wird geschlossen!")
|
|
active = False
|
|
elif (event.type == pygame.KEYDOWN):
|
|
if (event.key == pygame.K_UP):
|
|
print("Keydown")
|
|
print(rect2.x)
|
|
background.get_rect()
|
|
#rect1.move(ballpos_x, ballpos_y)
|
|
Player.move(5)
|
|
ballpos_y -= 10
|
|
elif (event.key == pygame.K_DOWN):
|
|
print("Keydown")
|
|
#rect1.move(ballpos_x, ballpos_y)
|
|
ballpos_y += 10
|
|
elif (event.key == pygame.K_RIGHT):
|
|
print("Keydown")
|
|
#rect1.move(ballpos_x, ballpos_y)
|
|
ballpos_x += 10
|
|
elif (event.key == pygame.K_LEFT):
|
|
print("Keydown")
|
|
#rect1.move(ballpos_x, ballpos_y)
|
|
ballpos_x -= 10
|
|
|
|
|
|
|
|
|
|
#Displayflip sorgt dafür, dass das Fenster entsprechend der Tickrate aktualisiert wird
|
|
#pygame.display.flip()
|
|
rect2.move(100, 10)
|
|
screen.blit(background,(0,0))
|
|
|
|
pygame.display.flip()
|
|
clock.tick(60)
|
|
pygame.quit() |