Пример #1
0
def handle_events():
    global running, dx, dy, x, y, target, speed
    evts = get_events()
    for e in evts:
        if e.type == SDL_QUIT:
            running = False
        elif e.type == SDL_KEYDOWN:
            if e.key == SDLK_ESCAPE:
                running = False
        elif e.type == SDL_MOUSEBUTTONDOWN:
            if e.button == SDL_BUTTON_LEFT:
                if speed > 0:
                    speed += 1
                    dx, dy = helper.delta((x, y), target[0], speed)
            elif e.button == SDL_BUTTON_RIGHT:
                if speed == 0:
                    speed += 1
                target.append((e.x, get_canvas_height() - e.y - 1))
                dx, dy = helper.delta((x, y), target[0], speed)
    if speed > 0:
        (x, y), done = helper.move_toward((x, y), (dx, dy), target[0])
        if done == True:
            dx, dy = 0, 0
            del target[0]
            if not target:
                speed = 0
            else:
                dx, dy = helper.delta((x, y), target[0], speed)
Пример #2
0
def move_character():
    global x, y, speed
    global move_list, move_count
    global animation_index

    if move_count < len(move_list):
        delta = helper.delta((x, y), move_list[move_count][0:2],
                             move_list[move_count][2])

        if move_count != 0:
            if delta[0] >= 0:
                animation_index = 1
            else:
                animation_index = 0

        (x, y), done = helper.move_toward((x, y), delta,
                                          move_list[move_count][0:2])

        if done:
            move_count += 1
    else:
        move_list.append((x, y, 0))
        move_count += 1
        if animation_index == 0:
            animation_index = 2
        elif animation_index == 1:
            animation_index = 3
Пример #3
0
    def update(self, tList):
        if len(tList) > 0:  # 목적지가 있다면
            dt = helper.delta((self.x, self.y),tList[0],self.speed)
            (self.x, self.y), done = helper.move_toward((self.x, self.y), dt, tList[0])
            if done == True:
                del(tList[0])
                self.speed = 1

    #    self.x += self.dx
    #    self.y += self.dy
        self.fidx = (self.fidx + 1) % 8
Пример #4
0
 def update(self):
     self.frame = (self.frame + 1) % 8
     self.delta = helper.delta(self.pos, self.rTarget, self.speed)
     self.pos, self.done = helper.move_toward(self.pos, self.delta,
                                              self.rTarget)
     if self.done == True:
         print(self.targetList)
         del self.targetList[0]
         if len(self.targetList) == 0:
             self.speed = 1
         else:
             self.rTarget = self.targetList[0]
def move_toward_obj(obj):
    global num, cnt
    if obj.target == None: return
    pos, done = helper.move_toward(obj.pos, obj.delta, obj.target)
    if done:
        obj.speed = 1
        obj.delta = 0, 0
        if (cnt != num):
            set_target(boy, (tx[num], ty[num]))
            num += 1
        else:
            obj.target = None
    obj.pos = list(pos)
def update():
    global done, target, speed

    if boy.pos != target:
        boy.finx = (boy.finx + 1) % 8
    else:
        if targets:
            target = targets.pop(0)
        else:
            speed = 0
        boy.finx = 0

    delta = helper.delta(boy.pos, target, speed)
    boy.pos, done = helper.move_toward(boy.pos, delta, target)
Пример #7
0
def handle_events():
    global running
    global dx, dy, x, y
    evts = get_events()
    boy.done = False
    for e in evts:
        if e.type == SDL_QUIT:
            running = False
        elif (e.type, e.key) == (SDL_KEYDOWN, SDLK_ESCAPE):
            running = False
        elif e.type == SDL_MOUSEBUTTONDOWN:
            boy.speed += 1
            boy.list.append((e.x, 600 - e.y - 1))
            boy.target = boy.list[0]
            boy.pos, boy.done = helper.move_toward(
                boy.pos, helper.delta(boy.pos, boy.target, boy.speed),
                boy.target)
Пример #8
0
    def update(self):
        self.frame = (self.frame + 1) % 8
        delta = helper.delta(
            (self.x, self.y),
            (self.target[self.target_idx][0], self.target[self.target_idx][1]),
            self.speed)
        result = helper.move_toward(
            (self.x, self.y), (delta[0], delta[1]),
            (self.target[self.target_idx][0], self.target[self.target_idx][1]))

        if result[1] is True:
            # Reset speed when getting to destination
            self.speed = 3
            if self.target_idx < len(self.target) - 1:
                self.target_idx += 1
        else:
            self.x = result[0][0]
            self.y = result[0][1]
Пример #9
0
done = True
fidx = 0
delta = 0, 0    # 이동 거리
speed = 1       # 프레임 당 이동 속도

Mx, My = 0,0    # 마우스 위치   

running = True

while running:
    clear_canvas()
    gra.draw(400,30)
    ch.clip_draw(fidx * 100, 0 , 100,100,pos[0],pos[1])
    update_canvas()

    handle_events()

    pos, done = helper.move_toward(pos,delta,target)

    if done == False:
        pos += delta
    else: speed = 1
    
    
    fidx = (fidx + 1 ) % 8
    delay(0.01)

close_canvas()
            
Пример #10
0
running = True
speed = 1
target = [0, 0]
delta = [0, 0]
pos = 150, 80
done = [0, 0]
x, y = get_canvas_width() // 2, 80
dx, dy = 0, 0
frame = 0

