def ZombieCollection(settings, shooter, zombies): # Requirement ID: 2.1.7 """Zombie Collection. This method determines how many zombies to put on the screen. With each level the zombies get smaller and more zombies fit on the screen. """ zomb = Zomb.Zombie(settings) available_space_x = settings.screen_width - zomb.rect.width if zomb.rect.width < 5: zomb.rect.width = 5 number_zombies_x = int(available_space_x / (zomb.rect.width)) #this method determines the space available to fit zombies. available_space_y = (settings.screen_height - (3 * zomb.rect.height) - shooter.rect.height) if zomb.rect.height < 5: zomb.rect.height = 5 number_rows = int(available_space_y / (2 * zomb.rect.height)) for row_number in range(number_rows): for zombie_number in range(number_zombies_x): zomb = Zomb.Zombie(settings) zombie_width = zomb.rect.width zomb.x = zombie_width + zombie_width * zombie_number zomb.rect.x = zomb.x zomb.rect.y = zomb.rect.height + 2 * zomb.rect.height * row_number zomb.CenterZombie() zomb.x = float(zomb.rect.x) zomb.y = float(zomb.rect.y) zombies.add(zomb)
def start_game(self, random_mode=False): self.enable_bt_scanning(False) self.exclude_out_moves() self.stop_tracking_moves() time.sleep(0.2) game_moves = [move.get_serial() for move in self.moves if self.out_moves[move.get_serial()] == Alive.on.value] self.teams = {serial: self.move_opts[serial][Opts.team.value] for serial in self.tracked_moves.keys() if self.out_moves[serial] == Alive.on.value} if random_mode: if len(self.con_games) <= 1: selected_game = self.con_games[0] else: if len(self.rand_game_list) >= len(self.con_games): #empty rand game list, append old game, to not play it twice self.rand_game_list = [self.old_game_mode] selected_game = random.choice(self.con_games) while selected_game in self.rand_game_list: selected_game = random.choice(self.con_games) self.old_game_mode = selected_game self.rand_game_list.append(selected_game) self.game_mode = selected_game if self.instructions: self.play_random_instructions() if self.game_mode == common.Games.Zombies.value: zombie.Zombie(game_moves, self.sensitivity) self.tracked_moves = {} elif self.game_mode == common.Games.Commander.value: commander.Commander(game_moves, self.sensitivity) self.tracked_moves = {} elif self.game_mode == common.Games.Ninja.value: speed_bomb.Bomb(game_moves) self.tracked_moves = {} elif self.game_mode == common.Games.Swapper.value: swapper.Swapper(game_moves, self.sensitivity) self.tracked_moves = {} elif self.game_mode == common.Games.KingoftheHill.value: kingofthehill.KingoftheHill(game_moves, self.sensitivity) self.tracked_moves = {} else: #may need to put in moves that have selected to not be in the game joust.Joust(self.game_mode, game_moves, self.teams, self.sensitivity) self.tracked_moves = {} if random_mode: self.game_mode = common.Games.Random.value if self.instructions: Audio('audio/Menu/tradeoff2.wav').start_effect() time.sleep(8) #turn off admin mode so someone can't accidentally press a button self.admin_move = None self.random_added = []
def load_data(self): self.map = TiledMap("Images/til.tmx") self.transicio = '' self.pf = PathFinder(self.map) self.gchamp = pygame.sprite.Group() self.champ = champs.Champ2(np.true_divide(self.map.camera.size,2),conf.mides_champ) self.gchamp.add(self.champ) self.pressed_keys = [] self.npcs = pygame.sprite.Group() self.z1 = zombie.Zombie(np.multiply(conf.tile_size,2))
def start_game(self, random_mode=False): self.enable_bt_scanning(False) self.exclude_out_moves() self.stop_tracking_moves() time.sleep(0.2) game_moves = [ move.get_serial() for move in self.moves if self.out_moves[move.get_serial()] == Alive.on.value ] self.teams = { serial: self.move_opts[serial][Opts.team.value] for serial in self.tracked_moves.keys() if self.out_moves[serial] == Alive.on.value } old_game_mode = self.game_mode if random_mode: if len(self.rand_game_list) <= 0: self.rand_game_list = list(range(GAME_MODES)) self.rand_game_list.remove(common.Games.JoustTeams.value) self.rand_game_list.remove(common.Games.Random.value) self.rand_game_list.remove(common.Games.Commander.value) self.game_mode = random.choice(self.rand_game_list) self.rand_game_list.remove(self.game_mode) self.play_random_instructions() if self.game_mode == common.Games.Zombies.value: zombie.Zombie(game_moves) self.tracked_moves = {} elif self.game_mode == common.Games.Commander.value: commander.Commander(game_moves) self.tracked_moves = {} else: #may need to put in moves that have selected to not be in the game joust.Joust(self.game_mode, game_moves, self.teams) self.tracked_moves = {} if random_mode: self.game_mode = old_game_mode Audio('audio/Menu/tradeoff2.wav').start_effect() time.sleep(8) self.random_added = []
# import the entire file with a .py extension import zombie # from zombie import Zombie import hero # Make a zombie object from the class zombie_object = zombie.Zombie(6, 8, 19, 'bat', 15) # ugly version of print all # print dir(zombie_object); # print vars(zombie_object); # make a hero object from the hero class heroObject = hero.Hero() # print vars(hero); hero.cheer_hero(heroObject)
def create_zombies(n): for i in range(n): z = zombie.Zombie() z.rect.x = random.randint(0, 500) z.rect.y = random.randint(0, 500) zombies.add(z)
def on_execute(self): if self.on_init() == False: self._running = False while self._running: # # event handling loop # for event in pygame.event.get(): if event.type == pygame.locals.QUIT: pygame.quit() sys.exit() #handling keyboard input #start moving if event.type == pygame.locals.KEYDOWN: if event.key == pygame.locals.K_w: self.pressed_up = True if event.key == pygame.locals.K_d: self.pressed_right = True if event.key == pygame.locals.K_s: self.pressed_down = True if event.key == pygame.locals.K_a: self.pressed_left = True #stop moving elif event.type == pygame.locals.KEYUP: if event.key == pygame.locals.K_w: self.pressed_up = False if event.key == pygame.locals.K_d: self.pressed_right = False if event.key == pygame.locals.K_s: self.pressed_down = False if event.key == pygame.locals.K_a: self.pressed_left = False #handling mouse input #looking around / aiming elif event.type == pygame.MOUSEMOTION: mousePos = event.pos #firing elif event.type == pygame.MOUSEBUTTONDOWN and event.button == 1: self.pressed_lmouse = True mousePos = event.pos shot = Shot.Shot(mousePos, self.player.getPosition()) self.shotList.append(shot) self.lineColor = (0, 0, 255) elif event.type == pygame.MOUSEBUTTONUP and event.button == 1: self.pressed_lmouse = False mousePos = event.pos self.lineColor = (255, 0, 0) #spawning zombies if event.type == self.ZOMBIESPAWN: newZombie = zombie.Zombie() self.zombieList.append(newZombie) newZombie.spawn(self.player.getPosition(), self.displaysurf) print("Zombie spawned") # # moving the player # if self.pressed_up: if self.player.getPosition().top > 0: self.player.move(0, -self.player.pace) if self.pressed_right: if self.player.getPosition( ).right < self.WINDOWWIDTH - self.player.pace: self.player.move(self.player.pace, 0) if self.pressed_down: if self.player.getPosition( ).bottom < self.WINDOWHEIGHT - self.player.pace: self.player.move(0, self.player.pace) if self.pressed_left: if self.player.getPosition().left > 0: self.player.move(-self.player.pace, 0) # # render # self.displaysurf.fill((255, 255, 255)) pygame.draw.line(self.displaysurf, self.lineColor, (self.player.getPosition().left + self.player.appearance.get_width() / 2, self.player.getPosition().top + self.player.appearance.get_height() / 2), mousePos) # # checking shot collision # for shot in self.shotList: #checking if the shot is out of the screen if shot.isOutOfScreen(self.WINDOWWIDTH, self.WINDOWHEIGHT): self.shotList.remove(shot) print("deleting shot") else: shot.move(self.displaysurf) # good style? (regarding the different data types in a single return statement) #checking if the shot is hitting a zombie collisionArray = shot.collisionCheck(self.zombieList) if collisionArray[0] == True: self.shotList.remove(shot) self.zombieList = collisionArray[1] print("deleting shot") # # zombie spawner # for zomb in self.zombieList: zomb.move(self.displaysurf) self.player.draw(self.displaysurf) self.fpsClock.tick(self.FPS) pygame.display.update()
from math import pi from time import sleep gen, positionC, sizeC, rangeC, positionZ, sizeZ, distance, nzomb = int(sys.argv[1]), [int(i) for i in sys.argv[2].split(',')],\ [int(i) for i in sys.argv[3].split(',')], int(sys.argv[4]), [int(i) for i in sys.argv[5].split(',')],\ [int(i) for i in sys.argv[6].split(',')], int(sys.argv[7]), int(sys.argv[8]) pop = evaluation.Population(nzomb, (positionC, sizeC, rangeC, 1000), (nzomb, sizeZ, positionZ, 2, distance)) pop.evaluate(gen) pygame.init() screen = pygame.display.set_mode((100, 100)) chromo = pop.population[-1] zs = [ zombie.Zombie(sizeZ, [positionZ[0], positionZ[1] + i * distance], 1) for i in range(nzomb) ] done = False count = 0 k = 0 while not done: #print(chromo.xposition) for event in pygame.event.get(): if event.type == pygame.QUIT: done = True if count % 10 == 0: if k < 100: chromo.move(chromo.angles[k])
def start_game(self, random_mode=False): self.enable_bt_scanning(False) self.exclude_out_moves() self.stop_tracking_moves() time.sleep(0.2) self.teams = { serial: self.move_opts[serial][Opts.team.value] for serial in self.tracked_moves.keys() if self.out_moves[serial] == Alive.on.value } game_moves = [ move.get_serial() for move in self.moves if self.out_moves[move.get_serial()] == Alive.on.value ] if len(game_moves ) < self.game_mode.minimum_players and self.ns.settings[ 'enforce_minimum']: Audio('audio/Menu/notenoughplayers.wav').start_effect() self.tracked_moves = {} return self.update_status('starting') if random_mode: good_random_modes = [ game for game in common.Games if game.name in self.ns.settings['random_modes'] ] good_random_modes = [ common.Games[game] for game in self.ns.settings['random_modes'] ] if self.ns.settings['enforce_minimum']: good_random_modes = [ game for game in good_random_modes if game.minimum_players <= len(game_moves) ] if len(good_random_modes) == 0: selected_game = common.Games.JoustFFA #force Joust FFA elif len(good_random_modes) == 1: selected_game = good_random_modes[0] else: if len(self.rand_game_list) >= len(good_random_modes): #empty rand game list, append old game, to not play it twice self.rand_game_list = [self.old_game_mode] selected_game = random.choice(good_random_modes) while selected_game in self.rand_game_list: selected_game = random.choice(good_random_modes) self.old_game_mode = selected_game self.rand_game_list.append(selected_game) self.game_mode = selected_game if self.ns.settings['play_instructions'] and self.ns.settings[ 'play_audio']: self.play_random_instructions() if self.game_mode == common.Games.Zombies: zombie.Zombie(game_moves, self.command_queue, self.ns, self.zombie_music) self.tracked_moves = {} elif self.game_mode == common.Games.Commander: commander.Commander(game_moves, self.command_queue, self.ns, self.commander_music) self.tracked_moves = {} elif self.game_mode == common.Games.Ninja: speed_bomb.Bomb(game_moves, self.command_queue, self.ns, self.commander_music) self.tracked_moves = {} elif self.game_mode == common.Games.Swapper: swapper.Swapper(game_moves, self.command_queue, self.ns, self.joust_music) self.tracked_moves = {} elif self.game_mode == common.Games.Tournament: tournament.Tournament(game_moves, self.command_queue, self.ns, self.joust_music) self.tracked_moves = {} else: if self.game_mode == common.Games.JoustFFA and self.experimental: print("Playing EXPERIMENTAL FFA Mode.") moves = [ common.get_move(serial, num) for num, serial in enumerate(game_moves) ] game = ffa.FreeForAll(moves, self.joust_music) game.run_loop() else: #may need to put in moves that have selected to not be in the game joust.Joust(game_moves, self.command_queue, self.ns, self.joust_music, self.teams, self.game_mode) self.tracked_moves = {} if random_mode: self.game_mode = common.Games.Random if self.ns.settings['play_instructions']: if self.ns.settings['play_audio']: Audio('audio/Menu/tradeoff2.wav').start_effect_and_wait() #reset music self.choose_new_music() #turn off admin mode so someone can't accidentally press a button self.admin_move = None self.random_added = []
def gameloop(): son = pygame.mixer.Sound("./assets/song/runnerz.wav") son.play() orientation = 'horizontal' bg = parallax.ParallaxSurface( (1280, 720), pygame.RLEACCEL ) #importations des différentes images du parallax ('...png') # + affectation d'une valeur pour la vitesse (', ...') bg.add('./assets/images/parallax/1.6.png', 6) bg.add('./assets/images/parallax/1.5.png', 5) bg.add('./assets/images/parallax/1.4.png', 4) bg.add('./assets/images/parallax/1.3.png', 3) bg.add('./assets/images/parallax/1.2.png', 2) bg.add('./assets/images/parallax/1.1.png', 1) run = True speed = 0 t_ref = 0 global wave_zombie global wave while run: #définition des différentes interractions (parallax) for event in pygame.event.get(): if event.type == QUIT: run = False paused = False pygame.quit() quit() if event.type == KEYDOWN and event.key == K_RIGHT: speed += 10 if event.type == KEYUP and event.key == K_RIGHT: speed -= 10 if event.type == KEYDOWN and event.key == K_LEFT: speed -= 10 if event.type == KEYUP and event.key == K_LEFT: speed += 10 if event.type == KEYDOWN and event.key == K_DOWN: orientation = 'horizontal' if event.type == KEYDOWN and event.key == K_SPACE: balles.append( balle.Balle(((player.rect.x), (player.rect.y + 50)), 'right')) shoot = pygame.mixer.Sound("./assets/song/shoot.wav") shoot.play() if event.type == pygame.USEREVENT: for i in range(wave_zombie): zombies.append(zombie.Zombie((1000 + i * 100, 570))) pygame.time.set_timer(pygame.USEREVENT, 0) if event.type == KEYDOWN and event.key == K_p: pygame.mixer.pause() paused = True pause() bg.scroll(speed, orientation) #mouvement du parallax t = pygame.time.get_ticks() if (t - t_ref) > 60: bg.draw(screen) systeme_vie() for z in zombies: if z.life > 0: z.handle_event(event) screen.blit(z.image, z.rect) waves_system(player, z) for b in balles: if b.life > 0: b.handle_event(event) screen.blit(b.image, b.rect) checkCollision(b, z) spawn(z) player.handle_event(event) #evenement du personnage screen.blit(player.image, player.rect) #affiche le personnage sur la fenetre pygame nbzombie_wave = sum(z.life for z in zombies) message_display('Vague : ' + str(wave) + ' Nombre de Zombies : ' + str(nbzombie_wave)) pygame.display.flip() clock.tick(10) if player.life == 0: gameover() pygame.quit()
pygame.init() screen = pygame.display.set_mode( (1280, 720), pygame.DOUBLEBUF) #création de la fenetre pygame pygame.display.set_caption('Runner Z') #titre de la fenetre pygame pygame.mouse.set_visible( 0) #afficher/cacher le curseur de souris (0:non visible / 1: visible) clock = pygame.time.Clock() player = nikita.Nikita( (150, 570)) #position sur la fenetre pygame du personnage zombies = [] balles = [] wave_zombie = 5 wave = 1 nbzombie_wave = 5 for i in range(wave_zombie): zombies.append(zombie.Zombie((1000 + i * 100, 570))) gameIcon = pygame.image.load('./assets/images/fond/logo1.png' ) #création de l'icone de la fenetre pygame pygame.display.set_icon(gameIcon) #affiche l'icone sur la fenetre pygame #--------------------------------------------------------------------- Menu pause ------------------------------------------------------------------------------ def main_background(): """ Fonction menu - affiche l'arrière plan (couleur) quand il est actif """ screen.fill(COLOR_BACKGROUND) def pause():
def AddEnemy(self, x, y, health=3, score=100, damage=1, reach=5): newenemy = zombie.Zombie(x, y, health, score, damage, reach) self.enemies.append(newenemy) return newenemy
def __init__(self, parent): Frame.__init__(self, parent, background="black") self.parent = parent self.parent.title("z") self.pack(fill=BOTH, expand=1) self.p = player.Player(self) w = 900 h = 550 sw = self.parent.winfo_screenwidth() sh = self.parent.winfo_screenheight() x = (sw - w) / 2 y = (sh - h) / 2 self.parent.geometry('%dx%d+%d+%d' % (w, h, x, y)) # create canvas canvas = Canvas(self, bg='black') canvas.pack(fill=BOTH, expand=1) self.canvas = canvas # create cells [for displaying coords] self.canvas_coords = canvas.create_text(725, 20, text="coords:", fill="white") self.cells = [] for x in range(0, 121): row = (math.floor(x / 11)) # row col = (x * 50) - (row * 550) colcoord = x - (row * 11) rel = [colcoord - 5, row - 5] c = Cell(col, row * 50, rel, self) self.cells.append(c) # create map [holds coords] self.map = [] map_max_range = 25 for x in range(0, map_max_range): for y in range(0, map_max_range): new_coord = coord.Coord(x, y, self) self.map.append(new_coord) # inputs self.parent.bind("<Key>", self.kpress) # create zombies self.zombies = [] for x in range(0, 10): z = zombie.Zombie(self, randint(1, 21), randint(1, 21)) self.zombies.append(z) # version self.version = canvas.create_text(725, 525, text="demo 2", fill="white") # things to appear in the side menu self.update_coords() self.xp_holder = canvas.create_rectangle(600, 50, 850, 75, outline="white", fill="black") self.xp_bar = canvas.create_rectangle(602, 52, 603, 73, fill="green") self.xp_label = canvas.create_text(725, 62.5, text="", fill="white") self.xp_level_label = canvas.create_text(725, 85, text=str(self.p.level), fill="white") self.update_xp()
def start_game(self, random_mode=False): self.enable_bt_scanning(False) self.exclude_out_moves() self.stop_tracking_moves() time.sleep(0.2) self.teams = { serial: self.move_opts[serial][Opts.team.value] for serial in self.tracked_moves.keys() if self.out_moves[serial] == Alive.on.value } game_moves = [ move.get_serial() for move in self.moves if self.out_moves[move.get_serial()] == Alive.on.value ] if len(game_moves) < common.minimum_players[ self.game_mode] and self.enforce_minimum: Audio('audio/Menu/notenoughplayers.wav').start_effect() self.tracked_moves = {} return self.update_status('starting') if random_mode: if self.enforce_minimum: good_con_games = [ i for i in self.con_games if common.minimum_players[i] <= len(game_moves) ] else: good_con_games = self.con_games if len(good_con_games) == 0: selected_game = 0 #force Joust FFA elif len(good_con_games) == 1: selected_game = good_con_games[0] else: if len(self.rand_game_list) >= len(good_con_games): #empty rand game list, append old game, to not play it twice self.rand_game_list = [self.old_game_mode] selected_game = random.choice(good_con_games) while selected_game in self.rand_game_list: selected_game = random.choice(good_con_games) self.old_game_mode = selected_game self.rand_game_list.append(selected_game) self.game_mode = selected_game if self.instructions and self.audio_toggle: self.play_random_instructions() if self.game_mode == common.Games.Zombies.value: zombie.Zombie(game_moves, self.sensitivity, self.command_queue, self.status_ns, self.audio_toggle, self.zombie_music) self.tracked_moves = {} elif self.game_mode == common.Games.Commander.value: commander.Commander(game_moves, self.sensitivity, self.command_queue, self.status_ns, self.commander_music) self.tracked_moves = {} elif self.game_mode == common.Games.Ninja.value: speed_bomb.Bomb(game_moves, self.command_queue, self.status_ns, self.audio_toggle, self.commander_music) self.tracked_moves = {} elif self.game_mode == common.Games.Swapper.value: swapper.Swapper(game_moves, self.sensitivity, self.command_queue, self.status_ns, self.audio_toggle, self.joust_music) self.tracked_moves = {} elif self.game_mode == common.Games.Tournament.value: tournament.Tournament(game_moves, self.sensitivity, self.command_queue, self.status_ns, self.audio_toggle, self.joust_music) self.tracked_moves = {} else: #may need to put in moves that have selected to not be in the game joust.Joust(self.game_mode, game_moves, self.teams, self.sensitivity, self.command_queue, self.status_ns, self.audio_toggle, self.joust_music) self.tracked_moves = {} if random_mode: self.game_mode = common.Games.Random.value if self.instructions: if self.audio_toggle: Audio('audio/Menu/tradeoff2.wav').start_effect() time.sleep(8) #reset music self.choose_new_music() #turn off admin mode so someone can't accidentally press a button self.admin_move = None self.random_added = []