def __init__(self, screen_dims): Dude.__init__(self, screen_dims) self.default_image, self.rect = load_image("res/player_base.png", -1) self.left_shoot_image, _ = load_image("res/player_shoot_left.png", -1) self.right_shoot_image, _ = load_image("res/player_shoot_right.png", -1) self.image = self.default_image self.jump_power = -10
class DudeCLI: def __init__(self): self.dude = Dude() def invoke(self): # print('\nCreating a project') # prj = self.dude.createProject(name='dpliakos', path = '/home/dpliakos/Desktop/prj') # self.dude.readProjects() # self.dude.workon('/home/dpliakos/Desktop/prj') # active = self.dude.activeProject # active.init() # active.open() # active.close() prj = self.dude.createProject( name='Meridian Trust', path='/home/dpliakos/Documents/pointBlank/meridian trust/site') self.dude.readProjects() self.dude.workon( '/home/dpliakos/Documents/pointBlank/meridian trust/site') active = self.dude.activeProject active.init() active.open() active.close() def parseArgs(self): pass
class DudeManager(): def __init__(self): self.dude = Dude() self.dudeIsInstalled = self.dude.checkInstallation() def installDude(self): self.dude.install() def removeDude(self): self.dude.clean() def updateDude(self): print('no update functionality yet!') pass
def __init__(self, screen_dims, hp, health_bar, pos): Dude.__init__(self, screen_dims) self.default_image, self.rect = load_image("res/grunt_base.png", -1) self.left_shoot_image, _ = load_image("res/grunt_shoot_left.png", -1) self.right_shoot_image, _ = load_image("res/grunt_shoot_right.png", -1) self.rect.x = pos[0] self.rect.y = pos[1] self.image = self.default_image self.health_bar = health_bar self.health_bar.rect.x = self.rect.x self.health_bar.rect.bottom = self.rect.y self.hp = hp self.ai = EnemyAI(self.rect) self.shot_interval = 80 + random.randint(0, 20) self.jump_power = -5 - random.randint(0, 5)
def __init__(self): """Start the game and create resources""" pygame.init() # Screen settings self.settings = Settings() self.screen = pygame.display.set_mode( (self.settings.screen_width, self.settings.screen_height)) pygame.display.set_caption("White Surpremist") # Dude settings self.dude = Dude(self) # Projectile settings self.projectiles = pygame.sprite.Group() self.projectile_direction = 'up'
def update(self, player_rect): Dude.update(self) self.health_bar.rect.x = self.rect.x self.health_bar.rect.bottom = self.rect.y self.ai.update(player_rect, self.rect, not self.grounded) direction = self.ai.shoot_dir() if direction == "left": self.shoot(K_RIGHT) elif direction == "right": self.shoot(K_LEFT) movedir, jmp = self.ai.move_dir() if movedir == "left": self.move(K_a) elif movedir == "right": self.move(K_d) if jmp: self.jump()
def loadDude(self): self.dude = Dude(self) self.dude.start()
class Game(): def __init__(self, _parent=None): self.parent = _parent # Containers self.game_objects = {} self.game_doors = {} self.game_objects_np = render.attachNewNode("Game_Objects") self.game_doors_np = render.attachNewNode("Player_Doors") self.game_doors_np.setPos(0, 0, 0) self.game_counter_node = None self.game_collector_nodes = [] self.redDudesCount = 0 self.blueDudesCount = 0 # Physics world self.physics_world = None self.builder = Builder(self) # level lights self.directLight = None # Dude class self.dude = None self.spawnPoints = self.builder.spawnPoints # HUD self.hud = Hud() # Lightshow self.elapsed = 0.0 def start(self, levelID, winCondition=25): self.winCondition = winCondition self.loadLevel("assets/level{}".format(levelID)) self.loadLights() # player self.loadPlayer("default") self.loadDude() # Timer taskMgr.add(self.update, "Game_Update_Task", 0) self.hud.show() # start the Lightshow taskMgr.add(self.discoLightTask, "the lightshow") def stop(self): self.player.stop() self.dude.stop() self.builder.cleanup() self.physics_world = None render.clearLight() self.directLight = None self.hud.hide() taskMgr.remove("the lightshow") def update(self, task): if self.game_counter_node is None: return ghost = self.game_counter_node.node() for node in ghost.getOverlappingNodes(): if "red" in node.name: self.redDudesCount += 1 self.physics_world.removeRigidBody(self.dude.dudes[node.name].node()) self.dude.dudes[node.name].removeNode() self.hud.update(self.redDudesCount, self.blueDudesCount) del self.dude.dudes[node.name] break elif "blue" in node.name: self.blueDudesCount += 1 self.physics_world.removeRigidBody(self.dude.dudes[node.name].node()) self.dude.dudes[node.name].removeNode() self.hud.update(self.redDudesCount, self.blueDudesCount) del self.dude.dudes[node.name] break if self.redDudesCount > self.blueDudesCount: base.messenger.send("lostGame") return Task.done elif self.blueDudesCount >= self.winCondition: base.messenger.send("wonGame") return Task.done for collectorGhostNP in self.game_collector_nodes: collectorGhost = collectorGhostNP.node() for node in collectorGhost.getOverlappingNodes(): if "red" in node.name: self.physics_world.removeRigidBody(self.dude.dudes[node.name].node()) self.dude.dudes[node.name].removeNode() self.hud.update(self.redDudesCount, self.blueDudesCount) del self.dude.dudes[node.name] return Task.cont def setPhysicsWorld(self, _physicsworld): self.physics_world = _physicsworld #### LOADERS #### def loadLevel(self, _filename): self.builder.parseEggFile(_filename) def loadLights(self): # Set a simple light dlight = DirectionalLight('DirectLight') dlnp = render.attachNewNode(dlight) dlnp.setHpr(-30, 0, 0) render.setLight(dlnp) self.directLight = dlnp self.discoLights = [] p1 = PointLight("PointLight1") p1.setColor(VBase4(1, 0, 0, 1)) p1.setAttenuation((0.08, 0, 0.05)) p1np = render.attachNewNode(p1) p1np.setPos(0, -5, 0) render.setLight(p1np) self.discoLights.append(p1) p2 = PointLight("PointLight2") p2.setColor(VBase4(0, 1, 0, 1)) p2.setAttenuation((0.08, 0, 0.05)) p2np = render.attachNewNode(p2) p2np.setPos(5, -5, 0) render.setLight(p2np) self.discoLights.append(p2) p3 = PointLight("PointLight3") p3.setColor(VBase4(0, 0, 1, 1)) p3.setAttenuation((0.08, 0, 0.05)) p3np = render.attachNewNode(p3) p3np.setPos(-5, -5, 0) render.setLight(p3np) self.discoLights.append(p3) p4 = PointLight("PointLight4") p4.setColor(VBase4(0, 0, 1, 1)) p4.setAttenuation((0.08, 0, 0.05)) p4np = render.attachNewNode(p4) p4np.setPos(-5, -5, 5) render.setLight(p4np) self.discoLights.append(p4) p5 = PointLight("PointLight1") p5.setColor(VBase4(0, 0, 1, 1)) p5.setAttenuation((0.08, 0, 0.05)) p5np = render.attachNewNode(p5) p5np.setPos(0, -5, 5) render.setLight(p5np) self.discoLights.append(p5) p6 = PointLight("PointLight1") p6.setColor(VBase4(0, 0, 1, 1)) p6.setAttenuation((0.08, 0, 0.05)) p6np = render.attachNewNode(p6) p6np.setPos(5, -5, 5) render.setLight(p6np) self.discoLights.append(p6) def discoLightTask(self, task): self.elapsed += globalClock.getDt() if self.elapsed > 0.75: for light in self.discoLights: newcolor = choice( [VBase4(0, 0, 1, 1), VBase4(0, 1, 0, 1), VBase4(1, 0, 0, 1), VBase4(0, 1, 1, 1), VBase4(1, 0, 1, 1), VBase4(1, 1, 0, 1),] ) light.setColor(newcolor) self.elapsed = 0.0 return task.cont def loadPlayer(self, _name): self.player = Player(self) self.player.start() def loadDude(self): self.dude = Dude(self) self.dude.start()
def __init__(self): self.dude = Dude() self.dudeIsInstalled = self.dude.checkInstallation()
from dude import Dude from attack import * if __name__ == '__main__': # give each their own attack dude1 = Dude(Fireball()) dude2 = Dude(Punch()) while True: print('dude1(health {}) attack'.format(dude1.health) ) # just making it easier to track who has what health dude1.attack(dude2) if dude2.health < 0: print('Dude1 wins') exit(0) input( '\n##################\npress any button to proceed to next round...' ) # simple way to slow down simulation so it easier to follow print('##################\ndude2(health {}) attack'.format( dude2.health)) dude2.attack(dude1) if dude1.health < 0: print('Dude2 wins') exit(0) input( '\n##################\npress any button to proceed to next round...' ) print('##################')
def __init__(self): self.dude = Dude()
class WSUP: """Overall class management""" def __init__(self): """Start the game and create resources""" pygame.init() # Screen settings self.settings = Settings() self.screen = pygame.display.set_mode( (self.settings.screen_width, self.settings.screen_height)) pygame.display.set_caption("White Surpremist") # Dude settings self.dude = Dude(self) # Projectile settings self.projectiles = pygame.sprite.Group() self.projectile_direction = 'up' def play_game(self): while True: self._check_events() self.dude.update() self._update_projectiles() self._update_screen() def _check_events(self): """Check for keypresses/mouse events""" for event in pygame.event.get(): if event.type == pygame.QUIT: sys.exit() elif event.type == pygame.KEYDOWN: self._check_keydown_events(event) elif event.type == pygame.KEYUP: self._check_keyup_events(event) def _check_keydown_events(self, event): """Method for key presses""" if event.key == pygame.K_RIGHT: self.dude.moving_right = True self.projectile_direction = 'right' elif event.key == pygame.K_LEFT: self.dude.moving_left = True self.projectile_direction = 'left' elif event.key == pygame.K_UP: self.dude.moving_up = True self.projectile_direction = 'up' elif event.key == pygame.K_DOWN: self.dude.moving_down = True self.projectile_direction = 'down' elif event.key == pygame.K_SPACE: self._fire_projectile() elif event.key == pygame.K_q: sys.exit() def _check_keyup_events(self, event): """Method for key releases""" if event.key == pygame.K_RIGHT: self.dude.moving_right = False elif event.key == pygame.K_LEFT: self.dude.moving_left = False elif event.key == pygame.K_UP: self.dude.moving_up = False elif event.key == pygame.K_DOWN: self.dude.moving_down = False def _fire_projectile(self): """Method to create projectiles in the projectiles group""" if len(self.projectiles) < self.settings.max_projectiles: new_projectile = Projectile(self) if self.projectile_direction == 'up': new_projectile.shooting_up = True elif self.projectile_direction == 'down': new_projectile.shooting_down = True elif self.projectile_direction == 'left': new_projectile.shooting_left = True elif self.projectile_direction == 'right': new_projectile.shooting_right = True self.projectiles.add(new_projectile) def _update_projectiles(self): """Update postion of projectiles and remove old ones""" self.projectiles.update(self) # Remove bullets that are off screen for projectile in self.projectiles.copy(): if projectile.rect.bottom <= 0: self.projectiles.remove(projectile) if projectile.rect.left <= 0: self.projectiles.remove(projectile) if projectile.rect.right >= self.settings.screen_width: self.projectiles.remove(projectile) if projectile.rect.top >= self.settings.screen_height: self.projectiles.remove(projectile) # print(len(self.projectiles)) def _update_screen(self): """Updates background colour, sprite, and screen""" self.screen.fill(self.settings.bg_colour) self.dude.blitme() for projectile in self.projectiles.sprites(): projectile.draw_projectile() pygame.display.flip()