Пример #1
0
 def update_lightmap(self):
     for x in range(ROOM_X):
         for y in range(ROOM_Y):
             self[x,y].base_light = 0
     for bx in range(ROOM_X):
         for by in range(ROOM_Y):
             block = self[bx,by]
             if block.material != None:
                 if block.material.light:
                     l = block.material.light
                     block.base_light+=l
                     for x in range(util.clip_to_range(bx-l,0,ROOM_X),util.clip_to_range(bx+l,0,ROOM_X)):
                         for y in range(util.clip_to_range(by-l,0,ROOM_Y),util.clip_to_range(by+l,0,ROOM_Y)):
                             if True or bx!=x or by!=y:
                                 if check_ray(bx,by,x,y,self):
                                     try:
                                         self[x,y].base_light += int(round((l/(((bx-x)**2+(by-y)**2)**block.material.light_dropoff))))
                                     except ZeroDivisionError:
                                         pass
                 else:
                     block.base_light += block.material.light_ambient
     for bx in range(ROOM_X):
         for by in range(ROOM_Y):
             self[bx,by].base_light = util.clip_to_range(self[bx,by].base_light,0,255)
Пример #2
0
 def dynamic_light(self,lights):
     self.clear_dynamic_light()
     for light in lights:
         block = self[light.x,light.y]
         block.dyn_light+=light.light
         temp = set()
         for x, y in EDGES:
             if not (light.x == x and light.y == y):
                 temp |= check_ray2(light.x,light.y,x,y,self)
         for x, y in temp:
             self[x,y].dyn_light += int(round((light.light/(((light.x-x)**2+(light.y-y)**2)**light.dropoff))))
                 
     for x in range(ROOM_X):
         for y in range(ROOM_Y):
             block = self[x,y]
             block.dyn_light = util.clip_to_range(block.dyn_light+block.base_light,0,255)-block.base_light
Пример #3
0
 def update(self,dt):
     if not self.dead:
         if not self.cooldown_jump and self.parent.keys[PLAYER_JUMP]:
             self.cooldown_jump = 1
             self.jumping = self.jump_time
         
         if self.jumping > 0:
             if self.parent.keys[PLAYER_JUMP]:
                 self.vy += self.jump_speed
                 self.jumping -= 1
             else:
                 self.jumping = 0
                 
             
         #    self.vy += ACCEL
         #elif self.parent.keys[PLAYER_DOWN]:
         #    self.vy -= ACCEL
         #else:
         self.vy -= GRAVITY
         if self.parent.keys[PLAYER_LEFT]:
             if self.dir != 1:
                 self.dir = 1
                 self.sprite.image = self.image_left
                 self.eye.image = self.eye_left
             self.vx -= ACCEL
         elif self.parent.keys[PLAYER_RIGHT]:
             if self.dir != 0:
                 self.dir = 0
                 self.sprite.image = self.image_right
                 self.eye.image = self.eye_right
             self.vx += ACCEL
         else:
             self.vx *= X_FRICTION
         
         self.vx = util.clip_to_range(self.vx,-X_MAX_SPEED,X_MAX_SPEED)
         self.vy = util.clip_to_range(self.vy,-Y_MAX_SPEED,Y_MAX_SPEED)
         
         self.sprite.x += self.vx
         self.sprite.y += self.vy
         
         ## Check Collisions Here
         for x in range(ROOM_X):
             ax = x * 16
             for y in range(ROOM_Y):
                 ay = y * 16
                 block = self.parent.room[x,y]
                 if block.material and block.material.solid:
                     if self.vy < 0:
                         if ay <= self.down < ay + 16 and (ax <= self.left < ax + 12 or ax+4 <= self.sprite.x < ax + 16 or ax+4 <= self.right < ax + 16):
                             self.vy = 0
                             self.sprite.y = y*16 + 16
                             self.cooldown_jump = 0
                         elif self.sprite.y < 0:
                             self.parent.room = self.parent.rooms[self.next_room]
                             self.sprite.y = SCREEN_Y-self.sprite.height
                             break
                     elif self.vy > 0:
                         if ay - 2 <= self.up < ay + 16 and (ax <= self.left < ax + 12 or ax+4 <= self.sprite.x < ax + 16 or ax+4 <= self.right < ax + 16):
                             self.sprite.y = y*16 - self.sprite.height -2
                             self.vy = 0
                             self.jumping = 0
                         elif self.sprite.y > SCREEN_Y -16:
                             self.parent.room = self.parent.rooms[self.next_room]
                             self.sprite.y = 16
                             break
                             
                     if self.vx < 0:
                         if ax <= self.left < ax + 16 and (ay <= self.down < ay + 13 or ay <= self.down+16 < ay + 16 or ay<= self.up < ay + 16):
                             self.sprite.x = x*16 + 15 + self.sprite.width/2
                             self.vx = 0
                         elif self.left < 0:
                             self.parent.room = self.parent.rooms[self.next_room]
                             self.sprite.x = SCREEN_X-10
                             break
                     elif self.vx > 0:
                         if ax <= self.right < ax + 16 and (ay <= self.down < ay + 13  or ay <= self.down+16 < ay + 16 or ay<= self.up < ay + 16):
                             self.sprite.x = x*16 - self.sprite.width/2 -1
                             self.vx = 0
                         elif self.right > ROOM_X*16:
                             self.parent.room = self.parent.rooms[self.next_room]
                             self.sprite.x = 10
                             break
         
         self.eye.set_position(self.sprite.x, self.sprite.y)
         
         if self.powerups['glow'].active:
             if self.parent.lights[id(self)].set_pos(util.clip_to_range(int(self.sprite.x/16),0,ROOM_X-1),
                                                     util.clip_to_range(int(self.up/16),0,ROOM_Y-1)):
                 self.parent.lights_need_update = True
         refresh = False
         for item, x, y in self.parent.room.specials:
             dx = x*16
             dy = y*16
             if (dx < self.left < dx+item.material.texture.width or dx < self.right < dx+item.material.texture.width) and (dy <= self.down+2 <= dy+item.material.texture.height or dy < self.up < dy+item.material.texture.height):
                 remove = item.destruct
                 if not item.needs_activation or self.parent.keys[PLAYER_ACTIVATE]:
                     if item.type == "vial":
                         self.powerups[item.type_detail].enabled = True
                         if item.description:
                             self.parent.show_message(item.description,"player")
                     elif item.type == "spike" and not self.immune:
                         self.kill_messy()
                     elif item.type == "sign":
                         self.parent.show_message(item.description,"sign")
                         item.needs_activation = True
                     elif item.type == "seam":
                         self.next_room = item.type_detail
                     elif item.type == "checkpoint" and not item.cooldown:
                         item.cooldown = True
                         self.parent.save()
                         
                     print "Enabled: ", item.material.name
                     if remove:
                         refresh = True
                         self.parent.room[x,y] = Block(None)
                         self.parent.room.specials.remove((item, x, y))
             elif item.type == "checkpoint":
                 item.cooldown = False
                     
         if refresh:
             self.parent.room.update_lightmap()
             self.parent.room.render_slow()
             self.parent.room.update_lightbatch()
             
         text = []
         self.integrity += REGEN_RATE
         for powerup in self.powerups.values():
             if powerup.active:
                 self.integrity -= powerup.cost
                 text.append(powerup.name)
         self.integrity_bar.set(self.integrity," | ".join(text))
         self.integrity = util.clip_to_range(self.integrity,0,100)
         
         if not self.integrity:
             self.kill_messy()
         
         if self.integrity < 25:
             self.blooper.set_rate(self.integrity/20)
         else:
             self.blooper.set_rate(0)