예제 #1
0
    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)
예제 #2
0
 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)
예제 #3
0
 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)
예제 #4
0
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)
예제 #5
0
 def __init__(self, velocity=Vector2D()):
     self.v = velocity
예제 #6
0
 def __init__(self, radius, position=Vector2D()):
     self.p = position
     self.r = radius
예제 #7
0
 def __init__(self, normal, position=Vector2D()):
     self.n = normal
     self.p = position
예제 #8
0
            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))
]
예제 #9
0
 def check(self, x, y):
     return abs(self.p - Vector2D(x, y)) <= self.r
예제 #10
0
    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=''):