while running:
    clear_canvas()

    grass.draw(400, 30)
    character.clip_draw(frame * 100, 0, 100, 100, pos[0], pos[1])

    update_canvas()

    frame = (frame + 1) % 7

    handle_events()
    pos, done = h.move_toward(pos, delta, target)
    if (done == True):
        speed = 1
        delta = [0, 0]
        target = [0, 0]
    print(pos, target, done)
    delay(0.05)

close_canvas()
Пример #11
0
running = True
move = False
x, y = 800 // 2, 90
destList = [(800 // 2, 90)]
destListCount = 1
frame = 0
speed = 0
done = 0

while running:
    clear_canvas()
    kpu_ground.draw(800 // 2, 30)
    character.clip_draw(frame * 100, 0, 100, 100, x, y)
    update_canvas()
    frame = (frame + 1) % 8
    if move:
        x, y = helper.move_toward((x, y),
                                  helper.delta((x, y), destList[destListCount],
                                               speed),
                                  destList[destListCount])[0]
        done = helper.move_toward((x, y),
                                  helper.delta((x, y), destList[destListCount],
                                               speed),
                                  destList[destListCount])[1]
    if done:
        if destListCount == len(destList) - 1:
            move = False
        speed = 1
        destListCount += 1
        done = 0
    handle_events()
Пример #12
0
        elif event.type == SDL_MOUSEBUTTONDOWN:
            boy.towardx = event.x
            boy.towardy = get_canvas_height() - event.y - 1
            boy.dx, boy.dy = helper.delta((boy.x, boy.y),
                                          (boy.towardx, boy.towardy), 5)
            (deltax, deltay) = helper.delta((boy.x, boy.y), (towardx, towardy),
                                            5)


running = True
while running:
    clear_canvas()
    grass.draw()
    boy.draw()
    update_canvas()

    handle_events()
    (posx, posy), done = helper.move_toward((boy.x, boy.y), (boy.dx, boy.dy),
                                            (boy.towardx, boy.towardy))
    if done == True:
        boy.x, boy.y = posx, posy

    boy.update()
    grass.update()

    if boy.x > get_canvas_width():
        running = False

    delay(0.01)

close_canvas()
Пример #13
0
speed = 1
destination = []

while running:
    clear_canvas()
    gra.draw(400, 30)

    ch.clip_draw(fidx * 100, 0, 100, 100, pos[0], pos[1])
    update_canvas()

    handle_events()

    if moving:
        fidx = (fidx + 1) % 8

    if not len(destination) == 0:
        delta = h.delta(pos, destination[0], speed)
        pos, arrive = h.move_toward(pos, delta, destination[0])

    if arrive:
        speed = 1
        if not len(destination) == 0:
            destination.pop(0)
        else:
            moving = True
            fidx = 0

    delay(0.02)

close_canvas()
now = 0  #현재 좌표를 가리키는 함수
x = 30
y = 80
dx = 0
dy = 0
mx = [30]
my = [80]
speed = 1
start = False
running = True
frame = 0
while running:
    clear_canvas()
    gra.draw(400, 30)
    img.clip_draw(frame * 100, 0, 100, 100, x, y)
    #두개의 이미지를 그려줌
    update_canvas()
    frame = (frame + 1) % 8
    handle_events()
    dx, dy = helper.delta([x, y], [mx[now], my[now]], speed)
    if dx == 0 and dy == 0 and start == True:
        speed = 1
        now += 1
        if len(mx) == now:
            #도착시했고 리스트의 다음값이 없을땐 now에 값을 더하지 않음. 리스트의 다음값이 없기때문에 다음좌표를 가리킬수 없음.
            now -= 1
    [x, y], done = helper.move_toward([x, y], [dx, dy], [mx[now], my[now]])
    delay(0.03)

close_canvas()
while running:
    clear_canvas()
    grass.draw(400, 30)
    character.clip_draw(frame * 100, 0, 100, 100, x, y)

    update_canvas()

    handle_events()

    if (tx == -1):
        x += 1
    elif num > list_num + 2:
        if h.move_toward([x, y], [
                h.delta([x, y], [goal[list_num + 1], goal[list_num + 2]],
                        speed)[0],
                h.delta([x, y], [goal[list_num + 1], goal[list_num + 2]],
                        speed)[1]
        ], [goal[list_num + 1], goal[list_num + 2]
            ]) != ([goal[list_num + 1], goal[list_num + 2]], True):
            x = x + h.delta([x, y], [goal[list_num + 1], goal[list_num + 2]],
                            speed)[0]
            y = y + h.delta([x, y], [goal[list_num + 1], goal[list_num + 2]],
                            speed)[1]
            speed_events()
        else:
            list_num += 2

    frame = (frame + 1) % 8

close_canvas()
Пример #16
0
            running = False
        elif e.type == SDL_MOUSEBUTTONDOWN:
            boy.speed += 1
            boy.list.append((e.x, 600 - e.y - 1))
            boy.target = boy.list[0]
            boy.pos, boy.done = helper.move_toward(
                boy.pos, helper.delta(boy.pos, boy.target, boy.speed),
                boy.target)


open_canvas(800, 600)

enter()

running = True

while running:
    handle_events()
    boy.pos, boy.done = helper.move_toward(
        boy.pos, helper.delta(boy.pos, boy.target, boy.speed), boy.target)

    update()

    clear_canvas()
    draw()
    update_canvas()

    delay(0.01)

close_canvas()