def __init__(self, color, radius, position=Vector2D(), velocity=Vector2D()): Round.__init__(self, radius, position) SolidBody.__init__(self, velocity) self.id = canv.create_oval(self.p.x - self.r, self.p.y - self.r, self.p.x + self.r, self.p.y + self.r) canv.itemconfig(self.id, fill=color)
def update_motion(self, event): m = Vector2D(event.x, event.y) m -= gun.p m /= abs(m) self.m = m.copy() m *= self.width p = self.p + m canv.coords(self.head_id, self.p.x, self.p.y, p.x, p.y)
def __init__(self, body_color, head_color, fired_color, thikness, radius, m, position=Vector2D(), velocity=Vector2D()): super().__init__(body_color, radius, position, velocity) self.head_color = head_color self.fired_color = fired_color self.width = abs(m) self.m = m / self.width pos = self.p + m self.fired = False self.head_id = canv.create_line(self.p.x, self.p.y, pos.x, pos.y, width=thikness, fill=self.head_color)
def new_game(event=''): vrem9 = time.time() canv.bind('<ButtonRelease-1>', game.mouse_up) canv.create_text(700, 100, text="Try to get it", justify=tk.CENTER, font="Verdana 14") canv.create_text(700, 130, text="YOUR SCORE:", justify=tk.CENTER, font="Verdana 14") game.label = canv.create_text(700, 160, text=0, justify=tk.CENTER, font="Verdana 14") while targets: for target in targets: target.update() for wall in walls: if target & wall: SolidRound.collide(target, wall) if time.time() - vrem9 > 1: vrem9 = time.time() targets.append( SolidRound( "red", rnd(20, 50), Vector2D(rnd(100, 750), rnd(50, 500)), Vector2D(rnd(-200, 200) / 200, rnd(-200, 200) / 200))) canv.update() time.sleep(0.01)
def __init__(self, velocity=Vector2D()): self.v = velocity
def __init__(self, radius, position=Vector2D()): self.p = position self.r = radius
def __init__(self, normal, position=Vector2D()): self.n = normal self.p = position
self.v.y = -5 def key_up(self, event): if event.keycode == 39: self.v.x = 0 if event.keycode == 37: self.v.x = 0 if event.keycode == 40: self.v.y = 0 if event.keycode == 38: self.v.y = 0 #-------------------------------------------------object_system--------------------------------------------------- gun = Gun("purple", "black", "orange", 10, 20, Vector2D(min_width, 0), Vector2D(30, 450)) targets = [ SolidRound("red", rnd(20, 50), Vector2D(rnd(100, 750), rnd(50, 500)), Vector2D(rnd(-200, 200) / 200, rnd(-200, 200) / 200)) for i in range(20) ] walls = [ Wall(Vector2D(0, -1), Vector2D(0, 600 - 30)), Wall(Vector2D(0, 1), Vector2D(0, 0)), Wall(Vector2D(1, 0), Vector2D(0, 0)), Wall(Vector2D(-1, 0), Vector2D(800, 0)) ]
def check(self, x, y): return abs(self.p - Vector2D(x, y)) <= self.r
score = 0 def mouse_up(self, event): for target in reversed(targets): if target.check(event.x, event.y): target.remove(targets) self.score += 1 canv.itemconfigure(game.label, text=self.score) break # -------------------------------------------------object_system--------------------------------------------------- game = Game() targets = [ SolidRound("red", rnd(20, 50), Vector2D(rnd(100, 750), rnd(50, 500)), Vector2D(rnd(-200, 200) / 200, rnd(-200, 200) / 200)) for i in range(20) ] walls = [ Wall(Vector2D(0, -1), Vector2D(0, 600 - 30)), Wall(Vector2D(0, 1), Vector2D(0, 0)), Wall(Vector2D(1, 0), Vector2D(0, 0)), Wall(Vector2D(-1, 0), Vector2D(800, 0)) ] # -----------------------------------------------------game_relise------------------------------------------------ def new_game(event=''):