import pygame from hoop import world, engine from control import Controller import constants, sprites class Player: def __init__(self, name, world): self.name = name self.fragCount = 0 self.avatar = sprites.Soldier(world, self) self.controller = Controller(self.avatar) self.opponent = None def update(self): self.controller.update() class Environment: """ Creates Player objects and spawns soldiers for them in the argument world. Also initializes all terrain in the default PySoldier map. """ def __init__(self, world): print 'Creating Environment' self.world = world self.spawnPoints = [(100,300), (1100,300)] self.nextSpawnPoint = 0 self.localPlayer = Player('John', world) self.remotePlayer = Player('Eric', world) self.localPlayer.opponent = self.remotePlayer self.remotePlayer.opponent = self.localPlayer self.spawn(self.localPlayer.avatar) self.spawn(self.remotePlayer.avatar) terrain1 = [(590,180,1),(610,180,1)] terrain2 = [(100,240,2),(1100,240,2),(450,190,2),(750,190,3),(180,150,2),(960,150,2)] terrain3 = [(450,120,3),(490,120,3),(530,100,3),(530,150,3),(670,150,3), (710,120,3),(770,120,3)] terrain4 = [(340,100,4),(380,100,4),(420,100,4),(860,100,4),(900,100,4),(940,100,4), (340,250,4),(380,250,4),(420,250,4),(860,230,4),(900,230,4),(940,250,4), (600,230,4),(6900,230,4),(510,230,4),(120,180,4),(1080,180,4)] terrain5 = [(30,20,5),(90,30,5),(150,40,5),(210,20,5),(270,20,5), (330,40,5),(390,40,5),(450,30,5),(510,20,5),(570,30,5), (630,30,5),(690,20,5),(750,30,5),(810,40,5),(870,40,5), (930,20,5),(990,20,5),(1050,40,5),(1110,30,5),(1170,20,5)] TotalTerrain = terrain1+terrain2+terrain3+terrain4+terrain5 self.populate(TotalTerrain) """ Takes the totalTerrain list and creates all level objects when launching application. """ def populate(self, points): for p in points: (x,y,dirtType) = p self.world.addToWorld(sprites.Dirt(dirtType), x, y, 0) """ Spawns the 2 soldiers in each end of the world and sets the spawn point to shift between the 2 places for future spawns. """ def spawn(self, soldier): print soldier (x, y) = self.spawnPoints[self.nextSpawnPoint] self.nextSpawnPoint += 1 if self.nextSpawnPoint >= len(self.spawnPoints): self.nextSpawnPoint = 0 soldier.alive = 1 self.world.addToWorld(soldier, x, y, 0) self.world.addToWorld(soldier.gun, x, y, 0) """ When a soldier dies his death is recorded by the angel. This method applies the new score. """ def reportDeath(self, soldier): soldier.player.opponent.fragCount += 1 Env = None