Esempio n. 1
0
    def see_player(self, room):
        player = room.level.player

        if not self.alive or not player.alive:
            self.sees_player = False
            return

        if abs(player.collider.y - self.collider.y) > 2 * helpers.TILE_SIZE:
            self.sees_player = False
            return

        if player.x > self.x:
            width = abs(self.collider.right - player.collider.left)
            collider = gameobject.GameObject(self.collider.right,
                                             self.collider.centery, width,
                                             helpers.TILE_SIZE)
        else:
            width = abs(self.collider.left - player.collider.right)
            collider = gameobject.GameObject(self.collider.left - width,
                                             self.collider.centery, width,
                                             helpers.TILE_SIZE)

        if collider.get_collisions(room):
            self.sees_player = False
        else:
            self.sees_player = True
 def test_crossing_func(self):
     game_object_1 = go.GameObject(50, 50, 50)
     game_object_2 = go.GameObject(50, 50, 50)
     result = go.has_crossing(game_object_1, game_object_2, 16)
     self.assertTrue(result)
     game_object_1 = go.GameObject(50, 51, 50)
     game_object_2 = go.GameObject(50, 100, 50)
     result = go.has_crossing(game_object_1, game_object_2, 16)
     self.assertFalse(result)
Esempio n. 3
0
 def __init__(self):
     self._running = True
     self._display_surf = None
     self.size = self.weight, self.height = 720, 720
     self.background = pygame.Surface(self.size)
     self.scenes = ["some_path", "some_other_path", "etc_you_get_the_idea"]
     self.current_scene = scene.Scene(self.scenes[0], player.Player(), [
         collectiblegameobject.CollectibleGameObject(
             "key.png", 50, 50, "Chujka", "Klucz do kurwy"),
         gameobject.GameObject("bed.png", 150, 150, "Luszko"),
         gameobject.GameObject("desk.png", 350, 300, "Dzwi")
     ])
     self.font = pygame.font.Font("assets/BebasNeue.otf", 15)
Esempio n. 4
0
 def __init__(self, surfaces, frameOffsets, x, y, totalDuration,
              frameDuration):
     self.gob = GameObjects.GameObject(surfaces, frameOffsets)
     self.x = x
     self.y = y
     self.hmirror = False
     self.vmirror = False
     self.totalDuration = totalDuration
     self.gob.animDur = frameDuration
     self.startTime = umachine.time_ms()
Esempio n. 5
0
 def spawn(self):
     if not self.representation:
         actual_object_size = Size(
             self.settings["tile_size"].width * self.settings["scale"] *
             game.settings.get('screen')["scale"],
             self.settings["tile_size"].height * self.settings["scale"] *
             game.settings.get('screen')["scale"])
         self.representation = gameobject.GameObject(
             self.settings["name"], self.settings["position"],
             actual_object_size, self.charset_lib["default"])
         game.add(self.representation)
