Added new classes
This commit is contained in:
3
.gitignore
vendored
3
.gitignore
vendored
@@ -1674,3 +1674,6 @@ modules/__pycache__/Tileset.cpython-312.pyc
|
||||
modules/__pycache__/Tiletype.cpython-312.pyc
|
||||
modules/__pycache__/Utils.cpython-312.pyc
|
||||
__pycache__/Animation.cpython-312.pyc
|
||||
__pycache__/Enemy.cpython-312.pyc
|
||||
__pycache__/GameObject.cpython-312.pyc
|
||||
__pycache__/Object.cpython-312.pyc
|
||||
|
||||
17
Enemy.py
Normal file
17
Enemy.py
Normal file
@@ -0,0 +1,17 @@
|
||||
import pygame
|
||||
import GameObject
|
||||
import Utils
|
||||
|
||||
class Enemy(object):
|
||||
def __init__(self, name, pos_x, pos_y, image) -> None:
|
||||
spawned_enemy = list()
|
||||
self.name = name
|
||||
self.image = image
|
||||
self.pos_x = pos_x
|
||||
self.pos_y = pos_y
|
||||
self.obj = GameObject.GameObject("Enemy", 0, 0, image)
|
||||
pass
|
||||
|
||||
def render(self, screen:pygame.Surface):
|
||||
screen.blit(self.image, (self.pos_x, self.pos_y))
|
||||
|
||||
22
GameObject.py
Normal file
22
GameObject.py
Normal file
@@ -0,0 +1,22 @@
|
||||
import pygame
|
||||
|
||||
class GameObject(object):
|
||||
def __init__(self, name, pos_x, pos_y, image=None,) -> None:
|
||||
self.name = name
|
||||
self.pos_x = pos_x
|
||||
self.pos_y = pos_y
|
||||
self.image = image
|
||||
pass
|
||||
|
||||
def render(self, screen:pygame.Surface):
|
||||
if(self.image is not None):
|
||||
screen.blit(self.image, (self.pos_x, self.pos_y))
|
||||
else:
|
||||
print("Kein Image hinterlegt!")
|
||||
|
||||
|
||||
|
||||
def setpos(self, pos_x, pos_y):
|
||||
self.pos_x = pos_x
|
||||
self.pos_y = pos_y
|
||||
|
||||
BIN
Rastergrafik.png
Normal file
BIN
Rastergrafik.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 158 B |
68
test.py
Normal file
68
test.py
Normal file
@@ -0,0 +1,68 @@
|
||||
import pygame
|
||||
import GameObject
|
||||
import Enemy
|
||||
import Utils
|
||||
|
||||
pygame.init()
|
||||
|
||||
|
||||
pygame.display.set_caption("TESTFENSTER")
|
||||
pygame.mouse.set_visible(True)
|
||||
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)
|
||||
|
||||
objects = list()
|
||||
|
||||
enemy1 = Enemy.Enemy("Penner", 500, 500, image_enemy)
|
||||
|
||||
|
||||
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
|
||||
|
||||
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
|
||||
for object in objects:
|
||||
object:GameObject.GameObject
|
||||
|
||||
if(pygame.mouse.get_pressed()[0]):
|
||||
object.setpos(mouse_pos[0], mouse_pos[1])
|
||||
|
||||
object.render(screen)
|
||||
|
||||
enemy1.render(screen)
|
||||
#if(mouse_pos <= (image.topleft+image.size) and mouse_pos >= image.topleft):
|
||||
# print("HIIIIITTT!!!!")
|
||||
|
||||
clock.tick(60)
|
||||
pygame.display.flip()
|
||||
Reference in New Issue
Block a user