def __init__(self, **kwargs): super().__init__(**kwargs) self.spr = 29 self.spd.y = -0.1 self.spd.x = 0.3 + p8.rnd(0.2) self.x += int(-1 + p8.rnd(2)) self.y += int(-1 + p8.rnd(2)) self.flip_x = helper.maybe() self.flip_y = helper.maybe() self.solids = False
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 draw(self): self.x += self.spd self.y += math.sin(self.off) self.off+= min(0.05,self.spd/32) p8.rectfill(self.x,self.y,self.x+self.s,self.y+self.s,self.c) if self.x>128+4: self.x=-4 self.y=p8.rnd(128)
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 draw(self): if self.state == 0: hit = self.collide(Player, 0, 8) if hit and hit.is_solid(0, 1): music(-1, 500, 7) sfx(37) pause_player = true hit.spd.x = 0 hit.spd.y = 0 self.state = 1 init_object(smoke, self.x, self.y) init_object(smoke, self.x + 8, self.y) self.timer = 60 self.particles = {} spr(96, self.x, self.y) spr(97, self.x + 8, self.y) elif self.state == 1: self.timer -= 1 shake = 5 flash_bg = true if self.timer <= 45 and count(self.particles) < 50: self.particles.append( Particle(x=1 + p8.rnd(14), y=0, h=32 + p8.rnd(32), spd=8 + p8.rnd(8))) if self.timer < 0: self.state = 2 self.particles = {} flash_bg = false new_bg = true init_object(orb, self.x + 4, self.y + 4) pause_player = false for p in self.particles: p.y += p.spd line(self.x + p.x, self.y + 8 - p.y, self.x + p.x, min(self.y + 8 - p.y + p.h, self.y + 8), 7) spr(112, self.x, self.y + 8) spr(113, self.x + 8, self.y + 8)
def __init__(self, **kwargs): super().__init__(single_tile=False, **kwargs) self.offset = p8.rnd(1) self.start = self.y self.timer = 0 self.hitbox = geom.Rect(x=-1, y=-1, w=10, h=10) self.popped = False self.balloon = p8.platform.TileGrid(p8.sprite_sheet, pixel_shader=p8.palette, tile_width=8, tile_height=8) self.string = p8.platform.TileGrid(p8.sprite_sheet, pixel_shader=p8.palette, tile_width=8, tile_height=8, x=0, y=6) self.append(self.balloon) self.append(self.string)
def maybe(): return p8.rnd(1) < 0.5
def draw(self): self.x += self.spd p8.rectfill(self.x,self.y,self.x+self.w,self.y+4+(1-self.w/64)*12,14 if game.new_bg else 1) if self.x > 128: self.x = -self.w self.y=p8.rnd(128-8)
def update(self): if game.pause_player: return input = p8.btn(game.k_right) and 1 or (p8.btn(game.k_left) and -1 or 0) # spikes collide if self._spike_collide(): self._die() # bottom death if self.y>128: self._die() on_ground=self._is_solid(0,1) on_ice=self._is_ice(0,1) # smoke particles if on_ground and not self.was_on_ground: game.objects.append(Smoke(x=self.x, y=self.y+4)) jump = p8.btn(game.k_jump) and not self.p_jump self.p_jump = p8.btn(game.k_jump) if jump: self.jbuffer=4 elif self.jbuffer>0: self.jbuffer-=1 dash = p8.btn(game.k_dash) and not self.p_dash self.p_dash = p8.btn(game.k_dash) if on_ground: self.grace=6 if self.djump<game.max_djump: game.psfx(54) self.djump=game.max_djump elif self.grace > 0: self.grace-=1 self.dash_effect_time -=1 if self.dash_time > 0: game.objects.append(Smoke(x=self.x, y=self.y)) self.dash_time-=1 self.spd.x=helper.appr(self.spd.x,self.dash_target.x,self.dash_accel.x) self.spd.y=helper.appr(self.spd.y,self.dash_target.y,self.dash_accel.y) else: # move maxrun=1 accel=0.6 deccel=0.15 if not on_ground: accel=0.4 elif on_ice: accel=0.05 if input==(-1 if self.flip_x else 1): accel=0.05 if abs(self.spd.x) > maxrun: self.spd.x=helper.appr(self.spd.x,helper.sign(self.spd.x)*maxrun,deccel) else: self.spd.x=helper.appr(self.spd.x,input*maxrun,accel) # facing if self.spd.x!=0: self.flip_x = (self.spd.x<0) # gravity maxfall=2 gravity=0.21 if abs(self.spd.y) <= 0.15: gravity*=0.5 # wall slide if input!=0 and self._is_solid(input,0) and not self._is_ice(input,0): maxfall=0.4 if p8.rnd(10)<2: game.objects.append(Smoke(x=self.x+input*6,y=self.y)) if not on_ground: self.spd.y=helper.appr(self.spd.y,maxfall,gravity) # jump if self.jbuffer>0: if self.grace>0: # normal jump game.psfx(1) self.jbuffer=0 self.grace=0 self.spd.y=-2 game.objects.append(Smoke(x=self.x, y=self.y+4)) else: # wall jump wall_dir = 0 if self._is_solid(-3,0): wall_dir = -1 elif self._is_solid(3,0): wall_dir = 1 if wall_dir!=0: game.psfx(2) self.jbuffer=0 self.spd.y=-2 self.spd.x=-wall_dir*(maxrun+1) if not self._is_ice(wall_dir*3,0): game.objects.append(Smoke(x=self.x+wall_dir*6,y=self.y)) # dash d_full=5 d_half=d_full*0.70710678118 if self.djump>0 and dash: game.objects.append(Smoke(x=self.x, y=self.y)) self.djump-=1 self.dash_time=4 game.has_dashed=True self.dash_effect_time=10 v_input = 0 if p8.btn(game.k_up): v_input = -1 elif p8.btn(game.k_down): v_input = 1 if input!=0: if v_input!=0: self.spd.x=input*d_half self.spd.y=v_input*d_half else: self.spd.x=input*d_full self.spd.y=0 elif v_input!=0: self.spd.x=0 self.spd.y=v_input*d_full else: self.spd.x=(-1 if self.flip_x else 1) self.spd.y=0 game.psfx(3) game.freeze=2 game.shake=6 self.dash_target.x=2*helper.sign(self.spd.x) self.dash_target.y=2*helper.sign(self.spd.y) self.dash_accel.x=1.5 self.dash_accel.y=1.5 if self.spd.y<0: self.dash_target.y*=.75 if self.spd.y!=0: self.dash_accel.x*=0.70710678118 if self.spd.x!=0: self.dash_accel.y*=0.70710678118 elif dash and self.djump<=0: game.psfx(9) game.objects.append(Smoke(x=self.x,y=self.y)) # animation self.spr_off+=0.25 if not on_ground: if self._is_solid(input,0): self.spr=5 else: self.spr=3 elif p8.btn(game.k_down): self.spr=6 elif p8.btn(game.k_up): self.spr=7 elif (self.spd.x==0) or (not p8.btn(game.k_left) and not p8.btn(game.k_right)): self.spr=1 else: self.spr=1+self.spr_off%4 # next level if self.y<-4 and game.level_index()<30: game.next_room() # was on the ground self.was_on_ground=on_ground
display = gb print("code loaded:", time.monotonic() - last_checkpoint) last_checkpoint = time.monotonic() if p8.platform_id == "adafruit": p8.load_resources("celeste-original.p8") elif p8.platform_id == "gb": p8.load_resources("celeste-gb.p8") elif p8.platform_id == "gbc": p8.load_resources("celeste-gbc.p8") print("resources loaded:", time.monotonic() - last_checkpoint) clouds = [] for i in range(1): #is 16 normally clouds.append( Cloud(p8.rnd(128), p8.rnd(128), 1 + p8.rnd(4), 32 + p8.rnd(32))) particles = [] for i in range(1): # was 24 particles.append( Particle(p8.rnd(128), p8.rnd(128), 0 + p8.flr(p8.rnd(5) / 4), 0.25 + p8.rnd(5), p8.rnd(1), 6 + p8.flr(0.5 + p8.rnd(1)))) # entry point title_screen() def print_recursive(o, indent=0): print(" " * indent + str(o), o.x, o.y) if not isinstance(o, p8.platform.Group): return