def get_frame_time(): global current_time frame_time = pico2d.get_time() - current_time current_time += frame_time return frame_time
def jump(self): jump_time = pico2d.get_time() - self.start_jumping_time self.jumping_count = (self.jumping_count + FRAMES_PER_JUMP * JUMP_PER_TIME * GameFrameWork.frame_time) jump_progress = int(self.jumping_count) / FRAMES_PER_JUMP # x = (2 * t ** 2 - 3 * t + 1) * p1[0] + (-4 * t ** 2 + 4 * t) * p2[0] + (2 * t ** 2 - t) * p3[0] # y = (2 * t ** 2 - 3 * t + 1) * p1[1] + (-4 * t ** 2 + 4 * t) * p2[1] + (2 * t ** 2 - t) * p3[1] self.pivot.x = int((2 * jump_progress ** 2 - 3 * jump_progress + 1) * self.start_point.x + (-4 * jump_progress ** 2 + 4 * jump_progress) * self.mid_point.x + (2 * jump_progress ** 2 - jump_progress) * self.end_point.x) self.pivot.y = int((2 * jump_progress ** 2 - 3 * jump_progress + 1) * self.start_point.y + (-4 * jump_progress ** 2 + 4 * jump_progress) * self.mid_point.y + (2 * jump_progress ** 2 - jump_progress) * self.end_point.y) if self.jump_dir == 'UP': if int(self.jumping_count) >= FRAMES_PER_JUMP - 1: self.pivot.x = copy.copy(self.end_point.x) self.pivot.y = copy.copy(self.end_point.y) self.check_jumping = False pass pass elif self.jump_dir == 'DOWN': if int(self.jumping_count) >= FRAMES_PER_JUMP - 1: self.pivot.x = copy.copy(self.end_point.x) self.pivot.y = copy.copy(self.end_point.y) self.check_jumping = False pass pass elif self.jump_dir == 'LEFT': if int(self.jumping_count) >= FRAMES_PER_JUMP - 1: self.pivot.x = copy.copy(self.end_point.x) self.pivot.y = copy.copy(self.end_point.y) self.check_jumping = False pass pass elif self.jump_dir == 'RIGHT': if int(self.jumping_count) >= FRAMES_PER_JUMP - 1: self.pivot.x = copy.copy(self.end_point.x) self.pivot.y = copy.copy(self.end_point.y) self.check_jumping = False pass pass pass
def run(start_state): global running, stack current_time = pico2d.get_time() running = True stack = [start_state] # 스택을 리스트로 구현함 start_state.enter() # 현재 상태의 enter()를 호출함 while (running): frame_time = get_frame_time() stack[-1].handle_events(frame_time) # 스택의 마지막 상태의 ~()를 호출함 stack[-1].update(frame_time) # update()에서 상태를 바꿔주는걸 넣어놓기 때문에 이 때 바뀜 stack[-1].draw() # frame_time = get_time() - current_time # frame_rate = 1.0 / frame_time # print("Frame Rate: %f fps, Frame Time: %f sec, " %(frame_rate, frame_time)) # current_time += frame_time # repeatedly delete the top of the stack while (len(stack) > 0): stack[-1].exit() stack.pop()
def init_jump(self, jump_dir=None): if self.check_jumping is False: self.check_moving_collide = False self.check_jumping = True self.start_point = copy.copy(self.pivot) self.mid_point = copy.copy(self.pivot) self.end_point = copy.copy(self.pivot) self.jump_dir = jump_dir self.jumping_count = 0 self.start_jumping_time = pico2d.get_time() if self.jump_dir == 'UP': self.mid_point.x += 10 self.mid_point.y += 25 self.end_point.y += 50 pass elif self.jump_dir == 'DOWN': self.mid_point.x += 10 self.mid_point.y -= 25 self.end_point.y -= 50 pass elif self.jump_dir == 'LEFT': self.mid_point.x -= 25 self.mid_point.y += 10 self.end_point.x -= 50 pass elif self.jump_dir == 'RIGHT': self.mid_point.x += 25 self.mid_point.y += 10 self.end_point.x += 50 pass pass pass
import pico2d x = 0 while (True): current_time = pico2d.get_time() x += 5 frame_time = pico2d.get_time() - current_time print("%f sec" % frame_time) current_time += frame_time