Esempio n. 6
0
def initGame():
    # Create "main menu" selectable menu items
    mMenu = menu.Selectable(Game.font, Game.screen)
    mMenuItem = menu.SelectableItem("New Game", constants.ACTION_NEWGAME)
    mMenu.addItem(mMenuItem)
    mMenuItem = menu.SelectableItem("Quit", constants.ACTION_QUIT)
    mMenu.addItem(mMenuItem)
    Game.menus.append(mMenu)
    # Create "choose mode" selectable menu items
    mMenu = menu.Selectable(Game.font, Game.screen)
    mMenuItem = menu.SelectableItem("1 Player", constants.ACTION_MODE1P)
    mMenu.addItem(mMenuItem)
    mMenuItem = menu.SelectableItem("2 Players", constants.ACTION_MODE2P)
    mMenu.addItem(mMenuItem)
    Game.menus.append(mMenu)
    # Create "score" texts
    mText = menu.Text(Game.font, Game.screen)
    mTextItem = menu.TextItem(
        Game.font, str(Game.score[constants.PLAYER_ONE]),
        (constants.WINDOW_WIDTH / 2.0) + (constants.WINDOW_WIDTH / 6),
        ((constants.WINDOW_HEIGHT - constants.GAMEAREA_HEIGHT) / 2.0) -
        (constants.WALL_THICKNESS / 2.0))
    mText.addItem(mTextItem)
    mTextItem = menu.TextItem(
        Game.font, str(Game.score[constants.PLAYER_TWO]),
        (constants.WINDOW_WIDTH / 2.0) - (constants.WINDOW_WIDTH / 6),
        ((constants.WINDOW_HEIGHT - constants.GAMEAREA_HEIGHT) / 2.0) -
        (constants.WALL_THICKNESS / 2.0))
    mText.addItem(mTextItem)
    Game.texts.append(mText)
    # Create pause text
    mText = menu.Text(Game.font, Game.screen)
    mTextItem = menu.TextItem(Game.font, "'P' Unpauses 'Esc' Quits",
                              (constants.WINDOW_WIDTH / 2.0),
                              (constants.WINDOW_HEIGHT / 3))
    mText.addItem(mTextItem)
    Game.texts.append(mText)
    # Player 1 paddle
    mGameObject = gameobject.Paddle(Game.screen, constants.PLAYER_ONE)
    Game.paddles.append(mGameObject)
    # Player 2 paddle
    mGameObject = gameobject.Paddle(Game.screen, constants.PLAYER_TWO)
    Game.paddles.append(mGameObject)
    # Ball
    mGameObject = gameobject.Ball(Game.screen)
    Game.balls.append(mGameObject)
    # Game area
    mGameObject = gameobject.GameObject(
        Game.screen, constants.GAMEOBJECT_WALL, constants.GAMEAREA_WIDTH,
        constants.GAMEAREA_HEIGHT, constants.GAMEAREA_X, constants.GAMEAREA_Y,
        constants.WALL_THICKNESS, constants.WALL_COLOR)
    Game.wall = mGameObject
Esempio n. 7
0
    def update(self, room):
        super().update(room)
        player = room.level.player

        height = abs(self.collider.y - player.collider.y)
        collider = gameobject.GameObject(self.collider.bottom,
                                         self.collider.left,
                                         self.collider.width, height)

        for c in collider.get_collisions(room):
            if c is not player and c is not self:
                self.sees_player = False
                break
        else:
            self.sees_player = True
            self.gravity_scale = 1
Esempio n. 8
0
 def read_levels(self):
     for level_name, level in self.levels.items():
         level.tileset = level.settings["tileset"]
         level.heightmap = level.settings["heightmap"]
         level.terrainmap = level.settings["terrainmap"]
         if "tile_width" in level.settings:
             level.tile_width = int(level.settings["tile_width"])
         if game.settings.get('debug')['on']:
             debug(level.settings, "Loaded Level " + level_name)
         for object_name, object_settings in level.settings["gobjects"].items():
             gobject_from_level_dict = game.add(
                 gameobject.GameObject(object_name,
                                       Position(object_settings['position'][0],
                                                object_settings['position'][1]),
                                       Size(object_settings["size"][0],
                                            object_settings["size"][1])))
             gobject_from_level_dict.chimg(object_settings["image"])
Esempio n. 9
0
    def __init__(self,
                 x,
                 y,
                 width,
                 height,
                 health,
                 path,
                 group=gameobject.CollisionGroup.enemies):
        super().__init__(x, y, width, height, path, group)

        self.spawn_x = x
        self.spawn_y = y
        self.alive = True
        self.bullets = []
        for s in self.sprites:
            s.play('idle')
        self.max_health = health
        self.health = self.max_health
        self.sees_player = False
        self.vision = gameobject.GameObject(0, 0, 0, 0)
 def test_camera_update(self):
     camera = go.Camera(500, 500)
     game_object_1 = go.GameObject(50, 50, 50)
     camera.update(game_object_1)
     self.assertTrue(True)
 def test_gameobject_explosion(self):
     camera = go.Camera(500, 500)
     game_object_1 = go.GameObject(50, 50, 50)
     game_display = s.GAME_DISPLAY
     game_object_1.draw_explosion(game_display, camera)
     self.assertTrue(True)
 def test_initialization(self):
     game_object = go.GameObject(50, 50, 50)
     self.assertTrue(isinstance(game_object, go.GameObject))
