def update(self): # jumping up if self.state == 0: if self.y < self.target.y + 16: self.state = 1 self.delay = 3 # falling elif self.state == 1: self.spd.y += 0.5 if self.spd.y > 0 and self.delay > 0: self.spd.y = 0 self.delay -= 1 if self.spd.y > 0 and self.y > self.target.y: self.y = self.target.y self.spd = geom.Vec(x=0, y=0) self.state = 2 self.delay = 5 game.shake = 5 game.objects.append(Smoke(x=self.x, y=self.y + 4)) p8.sfx(5) # landing elif self.state == 2: self.delay -= 1 self.spr = 6 if self.delay < 0: game.objects.remove(self) game.player = Player(x=self.x, y=self.y) game.objects.append(game.player)
def update(self): # fly away if self.fly: if self.sfx_delay > 0: self.sfx_delay -= 1 if self.sfx_delay <= 0: game.sfx_timer = 20 p8.sfx(14) self.spd.y = helper.appr(self.spd.y, -3.5, 0.25) if self.y < -16: game.objects.remove(self) # wait else: if game.has_dashed: self.fly = True self.step += 0.05 self.spd.y = p8.sin(self.step) * 0.5 # collect hit = self.collide(Player, 0, 0) if hit: hit.djump = game.max_djump game.sfx_timer = 20 p8.sfx(13) game.got_fruit[1 + game.level_index()] = True game.objects.append(LifeUp(x=self.x, y=self.y)) game.objects.remove(self)
def update(self): if game.has_key: self.timer-=1 self.x=int(self.start-1+p8.rnd(3)) if self.timer<=0: game.sfx_timer=20 p8.sfx(16) game.objects.append(Fruit(x=self.x, y=self.y-4)) game.objects.remove(self)
def update(self): hit = self.collide_with_player(0, 0) if hit: hit.djump = game.max_djump game.sfx_timer = 20 p8.sfx(13) game.got_fruit[1 + game.level_index()] = True game.objects.append(LifeUp(x=self.x, y=self.y)) game.objects.remove(self) self.off += 1 self.y = self.start + int(math.sin(self.off / 40) * 2.5)
def update(self): was=p8.flr(self.spr) self.spr=9+(math.sin(game.frames / 30)+0.5)*1 current=p8.flr(self.spr) if current==10 and current!=was: self.flip.x=not self.flip.x if self.check(Player,0,0): p8.sfx(23) game.sfx_timer=10 game.objects.remove(self) game.has_key=True
def _update(): game.frames = ((game.frames + 1) % 30) if game.frames == 0 and game.level_index() < 30: game.seconds = ((game.seconds + 1) % 60) if game.seconds == 0: game.minutes += 1 if game.music_timer > 0: game.music_timer -= 1 if game.music_timer <= 0: music(10, 0, 7) if game.sfx_timer > 0: game.sfx_timer -= 1 # cancel if freeze if game.freeze > 0: game.freeze -= 1 return # screenshake if game.shake > 0: game.shake -= 1 p8.camera() if game.shake > 0: p8.camera(-2 + p8.rnd(5), -2 + p8.rnd(5)) # restart (soon) if game.will_restart and game.delay_restart > 0: game.delay_restart -= 1 if game.delay_restart <= 0: game.will_restart = False load_room(game.room.x, game.room.y) # update each object for obj in game.objects: obj.move(obj.spd.x, obj.spd.y) obj.update() # start game if game.is_title(): if not game.start_game and (p8.btn(game.k_jump) or p8.btn(game.k_dash)): p8.music(-1) game.start_game_flash = 50 game.start_game = True p8.sfx(38) if game.start_game: game.start_game_flash -= 1 if game.start_game_flash <= -30: begin_game()
def __init__(self, **kwargs): super().__init__(**kwargs) print("init player spawn", self.x, self.y) p8.sfx(4) self.spr = 3 self.target = geom.Vec(x=self.x, y=self.y) self.y = 128 self.spd.y = -4 self.state = 0 self.delay = 0 self.solids = False helper.create_hair(self)
def draw(self): self.spr=118+(frames/5)%3 p8.spr(self.spr,self.x,self.y) if self.show: p8.rectfill(32,2,96,31,0) p8.spr(26,55,6) p8._print("x{}".format(self.score),64,9,7) draw_time(49,16) p8._print("deaths:{}".format(deaths),48,24,7) elif self.check(Player,0,0): p8.sfx(55) game.sfx_timer=30 self.show=True
def _die(self): game.sfx_timer=12 p8.sfx(0) game.deaths+=1 game.shake=10 game.player = None game.objects.remove(self) game.dead_particles=[] for dir in range(8): angle=(dir/8) game.dead_particles.append(DeadParticle(self.x+4, self.y+4, 10, geom.Vec(x=math.sin(angle)*3, y=math.cos(angle)*3))) game.restart_room()
def update(self): self.hitbox = geom.Rect(x=-1, y=-1, w=18, h=18) hit = self.collide_with_player(0, 0) if hit and hit.dash_effect_time > 0: hit.spd.x = -helper.sign(hit.spd.x) * 1.5 hit.spd.y = -1.5 hit.dash_time = -1 game.sfx_timer = 20 p8.sfx(16) game.objects.remove(self) game.objects_by_type[FakeWall].remove(self) game.objects.append(Smoke(x=self.x, y=self.y)) game.objects.append(Smoke(x=self.x + 8, y=self.y)) game.objects.append(Smoke(x=self.x, y=self.y + 8)) game.objects.append(Smoke(x=self.x + 8, y=self.y + 8)) game.objects.append(Fruit(x=self.x + 4, y=self.y + 4)) self.hitbox = geom.Rect(x=0, y=0, w=16, h=16)
def draw(self): self.spd.y = appr(self.spd.y, 0, 0.5) hit = self.collide(Player, 0, 0) if self.spd.y == 0 and hit: game.music_timer = 45 p8.sfx(51) game.freeze = 10 game.shake = 10 game.objects.remove(self) game.max_djump = 2 hit.djump = 2 p8.spr(102, self.x, self.y) off = game.frames / 30 for i in range(7): p8.circfill(self.x + 4 + math.cos(off + i / 8) * 8, self.y + 4 + math.sin(off + i / 8) * 8, 1, 7)
def draw(self): self.text="-- celeste mountain --#self memorial to those# perished on the climb" if self.check(Player,4,0): if self.index<len(self.text): self.index+=0.5 if self.index>=self.last+1: self.last+=1 p8.sfx(35) self.off=geom.Vec(x=8,y=96) for i in range(self.index): if self.text[i] != "#": p8.rectfill(self.off.x-2,self.off.y-2,self.off.x+7,self.off.y+6 ,7) p8._print(self.text[i],self.off.x,self.off.y,0) self.off.x+=5 else: self.off.x=8 self.off.y+=7 else: self.index=0 self.last=0
def psfx(num): if sfx_timer <= 0: p8.sfx(num)