This commit is contained in:
Michael S. 2024-02-27 20:23:23 +01:00
parent 2f549afa1f
commit f3e0cc1f9b

83
main.py
View file

@ -5,22 +5,72 @@ from math import radians,sin,cos
pygame.init() pygame.init()
default_font = pygame.font.SysFont("sans", 14) default_font = pygame.font.SysFont("sans", 14)
def draw_arrow(winkel,pos,radius): def bubble_sort(liste):
pygame.draw.line(screen,(255,255,255), n = len(liste)
pos[0]+sin(radians(winkel)*radius), for i in range(n):
pos[0]+sin(radians(winkel)*radius) for j in range(n - i - 1):
) if liste[j] > liste[j + 1]:
liste[j], liste[j + 1] = liste[j + 1], liste[j]
class Arrow():
def __init__(self,winkel,pos,radius) -> None:
self.radius = radius
self.winkel = winkel
self.pos = pos
self.länge = 60
def draw(self):
radian = radians(self.winkel+rotate)
pygame.draw.line(screen, (255, 255, 255),
(self.pos[0] + sin(radian) * self.radius, self.pos[1] + cos(radian) * self.radius),
(self.pos[0] + sin(radian) * (self.radius + self.länge), self.pos[1] + cos(radian) * (self.radius + self.länge)),
6)
pygame.draw.circle(screen,color,(self.pos[0] + sin(radian) * (self.radius + self.länge), self.pos[1] + cos(radian) * (self.radius + self.länge)),7)
def sind_winkel_nahe(self,winkel,toleranz=3):
winkel1 = winkel % 360
winkel2 = self.winkel % 360
differenz = abs(winkel1 - winkel2)
if differenz <= toleranz or differenz >= 360 - toleranz:return True
else:return False
class Bow():
def __init__(self,pos) -> None:
self.cooldown = 2
self.pos = pos
def draw(self):
pygame.draw.line(screen, (255, 255, 255),
self.pos,
(self.pos[0]+60, self.pos[1]),6)
pygame.draw.circle(screen,color,(self.pos[0]+60, self.pos[1]),7)
def shot(self):
arrows.append(Arrow(-90-rotate,circle_pos,circle_radius))
arrows = [10,50,80]
fill_screen = True fill_screen = True
show_debug = False show_debug = False
screen = pygame.display.set_mode((600,500)) screen = pygame.display.set_mode((600,500),pygame.RESIZABLE)
pygame.display.set_caption("Shot") pygame.display.set_caption("Shot")
screensize = pygame.display.get_window_size() screensize = pygame.display.get_window_size()
clock = pygame.time.Clock() clock = pygame.time.Clock()
arrows_test = []#[10,50,80,180]
circle_pos = screensize[0]//6*5,screensize[1]//2
circle_radius = 60
rotate = 0
rotate_speed = 1
bow = Bow((screensize[0]//6,screensize[1]//2))
arrows = []
for a in arrows_test:
arrows.append(Arrow(a,circle_pos,circle_radius))
bg_color = (0,0,0)
color = (255,255,255)
def get_debug_text(): def get_debug_text():
def text(text,line_counter): def text(text,line_counter):
debug_text = default_font.render(str(text), True, (240, 240, 240)) debug_text = default_font.render(str(text), True, (240, 240, 240))
@ -36,13 +86,15 @@ running = True
if __name__ == "__main__": if __name__ == "__main__":
while running: while running:
if fill_screen: if fill_screen:
screen.fill((0,0,0)) screen.fill(bg_color)
pressed_keys = pygame.key.get_pressed() pressed_keys = pygame.key.get_pressed()
if pressed_keys[pygame.K_ESCAPE]: if pressed_keys[pygame.K_ESCAPE]:
exit() exit()
if pressed_keys[pygame.K_SPACE] and not preview_pressed_keys[pygame.K_SPACE]: if pressed_keys[pygame.K_a] and not preview_pressed_keys[pygame.K_a]:
fill_screen = not fill_screen fill_screen = not fill_screen
if pressed_keys[pygame.K_SPACE] and not preview_pressed_keys[pygame.K_SPACE]:
bow.shot()
if pressed_keys[pygame.K_d] and not preview_pressed_keys[pygame.K_d]: if pressed_keys[pygame.K_d] and not preview_pressed_keys[pygame.K_d]:
show_debug = not show_debug show_debug = not show_debug
@ -53,8 +105,17 @@ if __name__ == "__main__":
exit() exit()
if event.type == pygame.WINDOWRESIZED: if event.type == pygame.WINDOWRESIZED:
screensize = pygame.display.get_window_size() screensize = pygame.display.get_window_size()
if event.type == pygame.WINDOWRESIZED:
pygame.draw.circle(screen,(100,100,100),(0,0),30) screensize = pygame.display.get_window_size()
circle_pos = screensize[0]//6*5,screensize[1]//2
for a in arrows:
a.pos = circle_pos
bow.pos = screensize[0]//6,screensize[1]//2
bow.draw()
pygame.draw.circle(screen,color,circle_pos,circle_radius)
for a in arrows:
a.draw()
rotate += 2
if show_debug: if show_debug:
get_debug_text() get_debug_text()