Testen für Main Klasse
This commit is contained in:
parent
215d2c4865
commit
9e66b315d6
2 changed files with 72 additions and 1 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
|
@ -220,6 +220,5 @@ __marimo__/
|
|||
.streamlit/secrets.toml
|
||||
|
||||
|
||||
der_test.py
|
||||
rechner.py
|
||||
data/
|
||||
72
der_test.py
Normal file
72
der_test.py
Normal file
|
|
@ -0,0 +1,72 @@
|
|||
import pygame
|
||||
import math
|
||||
|
||||
# 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), ]
|
||||
|
||||
vector2 = pygame.Vector2(30, 30)
|
||||
|
||||
schnittpunkt = pygame.Vector2(0, 0)
|
||||
|
||||
|
||||
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
|
||||
|
||||
# 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)
|
||||
|
||||
|
||||
pygame.draw.circle(screen, "red", player_pos, 40)
|
||||
|
||||
|
||||
end_pos = pygame.Vector2(player_pos[0]+300, player_pos[1])
|
||||
|
||||
pygame.draw.line(screen, (255, 255, 130), player_pos, end_pos, width=3)
|
||||
|
||||
# pygame.draw.line(screen, "cyan", (640, 360), vector2)
|
||||
|
||||
"""--------------------------------------- WICHTIG: Vector2.rotate() ---------------------------------------"""
|
||||
|
||||
for wall in walls:
|
||||
schnittpunkt = wall.clipline(player_pos, end_pos)[0]
|
||||
|
||||
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()
|
||||
Loading…
Reference in a new issue