def __init__(self, player): """ Create level 1. """ # Call the parent constructor Level.__init__(self, player, self._BACKGROUND_IMAGE) self.player = player self.show_text(self._INTRO_TEXT) self.level_limit = -1000 # Array with width, height, x, and y of platform level = [[210, 70, 500, 500], [210, 70, 800, 400], [210, 70, 1000, 500], [210, 70, 1120, 280], ] # Go through the array above and add platforms for platform in level: block = Platform() block.rect.x = platform[2] block.rect.y = platform[3] block.player = self.player self.platform_list.add(block) self.enemy_list = pygame.sprite.Group() self.make_n_random_enemies(2)
def __init__(self, width, height): Level.__init__(self, width, height) ##initialize blocks## boxtop = Terrain(20, -19, 40, 2, 0, 0,100, self, 0.5) boxleft= Terrain(-1,-5,2,30,0,0,100,self,0.5) boxbottom= Terrain(20,9,40,2,0,0,100,self,0.5) boxright= Terrain(41,-5,2,30,0,0,100,self,0.5) barrbottom = Terrain(15,-6,6,1,0,0,100,self,.5) barrright = Terrain(18.5,-11,1,10,0,0,100,self,.5) goal= Goal(38,-15.5,1,5,0,0,100,self,0.5) tramp1= Trampoline(7,7,6,1,0,0,100,self,.5) tramp2= Trampoline(36,7,6,1,0,0,100,self,.5) tramp3= Trampoline(32,-8,6,1,0,0,100,self,.5) tramp4= Trampoline(36,-23,6,1,0,0,100,self,.5) p = Player(2, 5, 1, 2, 0, 0, 1, self, 0.5) g = GoalBlock(16.5, -7, 2, 2, 0, 0, 2, self, 0.5) self.add_elem(p) self.add_elem(barrbottom) self.add_elem(barrright) self.add_elem(tramp1) self.add_elem(tramp2) self.add_elem(tramp3) self.add_elem(tramp4) self.add_elem(g) self.add_elem(boxtop) self.add_elem(boxright) self.add_elem(boxbottom) self.add_elem(boxleft) self.add_elem(goal)
def __init__(self, player): """ Create level 1. """ # Call the parent constructor Level.__init__(self, player) self.level_limit = -1500 # Array with width, height, x, and y of platform level = [ [210, 70, 500, 500], [210, 70, 800, 400], [210, 70, 1000, 500], [210, 70, 1120, 280], ] # Go through the array above and add platforms for platform in level: block = Platform(platform[0], platform[1]) block.rect.x = platform[2] block.rect.y = platform[3] block.player = self.player self.platform_list.add(block) # Add a custom moving platform block = MovingPlatform(70, 40) block.rect.x = 1350 block.rect.y = 280 block.boundary_left = 1350 block.boundary_right = 1600 block.change_x = 1 block.player = self.player block.level = self self.platform_list.add(block)
def processEvent(self, event): if event.type == pygame.USEREVENT and event.code == PAGEDEAD: m = MessageScene(self.director, self, 'Congratulations', "You have completed the game!\nNow you're entitled \nto the 3D version.", "Press to quit") m.messageBox.button.onMouseDown = lambda: pygame.event.post(pygame.event.Event(pygame.QUIT)) self.director.setScene(m) Level.processEvent(self, event)
def __init__(self): pygame.init() pygame.mixer.init() self.screen = pygame.display.set_mode((896, 896)) self.screen_rect = self.screen.get_rect() self.font = pygame.font.Font(None, 50) self.font2 = pygame.font.Font(None, 25) self.won = False self.lost = False pygame.display.set_caption("Bobby The Destroyer") self.clock = pygame.time.Clock() this_folder = os.path.dirname(os.path.abspath(__file__)) my_file = os.path.join(this_folder, 'maze_old.txt') self.level = Level(self.screen, my_file) self.player = Player(self.screen, 1, 1, self.level) self.guard = Guard(self.screen, 12, 1, self.player, self.level) self.bombs = [] self.numfin = 0 self.bombs.append(Bomb(self.screen, 3, 5, self.player, self.guard)) self.bombs.append(Bomb(self.screen, 3, 8, self.player, self.guard)) self.bombs.append(Bomb(self.screen, 10, 7, self.player, self.guard)) self.bombs.append(Bomb(self.screen, 10, 6, self.player, self.guard)) self.bombs.append(Bomb(self.screen, 12, 2, self.player, self.guard)) self.bombs.append(Bomb(self.screen, 12, 10, self.player, self.guard)) self.bombs.append(Bomb(self.screen, 7, 3, self.player, self.guard)) self.bombs.append(Bomb(self.screen, 7, 10, self.player, self.guard)) self.game_active = True self.bg = PhotoRect(self.screen, "background", 896, 896)
def __init__(self, player): Level.__init__(self, player) self.init_enemies() self.init_items() self.PLAYER_START = [72, 57] self.is_beatable = False self.init_labels()
def run(self): while True: self.event() self.show() self.level.traffic(self.player) if self.level.failed(self.player): pygame.mixer.Sound.play(self.l_sound) if not self.health.loose_health(): self.reset_game() else: time.sleep(1) self.player.reset() self.level = Level(self.screen, self.player, self.path_height) self.clean_events() self.player.image = self.player.u_image pygame.mixer.Sound.stop(self.l_sound) if self.player.player_won(): self.score.add_score() self.creat_text("Level completed!", (0, 255, 0)) pygame.mixer.Sound.play(self.w_sound) time.sleep(1) self.player.reset() self.level = Level(self.screen, self.player, self.path_height) self.player.image = self.player.u_image
def __init__(self, director, player): Level.__init__(self, director, player) self.player.rect.x = 766 self.player.rect.y = 82 self.enemyGroup.add([ Nazist(640, 140, self.player, director), # Nazist(640, 176, self.player, director), # Nazist(688, 18, self.player, director), Nazist(524, 51, self.player, director), # Nazist(524, 140, self.player, director), Nazist(345, 46, self.player, director), Nazist(345, 70, self.player, director), # Nazist(345, 100, self.player, director), Nazist(140, 145, self.player, director), Nazist(140, 175, self.player, director), Nazist(185, 10, self.player, director), Mr_H(27, 48, self.player, director) ]) self.bg = load_image("mapa_h.png", Constants.MAP_DIR) self.collisionBg = load_image("mapa_h_bg.png", Constants.BG_MAP_DIR) load_music("level_three.xm") pygame.mixer.music.set_volume(0.25) pygame.mixer.music.play(-1) player.setWeapons([WpnGrenade(), WpnRifle()])
def __init__(self): self.pencil = Pencil() self.level = Level(1) self.affichage = Affichage() self.player = self.get_user() self.nb_python = 0 self.db = Database()
class Grid: def __init__(self, levelmap, screen, grid_dim, view_coord): self.screen_pos = view_coord self.screen = screen # pygame display # tuple, grid dimensions (horizontal tiles, vertical tiles) self.size = grid_dim # View coordinates (offset from (0,0), in pixels) self.view_coord = view_coord self.tilesize = int(screen.get_rect().width / grid_dim[0]), \ int(screen.get_rect().height / grid_dim[1]) self.level = Level(levelmap) self.background = self.level.render(self.screen, self.size) self.entities = dict() def setLevel(self, levelmap): self.level = Level(levelmap) self.background = self.level.render(self.screen, self.size) def get_mod(self): return self.view_coord[0] % self.tilesize[0], \ self.view_coord[1] % self.tilesize[1] def add_entity(self, entity): for i in range(len(self.entities) + 1): if i not in self.entities: self.entities[i] = entity return i def remove_entity(self, entity): for i in self.entities: if entity is self.entities[i]: del self.entities[i] return i
def load(self): # get list of segment files seg_file_pattern = os.path.join('assets','data','segdata','*[0-9].gif') seg_files = glob.glob(seg_file_pattern) # load segments into pygame surfaces # creates Segments # groups segments into levels lvl_groups = {} for seg_file in seg_files: seg_id = string.split(os.path.basename(seg_file),'.')[1] filename = os.path.basename(seg_file) lvl_id = filename[:string.find(filename,'.')] segment = Segment(lvl_id + '.' + seg_id) if (lvl_id not in lvl_groups): lvl_groups[lvl_id] = [segment] else: lvl_groups[lvl_id].append(segment) # create Levels for lvl_id in lvl_groups.keys(): segments = lvl_groups[lvl_id] level = Level(lvl_id) for segment in segments: level.add_segment(segment) level.connect() self.levels[lvl_id] = level
def __init__(self, width, height): Level.__init__(self, width, height) ##initialize blocks## boxtop = Terrain(20, -19, 40, 2, 0, 0,100, self, 0.5) boxleft= Terrain(-1,-5,2,30,0,0,100,self,0.5) boxbottom= Terrain(27.0,9.0,54.0,2.0,0.0,0.0,100,self,0.5) boxright= Terrain(55,-5,2,30,0,0,100,self,0.5) goal= Goal(53,5,1,5,0,0,100,self,0.5) b = Block(2, 2, 4, 1, 0, 0, 1, self, 0.5) c = Player(7, 5, 1, 2, 0, 0, 1, self, 0.5) d = Block(4, 2, 4, 1, 0, 5, 2, self, 0.5) a = GoalBlock(4, 5, 2, 2, 0, 5, 2, self, 0.5) m = Trampoline(30, -4, 2, 1, 0, 0, 1, self, 0.5) e = Spike(30.0, 7.5, 41.0, 1.0, 0.0, 0.0, 100, self, 0.1) f = Spike(29.0, 6.5, 1.0, 1.0, 0.0, 0.0, 100, self, 0.1) self.add_elem(c) self.add_elem(m) self.add_elem(b) self.add_elem(a) self.add_elem(d) self.add_elem(e) self.add_elem(f) self.add_elem(boxtop) self.add_elem(boxright) self.add_elem(boxbottom) self.add_elem(boxleft) self.add_elem(goal)
def __init__(self, director, player): Level.__init__(self, director, player) self.player.rect.x = 782 self.player.rect.y = 912 self.dead_sub_boss = 0 #Counts the dead Centurions. self.enemyGroup.add([Legionnaire(987, 768, self.player, director), Legionnaire(1083, 768, self.player, director), Legionnaire(1119, 768, self.player, director), Legionnaire(987, 834, self.player, director), Legionnaire(477, 747, self.player, director), Legionnaire(645, 738, self.player, director), Legionnaire(477, 891, self.player, director), Legionnaire(645, 788, self.player, director), Centurion(150, 288, self.player, director), Centurion(1455, 288, self.player, director), Centurion(1329, 1248, self.player, director)]) self.door = Door(760, 575, 'door_sheet.png', -1, 'coordDoor.txt', [2], 'door_open.wav') self.doorGroup = EntityGroup([]) self.doorGroup.add(self.door) self.groups.append(self.doorGroup) self.bg = load_image("map_caesar_a_img.png", Constants.MAP_DIR) self.collisionBg = load_image( "map_caesar_a_bg.png", Constants.BG_MAP_DIR) load_music("level_one.it") pygame.mixer.music.set_volume(1) pygame.mixer.music.play(-1) player.setWeapons([WpnBlade("wpns2.png", -1, pygame.Rect(344, 342, 28, 28), "blade_swing.wav", 0.5), \ WpnBow("items-1.png", None, pygame.Rect(0, 24, 24, 24))])
def __init__(self, width, height): Level.__init__(self, width, height) ##initialize blocks## boxtop = Terrain(20, -19, 40, 2, 0, 0, 100, self, 0.5) boxleft = Terrain(-1, -5, 2, 30, 0, 0, 100, self, 0.5) boxbottom = Terrain(20, 9, 40, 2, 0, 0, 100, self, 0.5) boxright = Terrain(41, -5, 2, 30, 0, 0, 100, self, 0.5) barrbottom = Terrain(15, -6, 6, 1, 0, 0, 100, self, .5) barrright = Terrain(18.5, -11, 1, 10, 0, 0, 100, self, .5) goal = Goal(38, -15.5, 1, 5, 0, 0, 100, self, 0.5) tramp1 = Trampoline(7, 7, 6, 1, 0, 0, 100, self, .5) tramp2 = Trampoline(36, 7, 6, 1, 0, 0, 100, self, .5) tramp3 = Trampoline(32, -8, 6, 1, 0, 0, 100, self, .5) tramp4 = Trampoline(36, -23, 6, 1, 0, 0, 100, self, .5) p = Player(2, 5, 1, 2, 0, 0, 1, self, 0.5) g = GoalBlock(16.5, -7, 2, 2, 0, 0, 2, self, 0.5) self.add_elem(p) self.add_elem(barrbottom) self.add_elem(barrright) self.add_elem(tramp1) self.add_elem(tramp2) self.add_elem(tramp3) self.add_elem(tramp4) self.add_elem(g) self.add_elem(boxtop) self.add_elem(boxright) self.add_elem(boxbottom) self.add_elem(boxleft) self.add_elem(goal)
def __init__(self, director, player): Level.__init__(self, director, player) self.player.rect.x = 766 self.player.rect.y = 82 self.enemyGroup.add([Nazist(640, 140, self.player, director), # Nazist(640, 176, self.player, director), # Nazist(688, 18, self.player, director), Nazist(524, 51, self.player, director), # Nazist(524, 140, self.player, director), Nazist(345, 46, self.player, director), Nazist(345, 70, self.player, director), # Nazist(345, 100, self.player, director), Nazist(140, 145, self.player, director), Nazist(140, 175, self.player, director), Nazist(185, 10, self.player, director), Mr_H(27, 48, self.player, director)]) self.bg = load_image("mapa_h.png", Constants.MAP_DIR) self.collisionBg = load_image("mapa_h_bg.png", Constants.BG_MAP_DIR) load_music("level_three.xm") pygame.mixer.music.set_volume(0.25) pygame.mixer.music.play(-1) player.setWeapons([WpnGrenade(), WpnRifle()])
def __init__(self, player, active_sprite_list): """ Create level 1. """ # Call the parent constructor Level.__init__(self, player, self._BACKGROUND_IMAGE) self.show_text(self._INTRO_TEXT) self.active_sprite_list = active_sprite_list self.level_limit = -1000 # Array with type of platform, and x, y location of the platform. level = [ [210, 30, 450, 500], [210, 30, 850, 500], [210, 30, 1000, 500], ] # Go through the array above and add platforms for platform in level: block = Platform() block.rect.x = platform[2] block.rect.y = platform[3] block.player = self.player self.platform_list.add(block) toots = Toots(player, self.active_sprite_list) toots.level = self toots.rect.x = 1000 toots.rect.y = SCREEN_HEIGHT + 100 self.enemy_list = pygame.sprite.Group() self.enemy_list.add(toots)
class Game: """Game config""" def __init__(self): self.screen = Screen(300, 300, 20) self.level = Level(self.screen.sprite, self.screen) self.level.items_cord() self.guardian = Guardian(self.level) self.player = Player(self.level, self.screen.sprite, self.screen, self.guardian) self.needle = Items(self.level, "ressource/aiguille.png") self.ether = Items(self.level, "ressource/ether.png") self.syringue = Items(self.level, "ressource/seringue.png") self.pipe = Items(self.level, "ressource/tube_plastique.png") def collect_items(self): """Set items collection by player""" if self.player.rect == self.needle.rect: self.player.health_attack_up() elif self.player.rect == self.ether.rect: self.player.health_attack_up() elif self.player.rect == self.syringue.rect: self.player.health_attack_up() elif self.player.rect == self.pipe.rect: self.player.health_attack_up() def guardian_collide(self): """Set player behavior against guardian""" log_x, log_y = self.level.from_cord_to_grid(self.player.rect.x, self.player.rect.y) if self.level.level[log_y][log_x] == 3: self.player.health = self.player.health - self.guardian.attack self.guardian.health = self.guardian.health - self.player.attack
class GameManager: def __init__(self, entity_table): self.level = Level("content/level1.dat") self.level.load_from_file() self.description_manager = DescriptionManager(10) self.player = entity_table[0] index = 0 self.enemies = [] for entity in entity_table: if index == 0: index += 1 continue self.enemies.append(entity) index += 1 def update(self, orientation): if self.player.is_dead(): self.player.play_sound_through("content/sound/failure.wav") return "fail" self.player.attack(self.description_manager, self.enemies, orientation) total_dead = 0 for e in self.enemies: if not e.is_dead(): e.attack(self.description_manager, self.player, orientation) else: total_dead += 1 if total_dead == len(self.enemies): self.player.play_sound_through("content/sound/victory.wav") return "victory" return self.description_manager.get_str() def get_level(self): return self.level
def __init__(self, player): """ Create level 1. """ # Call the parent constructor Level.__init__(self, player) self.level_limit = -1000 # Array with type of platform, and x, y location of the platform. level = [ [210, 70, 500, 550], [210, 70, 800, 400], [210, 70, 1000, 500], [210, 70, 1120, 280], ] # Go through the array above and add platforms for platform in level: block = Platform(platform[0], platform[1]) block.rect.x = platform[2] block.rect.y = platform[3] block.player = self.player self.platform_list.add(block) # Add a custom moving platform block = MovingPlatform(70, 70) block.rect.x = 1500 block.rect.y = 300 block.boundary_top = 100 block.boundary_bottom = 550 block.change_y = -1 block.player = self.player block.level = self self.platform_list.add(block)
def __init__(self): #*************** основное window *************** self.win_width = settings.WIDTH_WIN # Ширина окна self.win_height = settings.HEIGHT_WIN # Высота окна self.win_display = (self.win_width, self.win_height) # Компановка self.timer = pygame.time.Clock() # Таймер кадров #*************** инициализация объектов *************** self.left = self.right = self.up = self.down = self.space = False self.exit_ = True # флаг для выхода self.windows = Windows() # инициализируем Windows self.TARGET = pygame.USEREVENT self.level1 = Level(settings.LEVEL_1) # Инициализируем level1 self.level1.load_level() self.player = Player( self.level1.ret_A()) # инициализируем Tank по карте self.enemy = Enemy(self.level1.ret_B()) self.platforms = self.level1.ret_tiles() self.end = (self.player.ret_topleft()[0] / 32, self.player.ret_topleft()[1] / 32) self.start = (self.level1.ret_B()[0] / 32, self.level1.ret_B()[1] / 32) #*************** блоки спрайтов *************** self.block_list = pygame.sprite.Group( ) #Это список спрайтов. Каждый блок добавляется в этот список. self.all_sprites_list = pygame.sprite.Group( ) # # Это список каждого спрайта. Все блоки, а также блок игрока. self.bullet_list = pygame.sprite.Group() #тес массив спрайтов пули self.block_list.add(self.platforms) self.all_sprites_list.add(self.player, self.enemy) self.walls = [] for i in self.block_list: x, y = i.rect.topleft self.walls.append((x / 32, y / 32))
def startGame(self): self.gameOverScreen.hide() self.cleanup() self.player = Player() self.currentLevel = Level("testLevel")
def initLevel(level_set, level): # Create an instance of this Level global myLevel myLevel = Level(level_set, level) # Draw this level gui.drawLevel(myLevel.getMatrix())
class GameSpace(): def __init__(self): pygame.init() pygame.display.set_caption('Tanks') self.screen = pygame.display.set_mode(WIN_DISPLAY) self.background = Surface(WIN_DISPLAY) self.background.fill(Color(WIN_COLOR)) self.timer = pygame.time.Clock() self.cf = ClientConnFactory(self) reactor.connectTCP(HOST,PORT,self.cf) reactor.run() def start(self): self.player = Player(100,100)# инициализируем Tank self.level1 = Level('level1.txt')#Инициализируем level1 self.level1.load_level() #self.test_loop() def tick(self): print 'tick' for e in pygame.event.get(): if e.type == QUIT: reactor.stop() raise SystemExit, "Quit" if e.type == KEYDOWN and e.key == K_LEFT: print '*'*100 print "KEYDOWN K_LEFT" self.sendData("KEYDOWN LEFT! Yu-hooo") print 'end tick for' #self.sendData("**********************Hello!") self.screen.blit(self.background,(0,0)) self.screen.blit(self.player.image,(100,100)) pygame.display.update() def sendData(self, data): self.cf.conn.send(data) def addData(self, data): print "INCOMING: ", data def test_loop(self): while True: for e in pygame.event.get(): if e.type == QUIT: raise SystemExit, "QUIT" if e.type == KEYDOWN and e.key == K_LEFT: print "KEYDOWN K_LEFT" self.screen.blit(self.background,(0,0)) self.screen.blit(self.player.image,(100,100)) pygame.display.update()
def extract_levels_from_content(self, file): self.levels = [] content = self.file_reader.read_content(file) levels = self.load_levels(content) for level in levels: level_object = Level() level_object.create_level(content, level) self.levels.append(level_object) return self.levels
def __init__(self, player): """ Create level 1. """ # Call the parent constructor Level.__init__(self, player) self.level_limit = -6000 BLOCK_WIDTH = 210 self.block_height = 70 # Array with width, height, x, and y of platform level = [ [BLOCK_WIDTH, BLOCK_HEIGHT, 500, 500], [BLOCK_WIDTH, BLOCK_HEIGHT, 800, 400], [BLOCK_WIDTH, BLOCK_HEIGHT, 1000, 500], [BLOCK_WIDTH, BLOCK_HEIGHT, 1120, 280], [BLOCK_WIDTH, BLOCK_HEIGHT, 1500, 280], [BLOCK_WIDTH, BLOCK_HEIGHT, 2000, 280], [BLOCK_WIDTH, BLOCK_HEIGHT, 2500, 280], [BLOCK_WIDTH, BLOCK_HEIGHT, 3000, 280], [BLOCK_WIDTH, BLOCK_HEIGHT, 3500, 280], [BLOCK_WIDTH, BLOCK_HEIGHT, 4000, 280], [BLOCK_WIDTH, BLOCK_HEIGHT, 4500, 280], [BLOCK_WIDTH, BLOCK_HEIGHT, 5000, 280], [BLOCK_WIDTH, BLOCK_HEIGHT, 5500, 280], [BLOCK_WIDTH, BLOCK_HEIGHT, 60000, 280], ] # Go through the array above and add platforms for platform in level: block = Platform(platform[0], platform[1]) block.rect.x = platform[2] block.rect.y = platform[3] block.player = self.player self.platform_list.add(block) # Add a custom moving platform block = MovingPlatform(70, 40) block.rect.x = 1350 block.rect.y = 280 block.boundary_left = 1350 block.boundary_right = 1600 block.change_x = 1 block.player = self.player block.level = self self.platform_list.add(block) # Add a custom enemy enemy = Enemy(30, 30) enemy.rect.x = 900 enemy.rect.y = 300 enemy.boundary_left = 800 enemy.boundary_right = 1000 enemy.change_x = 1 enemy.player = self.player enemy.level = self self.enemy_list.add(enemy)
def processEvent(self, event): if event.type == pygame.KEYDOWN and event.key == pygame.K_RETURN: nextLevel = LevelTwo(self.director, self.player) self.director.setScene(nextLevel) if event.type == pygame.KEYDOWN and event.key == pygame.K_F1: self.door.setActive(True) # nextLevel = LevelOneB(self.director, self.player) # self.director.setScene(nextLevel) Level.processEvent(self, event)
def loadRandomLevel(): global current_level global last_level # TODO: Make more levels by rotation and mirroring last_level = current_level current_level = random.randint(min_level, max_level) matrix = Level(level_set, current_level).matrix matrix.moves = 0 matrix.actions = "" return matrix
def initLevel(level_set,level): # Create an instance of this Level global myLevel myLevel = Level(level_set,level) # Draw this level drawLevel(myLevel.getMatrix()) global target_found target_found = False
def processEvent(self, event): if event.type == pygame.KEYDOWN and event.key == pygame.K_RETURN: nextLevel = LevelTwo(self.director, self.player) self.director.setScene(nextLevel) if event.type == pygame.USEREVENT and event.code == CAESARDEAD: nextLevel = LevelTwo(self.director, self.player) self.director.setScene(nextLevel) Level.processEvent(self, event)
def initLevel(level_set, level): # Create an instance of this Level global myLevel myLevel = Level(level_set, level) # Draw this level drawLevel(myLevel.getMatrix()) global target_found target_found = False
def processEvent(self, event): if event.type == pygame.KEYDOWN and event.key == pygame.K_RETURN: nextLevel = LevelFour(self.director, self.player) self.director.setScene(nextLevel) if event.type == pygame.USEREVENT and event.code == MRHDEAD: nextLevel = LevelFour(self.director, self.player) self.director.setScene(nextLevel) Level.processEvent(self, event)
def __init__(self): self.screen = Screen(300, 300, 20) self.level = Level(self.screen.sprite, self.screen) self.level.items_cord() self.guardian = Guardian(self.level) self.player = Player(self.level, self.screen.sprite, self.screen, self.guardian) self.needle = Items(self.level, "ressource/aiguille.png") self.ether = Items(self.level, "ressource/ether.png") self.syringue = Items(self.level, "ressource/seringue.png") self.pipe = Items(self.level, "ressource/tube_plastique.png")
def processEvent(self, event): if event.type == pygame.USEREVENT and event.code == PAGEDEAD: m = MessageScene( self.director, self, 'Congratulations', "You have completed the game!\nNow you're entitled \nto the 3D version.", "Press to quit") m.messageBox.button.onMouseDown = lambda: pygame.event.post( pygame.event.Event(pygame.QUIT)) self.director.setScene(m) Level.processEvent(self, event)
class playerTests(unittest.TestCase): def setUp(self): self.level = Level(200, 200) self.level.gen_base(60, 60) board = self.level.board self.player = Player(60, 60, '@', board) self.level.board[self.player.y][self.player.x - 1] = ' ' self.level.board[self.player.y][self.player.x + 1] = ' ' self.level.board[self.player.y - 1][self.player.x] = ' ' self.level.board[self.player.y + 1][self.player.x] = ' ' def test_playercantgothroughwalls(self): initx = self.player.x inity = self.player.y #Set a wall to the left of player self.level.board[self.player.y][self.player.x-1] = '+' self.player.move('a') assert self.player.y == inity and self.player.x == initx def test_playercanmoveleft(self): initx = self.player.x inity = self.player.y print(inity, " ", self.player.y) print(initx, " ", self.player.x) self.player.move('a') assert self.player.y == inity and self.player.x == initx -1 def test_playercanmoveright(self): initx = self.player.x inity = self.player.y self.player.move('d') assert self.player.y == inity and self.player.x == initx +1 def test_playercanmoveup(self): initx = self.player.x inity = self.player.y self.player.move('w') assert self.player.y == inity - 1 and self.player.x == initx def test_playercanmovedown(self): initx = self.player.x inity = self.player.y self.player.move('s') assert self.player.y == inity +1 and self.player.x == initx
def test_get_column_index(self): content = [ ["Plaats", "School", "Niveau", "Leerling", "Score", "Label"], ["Apeldoorn", "HAN", "HBO", "563631", "15", "test1"]] niveau = Level() niveau.name = "School" column_number = 1 result = niveau.get_column_index(content) self.assert_niveau_is_in_column_number(column_number, result)
def readDetailsForCustomLevel(self): """ This method allows to the user create and use a new customized level to generate Sudoku games. Note. This level will not be stored in the .xml file """ userLevel = Level(0, 0, "Custom level") userLevel.setBottomLimit = int(self.getUserInput("\ Please enter a number to set the minimun limit for empty spaces")) userLevel.setTopLimit = int(self.getUserInput("\ Please enter a number to set the maximun limit for empty spaces")) return userLevel
def __init__(self, levelmap, screen, grid_dim, view_coord): self.screen_pos = view_coord self.screen = screen # pygame display # tuple, grid dimensions (horizontal tiles, vertical tiles) self.size = grid_dim # View coordinates (offset from (0,0), in pixels) self.view_coord = view_coord self.tilesize = int(screen.get_rect().width / grid_dim[0]), \ int(screen.get_rect().height / grid_dim[1]) self.level = Level(levelmap) self.background = self.level.render(self.screen, self.size) self.entities = dict()
def get_level(self, lvl): level = self._dh.get_level(lvl) if not level: level = Level(lvl) texts = self.get_level_texts(lvl) if texts: for k, v in texts.items(): if v: setattr(level, '_%s' % k , v) if not level._boss: level._boss = random.choice(self._gamedata['boss']) return level
def test_get_variables(self): content = [["Plaats", "School", "Niveau", "Leerling", "Score", "Label"], ["Apeldoorn", "HAN", "HBO", "563631", "15", "test1"], ["Arnhem", "HAN", "HBO", "563631", "15", "test1"]] niveau = Level() expected_result = ["Apeldoorn", "Arnhem"] column_number = 0 niveau.name = "Plaats" variables = niveau.get_variables(column_number, content) self.assert_get_variables_contains(expected_result, variables)
def test_add_indexes_to_filtered_list(self): indexes_part_one = [0, 1, 2, 3, 4, 5, 6] indexes_part_two = [0, 1, 2, 3, 4, 5, 6] expected = [0, 1, 2, 3, 4, 5, 6, 0, 1, 2, 3, 4, 5, 6] niveau = Level() niveau.add_row_numbers_to_filtered_list(indexes_part_one) niveau.add_row_numbers_to_filtered_list(indexes_part_two) result = niveau.row_numbers self.assertEqual(expected, result)
def __init__(self, width, height): Level.__init__(self, width, height) ##initialize blocks## boxtop = Terrain(20, -19, 40, 2, 0, 0,100, self, 0.5) boxleft= Terrain(-1,-5,2,30,0,0,100,self,0.5) boxbottom= Terrain(20,9,40,2,0,0,100,self,0.5) boxright= Terrain(41,-5,2,30,0,0,100,self,0.5) goal= Goal(38,5,1,5,0,0,100,self,0.5) b10 = Block(1, 7, 2, 2, 0, 0, 1, self, 0.5) b20 = Block(3, 7, 2, 2, 0, 0, 1, self, 0.5) b30 = Block(5, 7, 2, 2, 0, 0, 1, self, 0.5) b40 = Block(7, 7, 2, 2, 0, 0, 1, self, 0.5) b50 = Block(9, 7, 2, 2, 0, 0, 1, self, 0.5) b11 = Block(1, 5, 2, 2, 0, 0, 1, self, 0.5) b21 = Block(3, 5, 2, 2, 0, 0, 1, self, 0.5) b31 = Block(5, 5, 2, 2, 0, 0, 1, self, 0.5) b41 = Block(7, 5, 2, 2, 0, 0, 1, self, 0.5) b51 = Block(9, 5, 2, 2, 0, 0, 1, self, 0.5) b12 = Block(1, 3, 2, 2, 0, 0, 1, self, 0.5) b22 = Block(3, 3, 2, 2, 0, 0, 1, self, 0.5) b32 = Block(5, 3, 2, 2, 0, 0, 1, self, 0.5) b42 = Block(7, 3, 2, 2, 0, 0, 1, self, 0.5) b52 = Block(9, 3, 2, 2, 0, 0, 1, self, 0.5) p = Player(15, 5, 1, 2, 0, 0, 1, self, 0.5) g = GoalBlock(17, 5, 2, 2, 0, 0, 2, self, 0.5) barrier = Terrain(35,-3,1,22,0,0,100,self,0.5) self.add_elem(p) self.add_elem(b10) self.add_elem(b20) self.add_elem(b30) self.add_elem(b40) self.add_elem(b50) self.add_elem(b11) self.add_elem(b21) self.add_elem(b31) self.add_elem(b41) self.add_elem(b51) self.add_elem(b12) self.add_elem(b22) self.add_elem(b32) self.add_elem(b42) self.add_elem(b52) self.add_elem(barrier) self.add_elem(g) self.add_elem(boxtop) self.add_elem(boxright) self.add_elem(boxbottom) self.add_elem(boxleft) self.add_elem(goal)
def __init__(self, director, player): Level.__init__(self, director, player) self.player.rect.x = 224 self.player.rect.y = 1273 self.laser0 = Laser(80, 340, 'laser_45.png') self.laser1 = Laser(400, 75, 'laser_45.png') self.laser2 = Laser(405, 332, 'laser_180.png') self.laser3 = Laser(80, 330, 'laser_180.png') self.laser4 = Laser(406, 341, 'laser_125.png') self.laser5 = Laser(80, 80, 'laser_125.png') self.laser6 = Laser(400, 350, 'laser_90.png') self.laserArray = [ self.laser0, self.laser1, self.laser2, self.laser3, self.laser4, self.laser5, self.laser6 ] self.laserGroup = EntityGroup([]) self.laserGroup.add(self.laser0, self.laser1, self.laser2, self.laser3, self.laser4, self.laser5, self.laser6) self.groups.append(self.laserGroup) self.laser0.active = False self.laser1.active = False self.activeLG = 1 # Pair of lasers active at a given time self.time = 0 self.page = Page(408, 135, self.player, director) self.enemyGroup.add([ FutureSoldier(141, 1084, self.player, director), # FutureSoldier(316, 1084, self.player, director), # FutureSoldier(141, 926, self.player, director), FutureSoldier(316, 926, self.player, director), FutureSoldier(686, 1260, self.player, director), FutureSoldier(508, 988, self.player, director), FutureSoldier(537, 1450, self.player, director), self.page ]) self.bg = load_image("map_page_img.png", Constants.MAP_DIR) self.collisionBg = load_image("map_page_bg.png", Constants.BG_MAP_DIR) self.invisibleFloor = InvisibleFloor( 384, 202, 59, 78) # Invisible sprite, it functions as a trigger self.invisibleFloorG = EntityGroup([]) self.invisibleFloorG.add(self.invisibleFloor) self.groups.append(self.invisibleFloorG) load_music("level_four.s3m") pygame.mixer.music.set_volume(0.5) pygame.mixer.music.play(-1) player.setWeapons([WpnBlade("lightsaber.png", -1, pygame.Rect(128, 77, 42, 42), "sthswng1.wav", 0.2), \ WpnLaser()])
def update(self, time): Level.update(self, time) if not self.door.active and self.dead_sub_boss == 3: #When all Centurions are dead we open the door self.door.setActive(True) if len(pygame.sprite.spritecollide(self.player,self.doorGroup,False)) == 1: if self.door.active == False: m = MessageScene(self.director, self, 'Warning', 'You shall not pass!', 'Press to continue') self.director.setScene(m) self.player.rect.y+=25 if self.door.active == True: nextLevel = LevelOneB(self.director, self.player) self.director.setScene(nextLevel)
def __init__(self, entity_table): self.level = Level("content/level1.dat") self.level.load_from_file() self.description_manager = DescriptionManager(10) self.player = entity_table[0] index = 0 self.enemies = [] for entity in entity_table: if index == 0: index += 1 continue self.enemies.append(entity) index += 1
def update(self, time): Level.update(self, time) self.time +=time if self.activeLG != 0 and self.time > 1000: self.change_lasers() self.time = 0 laser = pygame.sprite.spritecollideany(self.player, self.laserGroup, pygame.sprite.collide_mask) if laser != None and laser.active: self.player.hp = 0 if len(pygame.sprite.spritecollide(self.player,self.invisibleFloorG,True,pygame.sprite.collide_rect)) == 1: print 'Floor' self.disconnect_lasers() self.page.rect.x = 414 self.page.rect.y = 414
def __init__(self, director, player): Level.__init__(self, director, player) self.player.rect.x = 381 self.player.rect.y = 610 self.enemyGroup.add([Legionnaire(207, 447, self.player, director), Legionnaire(592, 447, self.player, director), Caesar(399, 336, self.player, director)]) self.bg = load_image("map_caesar_b_img.png", Constants.MAP_DIR) self.collisionBg = load_image( "map_caesar_b_bg.png", Constants.BG_MAP_DIR) load_music("level_one.it") pygame.mixer.music.set_volume(1) pygame.mixer.music.play(-1)
def __init__(self, player): Level.__init__(self, player) self.init_enemies() self.init_items() self.PLAYER_START = [105.2, 40] self.player.set_direction("up") self.is_beatable = False self.init_labels() self.time_between_fireballs = 0 self.checkpoint = 0 self.has_gotten_checkpoint_1 = False self.has_gotten_checkpoint_2 = False self.has_gotten_checkpoint_3 = False self.fireball_strength = 2 self.timer = 0 self.beaten = False
def __init__(self, director, player): Level.__init__(self, director, player) self.player.rect.x = 224 self.player.rect.y = 1273 self.laser0 = Laser(80, 340, 'laser_45.png') self.laser1 = Laser(400, 75, 'laser_45.png') self.laser2 = Laser(405, 332, 'laser_180.png') self.laser3 = Laser(80, 330, 'laser_180.png') self.laser4 = Laser(406, 341, 'laser_125.png') self.laser5 = Laser(80, 80, 'laser_125.png') self.laser6 = Laser(400, 350, 'laser_90.png') self.laserArray = [self.laser0, self.laser1, self.laser2, self.laser3, self.laser4, self.laser5, self.laser6] self.laserGroup = EntityGroup([]) self.laserGroup.add(self.laser0, self.laser1, self.laser2,self.laser3, self.laser4, self.laser5, self.laser6) self.groups.append(self.laserGroup) self.laser0.active = False self.laser1.active = False self.activeLG = 1 #Pair of lasers active at a given time self.time = 0 self.page = Page(408, 135, self.player, director) self.enemyGroup.add([FutureSoldier(141, 1084, self.player, director), FutureSoldier(316, 1084, self.player, director), FutureSoldier(141, 926, self.player, director), FutureSoldier(316, 926, self.player, director), FutureSoldier(686, 1260, self.player, director), FutureSoldier(508, 988, self.player, director), FutureSoldier(537, 1450, self.player, director), self.page]) self.bg = load_image("map_page_img.png", Constants.MAP_DIR) self.collisionBg = load_image("map_page_bg.png", Constants.BG_MAP_DIR) self.invisibleFloor = InvisibleFloor(384,202,59,78) #Invisible sprite, it functions as a trigger self.invisibleFloorG = EntityGroup([]) self.invisibleFloorG.add(self.invisibleFloor) self.groups.append(self.invisibleFloorG) load_music("level_four.s3m") pygame.mixer.music.set_volume(0.5) pygame.mixer.music.play(-1) player.setWeapons([WpnBlade("lightsaber.png", -1, pygame.Rect(128, 77, 42, 42), "sthswng1.wav", 0.2), \ WpnLaser()])
def encryptFile(): CharIndexMap.rangeTypeisCharacterBased=False start_time = time.time() baseMachineCfg=EnigmaConfigGenerator(RandomGenerator(123)).createMachineConfig("MCb") baseMachine=EnigmaDynamicFactory().createEnigmaMachineFromConfig(baseMachineCfg) baseMachine.adjustMachineSettings() levelMachine=EnigmaDynamicFactory().createEnigmaMachineFromModel("MCm") levelMachine.adjustMachineSettings() level=Level(baseMachine.getMachineSettings(),levelMachine.getMachineSettings()) elapsed_time = time.time() - start_time print("2 MAchines were created in :"+str(elapsed_time)) start_time = time.time() msg=FileReader().readSeqFromFile("tst.txt") elapsed_time = time.time() - start_time print("Parsed File to read Seq in : "+str(elapsed_time)) level.inputMsg=msg start_time = time.time() levelEncryptor=LevelEncryptor(baseMachine,levelMachine,level,RandomGenerator(123)) encLevel=levelEncryptor.encryptLevel() elapsed_time = time.time() - start_time print("Encrypted Seq in : "+str(elapsed_time)) FileReader().writeSeqTofile(encLevel.outputMsg,"tst.enc",True) print("Encrypted File written") encLevel.inputMsg="" start_time = time.time() levelDecryptor=LevelDecryptor(baseMachine,levelMachine,level) levelDecryptor.level=encLevel resultLevel=levelDecryptor.decryptLevel() elapsed_time = time.time() - start_time print("Decrypted Sequence in :"+str(elapsed_time)) FileReader().writeSeqTofile(resultLevel.inputMsg,"tst.dec",False) print("Decrypted File written") print("DONE !!")
def __init__(self, player): Level.__init__(self, player) self.init_enemies() self.init_items() self.PLAYER_START = [104, 78] self.is_beatable = False self.init_labels() self.time_between_fireballs = 0 self.checkpoint = 0 self.has_gotten_checkpoint_1 = False self.has_gotten_checkpoint_2 = False self.has_gotten_checkpoint_3 = False self.fireball_strength = 2 self.timer = 0 #Counts number of kegs the player has killed self.kegs = 0 self.player.inventory.append("fireball") self.has_fireball = True
def setUp(self): self.level = Level(200, 200) self.level.gen_base(60, 60) board = self.level.board self.player = Player(60, 60, '@', board) self.level.board[self.player.y][self.player.x - 1] = ' ' self.level.board[self.player.y][self.player.x + 1] = ' ' self.level.board[self.player.y - 1][self.player.x] = ' ' self.level.board[self.player.y + 1][self.player.x] = ' '
class LevelTests(unittest.TestCase): def setUp(self): self.width = 150 self.height = 200 self.level = Level(self.width, self.height) def test_width(self): assert self.level.width == self.width def test_height(self): assert self.level.height == self.height def test_genbase_outofbounds(self): self.level.gen_base(120, 120) assert self.level.board[2][2] == self.level.outofboundschar #outofbounds is 40 characters, so 41 should always be inbound def test_genbase_inbounds(self): self.level.gen_base(120, 120) assert self.level.board[41][41] == self.level.wallchar def test_genbase_adds_room(self): initial = len(self.level.rooms) self.level.gen_base(120, 120) aftergen = len(self.level.rooms) assert initial == 0 and aftergen == 1
def __init__(self, camera, luObserver, fxObserver, lvl): self.mSwitch = True self.mTimer = 0.0 self.mLevelDone = False self.mCamera = camera self.mLuObs = luObserver self.mFxObs = fxObserver self.contactListener = ContactListener() self.gravity = Gravity() self.physWorld = b2World(gravity=(0,0),doSleep=True, contactListener=self.contactListener) self.level = Level(self.physWorld, self.gravity, lvl) self.player = Player(self.level.mStartPos, self.physWorld, self.gravity) self.mEntityToFollow = self.player
def __init__(self, w, h, filename, data_path): #If a blank filename is passed, create a new level file 'new_level_1.ini, if the file exists in level_data, #increment i until a filename that does not exist in working dir is found if os.path.isfile(os.path.join(data_path, 'level_data', filename)): print("Existing level found, loading..") else: if filename is "": i = 0 while True: i += 1 filename = 'new_level_' + str(i) + '.ini' if not os.path.isfile(os.path.join(data_path, 'level_data', filename)): break Level.__init__(self, w, h, filename, data_path) self.selected_obj = None self.camera = EditCamera(800, 600, 2000, 800) #offsets from selected object's top left corner to mouse at time of selection self._sel_m_x = 0 self._sel_m_y = 0 self._menu_focus = False self.sel_target = SelectionTarget(data_path) level_options = GuiLevelOptions(False) quit_lvl_gui = GuiQuitLevel(False) obj_search_gui = GuiObjSearch(False) edit_obj_gui = GuiEditObj(True) self.gui_manager.add(QUIT_GAME, quit_lvl_gui) self.gui_manager.add(OBJECT_SEARCH, obj_search_gui) self.gui_manager.add(LEVEL_OPTIONS, level_options) self.gui_manager.add(EDIT_OBJ, edit_obj_gui) self.del_bind = pygame.K_d self.edit_bind = pygame.K_e self.options_bind = pygame.K_F1 self.spawn_bind = pygame.K_SPACE #1 = left mouse button self.sel_bind = 1
def __init__(self, player): """ Create level 1. """ # Call the parent constructor Level.__init__(self, player) self.level_limit = -1000 # Array with type of platform, and x, y location of the platform. level = [[210, 30, 450, 570], [210, 30, 850, 420], [210, 30, 1000, 520], [210, 30, 1120, 280], ] # Go through the array above and add platforms for platform in level: block = Platform(platform[0], platform[1]) block.rect.x = platform[2] block.rect.y = platform[3] block.player = self.player self.platform_list.add(block)
def reload(self, score=0, level=1): self.__level = level self.__Lev = Level() self.__Lev.findLadderCoordinates() self.__Lev.coinsGen() self.__Lev.findCoinCoordinates() self.__Lev.paintLadder() self.__Lev.levelLoad(self.__level) self.__win = False self.__Kong = Donkey(self.__Lev) self.__play = Player(self.__Lev, score) self.__firas = [Fireball(self.__Lev) for i in range(1000)] for fira in self.__firas: fira.getLevelProperties() self.__Kong.getLevelProperties() self.__play.getLevelProperties() self.__Kong.getDonkeyPosition() self.__play.getPlayerPosition()