def test_loadWeapon(self): game.isunittest.setIsUnitTest() fileTextureLoader.loadFromFiles() fileOffenseLoader.loadFromFiles() renderableCache.init(viewport=None) weaponData = fileOffenseLoader.weaponManager.getWeaponData( WeaponType.unittest) self.assertTrue(weaponData.actionTextureType is ActionType.unittest) self.assertTrue(weaponData.hitDetectionDirection == Direction.left) self.assertTrue(weaponData.damage == 10) self.assertTrue(weaponData.weaponHitArea[Direction.left].width == 5) self.assertTrue(weaponData.weaponHitArea[Direction.left].height == 3) self.assertTrue( weaponData.weaponHitArea[Direction.left].hitCd[0].x == 1) self.assertTrue( weaponData.weaponHitArea[Direction.left].hitCd[0].y == 0) self.assertTrue( weaponData.weaponHitArea[Direction.left].hitCd[1].x == 3) self.assertTrue( weaponData.weaponHitArea[Direction.left].hitCd[1].y == 0) self.assertTrue( weaponData.weaponHitArea[Direction.left].hitCd[2].x == 0) self.assertTrue( weaponData.weaponHitArea[Direction.left].hitCd[2].y == 1) self.assertTrue( weaponData.weaponHitArea[Direction.left].hitCd[5].x == 3) self.assertTrue( weaponData.weaponHitArea[Direction.left].hitCd[5].y == 2)
def test_loadEnemy(self): game.isunittest.setIsUnitTest() fileTextureLoader.loadFromFiles() enemyLoader = EnemyLoader() enemySeed = enemyLoader.getSeedForEnemy(EnemyType.unittest) self.assertTrue( enemySeed.characterTextureType is CharacterTextureType.stickfigure) self.assertTrue(enemySeed.weaponType is WeaponType.hitSquare) self.assertTrue(enemySeed.health == 100) self.assertTrue(enemySeed.enemyInfo.attackWindupTime == 1.0) self.assertTrue(enemySeed.attackBaseLocation['x'] == -1)
def test_loadTextureAction(self): game.isunittest.setIsUnitTest() fileTextureLoader.loadFromFiles() animation = fileTextureLoader.actionAnimationManager.getAnimation( ActionType.unittest, Direction.left) self.assertTrue(animation.height == 3) self.assertTrue(animation.width == 4) self.assertTrue(animation.frameCount == 3) self.assertTrue(animation.endless is False) self.assertTrue(animation.advanceByStep is False) self.assertTrue(animation.frameTime[0] == 0.1) self.assertTrue(animation.frameTime[1] == 0.1) self.assertTrue(animation.frameTime[2] == 0.1) self.assertTrue(animation.frameColors[0][0] == 'brightyellow') self.assertTrue(animation.frameColors[1][0] == 'brightyellow') self.assertTrue(animation.frameColors[2][0] == 'brightyellow') x = 0 y = 1 frameIndex = 0 self.assertTrue(animation.arr[frameIndex][y][x] == '<') x = 1 y = 1 self.assertTrue(animation.arr[frameIndex][y][x] == '<') x = 0 y = 2 self.assertTrue(animation.arr[frameIndex][y][x] == '<') x = 1 y = 2 self.assertTrue(animation.arr[frameIndex][y][x] == '<') frameIndex = 1 self.assertTrue(animation.arr[frameIndex][1][0] == '-') self.assertTrue(animation.arr[frameIndex][1][1] == '-') self.assertTrue(animation.arr[frameIndex][2][0] == '-') self.assertTrue(animation.arr[frameIndex][2][1] == '-') frameIndex = 2 self.assertTrue(animation.arr[frameIndex][1][0] == '<') self.assertTrue(animation.arr[frameIndex][1][1] == '') self.assertTrue(animation.arr[frameIndex][2][0] == '<') self.assertTrue(animation.arr[frameIndex][2][1] == '')
def test_loadTexturePhenomena(self): game.isunittest.setIsUnitTest() fileTextureLoader.loadFromFiles() animation = fileTextureLoader.phenomenaAnimationManager.readPhenomena( PhenomenaType.unittest) self.assertTrue(animation.height == 2) self.assertTrue(animation.width == 2) self.assertTrue(animation.frameCount == 2) self.assertTrue(animation.endless is True) self.assertTrue(animation.advanceByStep is False) self.assertTrue(animation.frameTime[0] == 0.1) self.assertTrue(animation.frameTime[1] == 0.2) self.assertTrue(animation.frameColors[0][0] == 'white') self.assertTrue(animation.frameColors[1][0] == 'green') x = 0 y = 0 frameIndex = 0 self.assertTrue(animation.arr[frameIndex][y][x] == 'A') x = 1 y = 0 self.assertTrue(animation.arr[frameIndex][y][x] == 'B') x = 0 y = 1 self.assertTrue(animation.arr[frameIndex][y][x] == 'C') x = 1 y = 1 self.assertTrue(animation.arr[frameIndex][y][x] == 'D') x = 0 y = 1 frameIndex = 1 self.assertTrue(animation.arr[frameIndex][y][x] == 'X')
def __init__(self, win, menuwin): self.pause: bool = False self.gameRunning: bool = True self.showStats = False self.showLog = False self.win = win self.world: esper.World = esper.World() viewport: Viewport = Viewport(win=win, world=self) self.statusBar: StatusBar = StatusBar(world=self, viewport=viewport) fileTextureLoader.loadFromFiles() fileOffenseLoader.loadFromFiles() textureEmiter: TextureEmiter = TextureEmiter(viewport=viewport, world=self.world) mapManager: MapManager = MapManager(viewport=viewport) sceneManager: SceneManager = SceneManager(viewport=viewport, world=self.world, mapManager=mapManager) renderableCache.init(viewport=viewport) particleEmiter = ParticleEmiter(viewport=viewport) particleProcessor = ParticleProcessor(viewport=viewport, particleEmiter=particleEmiter) gametimeProcessor = GametimeProcessor() aiProcessor = AiProcessor() characterAnimationProcessor = CharacterAnimationProcessor() playerProcessor = PlayerProcessor(viewport=viewport) enemyProcessor = EnemyProcessor(viewport=viewport) attackableProcessor = AttackableProcessor() offensiveAttackProcessor = OffensiveAttackProcessor() offensiveSkillProcessor = OffensiveSkillProcessor() movementProcessor = MovementProcessor(mapManager) inputProcessor = InputProcessor() renderableProcessor = RenderableProcessor( textureEmiter=textureEmiter, particleEmiter=particleEmiter) renderableMinimalProcessor = RenderableMinimalProcessor( viewport=viewport, textureEmiter=textureEmiter) sceneProcessor = SceneProcessor( viewport=viewport, sceneManager=sceneManager, ) particleEmiterProcessor = ParticleEmiterProcessor( particleEmiter=particleEmiter) damageProcessor = DamageProcessor() environmentProcessor = EnvironmentProcessor(viewport=viewport, mapManager=mapManager) passiveAttackProcessor = PassiveAttackProcessor() defenseProcessor = DefenseProcessor() onhitProcessor = OnhitProcessor() emitMirageParticleEffect = ParticleMirageEmiterProcessor( particleEmiter=particleEmiter) self.sceneProcessor: SceneProcessor = sceneProcessor # show F1 stats self.viewport: Viewport = viewport # for keyboardinput in nkeyrollover.py self.mapManager: MapManager = mapManager # map is handled here in game self.sceneManager: SceneManager = sceneManager # to check for showmap here in game self.bg = self.createBg(Config.columns, Config.rows) # Lots of comments to check if the order of the processors really work, # as Messaging looses all messages on every iteration (use DirectMessaging # instead) self.world.add_processor(gametimeProcessor) # KeyboardInput:getInput() # p generate: Message PlayerKeypress # p handle: Message PlayerKeyPress (movement) # p generate: DirectMessage movePlayer self.world.add_processor(inputProcessor) # p handle: DirectMessage movePlayer # e handle: DirectMessage moveEnemy # p generate: Message PlayerLocation # p generate: Message EmitMirageParticleEffect (appear) # x generate: Message EntityMoved self.world.add_processor(movementProcessor) # p handle: Message PlayerLocation # e generate: DirectMessage moveEnemy # x generate: Message EmitTextureMinimal self.world.add_processor(aiProcessor) # e handle: DirectMessage moveEnemy # p handle: Message PlayerKeyPress (space/attack, weaponselect) # p generate: Message PlayerAttack (via OffensiveAttack) # x generate: Message AttackAt (via OffensiveAttack) # x generate: Message EmitActionTexture (via OffensiveAttack) # x generate: Message EmitTextureMinimal (via OffensiveAttack) self.world.add_processor(offensiveAttackProcessor) # p handle: Message PlayerKeyPress (skill activate) # x generate: Message EmitParticleEffect (skill) # x generate: DirectMessage activateSpeechBubble self.world.add_processor(offensiveSkillProcessor) # x handle: Message EmitParticleEffect # x generate: Message AttackAt (for skills) self.world.add_processor(particleEmiterProcessor) # x generate: Message AttackAt (passive DoT) self.world.add_processor(passiveAttackProcessor) # x generate: Message AttackAt (via particle, dmg on move) self.world.add_processor(particleProcessor) # x handle: Message AttackAt # x generate: Message EmitMirageParticleEffect (impact) self.world.add_processor(onhitProcessor) # x handle: Message AttackAt # x generate: DirectMessage receiveDamage self.world.add_processor(damageProcessor) # x change: Message receiveDamage # x generate: Message EmitMirageParticleEffect (floating 'Blocked') self.world.add_processor(defenseProcessor) # x handle: DirectMessage receiveDamage # x generate: Message EntityStun # x generate: Message EntityEndStun # x generate: Message EntityDying # x generate: Message EmitTexture # x generate: Message Gameover # x generate: Message EmitMirageParticleEffect (floating Damage) self.world.add_processor(attackableProcessor) # x handle: Message EmitMirageParticleEffect self.world.add_processor(emitMirageParticleEffect) # p handle: Message PlayerLocation # x handle: Message EntityDying # p handle: Message PlayerKeypress # x handle: Message Gameover # e generate: Message SpawnEnemy # p generate: Message SpawnPlayer # x generate: DirectMessage activateSpeechBubble # x generate: Message ScreenMove # x generate: Message GameStart self.world.add_processor(sceneProcessor) # x handle: Message ScreenMove # x handle: Message GameStart self.world.add_processor(environmentProcessor) # e handle: Message SpawnEnemy # e generate: Message EntityAttack # x generate: Message EntityDead self.world.add_processor(enemyProcessor) # p handle: Message SpawnPlayer # p handle: Message PlayerAttack self.world.add_processor(playerProcessor) # e handle: Message EntityDying # p handle: Message PlayerAttack # x handle: Message AttackWindup # x handle: Message EntityAttack # x handle: Message EntityMoved # x handle: Message EntityStun # x handle: Message EntityEndStun self.world.add_processor(characterAnimationProcessor) # x handle: Message EmitTextureMinimal # x handle: Message EmitTexture self.world.add_processor(renderableMinimalProcessor) # x handle: DirectMessage activateSpeechBubble (emit) # x generate: DirectMessage activateSpeechBubble (because of damage) self.world.add_processor(renderableProcessor)
def reloadAllTextures(self): fileTextureLoader.loadFromFiles()
def test_actionemiter(self): game.isunittest.setIsUnitTest() fileTextureLoader.loadFromFiles() self.viewport = MockWin(20, 10) self.world = esper.World() self.textureEmiter = TextureEmiter(viewport=self.viewport, world=self.world) renderableCache.init(viewport=self.viewport) particleEmiter = ParticleEmiter(viewport=self.viewport) renderableProcessor = RenderableProcessor( textureEmiter=self.textureEmiter, particleEmiter=particleEmiter) movementProcessor = MovementProcessor(mapManager=None) inputProcessor = InputProcessor() renderableMinimalProcessor = RenderableMinimalProcessor( viewport=self.viewport, textureEmiter=self.textureEmiter) self.world.add_processor(inputProcessor) self.world.add_processor(movementProcessor) self.world.add_processor(renderableMinimalProcessor) self.world.add_processor(renderableProcessor) location = Coordinates(10, 10) self.textureEmiter.makeActionTexture( actionTextureType=ActionType.unittest, location=location, fromPlayer=True, direction=Direction.right, physics=None) messages = messaging.getByType(MessageType.PlayerAttack) for message in messages: print(message.data['hitLocations']) hl = message.data['hitLocations'] self.assertTrue(hl[0].x == 12) self.assertTrue(hl[0].y == 11) self.assertTrue(hl[1].x == 12) self.assertTrue(hl[1].y == 12) self.assertTrue(hl[2].x == 13) self.assertTrue(hl[2].y == 11) self.assertTrue(hl[3].x == 13) self.assertTrue(hl[3].y == 12) # process it targetFrameTime = 1.0 / Config.fps self.world.process(targetFrameTime) self.assertTrue(self.viewport.peek(12, 11) == '>') self.assertTrue(self.viewport.peek(12, 12) == '>') self.assertTrue(self.viewport.peek(13, 11) == '>') self.assertTrue(self.viewport.peek(13, 12) == '>') self.world.process(0.1) # animation len self.assertTrue(self.viewport.peek(12, 11) == '-') self.assertTrue(self.viewport.peek(12, 12) == '-') self.assertTrue(self.viewport.peek(13, 11) == '-') self.assertTrue(self.viewport.peek(13, 12) == '-')
def test_renderableCollisionDetection(self): game.isunittest.setIsUnitTest() fileTextureLoader.loadFromFiles() self.viewport = MockWin(20, 10) self.world = esper.World() self.textureEmiter = None particleEmiter = ParticleEmiter(viewport=self.viewport) renderableProcessor = RenderableProcessor( textureEmiter=self.textureEmiter, particleEmiter=particleEmiter) movementProcessor = MovementProcessor(mapManager=None) inputProcessor = InputProcessor() renderableMinimalProcessor = RenderableMinimalProcessor( viewport=self.viewport, textureEmiter=self.textureEmiter) self.world.add_processor(inputProcessor) self.world.add_processor(movementProcessor) self.world.add_processor(renderableMinimalProcessor) self.world.add_processor(renderableProcessor) # Player playerEntity = self.world.create_entity() texture = CharacterTexture( characterTextureType=CharacterTextureType.player, characterAnimationType=CharacterAnimationType.standing, name='Player') coordinates = Coordinates(10, 10) playerRenderable = Renderable(texture=texture, viewport=self.viewport, parent=None, coordinates=coordinates, direction=Direction.right, name='Player') physics = Physics() self.world.add_component(playerEntity, playerRenderable) self.world.add_component(playerEntity, physics) # /Player # Enemy enemyEntity = self.world.create_entity() texture = CharacterTexture( characterTextureType=CharacterTextureType.player, characterAnimationType=CharacterAnimationType.standing, name='Enemy') coordinates = Coordinates(10, 10) enemyRenderable = Renderable(texture=texture, viewport=self.viewport, parent=None, coordinates=coordinates, direction=Direction.right, name='Enemy') physics = Physics() self.world.add_component(enemyEntity, enemyRenderable) self.world.add_component(playerEntity, physics) # /Enemy # process it targetFrameTime = 1.0 / Config.fps # sprites overlap, but not with chars (foot is in shoulder) # o # /|\ # o/ \ # /|\ # / \ enemyRenderable.coordinates.y -= 2 enemyRenderable.coordinates.x += 2 self.world.process(targetFrameTime) self.viewport.internalPrint() overlap = enemyRenderable.overlapsWith(playerRenderable) self.assertTrue(overlap) # inprecise check, true overlap = playerRenderable.overlapsWithRenderablePixel(enemyRenderable) self.assertFalse(overlap) # precise check, false overlap = enemyRenderable.overlapsWithRenderablePixel(playerRenderable) self.assertFalse(overlap) # precise check, false empty = EntityFinder.isDestinationEmpty(self.world, enemyRenderable) self.assertTrue(empty) empty = EntityFinder.isDestinationEmpty(self.world, playerRenderable) self.assertTrue(empty) distance = enemyRenderable.distanceToBorder(playerRenderable) self.assertTrue(distance['x'] == -1) self.assertTrue(distance['y'] == -1)
def test_renderableBasic(self): game.isunittest.setIsUnitTest() fileTextureLoader.loadFromFiles() self.viewport = MockWin(20, 10) self.world = esper.World() self.textureEmiter = None particleEmiter = ParticleEmiter(viewport=self.viewport) renderableProcessor = RenderableProcessor( textureEmiter=self.textureEmiter, particleEmiter=particleEmiter) movementProcessor = MovementProcessor(mapManager=None) inputProcessor = InputProcessor() renderableMinimalProcessor = RenderableMinimalProcessor( viewport=self.viewport, textureEmiter=self.textureEmiter) self.world.add_processor(inputProcessor) self.world.add_processor(movementProcessor) self.world.add_processor(renderableMinimalProcessor) self.world.add_processor(renderableProcessor) # Player playerEntity = self.world.create_entity() texture = CharacterTexture( characterTextureType=CharacterTextureType.player, characterAnimationType=CharacterAnimationType.standing, name='Player') coordinates = Coordinates(10, 10) renderable = Renderable(texture=texture, viewport=self.viewport, parent=None, coordinates=coordinates, direction=Direction.right, name='Player') self.world.add_component(playerEntity, renderable) # /Player # process it targetFrameTime = 1.0 / Config.fps self.world.process(targetFrameTime) self.viewport.internalPrint() # check if head is at correct position self.assertTrue(self.viewport.peek(11, 10) == 'o') extCoords = renderable.getLocationAndSize() self.assertTrue(extCoords.x == 10) self.assertTrue(extCoords.y == 10) self.assertTrue(extCoords.width == 3) self.assertTrue(extCoords.height == 3) locCenter = renderable.getLocationCenter() self.assertTrue(locCenter.x == 11) self.assertTrue(locCenter.y == 11) self.assertTrue(self.viewport.peek(11, 11) == '|') # body attackLocation = renderable.getAttackBaseLocation() self.assertTrue(attackLocation.x == 13) self.assertTrue(attackLocation.y == 11) attackLocation = renderable.getAttackBaseLocationInverted() self.assertTrue(attackLocation.x == 9) self.assertTrue(attackLocation.y == 11) p = Coordinates(9, 9) self.assertFalse(renderable.isHitBy([p])) p = Coordinates(13, 13) # in sprite, but dest is empty self.assertFalse(renderable.isHitBy([p])) p = Coordinates(10, 10) # in sprite, but on head (not empty) self.assertFalse(renderable.isHitBy([p])) p = Coordinates(11, 10) self.assertTrue(renderable.isHitBy([p])) p = Coordinates(12, 12) self.assertTrue(renderable.isHitBy([p])) renderable.setDirection(Direction.left) attackLocation = renderable.getAttackBaseLocation() self.assertTrue(attackLocation.x == 9) self.assertTrue(attackLocation.y == 11) attackLocation = renderable.getAttackBaseLocationInverted() self.assertTrue(attackLocation.x == 13) self.assertTrue(attackLocation.y == 11)