levelloading
This commit is contained in:
parent
f3e0cc1f9b
commit
bf5e74fe57
3 changed files with 51 additions and 27 deletions
BIN
__pycache__/levels.cpython-311.pyc
Normal file
BIN
__pycache__/levels.cpython-311.pyc
Normal file
Binary file not shown.
6
levels.py
Normal file
6
levels.py
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
levels = [
|
||||||
|
(2,[50,120]),
|
||||||
|
(3,[50,80,100]),
|
||||||
|
(4,[50,80,100,120]),
|
||||||
|
(4,[0,80,100,120]),
|
||||||
|
]
|
72
main.py
72
main.py
|
@ -1,17 +1,32 @@
|
||||||
#!/usr/bin/python3
|
#!/usr/bin/python3
|
||||||
import pygame
|
import pygame
|
||||||
from math import radians,sin,cos
|
from math import radians,sin,cos
|
||||||
|
import levels
|
||||||
|
|
||||||
pygame.init()
|
pygame.init()
|
||||||
default_font = pygame.font.SysFont("sans", 14)
|
default_font = pygame.font.SysFont("sans", 14)
|
||||||
|
|
||||||
|
def get_debug_text():
|
||||||
|
def text(text,line_counter):
|
||||||
|
debug_text = default_font.render(str(text), True, (240, 240, 240))
|
||||||
|
screen.blit(debug_text,(0,line_counter*default_font.get_height()))
|
||||||
|
|
||||||
|
line_counter = 1
|
||||||
|
globalvars =globals()
|
||||||
|
for a in globalvars:
|
||||||
|
text(f"{str(a)} = {str(globalvars[a])}",line_counter)
|
||||||
|
line_counter += 1
|
||||||
|
|
||||||
def bubble_sort(liste):
|
def bubble_sort(liste):
|
||||||
n = len(liste)
|
n = len(liste)
|
||||||
for i in range(n):
|
for i in range(n):
|
||||||
for j in range(n - i - 1):
|
for j in range(n - i - 1):
|
||||||
if liste[j] > liste[j + 1]:
|
if liste[j] > liste[j + 1]:
|
||||||
liste[j], liste[j + 1] = liste[j + 1], liste[j]
|
liste[j], liste[j + 1] = liste[j + 1], liste[j]
|
||||||
|
def make_level(level):
|
||||||
|
for a in levels.levels[level][1]:
|
||||||
|
arrows.append(Arrow(a,circle_pos,circle_radius))
|
||||||
|
return levels.levels[level][0]
|
||||||
|
|
||||||
class Arrow():
|
class Arrow():
|
||||||
def __init__(self,winkel,pos,radius) -> None:
|
def __init__(self,winkel,pos,radius) -> None:
|
||||||
|
@ -38,53 +53,54 @@ class Bow():
|
||||||
def __init__(self,pos) -> None:
|
def __init__(self,pos) -> None:
|
||||||
self.cooldown = 2
|
self.cooldown = 2
|
||||||
self.pos = pos
|
self.pos = pos
|
||||||
|
self.posa = self.pos
|
||||||
|
self.animate = False
|
||||||
def draw(self):
|
def draw(self):
|
||||||
pygame.draw.line(screen, (255, 255, 255),
|
pygame.draw.line(screen, (255, 255, 255),
|
||||||
self.pos,
|
self.posa,
|
||||||
(self.pos[0]+60, self.pos[1]),6)
|
(self.posa[0]+60, self.posa[1]),6)
|
||||||
pygame.draw.circle(screen,color,(self.pos[0]+60, self.pos[1]),7)
|
pygame.draw.circle(screen,color,(self.posa[0]+60, self.posa[1]),7)
|
||||||
|
def update(self):
|
||||||
|
if self.animate:
|
||||||
|
x,y = self.posa
|
||||||
|
x += 40
|
||||||
|
self.posa = x,y
|
||||||
|
if x >= circle_pos[0]-60:
|
||||||
|
self.animate = False
|
||||||
|
self.posa = self.pos
|
||||||
|
arrows.append(Arrow(-90-rotate,circle_pos,circle_radius))
|
||||||
|
|
||||||
|
self.draw()
|
||||||
def shot(self):
|
def shot(self):
|
||||||
arrows.append(Arrow(-90-rotate,circle_pos,circle_radius))
|
self.animate = True
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
fill_screen = True
|
fill_screen = True
|
||||||
show_debug = False
|
show_debug = False
|
||||||
screen = pygame.display.set_mode((600,500),pygame.RESIZABLE)
|
screen = pygame.display.set_mode((900,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]//5*4,screensize[1]//2
|
||||||
circle_pos = screensize[0]//6*5,screensize[1]//2
|
circle_radius = 110
|
||||||
circle_radius = 60
|
|
||||||
rotate = 0
|
rotate = 0
|
||||||
rotate_speed = 1
|
rotate_speed = 1
|
||||||
|
|
||||||
bow = Bow((screensize[0]//6,screensize[1]//2))
|
bow = Bow((screensize[0]//5,screensize[1]//2))
|
||||||
|
|
||||||
arrows = []
|
arrows = []
|
||||||
for a in arrows_test:
|
|
||||||
arrows.append(Arrow(a,circle_pos,circle_radius))
|
|
||||||
|
|
||||||
bg_color = (0,0,0)
|
bg_color = (0,0,0)
|
||||||
color = (255,255,255)
|
color = (255,255,255)
|
||||||
|
|
||||||
def get_debug_text():
|
level = 0
|
||||||
def text(text,line_counter):
|
to_shot = make_level(0)
|
||||||
debug_text = default_font.render(str(text), True, (240, 240, 240))
|
|
||||||
screen.blit(debug_text,(0,line_counter*default_font.get_height()))
|
|
||||||
|
|
||||||
line_counter = 1
|
|
||||||
globalvars =globals()
|
|
||||||
for a in globalvars:
|
|
||||||
text(f"{str(a)} = {str(globalvars[a])}",line_counter)
|
|
||||||
line_counter += 1
|
|
||||||
|
|
||||||
running = True
|
running = True
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
while running:
|
while running:
|
||||||
|
arrow_angles = []
|
||||||
if fill_screen:
|
if fill_screen:
|
||||||
screen.fill(bg_color)
|
screen.fill(bg_color)
|
||||||
pressed_keys = pygame.key.get_pressed()
|
pressed_keys = pygame.key.get_pressed()
|
||||||
|
@ -107,14 +123,16 @@ if __name__ == "__main__":
|
||||||
screensize = pygame.display.get_window_size()
|
screensize = pygame.display.get_window_size()
|
||||||
if event.type == pygame.WINDOWRESIZED:
|
if event.type == pygame.WINDOWRESIZED:
|
||||||
screensize = pygame.display.get_window_size()
|
screensize = pygame.display.get_window_size()
|
||||||
circle_pos = screensize[0]//6*5,screensize[1]//2
|
circle_pos = screensize[0]//5*4,screensize[1]//2
|
||||||
|
bow.pos = screensize[0]//5,screensize[1]//2
|
||||||
|
bow.posa = screensize[0]//5,screensize[1]//2
|
||||||
for a in arrows:
|
for a in arrows:
|
||||||
a.pos = circle_pos
|
a.pos = circle_pos
|
||||||
bow.pos = screensize[0]//6,screensize[1]//2
|
bow.update()
|
||||||
bow.draw()
|
|
||||||
pygame.draw.circle(screen,color,circle_pos,circle_radius)
|
pygame.draw.circle(screen,color,circle_pos,circle_radius)
|
||||||
for a in arrows:
|
for a in arrows:
|
||||||
a.draw()
|
a.draw()
|
||||||
|
arrow_angles.append(a.winkel)
|
||||||
rotate += 2
|
rotate += 2
|
||||||
|
|
||||||
if show_debug:
|
if show_debug:
|
||||||
|
|
Loading…
Reference in a new issue