Halb-Funktioniertendes Flashlight System
This commit is contained in:
parent
78a87589d1
commit
82b69ef5de
1 changed files with 21 additions and 4 deletions
25
game.py
25
game.py
|
|
@ -8,7 +8,7 @@ SCREEN_HEIGHT = 480
|
|||
class Game:
|
||||
def __init__(self):
|
||||
pygame.init()
|
||||
|
||||
|
||||
pygame.display.set_caption("School Game")
|
||||
|
||||
self.clock = pygame.Clock()
|
||||
|
|
@ -28,11 +28,22 @@ class Game:
|
|||
|
||||
self.player_pos = pygame.Vector2(self.display.get_width() / 2, self.display.get_height() / 2)
|
||||
|
||||
self.item_rect = pygame.Rect(60, 40, 10, 10)
|
||||
|
||||
self.flashlight = 0
|
||||
|
||||
self.color_item = (0, 0, 0)
|
||||
|
||||
#self.circle = pygame.geometry.Circle(self.player_pos[0], self.player_pos[1], 30)
|
||||
|
||||
def run(self) -> None:
|
||||
while self.running:
|
||||
# Background
|
||||
self.display.fill((0, 0, 0, 0))
|
||||
|
||||
self.player_rect = pygame.Rect(self.player_pos[0]-10, self.player_pos[1]-10, 20, 20)
|
||||
|
||||
|
||||
# Event-Keys
|
||||
for event in pygame.event.get():
|
||||
if event.type == pygame.QUIT:
|
||||
|
|
@ -43,9 +54,11 @@ class Game:
|
|||
self.running = False
|
||||
|
||||
# Player-Draw
|
||||
pygame.draw.circle(self.display, (255, 255, 255, 0), self.player_pos, 30)
|
||||
self.flashlight = pygame.draw.circle(self.display, (255, 255, 255, 0), self.player_pos, 30)
|
||||
|
||||
pygame.draw.rect(self.display, (255, 0, 0), pygame.Rect(self.player_pos[0]-10, self.player_pos[1]-10, 20, 20))
|
||||
pygame.draw.rect(self.display, self.color_item, self.item_rect)
|
||||
|
||||
pygame.draw.rect(self.display, (255, 0, 0), self.player_rect)
|
||||
|
||||
# Smooth Movement
|
||||
keys = pygame.key.get_pressed()
|
||||
|
|
@ -58,7 +71,11 @@ class Game:
|
|||
if keys[pygame.K_d]:
|
||||
self.player_pos.x += 300 * self.dt
|
||||
|
||||
|
||||
if not self.flashlight.colliderect(self.item_rect):
|
||||
self.color_item = (0,0,0)
|
||||
else:
|
||||
self.color_item = (0, 0, 255)
|
||||
|
||||
self.screen.blit(
|
||||
pygame.transform.scale(self.display, self.screen.get_size())
|
||||
)
|
||||
|
|
|
|||
Loading…
Reference in a new issue