Esempio n. 13
0
 def __init__(self):
     super().game_objects.append(gameobject.GameObject())
     super().game_objects.append(gameobject.GameObject())
     super().game_objects.append(gameobject.GameObject())
Esempio n. 14
0
def loadLevel():
    Game.bricks[:] = []
    Game.paddles[:] = []
    Game.balls = []
    Game.powerUps = []
    Game.wall = None
    level = [[]]

    # Load the level from a file
    filename = os.path.join(os.getcwd(), str(Game.levelNow) + ".txt")
    print "Trying to open " + filename

    if fileAccessible(filename, 'r') == True:
        with open(filename) as f:
            level = f.readlines()
        constants.LEVEL_WIDTH = len(level[0]) - 1
        constants.LEVEL_HEIGHT = len(level)
    else:
        print "Could not open " + filename
        print "Creating a dummy level"
        Game.levelNow = 0
        constants.LEVEL_WIDTH = 10
        constants.LEVEL_HEIGHT = 6
        level = [['1' for x in range(constants.LEVEL_WIDTH)]
                 for x in range(constants.LEVEL_HEIGHT)]

    # Adjust the dimensions of bricks, paddles and game area
    constants.BRICK_WIDTH = ceil(constants.WINDOW_WIDTH *
                                 (1.0 / (constants.LEVEL_WIDTH + 15)))
    if constants.BRICK_THICKNESS == 0:
        constants.GAMEAREA_WIDTH = ceil(constants.WALL_THICKNESS + (
            (constants.BRICK_WIDTH + constants.BRICK_THICKNESS) *
            constants.LEVEL_WIDTH) + 1)
    else:
        constants.GAMEAREA_WIDTH = ceil(constants.WALL_THICKNESS + (
            (constants.BRICK_WIDTH + constants.BRICK_THICKNESS) *
            constants.LEVEL_WIDTH))
    constants.GAMEAREA_X = ceil((constants.WINDOW_WIDTH / 2.0) -
                                (constants.GAMEAREA_WIDTH / 2.0))

    constants.BALL_STARTINGSPEED = constants.WINDOW_HEIGHT * 0.006
    constants.PADDLE_STARTINGSPEED = constants.WINDOW_WIDTH * 0.005
    constants.PADDLE_WIDTH = ceil(constants.WINDOW_WIDTH * 0.10)
    constants.PADDLE_HEIGHT = ceil(constants.PADDLE_WIDTH * 0.125)

    # Create game objects
    # Player 1 paddle
    mGameObject = gameobject.Paddle(Game.screen, constants.PLAYER_ONE)
    Game.paddles.append(mGameObject)
    # Player 2 paddle
    mGameObject = gameobject.Paddle(Game.screen, constants.PLAYER_TWO)
    Game.paddles.append(mGameObject)
    # The ball
    mGameObject = gameobject.Ball(Game.screen)
    Game.balls.append(mGameObject)
    # The game area
    mGameObject = gameobject.GameObject(
        Game.screen, constants.GAMEOBJECT_WALL, constants.GAMEAREA_WIDTH,
        constants.GAMEAREA_HEIGHT, constants.GAMEAREA_X, constants.GAMEAREA_Y,
        constants.WALL_THICKNESS, constants.WALL_COLOR)
    Game.wall = mGameObject
    # Balls left indicator
    updateBallIndicator()

    if Game.numPlayers == 1:
        Game.paddles[constants.PLAYER_TWO].disable()
    elif Game.numPlayers == 2:
        Game.paddles[constants.PLAYER_TWO].enable()

    for i in range(0, constants.LEVEL_HEIGHT):
        for j in range(0, constants.LEVEL_WIDTH):
            if level[i][j] != '0':
                if constants.BRICK_THICKNESS == 0:
                    padding = 1
                else:
                    padding = 0
                mGameObject = gameobject.Brick(
                    Game.screen, level[i][j],
                    (constants.GAMEAREA_X +
                     floor(constants.WALL_THICKNESS / 2.0) +
                     ceil(constants.BRICK_THICKNESS / 2.0) +
                     ((constants.BRICK_WIDTH + constants.BRICK_THICKNESS) * j)
                     + padding),
                    (constants.GAMEAREA_Y +
                     floor(constants.WALL_THICKNESS / 2.0) +
                     ceil(constants.BRICK_THICKNESS / 2.0) +
                     ((constants.BRICK_HEIGHT + constants.BRICK_THICKNESS) * i)
                     + padding), i, j)
                Game.bricks.append(mGameObject)
            print level[i][j],
        print ""

    Game.bricksLeft = len(Game.bricks)
    print "level loaded"
