def createPlayer(self): viewPort = self.viewPort images = self.images # How big the player starts off. playerStartPos = Point(viewPort.halfWidth, viewPort.halfHeight) # Sets up the movement style of the player. # playerBounds = gd.RectangleBoundary( Rectangle( Point( 0, 220 ), Point( 900, 550 ) ) ) playerBounds = gd.CollisionBoundary() moveStyle = gd.KeyMovementStyle(boundaryStyle=playerBounds) moveStyle.setMoveRate(MOVERATE) moveStyle.setBounceRates(BOUNCERATE, BOUNCEHEIGHT) leftImages = go.ImageAnimation( [images.Jimmy_Pixel_RightL, images.Jimmy_Pixel_Right_WalkL]) rightImages = go.ImageAnimation( [images.Jimmy_Pixel_RightR, images.Jimmy_Pixel_Right_WalkR]) playerImages = go.ImageCollection(left=leftImages, right=rightImages) collisionSpec = go.CollisionSpecification(width=0.38, left=0.32) return go.Player(playerStartPos, moveStyle, size=JIMSIZE, ratio=1.0, image=playerImages, name='Jimmy Pixel', collisionSpecification=collisionSpec)
def build_level(level_path): with open(level_path) as file: level = file.read() x = mg.PADDING y = mg.PADDING neutral_group = pygame.sprite.Group([]) enemy_group = pygame.sprite.Group([]) player_group = pygame.sprite.Group([]) plate_group = pygame.sprite.Group([]) bush_group = pygame.sprite.Group([]) base_group = pygame.sprite.Group([]) water_group = pygame.sprite.Group([]) for ch in level: if ch == "X": neutral_group.add(go.NormalBricksBlock(x, y, 1)) neutral_group.add(go.NormalBricksBlock(x + 25, y, 1)) neutral_group.add(go.NormalBricksBlock(x, y + 25, 1)) neutral_group.add(go.NormalBricksBlock(x + 25, y + 25, 1)) elif ch == 'U': neutral_group.add(go.WhiteBricksBlock(x, y, 300)) elif ch == "S": neutral_group.add(go.NormalBricksBlock(x + 25, y + 25, 1)) base_group.add(go.Base(x + 50, y + 50)) neutral_group.add(go.NormalBricksBlock(x + 50, y + 25, 1)) neutral_group.add(go.NormalBricksBlock(x + 75, y + 25, 1)) neutral_group.add(go.NormalBricksBlock(x + 100, y + 25, 1)) neutral_group.add(go.NormalBricksBlock(x + 25, y + 50, 1)) neutral_group.add(go.NormalBricksBlock(x + 25, y + 75, 1)) neutral_group.add(go.NormalBricksBlock(x + 100, y + 50, 1)) neutral_group.add(go.NormalBricksBlock(x + 100, y + 75, 1)) elif ch == "B": bush_group.add(go.Bush(x, y)) bush_group.add(go.Bush(x + 25, y)) bush_group.add(go.Bush(x, y + 25)) bush_group.add(go.Bush(x + 25, y + 25)) elif ch == "E": enemy_group.add(go.Enemy(x, y, 2, 150, 0.1, 400)) elif ch == "L": plate_group.add(go.Plate(x, y)) elif ch == "W": water_group.add(go.Water(x, y)) elif ch == "P": player_group.add(pygame.sprite.Group([go.Player(x, y, 5, 200, 1)])) if (x + mg.BLOCK_SIZE) > mg.FIELD_WIDTH + mg.PADDING: x = mg.PADDING y += mg.BLOCK_SIZE else: x += mg.BLOCK_SIZE # groups: 0-player 1-neutral, 2-enemy, 3-bullets, 4-boom 5-bushes , 6-plates, 7-base, # 8-gui, 9-spawner 10 - water 12-items return [player_group, neutral_group, enemy_group, pygame.sprite.Group([]), pygame.sprite.Group([]), bush_group, plate_group, base_group, pygame.sprite.Group([go.Frame()]), pygame.sprite.Group([]), water_group, pygame.sprite.Group([]), pygame.sprite.Group([])]
def __init__(self): self.client = client.Client() self.screen = wm.Screen() self.player = go.Player() self.map = wm.Map({"Players": pg.sprite.Group(self.player), "Bullets": pg.sprite.Group()}) self.camera = wm.Camera(self.screen.resolution, self.map.image.get_size()) self.input = pg.key.get_pressed() self.gameOn = True self.clock = pg.time.Clock() self.dt = 0
def createPlayer(self): viewPort = self.viewPort images = self.images # How big the player starts off. playerStartPos = Point(viewPort.halfWidth, viewPort.halfHeight) # Sets up the movement style of the player. # playerBounds = game_dynamics.RectangleBoundary( Rectangle( Point( 0, 220 ), Point( 900, 550 ) ) ) playerBounds = game_dynamics.CollisionBoundary() moveStyle = game_dynamics.KeyMovementStyle(boundaryStyle=playerBounds) moveStyle.setMoveRate(MOVERATE) moveStyle.setBounceRates(BOUNCERATE, BOUNCEHEIGHT) playerImages = go.ImageCollection(left=images.manL, right=images.manR) return go.Player(playerStartPos, moveStyle, size=MANSIZE, ratio=1.0, image=playerImages)
from pygame.locals import * import window_manager as wm import game_objects as go import object_interaction_manager as oim import files_manager as fm # we can imagine that each short cut key have a string corresping to the action he want to do, so in action you may change those bind pg.init() pg.display.init() print(pg.display.Info()) size_window = (800, 600) screen = pg.display.set_mode(size_window) clock = pg.time.Clock() gameOn = True pg.key.set_repeat(10, 10) player = go.Player() groupe_actif = pg.sprite.Group(player) groupe_list = [groupe_actif.copy()] map = wm.Map(groupe_list, groupe_actif) camera = wm.Camera(size_window, map.image.get_size()) map.render(screen, camera.rect) pg.display.update() while gameOn: dt = clock.tick(50) / 1000 player.set_attr("tick", dt) camera.set_attr("tick", dt)
import pygame pygame.init() import random from settings import * import game_objects import time level = game_objects.Level(140) # healthbar = game_objects.Healthbar(15, 100, 20) player = game_objects.Player(level, None) bullet = game_objects.Bullet(player) # obstacle = game_objects.Obstacle(player, x=500, y=300) speed = player.speed game_exit = False jump = False create_bullet = False wallpaper = pygame.image.load('background.png') while not game_exit: for event in pygame.event.get(): if event.type == pygame.QUIT: game_exit = True if event.type == pygame.MOUSEBUTTONDOWN: mouse_x, mouse_y = pygame.mouse.get_pos() # healthbar.damage(1) create_bullet = True
def change_add(self, change): values = change.get("values") if change.get("type") == "Player": temp = game_objects.Player(connection=self.serv_conn, parent_game=self, id=values.get("id"), name=values.get("name"), time=values.get("time"), expensivium=values.get("expensivium"), money=values.get("money")) self.ai.players.append(temp) if change.get("type") == "RobotType": temp = game_objects.RobotType(connection=self.serv_conn, parent_game=self, id=values.get("id"), max_health=values.get("max_health"), range=values.get("range"), splash=values.get("splash"), damage=values.get("damage"), movement=values.get("movement"), attacks=values.get("attacks")) self.ai.robotTypes.append(temp) if change.get("type") == "Robot": temp = game_objects.Robot(connection=self.serv_conn, parent_game=self, id=values.get("id"), x=values.get("x"), y=values.get("y"), owner=values.get("owner"), type=values.get("type"), health=values.get("health"), moves_left=values.get("moves_left"), attack_left=values.get("attack_left"), max_health=values.get("max_health"), range=values.get("range"), splash=values.get("splash"), damage=values.get("damage"), movement=values.get("movement"), attacks=values.get("attacks")) self.ai.robots.append(temp) if change.get("type") == "Factory": temp = game_objects.Factory(connection=self.serv_conn, parent_game=self, id=values.get("id"), x=values.get("x"), y=values.get("y"), owner=values.get("owner")) self.ai.factorys.append(temp) if change.get("type") == "Mine": temp = game_objects.Mine(connection=self.serv_conn, parent_game=self, id=values.get("id"), x=values.get("x"), y=values.get("y"), owner=values.get("owner")) self.ai.mines.append(temp) if change.get("type") == "Tile": temp = game_objects.Tile(connection=self.serv_conn, parent_game=self, id=values.get("id"), x=values.get("x"), y=values.get("y"), wall=values.get("wall")) self.ai.tiles.append(temp) return True
game_field = gamefield.GameField() game_field.music.play() class ObjectsRepository: trees = [] bricks = [] boxes = [] box_targets = [] player = (0, 0) level = 0 ob = ObjectsRepository() gamefield.load_level("1", ob, batch) player = game_objects.Player(None, ob.player) # TODO: избавиться от лишних объектов trees = ob.trees bricks = ob.bricks boxes = ob.boxes box_targets = ob.box_targets window = pyglet.window.Window(width=(CELL_SIZE * 10), height=(CELL_SIZE * 10), caption="Gecko Soko") window.set_mouse_visible(True) fps_display = pyglet.window.FPSDisplay(window) fps_display.label.y = 0 label = pyglet.text.Label('[{0}, {1}]'.format(player.row, player.column),
import pygame pygame.init() import random from settings import * import game_objects import time level = game_objects.Level(140) healthbar = game_objects.Healthbar(100, 200, 40) player = game_objects.Player(level, healthbar) bullet = game_objects.Bullet(player) # obstacle = game_objects.Obstacle(player, x=500, y=300) speed = player.speed game_exit = False jump = False create_bullet = False # wallpaper = pygame.image.load('background.png') while not game_exit: for event in pygame.event.get(): if event.type == pygame.QUIT: game_exit = True if event.type == pygame.MOUSEBUTTONDOWN: mouse_x, mouse_y = pygame.mouse.get_pos() # healthbar.damage(1) create_bullet = True