import pygame import GameObject import Enemy import Utils import random pygame.init() pygame.display.set_caption("TESTFENSTER") pygame.mouse.set_visible(True) #pygame.key.set_repeat(1, 30) screen = pygame.display.set_mode((800,600)) clock = pygame.time.Clock() image_enemy = Utils.load_image("Rastergrafik.png") testimage = Utils.load_image("Rastergrafik.png") #testimage.set_colorkey((255,0,255), pygame.RLEACCELOK) enemy = Enemy.Enemy("Enemy-1", (screen.get_size()[0]/2) -30,30,35,35, screen, testimage) player = GameObject.Player("TEST", (screen.get_size()[0]/2)-17, screen.get_size()[1]-100, 35, 35, testimage) gamestate = True pos_x = 50 pos_y = 50 while(gamestate): screen.fill((255,255,255)) for event in pygame.event.get(): if(event.type == pygame.QUIT): gamestate = False player.handle_input(event) image = screen.blit(testimage, (pos_x, pos_y)) mouse_pos = pygame.mouse.get_pos() #print(mouse_pos) #print(image.topleft) #Gibt die Position einen Surfaces "obenlinks" aus #print(image.size) #Gibt die Größe eines Surfaces aus max = tuple(map(lambda i, j : i+j, image.topleft, image.size)) #Wenn Mausposition X-Achse innerhalb Anfangsposition+Breite if(mouse_pos[0] <= max[0] and mouse_pos[0] >= image.topleft[0]): #Wenn Mausposition Y-Achse innerhalb Anfangsposition+Höhe if(mouse_pos[1] <= max[1] and mouse_pos[1] >= image.topleft[1]): print("Treffer") pos_x = mouse_pos[0] pos_y = mouse_pos[1] #Rendere alle Objecte in objects Liste rand = random.randint(0, 100) if rand == 50: enemy.fire(screen) if rand == 20: enemy.move(5) if rand == 50: enemy.move(-5) enemy.shoot() player.render(screen) enemy.render(screen) #if(mouse_pos <= (image.topleft+image.size) and mouse_pos >= image.topleft): # print("HIIIIITTT!!!!") clock.tick(60) pygame.display.flip()