def tick(self): rx, ry, dx, dy = self.orientation() if self.flipped: rx = -rx ry = -ry if self.invulnerable: self.invulnerable -= 1 if self.turnfrenzy: if self.turnfrenzy > 1: self.dx += self.jumpx self.dy += self.jumpy self.turnfrenzy -= 1 else: self.dx -= rx * 0.3 self.dy -= ry * 0.3 self.angle = 180 * math.atan2(-dx, dy) / math.pi if random.randint(0, 60 * 10) == 0: self.flipped = not self.flipped self.turnfrenzy = 15 self.jumpx = self.dx * 0.2 self.jumpy = self.dy * 0.2 Animated.tick(self) Orb.tick(self)
def tick(self): rx, ry, dx, dy = self.orientation() falling = self.sameway(dx, dy) ground = self.get_colliders(dx * 2, dy * 2) if self.movex > 0: self.frame += 1 if self.frame == 8: self.frame = 0 self.revolve += 1 else: self.frame -= 1 if self.frame == -1: self.frame = 7 self.revolve += 1 if self.revolve >= 1: self.revolve = 0 run.run.wood3.play(0.5, self) if ground: if falling > 0: self.dx -= falling * dx self.dy -= falling * dy self.dx -= dx * 0.4 self.dy -= dy * 0.4 else: self.dx += dx * 0.4 self.dy += dy * 0.4 self.dx += self.movex * rx * 0.35 self.dy += self.movex * ry * 0.35 ox = self.x oy = self.y Orb.tick(self) ox -= self.x oy -= self.y if ox ** 2 + oy ** 2 < 0.2 * 0.2: self.stuck += 1 if self.stuck > 10: self.stuck = 0 self.movex = -self.movex
def tick(p): game = run.run.game kx = p.kx ky = p.ky rx = game.rightx ry = game.righty dx = game.downx dy = game.downy gx = game.gravityx gy = game.gravityy if p.jumping: p.jumping -= 1 jumpx = 0 jumpy = 0 ground = p.get_colliders(dx * 2, dy * 2) falling = p.sameway(dx, dy) # If we are falling right into the ground, handle it in the next tick # after we bounce. Also a fudge factor of 3 pixels to make it all work # smooth :P if falling > 3: ground = [] if ground: if falling < -1: v = falling / -6.0 if v > 1.0: v = 1.0 #run.run.wood2.play(v, p) if p.frame == 16: p.frame = 0 gx = 0 gy = 0 if ky < 0 and p.jumping == 0: if kx == 0: p.frame = 16 jumpx = -15 * dx jumpy = -15 * dy v = 1.0 else: jumpx = -12 * dx + kx * 2 * rx jumpy = -12 * dy + kx * 2 * ry v = 0.8 p.jumping = 20 run.run.jump.play(v, p) else: pass for g in ground: g.touch(p, 0) if ky > 0: for g in ground: g.interact() if kx and ground: # jump a bit up when going sideways # If we are actually falling down (no more than 2 pixels due to # check earlier) - cancel it away to move smoother. if falling > 0: p.dx -= falling * dx p.dy -= falling * dy p.dx -= 0.45 * dx p.dy -= 0.45 * dy p.dx += kx * 0.4 * rx + jumpx + gx * 0.2 p.dy += kx * 0.4 * ry + jumpy + gy * 0.2 if kx > 0: p.flipped = True if kx < 0: p.flipped = False if p.frame == 16 and falling > 1: p.frame = 0 if kx and p.frame < 16: p.runcycle += 8 p.runcycle %= 256 p.frame = p.runcycle / 16 if not kx and p.frame < 16: p.runcycle = 0 p.frame = 0 Orb.tick(p)