def update(self): # idling if self.state == 0: if (self.collide_with_player(0,-1) or self.collide_with_player(-1,0) or self.collide_with_player(1,0)): self._break() # shaking elif self.state==1: self.delay-=1 print("shake", self.delay) if self.delay<=0: self.state=2 self.delay=60 #how long it hides for self.collideable=False # invisible, waiting to reset elif self.state==2: self.delay-=1 if self.delay<=0 and not self.collide_with_player(0,0): game.psfx(7) self.state=0 self.collideable=True game.objects.append(Smoke(x=self.x, y=self.y))
def update(self): if self.hide_for > 0: self.hide_for -= 1 if self.hide_for <= 0: self.spr = 18 self.delay = 0 elif self.spr == 18: hit = self.collide_with_player(0, 0) if hit and hit.spd.y >= 0: self.spr = 19 hit.y = self.y - 4 hit.spd.x *= 0.2 hit.spd.y = -3 hit.djump = game.max_djump self.delay = 10 game.objects.append(Smoke(x=self.x, y=self.y)) # breakable below us below = self.collide(FallFloor, 0, 1) if below: below._break() game.psfx(8) elif self.delay > 0: self.delay -= 1 if self.delay <= 0: self.spr = 18 # begin hiding if self.hide_in > 0: self.hide_in -= 1 if self.hide_in <= 0: self.hide_for = 60 self.spr = 0
def _break(self): if self.state==0: game.psfx(15) self.state=1 self.delay=15 # how long until it falls game.objects.append(Smoke(x=self.x, y=self.y)) s=self.collide(spring.Spring,0,-1) if s: s._break()
def update(self): if not self.popped: self.offset += 0.01 self.y = int(self.start + p8.sin(self.offset) * 2) hit = self.collide(Player, 0, 0) if hit and hit.djump < game.max_djump: game.psfx(6) game.objects.append(Smoke(x=self.x, y=self.y)) hit.djump = game.max_djump self.popped = True self.timer = 60 self.balloon[0] = 0 self.string[0] = 0 else: self.balloon[0] = 22 self.string[0] = 13 + int((self.offset * 8) % 3) elif self.timer > 0: self.timer -= 1 else: game.psfx(7) game.objects.append(Smoke(x=self.x, y=self.y)) self.popped = False
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