def __init__(self, _actor): self.actor = _actor self.current_ecb = spriteManager.RectSprite( self.actor.sprite.bounding_rect.copy(), pygame.Color('#ECB134')) self.current_ecb.rect.center = self.actor.sprite.bounding_rect.center self.original_size = self.current_ecb.rect.size self.tracking_rect = self.current_ecb.rect.copy() self.game_state = self.actor.game_state self.previous_ecb = spriteManager.RectSprite( self.current_ecb.rect.copy(), pygame.Color('#EA6F1C'))
def __init__(self, _position): spriteManager.Sprite.__init__(self) self.joystick_sprite = spriteManager.ImageSprite( settingsManager.createPath('sprites/joyTest.png')) self.j_loc_sprite = spriteManager.RectSprite(pygame.Rect(0, 0, 10, 10), [255, 255, 255]) self.j_status = spriteManager.TextSprite('No Input', 'Orbitron Medium') self.j_status.rect.midtop = self.joystick_sprite.rect.midbottom self.rect = pygame.Rect( _position, 0, self.j_loc_sprite.rect.height + self.j_status.rect.height, self.j_loc_sprite.rect.width)
def getMovementCollisionsWith(_object, _spriteGroup): future_rect = _object.ecb.current_ecb.rect.copy() future_rect.x += _object.change_x future_rect.y += _object.change_y collide_sprite = spriteManager.RectSprite( _object.ecb.current_ecb.rect.union(future_rect)) check_dict = { k: _object.ecb.pathRectIntersects(k.rect, _object.change_x, _object.change_y) for k in pygame.sprite.spritecollide(collide_sprite, _spriteGroup, False) } return sorted(filter(lambda k: check_dict[k] <= 1, check_dict), key=lambda q: check_dict[q])
def isCeilinged(_object, _objectList, _checkVelocity=True): _object.ecb.normalize() _object.ecb.current_ecb.rect.y -= 4 collide_sprite = spriteManager.RectSprite( _object.ecb.current_ecb.rect.union(_object.ecb.previous_ecb.rect)) block_hit_list = pygame.sprite.spritecollide(collide_sprite, _objectList, False) _object.ecb.current_ecb.rect.y += 4 for block in block_hit_list: if block.solid: if _object.ecb.current_ecb.rect.top >= block.rect.bottom - 4 and ( not _checkVelocity or (hasattr(_object, 'change_y') and hasattr(block, 'change_y') and _object.change_y < block.change_y + 1)): return True return False
def isRightWalled(_object, _objectList, _checkVelocity=True): _object.ecb.normalize() _object.ecb.current_ecb.rect.x += 4 collide_sprite = spriteManager.RectSprite( _object.ecb.current_ecb.rect.union(_object.ecb.previous_ecb.rect)) block_hit_list = pygame.sprite.spritecollide(collide_sprite, _objectList, False) _object.ecb.current_ecb.rect.x -= 4 for block in block_hit_list: if block.solid: if _object.ecb.current_ecb.rect.right <= block.rect.left + 4 and ( not _checkVelocity or (hasattr(_object, 'change_x') and hasattr(block, 'change_x') and _object.change_x > block.change_x - 1)): return True return False
def checkLeftWall(_object, _objectList, _checkVelocity=True): _object.ecb.normalize() _object.ecb.current_ecb.rect.x -= 4 collide_sprite = spriteManager.RectSprite( _object.ecb.current_ecb.rect.union(_object.ecb.previous_ecb.rect)) wall_block = pygame.sprite.Group() block_hit_list = pygame.sprite.spritecollide(collide_sprite, _objectList, False) _object.ecb.current_ecb.rect.x += 4 for block in block_hit_list: if block.solid: if _object.ecb.current_ecb.rect.left >= block.rect.right - 4 and ( not _checkVelocity or (hasattr(_object, 'change_x') and hasattr(block, 'change_x') and _object.change_x < block.change_x + 1)): wall_block.add(block) return wall_block
def isGrounded(_object, _objectList, _checkVelocity=True): _object.ecb.normalize() _object.ecb.current_ecb.rect.y += 4 collide_sprite = spriteManager.RectSprite( _object.ecb.current_ecb.rect.union(_object.ecb.previous_ecb.rect)) block_hit_list = pygame.sprite.spritecollide(collide_sprite, _objectList, False) _object.ecb.current_ecb.rect.y -= 4 for block in block_hit_list: if block.solid or (_object.platform_phase <= 0): if (_object.ecb.current_ecb.rect.bottom <= block.rect.top + 4) and (not _checkVelocity or (hasattr(_object, 'change_y') and hasattr(block, 'change_y') and _object.change_y > block.change_y - 1)): return True return False
def endBattle(self, _exitStatus): if not (_exitStatus == 1 or _exitStatus == 2 or _exitStatus == 3): print( "An error occured that caused TUSSLE to stop working. If you can replicate this error, please file a bug report so the relevant developers can fix it. Post-mortem debugging coming soon. " ) result_sprites = [] width = settingsManager.getSetting('windowWidth') height = settingsManager.getSetting('windowHeight') for i in range(0, len(self.players)): print(self.players) print("player" + str(i)) fighter = self.players[i] result_sprite = spriteManager.RectSprite( pygame.Rect((width / 4) * i, 0, (width / 4), height), pygame.Color(settingsManager.getSetting('playerColor' + str(i)))) result_sprite.image.set_alpha(255) name_sprite = spriteManager.TextSprite(fighter.name, _size=24) name_sprite.rect.midtop = (result_sprite.rect.width / 2, 0) result_sprite.image.blit(name_sprite.image, name_sprite.rect.topleft) score = fighter.data_log.getData('KOs') - fighter.data_log.getData( 'Falls') text = spriteManager.TextSprite('Score: ' + str(score)) result_sprite.image.blit(text.image, (0, 32)) dist = 48 print(fighter.data_log.data) for item, val in fighter.data_log.data.items(): text = spriteManager.TextSprite(str(item) + ': ' + str(val)) result_sprite.image.blit(text.image, (0, dist)) dist += 16 result_sprites.append(result_sprite) confirmed_list = [False] * len( result_sprites ) #This pythonic hacking will make a list of falses equal to the result panels while 1: for event in pygame.event.get(): if event.type == pygame.QUIT: os._exit(1) return -1 for i in range(0, len(self.players)): controls = settingsManager.getControls(i) k = controls.getInputs(event) if k == 'attack': result_sprites[i].image.set_alpha(0) confirmed_list[i] = True elif k == 'special': result_sprites[i].image.set_alpha(255) confirmed_list[i] = False if event.type == pygame.KEYDOWN: if event.key == pygame.K_RETURN: print("Saving screenshot") pygame.image.save( self.screen, settingsManager.createPath('screenshot.jpg')) if event.key == pygame.K_ESCAPE: return self.screen.fill((0, 0, 0)) for sprite in result_sprites: sprite.draw(self.screen, sprite.rect.topleft, 1.0) if all(confirmed_list): return pygame.display.flip() return
def store(self): self.previous_ecb = spriteManager.RectSprite(self.current_ecb.rect, pygame.Color('#EA6F1C')) self.tracking_rect.center = self.actor.posx, self.actor.posy