Compare commits
2 commits
88ead565ba
...
215d2c4865
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
215d2c4865 | ||
|
|
ca2559fcc0 |
2 changed files with 31 additions and 15 deletions
3
.gitignore
vendored
3
.gitignore
vendored
|
|
@ -221,4 +221,5 @@ __marimo__/
|
||||||
|
|
||||||
|
|
||||||
der_test.py
|
der_test.py
|
||||||
rechner.py
|
rechner.py
|
||||||
|
data/
|
||||||
43
game.py
43
game.py
|
|
@ -1,5 +1,5 @@
|
||||||
import pygame
|
import pygame
|
||||||
|
import math
|
||||||
|
|
||||||
SCREEN_WIDTH = 1280
|
SCREEN_WIDTH = 1280
|
||||||
SCREEN_HEIGHT = 720
|
SCREEN_HEIGHT = 720
|
||||||
|
|
@ -41,7 +41,12 @@ class Game:
|
||||||
self.player_width = 20
|
self.player_width = 20
|
||||||
self.player_height = 20
|
self.player_height = 20
|
||||||
|
|
||||||
#self.circle = pygame.geometry.Circle(self.player_pos[0], self.player_pos[1], 30)
|
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:
|
def run(self) -> None:
|
||||||
while self.running:
|
while self.running:
|
||||||
|
|
@ -68,12 +73,25 @@ class Game:
|
||||||
self.speed = 300
|
self.speed = 300
|
||||||
|
|
||||||
# Player-Draw
|
# 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, self.color_item, self.item_rect)
|
||||||
|
|
||||||
pygame.draw.rect(self.display, (255, 0, 0), self.player_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
|
# Smooth Movement
|
||||||
keys = pygame.key.get_pressed()
|
keys = pygame.key.get_pressed()
|
||||||
|
|
||||||
|
|
@ -136,19 +154,16 @@ class Game:
|
||||||
|
|
||||||
return distance <= circle_r
|
return distance <= circle_r
|
||||||
|
|
||||||
# def ausserhalb_des_bildschirms(self, x, y, width, height):
|
def calculate_flashlight_radiate(self, degrees, start_pos, length):
|
||||||
# if x > width:
|
angle_deg = degrees # Angle in degrees
|
||||||
# return False
|
|
||||||
# if x < 0:
|
|
||||||
# return False
|
|
||||||
|
|
||||||
# if y > height:
|
# Convert degrees to radians for math functions
|
||||||
# return False
|
angle_rad = math.radians(angle_deg)
|
||||||
# if y < 0:
|
end_x = start_pos[0] + length * math.cos(angle_rad)
|
||||||
# return False
|
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 True
|
|
||||||
|
|
||||||
|
return end_pos
|
||||||
|
|
||||||
game = Game()
|
game = Game()
|
||||||
game.run()
|
game.run()
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue