def deactivate (self): self.active = False self.animating = True self.anim_reverse = False self.solid = True resourcemanager.get("sound.deactivate").play()
def activate (self): resourcemanager.get("sound.menu_select").play() if self.callback: if self.data: self.callback(self.data) else: self.callback()
def deactivate (self): if not self.active: return self.active = False self.deactivate_connections() resourcemanager.get("sound.switch_off").play()
def pull (self, direction): rx, ry = self.world.get_relative_delta(direction) self.x_coord -= rx self.y_coord -= ry self.xvec -= rx self.yvec -= ry self.smoothing = True resourcemanager.get("sound.block_push").play()
def update (self, t, dt): if self.broken: # setting the time it was broken for the animation to begin if self.break_time == 0: self.break_time = t resourcemanager.get("sound.crumble").play() time_passed = t - self.break_time if time_passed < self.break_duration: self.frame = 0+math.ceil(time_passed*self.ani_frames/self.break_duration) else: self.solid = False self.frame = self.ani_frames+1 self.zindex = -2
def cyl(self): try: return self._prop["cyl"] except: v1, v2 = resourcemanager.get(self._prop["res"]).aabb v1 = [i * self._prop["scale"] for i in v1] v2 = [i * self._prop["scale"] for i in v1] self._prop["cyl"] = [max(abs(i[0]), abs(i[1])) for i in zip(v1, v2)]
def render (self, target, t, dt): if self.texture == None: self.texture = resourcemanager.get(self.texture_id) if self.sprite == None: self.sprite = sf.Sprite(self.texture) # world size in pixels ww = (self.world.maxx + 1) * PIXELS_PER_METER if self.world else 0 wh = (self.world.maxy + 1) * PIXELS_PER_METER if self.world else 0 # view x/y vx = target.view.center[0] - target.view.width/2 vy = target.view.center[1] - target.view.height/2 # corner offset, 0 or top left of visible screen topx = min(0, vx) topy = min(0, vy) # calculated width/height needed to cover the screen or level rw = max(target.width, ww) rh = max(target.height, ww) # minimum texture width/height multiple to cover rw/rh (rounded up) tw = math.ceil(rw/self.texture.width) * self.texture.width th = math.ceil(rh/self.texture.height) * self.texture.height if self.tile: self.sprite.texture.repeated = True self.sprite.texture_rect = sf.IntRect(0, 0, tw * 2, th * 2) #if self.scroll > 0: topx = vx * self.scroll topy = vy * self.scroll # FIXME: NOT framerate independent self.xautoscroll += self.autoscroll[0] * dt self.yautoscroll += self.autoscroll[1] * dt # calculated corners - offset + size + autoscroll offset self.sprite.x = topx - tw + self.xautoscroll self.sprite.y = topy - th + self.yautoscroll # when the texture runs off screen # 1. reset autoscroll to view position - current corner # 2. move the texture back one [view position - width/height ] # these must be done to seamlessly loop things # 0 or vx/y are our origin if self.sprite.x > min(0, vx): self.xautoscroll = vx - topx self.sprite.x = vx - tw if self.sprite.y > min(0, vy): self.yautoscroll = vy - topy #0 #vy * self.scroll self.sprite.y = vy - th target.draw(self.sprite)
def activate (self): if self.active: return self.active = True update = True for switch in self.blockgroup.blocks: if not switch.active: update = False break if update: self.activate_connections() resourcemanager.get("sound.switch_on").play()
def update (self, t, dt): super(PillarBlock, self).update(t, dt) # TODO: add a notify hook if not self.animcomplete: if not self.moveable: if self.time_fell == 0: self.time_fell = t if math.ceil((t - self.time_fell)*10)%3 == 0: self.frame += 1 if self.frame == 2: self.animcomplete = True self.solid = False self.zindex = -2 resourcemanager.get("sound.thud").play()
def update (self, t, dt): stopped = False if self.smoothing: self.update_movement(t, dt) if self.is_near_grid(): if not self.world.can_move_to_tile((self.x_coord + self.xvec, self.y_coord + self.yvec)): self.snap_to_grid() self.xvec = self.yvec = 0 self.smoothing = False stopped = True else: self.x_coord += self.xvec self.y_coord += self.yvec if stopped: resourcemanager.get("sound.ice_block").play()
def draw(self): glPushMatrix() # Posición glRotatef(self._prop["pos"][0], 1, 0, 0) # x phi glRotatef(self._prop["pos"][1], 0, 1, 0) # y theta glRotatef(self._prop["pos"][2], 0, 0, 1) # z gao glTranslatef(0, 0, self._prop["pos"][3]) # w rho # Rotación glRotatef(self._prop["rot"][0], 1, 0, 0) glRotatef(self._prop["rot"][1], 0, 1, 0) glRotatef(self._prop["rot"][2], 0, 0, 1) # Escala glScalef(self._prop["scale"], self._prop["scale"], self._prop["scale"]) resourcemanager.get(self._prop["res"]).draw() glPopMatrix()
def __init__ (self, game, width = 50): self.game = game self.x = 0 self.y = 0 self.width = width self.font = resourcemanager.get('font.menu') self.entries = [] self.selected_index = 0 self.input = []
def collision_with_entity (self, entity, t, dt): if entity == self.world.player and \ abs(entity.x - self.x) < 0.3 and \ abs(entity.y - self.y) < 0.3: if self.teletime is None: self.teletime = t + self.duration if t >= self.teletime: self.teletime = None # FIXME: add teleport functions in world, and call them here x, y, level = self.location if level: print "[TeleportBlock] cross-level teleportation not implemented!" resourcemanager.get("sound.teleport").play() else: entity.x = x entity.y = y resourcemanager.get("sound.teleport").play() else: self.teletime = None
def execute_action(self): resourcemanager.get("sound.menu_select").play() entry = self.entries[self.selected_index] entry['callback'](entry['data']) if entry['data'] else entry['callback']()
def change_selected(self, index): if not index == self.selected_index: self.selected_index = index resourcemanager.get("sound.menu_change").play()