Compare commits
No commits in common. "2a0066deca119edc0ce0e40d5a5a6deaee6c1955" and "215d2c486580801b2d45a449faa1c202c48d824c" have entirely different histories.
2a0066deca
...
215d2c4865
6 changed files with 14 additions and 270 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
|
@ -220,5 +220,6 @@ __marimo__/
|
||||||
.streamlit/secrets.toml
|
.streamlit/secrets.toml
|
||||||
|
|
||||||
|
|
||||||
|
der_test.py
|
||||||
rechner.py
|
rechner.py
|
||||||
data/
|
data/
|
||||||
104
der_test.py
104
der_test.py
|
|
@ -1,104 +0,0 @@
|
||||||
import math
|
|
||||||
|
|
||||||
import pygame
|
|
||||||
|
|
||||||
# pygame setup
|
|
||||||
pygame.init()
|
|
||||||
screen = pygame.display.set_mode((1280, 720))
|
|
||||||
clock = pygame.time.Clock()
|
|
||||||
running = True
|
|
||||||
dt = 0
|
|
||||||
|
|
||||||
player_pos = pygame.Vector2(screen.get_width() / 2, screen.get_height() / 2)
|
|
||||||
|
|
||||||
walls = [
|
|
||||||
pygame.Rect(980, 100, 50, 440),
|
|
||||||
pygame.Rect(280, 650, 720, 35),
|
|
||||||
]
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
while running:
|
|
||||||
# poll for events
|
|
||||||
# pygame.QUIT event means the user clicked X to close your window
|
|
||||||
for event in pygame.event.get():
|
|
||||||
if event.type == pygame.QUIT:
|
|
||||||
running = False
|
|
||||||
|
|
||||||
if event.type == pygame.KEYDOWN:
|
|
||||||
if event.key == pygame.K_ESCAPE:
|
|
||||||
running = False
|
|
||||||
|
|
||||||
if event.key == pygame.K_ESCAPE:
|
|
||||||
running = False
|
|
||||||
|
|
||||||
# fill the screen with a color to wipe away anything from last frame
|
|
||||||
screen.fill("black")
|
|
||||||
|
|
||||||
for wall in walls:
|
|
||||||
pygame.draw.rect(screen, "grey", wall)
|
|
||||||
|
|
||||||
end_pos = pygame.Vector2(player_pos[0] + 300, player_pos[1])
|
|
||||||
|
|
||||||
# pygame.draw.line(screen, "cyan", (640, 360), vector2)
|
|
||||||
|
|
||||||
"""--------------------------------------- WICHTIG: Vector2.rotate() ---------------------------------------"""
|
|
||||||
|
|
||||||
|
|
||||||
ray_end = pygame.Vector2()
|
|
||||||
light_points = []
|
|
||||||
vector = pygame.Vector2(300, 0)
|
|
||||||
|
|
||||||
# Lichtstrahlen berechnen
|
|
||||||
for i in range(360):
|
|
||||||
|
|
||||||
rotated = vector.rotate(i)
|
|
||||||
ray_end = player_pos + rotated
|
|
||||||
|
|
||||||
|
|
||||||
# Überschneidung mit den Wänden prüfen
|
|
||||||
for wall in walls:
|
|
||||||
überschneidung = wall.clipline(player_pos, ray_end)
|
|
||||||
|
|
||||||
if überschneidung:
|
|
||||||
schnittpunkt = pygame.Vector2(überschneidung[0])
|
|
||||||
|
|
||||||
ray_end = schnittpunkt
|
|
||||||
|
|
||||||
|
|
||||||
light_points.append(ray_end)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
pygame.draw.polygon(
|
|
||||||
screen,
|
|
||||||
"yellow",
|
|
||||||
light_points
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
pygame.draw.circle(screen, "red", player_pos, 40)
|
|
||||||
|
|
||||||
keys = pygame.key.get_pressed()
|
|
||||||
if keys[pygame.K_w]:
|
|
||||||
player_pos.y -= 300 * dt
|
|
||||||
if keys[pygame.K_s]:
|
|
||||||
player_pos.y += 300 * dt
|
|
||||||
if keys[pygame.K_a]:
|
|
||||||
player_pos.x -= 300 * dt
|
|
||||||
if keys[pygame.K_d]:
|
|
||||||
player_pos.x += 300 * dt
|
|
||||||
|
|
||||||
# flip() the display to put your work on screen
|
|
||||||
pygame.display.flip()
|
|
||||||
|
|
||||||
# limits FPS to 60
|
|
||||||
# dt is delta time in seconds since last frame, used for framerate-
|
|
||||||
# independent physics.
|
|
||||||
dt = clock.tick(60) / 1000
|
|
||||||
|
|
||||||
|
|
||||||
pygame.quit()
|
|
||||||
53
game.py
53
game.py
|
|
@ -1,6 +1,5 @@
|
||||||
import math
|
|
||||||
|
|
||||||
import pygame
|
import pygame
|
||||||
|
import math
|
||||||
|
|
||||||
SCREEN_WIDTH = 1280
|
SCREEN_WIDTH = 1280
|
||||||
SCREEN_HEIGHT = 720
|
SCREEN_HEIGHT = 720
|
||||||
|
|
@ -75,40 +74,14 @@ class Game:
|
||||||
|
|
||||||
# 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])
|
||||||
|
|
||||||
|
|
||||||
"""RAYCASTING"""
|
|
||||||
ray_end = pygame.Vector2()
|
|
||||||
light_points = []
|
|
||||||
vector = pygame.Vector2(75, 0)
|
|
||||||
|
|
||||||
# Lichtstrahlen berechnen
|
|
||||||
for i in range(360):
|
for i in range(360):
|
||||||
|
end_pos = self.calculate_flashlight_radiate(i, self.player_pos, 50)
|
||||||
|
|
||||||
rotated = vector.rotate(i)
|
# rect = pygame.Rect(self.player_pos[0], self.player_pos[1], end_pos[0], end_pos[1])
|
||||||
ray_end = self.player_pos + rotated
|
|
||||||
|
|
||||||
|
# pygame.draw.rect(self.display, (255, 255, 130), rect)
|
||||||
|
|
||||||
# Überschneidung mit den Wänden prüfen
|
pygame.draw.line(self.display, (255, 255, 130), self.player_pos, end_pos, width=3)
|
||||||
for wall in self.walls:
|
|
||||||
überschneidung = wall.clipline(self.player_pos, ray_end)
|
|
||||||
|
|
||||||
if überschneidung:
|
|
||||||
schnittpunkt = pygame.Vector2(überschneidung[0])
|
|
||||||
|
|
||||||
ray_end = schnittpunkt
|
|
||||||
|
|
||||||
|
|
||||||
light_points.append(ray_end)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
pygame.draw.polygon(
|
|
||||||
self.display,
|
|
||||||
"yellow",
|
|
||||||
light_points
|
|
||||||
)
|
|
||||||
|
|
||||||
pygame.draw.rect(self.display, self.color_item, self.item_rect)
|
pygame.draw.rect(self.display, self.color_item, self.item_rect)
|
||||||
|
|
||||||
|
|
@ -181,16 +154,16 @@ class Game:
|
||||||
|
|
||||||
return distance <= circle_r
|
return distance <= circle_r
|
||||||
|
|
||||||
# def calculate_flashlight_radiate(self, degrees: int, start_pos: tuple[int, int] | list[int, int] | pygame.Vector2, length: int) -> tuple[int, int]:
|
def calculate_flashlight_radiate(self, degrees, start_pos, length):
|
||||||
# angle_deg = degrees # Angle in degrees
|
angle_deg = degrees # Angle in degrees
|
||||||
|
|
||||||
# # Convert degrees to radians for math functions
|
# Convert degrees to radians for math functions
|
||||||
# angle_rad = math.radians(angle_deg)
|
angle_rad = math.radians(angle_deg)
|
||||||
# end_x = start_pos[0] + length * math.cos(angle_rad)
|
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_y = start_pos[1] - length * math.sin(angle_rad) # Minus because y increases downward in Pygame
|
||||||
# end_pos = (int(end_x), int(end_y))
|
end_pos = (int(end_x), int(end_y))
|
||||||
|
|
||||||
# return end_pos
|
return end_pos
|
||||||
|
|
||||||
game = Game()
|
game = Game()
|
||||||
game.run()
|
game.run()
|
||||||
|
|
|
||||||
44
lesen.txt
44
lesen.txt
File diff suppressed because one or more lines are too long
52
polygon.py
52
polygon.py
|
|
@ -1,52 +0,0 @@
|
||||||
# Example file showing a basic pygame "game loop"
|
|
||||||
import pygame
|
|
||||||
import math
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# pygame setup
|
|
||||||
pygame.init()
|
|
||||||
screen = pygame.display.set_mode((1280, 720))
|
|
||||||
clock = pygame.time.Clock()
|
|
||||||
running = True
|
|
||||||
|
|
||||||
def calculate_flashlight_radiate(degrees: int, start_pos: tuple[int, int] | list[int, int] | pygame.Vector2, length: int) -> tuple[int, int]:
|
|
||||||
angle_deg = degrees # Angle in degrees
|
|
||||||
|
|
||||||
# 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
|
|
||||||
|
|
||||||
|
|
||||||
points = []
|
|
||||||
|
|
||||||
while running:
|
|
||||||
# poll for events
|
|
||||||
# pygame.QUIT event means the user clicked X to close your window
|
|
||||||
for event in pygame.event.get():
|
|
||||||
if event.type == pygame.QUIT:
|
|
||||||
running = False
|
|
||||||
|
|
||||||
# fill the screen with a color to wipe away anything from last frame
|
|
||||||
screen.fill("purple")
|
|
||||||
|
|
||||||
# RENDER YOUR GAME HERE
|
|
||||||
for i in range(360):
|
|
||||||
point = calculate_flashlight_radiate(i, (640, 360), 50)
|
|
||||||
points.append(point)
|
|
||||||
|
|
||||||
pygame.draw.polygon(screen, (27, 134, 3), points)
|
|
||||||
|
|
||||||
points = []
|
|
||||||
|
|
||||||
# flip() the display to put your work on screen
|
|
||||||
pygame.display.flip()
|
|
||||||
|
|
||||||
clock.tick(60) # limits FPS to 60
|
|
||||||
|
|
||||||
pygame.quit()
|
|
||||||
30
testo.py
30
testo.py
|
|
@ -1,30 +0,0 @@
|
||||||
# Example file showing a basic pygame "game loop"
|
|
||||||
import pygame
|
|
||||||
|
|
||||||
# pygame setup
|
|
||||||
pygame.init()
|
|
||||||
screen = pygame.display.set_mode((1280, 720))
|
|
||||||
clock = pygame.time.Clock()
|
|
||||||
running = True
|
|
||||||
|
|
||||||
while running:
|
|
||||||
# poll for events
|
|
||||||
# pygame.QUIT event means the user clicked X to close your window
|
|
||||||
for event in pygame.event.get():
|
|
||||||
if event.type == pygame.QUIT:
|
|
||||||
running = False
|
|
||||||
|
|
||||||
# fill the screen with a color to wipe away anything from last frame
|
|
||||||
screen.fill("purple")
|
|
||||||
|
|
||||||
# RENDER YOUR GAME HERE
|
|
||||||
vector = pygame.Vector2(640, 360)
|
|
||||||
for i in range(10):
|
|
||||||
print(vector.rotate(i))
|
|
||||||
|
|
||||||
# flip() the display to put your work on screen
|
|
||||||
pygame.display.flip()
|
|
||||||
|
|
||||||
clock.tick(60) # limits FPS to 60
|
|
||||||
|
|
||||||
pygame.quit()
|
|
||||||
Loading…
Reference in a new issue