Compare commits
2 commits
88ead565ba
...
215d2c4865
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
215d2c4865 | ||
|
|
ca2559fcc0 |
2 changed files with 31 additions and 15 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
|
@ -222,3 +222,4 @@ __marimo__/
|
|||
|
||||
der_test.py
|
||||
rechner.py
|
||||
data/
|
||||
41
game.py
41
game.py
|
|
@ -1,5 +1,5 @@
|
|||
import pygame
|
||||
|
||||
import math
|
||||
|
||||
SCREEN_WIDTH = 1280
|
||||
SCREEN_HEIGHT = 720
|
||||
|
|
@ -41,6 +41,11 @@ class Game:
|
|||
self.player_width = 20
|
||||
self.player_height = 20
|
||||
|
||||
self.walls = [
|
||||
pygame.Rect(100, 100, 20, 50)
|
||||
]
|
||||
|
||||
|
||||
# self.circle = pygame.geometry.Circle(self.player_pos[0], self.player_pos[1], 30)
|
||||
|
||||
def run(self) -> None:
|
||||
|
|
@ -68,12 +73,25 @@ class Game:
|
|||
self.speed = 300
|
||||
|
||||
# Player-Draw
|
||||
self.flashlight = pygame.draw.circle(self.display, (255, 255, 255, 0), self.flashlight_rect[0], self.flashlight_rect[1])
|
||||
# self.flashlight = pygame.draw.circle(self.display, (255, 255, 255, 0), self.flashlight_rect[0], self.flashlight_rect[1])
|
||||
for i in range(360):
|
||||
end_pos = self.calculate_flashlight_radiate(i, self.player_pos, 50)
|
||||
|
||||
# rect = pygame.Rect(self.player_pos[0], self.player_pos[1], end_pos[0], end_pos[1])
|
||||
|
||||
# pygame.draw.rect(self.display, (255, 255, 130), rect)
|
||||
|
||||
pygame.draw.line(self.display, (255, 255, 130), self.player_pos, end_pos, width=3)
|
||||
|
||||
pygame.draw.rect(self.display, self.color_item, self.item_rect)
|
||||
|
||||
pygame.draw.rect(self.display, (255, 0, 0), self.player_rect)
|
||||
|
||||
|
||||
|
||||
for wall in self.walls:
|
||||
pygame.draw.rect(self.display, "grey", wall)
|
||||
|
||||
# Smooth Movement
|
||||
keys = pygame.key.get_pressed()
|
||||
|
||||
|
|
@ -136,19 +154,16 @@ class Game:
|
|||
|
||||
return distance <= circle_r
|
||||
|
||||
# def ausserhalb_des_bildschirms(self, x, y, width, height):
|
||||
# if x > width:
|
||||
# return False
|
||||
# if x < 0:
|
||||
# return False
|
||||
def calculate_flashlight_radiate(self, degrees, start_pos, length):
|
||||
angle_deg = degrees # Angle in degrees
|
||||
|
||||
# if y > height:
|
||||
# return False
|
||||
# if y < 0:
|
||||
# return False
|
||||
|
||||
# return True
|
||||
# Convert degrees to radians for math functions
|
||||
angle_rad = math.radians(angle_deg)
|
||||
end_x = start_pos[0] + length * math.cos(angle_rad)
|
||||
end_y = start_pos[1] - length * math.sin(angle_rad) # Minus because y increases downward in Pygame
|
||||
end_pos = (int(end_x), int(end_y))
|
||||
|
||||
return end_pos
|
||||
|
||||
game = Game()
|
||||
game.run()
|
||||
|
|
|
|||
Loading…
Reference in a new issue