Example #1
0
    def appendTarget(self, target):
        if target == self.pos: return
        for t in self.targets:
            if t == target: return

        self.targets.append(target)
        self.speed += 1
        helper.set_target(self, self.targets[0])
        self.updateAction(self.delta[0], 0)
Example #2
0
    def appendTarget(self, target):
        if target == self.pos: return
        for t in self.targets:
            if t == target: return

        self.targets.append(target)
        self.speed += 1
        print('speed =', self.speed, 'to', self.targets[0], 'adding target:',
              target)
        helper.set_target(self, self.targets[0])
        self.updateAction(self.delta[0], 0)
Example #3
0
def handle_events():
    global running, x, y, dx, dy, tx, ty
    events = get_events()
    for event in events:
        if event.type == SDL_QUIT:
            running = False
        elif event.type == SDL_KEYDOWN:
            if event.key == SDLK_ESCAPE:
                running = False
        elif event.type == SDL_MOUSEBUTTONDOWN:
            tx, ty = event.x, get_canvas_height() - event.y - 1
            helper.set_target(boy, (tx, ty))
            boy.speed += 2
Example #4
0
    def update(self):
        x, y = self.pos
        dx, dy = self.delta
        self.pos = x + dx, y + dy

        if self.target is not None:
            ddx = -self.delta[0]
            helper.move_toward_obj(self)
            if self.target == None:
                print("Removing target: ", self.targets[0],
                      " from %d target(s)." % len(self.targets))
                del self.targets[0]
                if len(self.targets) > 0:
                    helper.set_target(self, self.targets[0])
Example #5
0
def handle_events():

    global running
    global boy

    events = get_events()

    for e in events:
        if e.type == SDL_QUIT:
            running = False

        elif e.type == SDL_MOUSEBUTTONDOWN:
            helper.set_target(boy, (e.x, 600 - 1 - e.y))

            boy.speed += 1

        elif e.type == SDL_KEYDOWN and e.key == SDLK_ESCAPE:
            running = False
Example #6
0
    def update(self):
        x, y = self.pos
        dx, dy = self.delta
        self.pos = x + dx, y + dy

        if self.target is not None:
            ddx = -self.delta[0]
            helper.move_toward_obj(self)
            if self.target == None:
                print("Done")
                print("Removing target: ", self.targets[0], " from %d target(s)." % len(self.targets))
                del self.targets[0]
                if len(self.targets) > 0:
                    helper.set_target(self, self.targets[0])
                    self.updateAction(self.delta[0], 0)
                else:
                    self.speed = 0
        self.fidx = (self.fidx + 1) % 8
Example #7
0
    def update(self):
        stage1 = ((26, 45), (94, 90), (162, 135), (230, 180))

        x, y = self.pos
        dx, dy = self.delta
        self.pos = x + dx, y + dy
        self.animation += self.count
        bex, bey = self.pos
        if (self.animation > 0.9):
            self.animation = 0
        if (x > 741):
            self.pos = 741, y + dy
        if (x < 60):
            self.pos = 60, y + dy
        if (y > 538):
            self.pos = x + dx, 538
        if (y < 81):
            self.pos = x + dx, 81

        unx1, uny1 = stage1[3]
        if (self.action == 1 and (unx1 - 20 <= x and unx1 + 90 >= x
                                  and uny1 + 20 <= y and uny1 + 80 >= y)):
            self.pos = x - 5, y
        elif (self.action == 0 and (unx1 - 20 <= x and unx1 + 90 >= x
                                    and uny1 + 20 <= y and uny1 + 80 >= y)):
            self.pos = x + 5, y
        elif (self.action == 5 and (unx1 - 20 <= x and unx1 + 90 >= x
                                    and uny1 + 20 <= y and uny1 + 80 >= y)):
            self.pos = x, y - 5
        elif (self.action == 4 and (unx1 - 20 <= x and unx1 + 90 >= x
                                    and uny1 + 20 <= y and uny1 + 80 >= y)):
            self.pos = x, y + 5

        if self.target is not None:
            ddx = -self.delta[0]
            helper.move_toward_obj(self)
            if self.target == None:
                del self.targets[0]
                if len(self.targets) > 0:
                    helper.set_target(self, self.targets[0])
                    self.updateAction(self.delta[0], 0)
                else:
                    self.speed = 0
                    self.updateAction(0, ddx)
Example #8
0
    def update(self):
        map1 = ((94,45),(94,135),(94,225),(94,320),(94,415),(94,508) ,\
                (230,45),(230,135),(230,225),(230,320),(230,415),(230,508) ,\
                (365,45),(365,135),(365,225),(365,320),(365,415),(365,508) ,\
                (503,45),(503,135),(503,225),(503,320),(503,415),(503,508) ,\
                (639,45),(639,135),(639,225),(639,320),(639,415),(639,508))

        x, y = self.pos
        dx, dy = self.delta
        self.pos = x + dx, y + dy
        self.animation += self.count

        if (self.animation > 0.9):
            self.animation = 0
        if (x > 741):
            self.pos = 741, y + dy
        if (x < 60):
            self.pos = 60, y + dy
        if (y > 538):
            self.pos = x + dx, 538
        if (y < 81):
            self.pos = x + dx, 81

        sx1, sy1 = self.save1
        if sx1 - 100 <= x and sx1 + 100 >= x and sy1 - 70 <= y and sy1 + 70 >= y:
            self.lifecount -= 0.01
        else:
            self.lifecount -= 0.05
        sx2, sy2 = self.save2
        if sx2 - 100 <= x and sx2 + 100 >= x and sy2 - 70 <= y and sy2 + 70 >= y:
            self.lifecount -= 0.01
        else:
            self.lifecount -= 0.05

        sx3, sy3 = self.save3
        if sx3 - 100 <= x and sx3 + 100 >= x and sy3 - 70 <= y and sy3 + 70 >= y:
            self.lifecount -= 0.01
        else:
            self.lifecount -= 0.05

        print("1p", self.lifecount)
        if self.lifecount < 0:
            gfw.change(winp2)

        for i in range(30):
            unx1, uny1 = map1[i]
            if (self.action == 1 and (unx1 - 20 < x and unx1 + 90 > x
                                      and uny1 + 20 < y and uny1 + 80 > y)):
                self.pos = x - 5, y
            elif (self.action == 0 and (unx1 - 20 < x and unx1 + 90 > x
                                        and uny1 + 20 < y and uny1 + 80 > y)):
                self.pos = x + 5, y
            elif (self.action == 5 and (unx1 - 20 < x and unx1 + 90 > x
                                        and uny1 + 20 < y and uny1 + 80 > y)):
                self.pos = x, y - 5
            elif (self.action == 4 and (unx1 - 20 < x and unx1 + 90 > x
                                        and uny1 + 20 < y and uny1 + 80 > y)):
                self.pos = x, y + 5

        if self.target is not None:
            ddx = -self.delta[0]
            helper.move_toward_obj(self)
            if self.target == None:
                del self.targets[0]
                if len(self.targets) > 0:
                    helper.set_target(self, self.targets[0])
                    self.updateAction(self.delta[0], 0)
                else:
                    self.speed = 0
                    self.updateAction(0, ddx)