Esempio n. 15
0
import pygame, draw, gameobject, scene, events, text, walker, platformer, snake, threading, space
from pygame.locals import *

pygame.init()
pygame.display.set_caption('dbd')
clock = pygame.time.Clock()

bed = gameobject.GameObject('bed', 'assets/bed.png', 400, 200)
sleepy = gameobject.GameObject('sleepy', 'assets/wakingup.png', 400, 200)
textbox = gameobject.GameObject('textbox', 'assets/textbox.png', 64, 350, 128)
walker = walker.Walker('walker', 'assets/walkingd.png', 570, 200)
lunch = gameobject.GameObject('lunch', 'assets/lunchlady.png', 320, 200)
essay = gameobject.GameObject('essay', 'assets/essay.png', 340, 100, 32, 32, 8)

bedscene = scene.Scene()
bedscene.add(bed)
bedscene.add_actor(sleepy)
lunchscene = scene.Scene()
lunchscene.add_actor(walker)
lunchscene.add(lunch)
essayscene = scene.Scene()
essayscene.add_actor(essay)
scenes = [bedscene, lunchscene, essayscene]
curscene = 0
gamevars = {'state': 1}


def state(s=None):
    if s:
        gamevars['state'] = s
    return gamevars['state']
Esempio n. 16
0
tilemap.set_tile(0xb, tileSize, tileSize, data.tile11)
tilemap.set_tile(0xc, tileSize, tileSize, data.tile12)
tilemap.set_tile(0xd, tileSize, tileSize, data.tile13)
tilemap.set_tile(0xe, tileSize, tileSize, data.tile14)
tilemap.set_tile(0xf, tileSize, tileSize, data.tile15)

# Setup global variables
glob.viewPortX = 0
glob.viewPortY = 0

# setup sprite group
all_objects = sprite.Group()
all_objects_list = []

#Init game objects
targetCityGob = GameObjects.GameObject(
    [data.targetCity6x5_f1, data.targetCity6x5_f2], [[0, 0], [0, 0]])
targetCityGob.wx = 282 - 3
targetCityGob.wy = 75 - 3
targetCityGob.active = False
all_objects.add(targetCityGob)
all_objects_list.append(targetCityGob)

heroGob = GameObjects.GameObject([data.heroUp_f1, data.heroUp_f2],
                                 [[0, 0], [0, 0]])
dustGob1 = GameObjects.GameObject(
    [data.dustRight_f1, data.dustRight_f2, data.dustRight_f3],
    [[0, 0], [0, 0], [0, 0]])
dustGob1.animMode = "once"

infectedPeople = GameObjects.GameObject([data.infected_f1, data.infected_f2],
                                        [[0, 0], [0, 0]])