def __init__(self, terrain_string, directions, item=None): if terrain_string is None: raise AttributeError("Terrain must be supplied") else: self._terrain = terrain.Terrain(terrain_string) if directions is None or len(directions) == 0: self._move_north = False self._move_east = False self._move_south = False self._move_west = False else: if 'n' in directions.lower(): self._move_north = True else: self._move_north = False if 'e' in directions.lower(): self._move_east = True else: self._move_east = False if 's' in directions.lower(): self._move_south = True else: self._move_south = False if 'w' in directions.lower(): self._move_west = True else: self._move_west = False self._item = item
def __init__(self): # Variables for game state self.score = 0 self.state = 1 self.multiplier = 1 self.gas = 0 self.playing = True # Used to see if there is no collision (0), a crash (1), or a potential landing (2) self.collided = 0 # Variables for physics self.dt = .01 self.xVel = 0 self.yVel = 0 self.x = 0 self.y = 0 self.ang = 0 # Used to see what kind of landing: good landing (1), hard landing (2), or a crash (3) self.landingType = 0 # Ship and terrain objects self.ship = lander.Ship() self.terrain = land.Terrain() self.xTerrain = [] self.yTerrain = [] # Used to schedule a life reset after the landing/crash screen self.resetScheduled = False
def __init__(self, screen, clock): self.screen = screen self.clock = clock self.game_started = False self.quit_button = menu.MenuButton(display_width / 2 - 150, display_height / 2, quit_button_img, "quit") self.start_button = menu.MenuButton(display_width / 2 - 150, display_height / 4, start_button_img, "start") self.leaderboard_button = menu.MenuButton(display_width / 2 - 450, display_height / 6, leaderboard_button_img, "leaderboard") self.back_button = menu.MenuButton(display_width / 4, display_height - 100, back_button_img, "back") self.menu_table = menu.MainMenu(self.screen, self.quit_button, self.start_button, self.leaderboard_button) self.leaderboard_table = leaderboard.Leaderboard( leaderboard_storage, screen) self.create_start_leaderboard() self.death_screen_table = death_screen.Death_screen( screen, self.back_button) self.game_surface = terrain.Terrain() self.player = player.Player(PLAYER_POS_X, PLAYER_POS_Y, self.screen) self.army = player.AlienArmy(self.player, self.screen)
def redrawGameWindow(gamestate): """ The main drawing function of the game :param gamestate: Decoded Json string :return: Draws the game graphics """ global index global alive global uniqueID #print(gamestate["tanks"]) if gamestate["tanks"][str(uniqueID)]["alive"] == False: alive = False win.blit(chosenBackground, (0, 0)) projectiles = gamestate["projectile"] projList = [] projToBeRemoved = [] for key in projectiles: projList.append(key) if key in projectileDict: projectileDict[key].draw(win, projectiles[key]) else: projectileDict[key] = projectile.Projectile(projectiles[key]) projectileDict[key].draw(win, projectiles[key]) for key in projectileDict: if key not in projList: projToBeRemoved.append(key) for key in projToBeRemoved: spriteCount = explosionEffect.draw(win, round(projectileDict[key].x), round(projectileDict[key].y), centerHandle) if spriteCount > 10: projectileDict.pop(key) tanks = gamestate["tanks"] for key in tanks: if key in tanksDict: tanksDict[key].draw(win, tanks[key]) else: tanksDict[key] = Tank(tanks[key], mh.tankCounter) tanksDict[key].draw(win, tanks[key]) if mh.tankCounter < 4: mh.tankCounter += 1 else: mh.tankCounter = 0 # generate terrain terrainMap = gamestate["terrain"] for key in terrainMap: terrainDict[key] = terrain.Terrain(terrainMap[key]) if chosenBackground == rs.bg2: terrainDict[key].drawForest(win, terrainMap[key]) else: terrainDict[key].drawWinter(win, terrainMap[key]) pygame.display.update()
def __init__(self): self.terrestrial = terrain.Terrain(TERRAIN_SIZE) self.place_base_station() self.place_satellite() self.place_mobiles_randomly(NUMBER_OF_USERS) # Generate content with zipf distribution self.contents = content.generate_zipf_content(NUMBER_OF_CONTENTS, CONTENT_SIZE, ZIPF_PARAMETER)
def __init__(self): self.coordinate = [] self.maxx = maxx self.maxy = maxy self.picture = [] for i in range(self.maxx): self.coordinate.append([]) #self.picture.append([]) for j in range(self.maxy): self.coordinate[i].append(Pair(None, terrain.Terrain()))
def __init__(self, radius: int, screen_size: int, terrain_size: int): self.terrain_size = terrain_size self.radius = radius self.layout = pl.Layout(pl.layout_pointy, pl.Point(terrain_size, terrain_size), pl.Point(screen_size // 2, screen_size // 2)) # replace this map to switch from hexes to i.e. squares self.map = {p: te.Terrain(p) for p in pl.generate_hex_map(radius)} for k, v in self.map.items(): v.neighbors = self.neighborhood(k, v)
def __init__(self, *args): self.game_running = True self.game_over = False self.g = 15 self.terrains = [] self.characters = [] for char in args: self.characters.append(char) self.terrains.append(terrain.Terrain((200, 600), (1100, 50)))
def __init__(self, window): self.window = window self.initialize_gl() try: with open('terrain.pickle', 'rb') as f: self.terrain = pickle.load(f) except Exception: logging.exception( 'Could not load terrain - Starting with default terrain.') self.terrain = terrain.Terrain(20, 20) self.pointed = (-1, -1, -1) self.profile = True self._cached_terrain_data = None
def __init__(self) -> None: self.terr = terrain.Terrain() self.civs: List[civ.Civ] = [] self.active_civ = 0 self.perspective_civ = 0 self.pointer = sprite.Pointer() self.selected_sprite: Optional[sprite.Sprite] = None self.selected_index: int self.targets: List[sprite.Sprite] = [] self.menu: List[sprite.Sprite] = [] self.control: List[sprite.Sprite] = [ sprite.Button((400, 75), 'End turn') ] self.pushed_button: Optional[sprite.Button] = None self.animating_sprite: Optional[sprite.Sprite] = None self.message = '' self.history: List[Action] = [] self.history_pos = 0 self.display_mode = True self.replay = False
def setUp(self): self.__terrain = terrain.Terrain(1)
def gameloop(): terrain = t.Terrain() terrain.initcases() collide = terrain.getCollide() arbres = terrain.getArbres() posArbres = terrain.getPosArbres() arbrescoupes = [] posArbrescoupes = [] lesmechants = [] ressorts = terrain.getRessorts() collide = terrain.getCollide() vue = vj.Vue() bucheron = b.Bucheron() son = pygame.mixer.Sound("Theme.ogg") son.play(loops=1, maxtime=0, fade_ms=0) saut = pygame.mixer.Sound("saut.wav") special = pygame.mixer.Sound("special.wav") attB = pygame.mixer.Sound("attaque_hache.wav") missilGravite = proj.projectile(bucheron.getx(), bucheron.gety()) missilActive = False missilDirection = "" lesmechants.append(mech.Mechant("G", -200)) lesmechants.append(mech.Mechant("D", 1100)) lvlsupp = 3 for m in lesmechants: m.respawn() bucheron.bougergauche(collide) debutjeu = pygame.time.get_ticks() // 1000 son.play() son.set_volume(0.2) vue.Update(terrain, bucheron, fenetre, lesmechants, arbres, missilGravite, debutjeu) jumpCount = 10 # mainloop gameexit = False timer = 180 while (not (gameexit)) and (timer >= 0): clock.tick(60) for event in pygame.event.get(): # On parcours la liste de tous les événements reçus if event.type == pygame.QUIT: gameexit = True pygame.quit() quit() keys = pygame.key.get_pressed() if bucheron.getchargeUltim() > 7: bucheron.setchargeUltim(8) if not (bucheron.getisJump()): if keys[pygame.K_SPACE] or pygame.Rect(bucheron.gethitbox()).collidelist(ressorts) != -1: if pygame.Rect(bucheron.gethitbox()).collidelist(ressorts) != -1: bucheron.setJumpCount(12.5) saut.set_volume(0.3) saut.play() bucheron.setisJump(True) else: bucheron.sauter(collide) if keys[pygame.K_d]: attB.set_volume(0.7) attB.play() bucheron.attack() elif keys[pygame.K_f] and bucheron.getchargeUltim() > 7: special.set_volume(0.7) special.set_volume(2) special.play() bucheron.attackSpe() bucheron.resetchargeUltim() elif keys[pygame.K_LEFT]: bucheron.bougergauche(collide) elif keys[pygame.K_RIGHT]: bucheron.bougerdroite(collide) else: bucheron.pasbouger() if terrain.getTour().getnbbuche() > lvlsupp: lesmechants.append(mech.Mechant("G", -250)) lvlsupp += 3 # Exécution de l'attaque Speciale Jutsu if bucheron.isAttackingSpe(): missilActive = True missilGravite = proj.projectile(bucheron.getx(), bucheron.gety()) missilGravite.ajouterhitbox() if bucheron.getoldleft(): missilDirection = "G" else: missilDirection = "D" if missilGravite.getx() < -100 or missilGravite.getx() > 1000: missilActive = False missilGravite = proj.projectile(bucheron.getx(), bucheron.gety()) if missilActive: if missilDirection == "G": missilGravite.shoot("G") else: missilGravite.shoot("D") else: missilGravite.retirerhitbox() if bucheron.getCoupHache(): i = -1 if bucheron.getoldleft(): if not pygame.Rect(bucheron.gethitboxAttG()).collidelist(arbres) == -1: for j in range(0, len(arbres)): if pygame.Rect(bucheron.gethitboxAttG()).colliderect(arbres[j]): i = j for m in lesmechants: if pygame.Rect(bucheron.gethitboxAttG()).colliderect(m.gethitbox()): m.tuer() m.respawn() bucheron.addchargeultim() else: if not pygame.Rect(bucheron.gethitboxAttD()).collidelist(arbres) == -1: for j in range(0, len(arbres)): if pygame.Rect(bucheron.gethitboxAttD()).colliderect(arbres[j]): i = j for m in lesmechants: if pygame.Rect(bucheron.gethitboxAttD()).colliderect(m.gethitbox()): m.tuer() m.respawn() bucheron.addchargeultim() if i != -1: terrain.getCases()[posArbres[i][1]][posArbres[i][0]].setType(tc.typecase.ARBRECOUPE) arbrescoupes.append(arbres[i]) posArbrescoupes.append((posArbres[i])) del arbres[i] del posArbres[i] if bucheron.getbucheportee() < 2: bucheron.ajoutbuche() if len(arbres) < 1: arbres = arbrescoupes posArbres = posArbrescoupes arbrescoupes = [] posArbrescoupes = [] for i in range(0, len(posArbres)): terrain.getCases()[posArbres[i][1]][posArbres[i][0]].setType(tc.typecase.ARBRE) if pygame.Rect(bucheron.gethitbox()).colliderect( terrain.getTour().gethitbox()) and bucheron.getbucheportee() > 0: terrain.getTour().augnbbuche(bucheron.getbucheportee()) bucheron.rstbuche() def majmechant(ennemi): if pygame.Rect(ennemi.gethitbox()).colliderect(bucheron.gethitbox()): if bucheron.getbucheportee() > 0: bucheron.setbucheportee(bucheron.getbucheportee() - 1) # enlever une buche au bucheron if pygame.Rect(ennemi.gethitbox()).colliderect(terrain.getTour().gethitbox()): ennemi.tuer() ennemi.respawn() if terrain.getTour().getnbbuche() > 0: terrain.getTour().setnbbuche(terrain.getTour().getnbbuche() - 1) if pygame.Rect(ennemi.gethitbox()).colliderect(missilGravite.gethitbox()): ennemi.setenlevitation(True) if ennemi.getenlevitation(): if ennemi.gety() < -20: ennemi.respawn() ennemi.setenlevitation(False) else: ennemi.leviter() else: ennemi.setvitesse(2) ennemi.deplacer() for m in lesmechants: majmechant(m) vue.Update(terrain, bucheron, fenetre, lesmechants, arbres, missilGravite, debutjeu) if (pygame.time.get_ticks() // 1000 - debutjeu) == 180: new_score = terrain.getTour().getnbbuche() finloop(new_score) pygame.mixer.music.stop()
import mechants as mech import RecupText as rete import projectile as proj import pickle as pk from pygame.locals import * pygame.init() fenetre = pygame.display.set_mode((1000, 700)) pygame.display.set_caption('Menu') clock = pygame.time.Clock() immobileDroite = [pygame.image.load('Bucheron-Stop-Right0.png'), pygame.image.load('Bucheron-Stop-Right1.png')] attaqueDroite = [pygame.image.load('att D1.png'), pygame.image.load('att D3.png')] terrain = t.Terrain() nom = "" new_score = 0 def finloop(new_score): while True: for event in pygame.event.get(): # print(event) if event.type == pygame.QUIT: pygame.quit() quit() nom = rete.name(fenetre) ##Permet de reset tout le fichier des scores (supprime les high scores donc WOLAH FAUT PAS Y TOUCHER)
def load(self): levels = self.get_levels() if self.level_id > len(levels) - 1: self.app.set_state(main.WIN) self.app.score_manager.save() else: self.app.gui_manager.set_state(gui_manager.FADE_IN) self.app.game_manager.clear_level() self.level_name = levels[self.level_id] self.app.gui_manager.update_times( self.app.score_manager.run_scores.get( util.get_filename(self.mode, self.level_name), 0), self.app.score_manager.get_record(self.mode, self.level_name)) # map_data = levels.levels[self.level_id]() if self.mode == 0: directory = 'levels' elif self.mode == 1: directory = 'survival' with open('{}/{}.dat'.format(directory, self.level_name), 'rb') as f: map_data = pickle.load(f) scene = self.app.renderer.scene model_name, texture = map_data['terrain'] self.app.game_manager.terrain = terrain.Terrain( self.app, model_name, texture) scene.add(self.app.game_manager.terrain.canvas) self.app.game_manager.player.spawn(map_data['spawn_pos']) if self.mode == 0: self.app.game_manager.goal.spawn(map_data['goal_pos']) elif self.mode == 1: self.app.game_manager.goal.despawn() for data in map_data['buildings']: b = building.Building(self.app, building.Building.data[data[0]], data[1:4], data[4]) # b = building.Building(self.app, building.Building.data[data[0]], data[1:4], 0) self.app.game_manager.game_objects.add(b) scene.add(b.canvas) for data in map_data['platforms']: if data[0] == 0: platform.Hedge(self.app, data[1:4]) elif data[0] == 1: platform.InvisiblePlatform(self.app, data[1:4]) elif data[0] == 2: platform.LavaPlatform(self.app, data[1:4]) elif data[0] == 3: platform.Trampoline(self.app, data[1:4]) for data in map_data['elevators']: e = elevator.Elevator(self.app, data[1:4], data[4]) self.app.game_manager.game_objects.add(e) # spawn later scene.add(e.canvas) for data in map_data['powerups']: if data[0] == 0: e = powerup.Fuel(self.app, data[1:4]) self.app.game_manager.game_objects.add(e) # spawn later scene.add(e.canvas) elif data[0] == 1: e = powerup.Health(self.app, data[1:4]) self.app.game_manager.game_objects.add(e) # spawn later scene.add(e.canvas) elif data[0] == 2: e = powerup.SlowTime(self.app, data[1:4]) self.app.game_manager.game_objects.add(e) # spawn later scene.add(e.canvas) for data in map_data['vehicles']: if data[0] == 0: v = car.Car(self.app) elif data[0] == 1: v = helicopter.Helicopter(self.app) v.spawn(data[1:4]) for data in map_data['enemies']: if data[0] == 0: enemy.Turret(self.app, data[1:4]) elif data[0] == 1: enemy.Bee(self.app, data[1:4]) elif data[0] == 2: enemy.BowlSpawner(self.app, data[1:4]) elif data[0] == 3: enemy.InvisibleEnemy(self.app, data[1:4]) self.app.game_manager.set_state(self.mode)
eventManager = global_vars.eventManager _fps = 0.05 _terrainImg = pygame.image.load('dirt.bmp') _tankImg = pygame.image.load('tankorig.bmp') _soldatImg = pygame.image.load('soldatsprite.bmp') _numTanks = ('Tank', 'Tank', 'Tank', 'Soldat', 'Soldat') _tankDimensions = _tankImg.get_rect() _soldatDimensions = _soldatImg.get_rect() fpsClock = pygame.time.Clock() _turnTime = 5 background = global_vars.background window = global_vars.window pygame.display.set_caption('TANKS') global_vars.layerManager.newSprite(background, background.get_rect()) terrainModel = terrain.Terrain(background.get_rect(), background.get_rect().height // 2) global_vars.layerManager.newTerrain(_terrainImg, terrainModel) oldTime = 0 turn = 0 global_vars.idLookup = [0] * len(_numTanks) ctr = None def init(): ''' Initializes tanks, first function called ''' for i in range(len(_numTanks)): if _numTanks[i] == 'Tank': newTank = tank.Tank(_tankImg, pygame.Rect(50 + i * 50 + i * _tankDimensions.width, terrainModel.maxHeight - _tankDimensions.height, _tankDimensions.width, _tankDimensions.height), terrainModel) elif _numTanks[i] == 'Soldat': newTank = tank.Soldat(_soldatImg, pygame.Rect(50 + i * 50 + i * (_soldatDimensions.width + 25),
from defines import * pygame.init() # Set running directory. if os.path.dirname(__file__): os.chdir(os.path.dirname(__file__)) w = world.World() w.new() pygame.display.set_caption("Map") window = pygame.display.set_mode((TERRAIN_WIDTH * 12, TERRAIN_HEIGHT * 14)) screen = pygame.display.get_surface() t = terrain.Terrain() f = feature.Feature() v = view.View(w, t, f, screen, 12, 14) v.locate(10, 10) v.update() pygame.display.flip() while 1: event = pygame.event.wait() if event.type == pygame.QUIT: sys.exit()