Example #1
0
    def __init__(self, name, range, map_conf, *args, **kwargs):
        self.name = name
        self.range = range
        self.map_conf = map_conf
        super(display_sensors, self).__init__(*args, **kwargs)
        map = pyglet.image.load("map.png")
        heatbar = pyglet.image.load("heatbar.png")
        self.map = pyglet.sprite.Sprite(map, x=0, y=0)
        self.heatbar = pyglet.sprite.Sprite(heatbar, x=map.width, y=0)
        self.height = self.heatbar.height
        self.set_caption(name)
        self.set_size(map.width + heatbar.width, map.height)
        self.robot = GameObject(0, 0, "robot.png")
        self.pos = []
        self.pxPos = [[], []]
        self.color = []

        rospy.Subscriber(self.name, Int64, self.callback)
        self.sensor = 0
        rospy.Subscriber("/amcl_pose", PoseWithCovarianceStamped,
                         self.get_position)
        self.position = PoseWithCovarianceStamped()
        self.waypoints = []
        self.PxWaypoints = []
        self.key = None
        self.frame_id = rospy.get_param('~goal_frame_id', 'map')
        # Get a move_base action client
        self.client = actionlib.SimpleActionClient('move_base', MoveBaseAction)
        rospy.loginfo('Connecting to move_base...')
        self.client.wait_for_server()
        rospy.loginfo('Connected to move_base.')
        rospy.Subscriber("/move_base/status", GoalStatusArray, self.get_status)
        self.status = 0
 def __init__(self, width, height, color, grid):
     GameObject.__init__(self, width, height, color, grid)
     self.ai = None
     self.fed = 0
     self.lastState = None
     self.lastAction = None
     self.previousPositionTuples = []
Example #3
0
 def __init__(self):
     self.monster = GameObject("../Images/Monsters/1.png", 960, 660)
     self.radishes = []
     self.tacos = []
     self.window = pygame.display.set_mode((1920, 1080))
     self.clock = pygame.time.Clock()
     self.isGameOver = False
Example #4
0
    def __init__(self, gridPosX, gridPosY, main, name, farmindex, boardPosX,
                 boardPosY):
        super().__init__(gridPosX, gridPosY, main)
        # print(f'GridposX = {gridPosX}', f'GridposY = {gridPosY}')
        self.posX = GameObject.getPos(self)[0]
        self.posY = GameObject.getPos(self)[1]
        self.boardPosX = boardPosX
        self.boardPosY = boardPosY
        self.__sizeX = 64
        self.__sizeY = 64
        self.defaultPosX = self.posX
        self.defaultPosY = self.posY
        self.farmindex = farmindex

        self.__degree = -360
        self.__angle = -720

        self.name = name  # This is here because why not
        self.main = main
        self.shakeCount = 0

        self.time = 2000
        self.growTimer = self.time

        self.isOccupied = False
        self.isShaking = False
        self.isWatered = False
        self.isGrown = False
        self.animating = False

        self.islocked = True
        self.isHardLocked = True
Example #5
0
	def onTeleportSpaceCB(self, spaceCellMailbox, spaceUType, position, direction):
		"""
		defined.
		baseapp返回teleportSpace的回调
		"""
		self.teleportingSpaceUType = spaceUType
		GameObject.onTeleportSpaceCB(self, spaceCellMailbox, spaceUType, position, direction)
Example #6
0
 def __init__(self, width, height, color, grid):
     GameObject.__init__(self, width, height, color, grid)
     self.ai = None
     self.fed = 0
     self.lastState = None
     self.lastAction = None
     self.previousPositionTuples = []
    def __init__(self, sprite_can, io):
        GameObject.__init__(self)

        self.target_obj = sprite_can
        self.io_device = io

        self.max_speed = self.target_obj.height * 0.025
        self.jump_velocity = self.target_obj.height * 0.05
Example #8
0
 def __init__(self, x, y, w, h, owner):
     GameObject.__init__(self, x, y, w, h)
     self.color = choice([colors.BLACK, colors.RED2])
     self.owner = owner
     self.x = x
     self.y = y
     self.r = (w**2 + h**2)**0.5
     self.mouse_button_pressed = False
Example #9
0
    def __init__(self):
        GameObject.init_object(self)

        # Components definitions
        self.transform = Transform(Vector2(100, 100, 1), Vector2(0, 0, 0),
                                   Vector2(0, 0, 0))
        self.sprite = Resources.load("pompier.png")
        self.sprite = pygame.transform.scale(self.sprite, (100, 100))
Example #10
0
	def testNonIntegerMovement(self):
		gameMap = GameMap(1000)
		gameObject = GameObject([1, 0], 'drone', 'owen')
		gameObject.velocity = [-0.5, 0]
		gameMap.addObject(gameObject)

		gameMap.update()
		self.assertEqual(gameObject.loc, [0.5, 0])
Example #11
0
 def __init__(self, *args, **kwargs):
     super().__init__(*args, **kwargs)
     self.set_location(400, 100)
     self.frame_rate = 1 / 60.0
     self.player = GameObject(posx=200, posy=225, image="Mario_Super.png")
     self.background = BackgroundObject(posx=0,
                                        posy=0,
                                        image="background_0.jpg")
Example #12
0
def init(scene_to_init):
    score = 0
    cat = GameObject('cat_asset', 'cat')
    roof = GameObject('roof_asset', 'roof')
    scene_to_init.add_object(cat)
    scene_to_init.add_object(roof)

    return clear_screen()
Example #13
0
	def __init__(self):
		GameObject.__init__(self)
		self.createInNewSpace(None)
		
		self.spaceUTypeB = self.cellData["spaceUType"]
		
		# 这个地图上创建的entity总数
		self.tmpCreateEntityDatas = list(d_spaces.datas[self.spaceUTypeB].get("entities", []))
 def __init__(self, x, y, w, h, color, offset):
     GameObject.__init__(self, x, y, w, h)
     self.color = color
     self.offset = offset
     self.moving_left = False
     self.moving_right = False
     self.moving_up = False
     self.moving_down = False
Example #15
0
class GameWindow(pyglet.window.Window):
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.set_location(400, 100)
        self.frame_rate = 1/60.0
        self.player = GameObject( posx = 200, posy = 200 ,image = "Mario_Super.png")
        self.enemie1 = Enemies(posx=500, posy=200, image="goomba_1.png")
        self.enemie2 = Enemies(posx=300, posy=200, image="goomba_1.png")
        self.background = BackgroundObject(posx = 0, posy = 0, image ='background_0.jpg')
        self.brick = BackgroundObject(posx=0, posy=0, image='brick.png')


    def on_key_press(self, symbol, modifiers):
        if symbol == key.RIGHT:
            self.player.velx = 150
            self.background.velx = -150
        if symbol == key.LEFT:
            self.player.velx = -150
            self.background.velx = 150
        if symbol == key.UP:
            self.player.vely = 150
        if symbol == key.DOWN:
            self.player.vely = -150
        if symbol == key.A:
            self.player.imageList = self.player.image_list_attack
        if symbol == key.W:
            self.player.imageList = self.player.image_list_walk
            self.background.velx = -150
        if symbol == key.S:
            self.player.imageList = self.player.image_list_swim
        if symbol == key.D:
            self.player.imageList = self.player.image_list_dash
        if symbol == key.J:
            self.player.imageList = self.player.image_list_jump
        if symbol == key.C:
            self.player.imageList = self.player.image_list_climb

    def on_key_release(self, symbol, modifiers):
        if symbol in (key.RIGHT, key.LEFT):
            self.player.velx = 0
            self.background.velx = 0
        if symbol in (key.UP, key.DOWN, key.C):
            self.player.vely =0
        if symbol in (key.A, key.W, key.S, key.D, key.J, key.C):
            self.player.imageList = self.player.image_list_default
            self.background.velx = 0

    def on_draw(self):
        self.clear()
        self.background.draw()
        self.brick.draw()
        self.player.draw()
        self.enemie1.draw()
        self.enemie2.draw()

    def update(self, dt):
        self.player.update(dt)
        self.background.update()
Example #16
0
    def onTeleportSpaceCB(self, spaceCellMailbox, spaceUType, position,
                          direction):
        """
		defined.
		baseapp返回teleportSpace的回调
		"""
        self.teleportingSpaceUType = spaceUType
        GameObject.onTeleportSpaceCB(self, spaceCellMailbox, spaceUType,
                                     position, direction)
Example #17
0
 def test_syntax_checker_good_game1(self):
     # minimal valid game
     game_internal = Game(
         [[GameObject('starting_room'),
           GameObject('final_room')], [],
          [GamePassage(11, 'starting_room', 'final_room', 'N', 'S')], [],
          [], 'final_room', {}])
     assert (GameSyntaxChecker().check(game_internal) == '')
     assert (GameSolver().solve(game_internal) == [['go', 'N']])
Example #18
0
 def __init__(self, texture, application):
     GameObject.__init__(self)
     self.sprite = sf.Sprite(texture)
     self.addChild(self.sprite)
     self.application = application
     x = texture.width / 2
     y = texture.height / 2
     self.origin = sf.Vector2(texture.width / 2, texture.height / 2)
     self.animations = Animation.createRandomGroup(self)
Example #19
0
    def alterHealth(self,
                    dHealth,
                    incomingImpulse,
                    flinchValue,
                    overcharge=False):
        GameObject.alterHealth(self, dHealth, incomingImpulse, flinchValue,
                               overcharge)

        self.updateHealthUI()
Example #20
0
 def test_syntax_checker_wrong_game_9(self):
     game_internal = Game([[GameObject('roomA'),
                            GameObject('roomB')], [],
                           [
                               GamePassage(11, 'roomA', 'roomB', 'N', 'S'),
                               GamePassage(12, 'roomB', 'roomA', 'W', 'S')
                           ], [], [], 'roomB', {}])
     assert (GameSyntaxChecker().check(game_internal) ==
             'multiple passages between the rooms roomA, roomB')
Example #21
0
    def __init__(self):
        GameObject.init_object(self)

        # Components definitions
        self.transform = Transform(Vector2(0, 0, 0), Vector2(0, 0, 0),
                                   Vector2(0, 0, 0))
        self.sprite = Resources.load("flamme.png")
        self.sprite = pygame.transform.scale(self.sprite, (50, 50))
        self.animator = AnimatorController()
Example #22
0
 def __init__(self, x, y, w, h, dots):
     GameObject.__init__(self, x + 10, y + 10, w, h)
     self.color = choice([colors.BLACK, colors.RED2])
     self.r = (w**2 + h**2)**0.5
     self.mouse_button_pressed = False
     self.live = 0
     self.mo = True
     self.dots = dots
     self.time = 0
Example #23
0
 def __init__(self, *args, **kwargs):
     super().__init__(*args, **kwargs)
     self.set_location(400, 100)
     self.frame_rate = 1/60.0
     self.player = GameObject( posx = 200, posy = 200 ,image = "Mario_Super.png")
     self.enemie1 = Enemies(posx=500, posy=200, image="goomba_1.png")
     self.enemie2 = Enemies(posx=300, posy=200, image="goomba_1.png")
     self.background = BackgroundObject(posx = 0, posy = 0, image ='background_0.jpg')
     self.brick = BackgroundObject(posx=0, posy=0, image='brick.png')
Example #24
0
    def cleanup(self):
        if self.blastModel is not None:
            self.blastModel.removeNode()
            self.blastModel = None

        if self.collider is not None and not self.collider.isEmpty():
            self.collider.clearPythonTag(TAG_OWNER)
            self.collider.removeNode()
        self.collider = None

        GameObject.cleanup(self)
Example #25
0
 def test_syntax_checker_wrong_game_10(self):
     game_internal = Game(
         [[GameObject('roomA'),
           GameObject('roomB'),
           GameObject('roomC')], [],
          [
              GamePassage(11, 'roomA', 'roomB', 'N', 'S'),
              GamePassage(11, 'roomB', 'roomC', 'W', 'S')
          ], [], [], 'roomC', {}])
     assert (GameSyntaxChecker().check(game_internal) ==
             'passage identifiers are not unique, 11')
Example #26
0
 def test_syntax_checker_wrong_game29(self):
     game_internal = Game(
         [[GameObject('starting_room'),
           GameObject('final/room')], [],
          [GamePassage(11, 'starting_room', 'final/room', 'N', 'S')], [],
          [], 'final/room', {}])
     verdict = GameSyntaxChecker().check(game_internal)
     assert (
         verdict ==
         'game object names can contain only lower case alphabets and _, final/room'
     )
 def __init__(self):
     super().__init__()
     self.atk = 0
     self.hp = 0
     self.hpUI = GameObject()
     self.atkUI = GameObject()
     self.statusFont = None
     self.hpUIdpos = (35, 35)
     self.atkUIdpos = (2, 35)
     self.type = 0
     self.owner = 0
     self.state = 0
Example #28
0
    def __init__(self, screen):
        images = dict()
 
        for face in ["Front", "Left", "Right"]:
            try:
                images[face] = pygame.image.load(Player.src.format(face))
            except:
                print("Could not load player {0} image".format(face))
                exit(-1)
        
        new_y = screen.get_rect().bottom - images["Front"].get_rect().top
        GameObject.__init__(self, screen, images, "Front", 0, new_y, 0, 0, False)
Example #29
0
 def test_syntax_checker_wrong_game_15(self):
     game_internal = Game([[
         GameObject('roomA'),
         GameObject('roomC'),
         GameObject('roomB'),
         GameObject('roomC')
     ], [],
                           [
                               GamePassage(11, 'roomA', 'roomB', 'N', 'S'),
                               GamePassage(12, 'roomB', 'roomC', 'N', 'S')
                           ], [], [], 'roomC', {}])
     verdict = GameSyntaxChecker().check(game_internal)
     assert (verdict == 'found two objects with the same name, roomC')
Example #30
0
 def test_syntax_checker_wrong_game_11(self):
     game_internal = Game([[
         GameObject('roomA'),
         GameObject('roomB'),
         GameObject('roomC'),
         GameObject('roomD')
     ], [],
                           [
                               GamePassage(11, 'roomA', 'roomB', 'N', 'S'),
                               GamePassage(12, 'roomC', 'roomD', 'N', 'S')
                           ], [], [], 'roomB', {}])
     assert (GameSyntaxChecker().check(game_internal) ==
             'not all rooms are accessible, roomC')
Example #31
0
 def test_syntax_checker_wrong_game_6(self):
     game_internal = Game([[
         GameObject('roomA'),
         GameObject('roomB'),
         GameObject('roomC'),
         GameObject('roomD')
     ], [],
                           [
                               GamePassage(11, 'roomA', 'roomB', 'N', 'S'),
                               GamePassage(12, 'roomB', 'roomC', 'N', 'S')
                           ], [], [], 'roomD', {}])
     assert (GameSyntaxChecker().check(game_internal) ==
             'final room is not reachable')
Example #32
0
    def __init__(self, screen):
        images = dict()

        for face in ["Front", "Left", "Right"]:
            try:
                images[face] = pygame.image.load(Player.src.format(face))
            except:
                print("Could not load player {0} image".format(face))
                exit(-1)

        new_y = screen.get_rect().bottom - images["Front"].get_rect().top
        GameObject.__init__(self, screen, images, "Front", 0, new_y, 0, 0,
                            False)
Example #33
0
    def __init__(self, terminalHandler=stdout, debug=None):
        super().__init__(terminalHandler, debug)

        self.bus = smbus.SMBus(1)
        self.bus.write_byte(constants.BAT_BUTTONS_I2C_ADDRESS, 0xFF)
        self.bus.write_byte(constants.BALL_LED_I2C_ADDRESS, 0xFF)

        self.batButtonState = 0xFF

        GPIO.setmode(GPIO.BCM)
        GPIO.setup(constants.BAT_BUTTONS_INTERRUPT_PIN, GPIO.IN, pull_up_down=GPIO.PUD_UP)
        GPIO.add_event_detect(
            constants.BAT_BUTTONS_INTERRUPT_PIN, GPIO.FALLING, callback=self.handleControllerInterrupt)

        for pin in constants.LED_PINS:
            GPIO.setup(pin, GPIO.OUT)
        self.lastLED = None

        self.scoreLeft = Number(0, 29, 2, "cyan")
        self.scoreRight = Number(0, 49, 2, "pink")

        self.leftController = CPLDHandler(
            self.bus, constants.LEFT_BAT_I2C_ADDRESS
        )
        self.rightController = OnBoardADCHandler(self.bus, constants.RIGHT_BAT_I2C_ADDRESS, constants.RIGHT_BAT_CMD_CODE)

        self.batLeft = Bat(3, 12, 6, "cyan", self.leftController)
        self.batRight = Bat(77, 12, -6, "pink", self.rightController)

        self.edges = [
            GameObject(0, -1, constants.PONG_WIDTH, 1, "red"),
            #deleted the "+1" that followed constants.PONG_HEIGHT
            GameObject(0, constants.PONG_HEIGHT + 1,
                       constants.PONG_WIDTH, 1, "red"),
        ]

        self.ball = Ball(
            10, 20, constants.SERVE_SPEED, "green", self.edges +
            [self.batLeft, self.batRight], 25, 1, 1
        )

        self.addObjects(
            [self.scoreLeft, self.scoreRight, self.batLeft, self.batRight, self.ball]
            + self.edges
        )

        self.ball.serving = 'right'
        self.serves = 0

        self.gameOver = False
        self.winnerText = None
Example #34
0
 def test_syntax_checker_wrong_game16(self):
     game_internal = Game([[
         GameObject('starting_room', [],
                    [GameObject('door', [GameObjectAttribute.IMMOBILE])]),
         GameObject('ending_room')
     ], [],
                           [
                               GamePassage(11, 'starting_room',
                                           'ending_room', 'N', 'S',
                                           [GameObjectAttribute.INVISIBLE])
                           ], [GamePassageRevealAction('', '', 11)], [],
                           'ending_room', {}])
     verdict = GameSyntaxChecker().check(game_internal)
     assert (verdict == 'found an action without actors')
Example #35
0
    def __init__(self, pos, auraModel, contents):
        GameObject.__init__(self, pos, auraModel, None, 100, 0, "item", 1, 0)

        self.actor.setBillboardAxis()
        self.actor.setTransparency(True)
        self.actor.setLightOff(1)

        self.weaponCollider.node().setFromCollideMask(0)
        self.weaponCollider.node().setIntoCollideMask(MASK_FROM_PLAYER)
        self.weaponCollider.node().modifySolid(0).setTangible(False)
        self.weaponCollider.setZ(-self.height*0.5)

        self.contents = contents
        self.contents.root.setPos(pos)
    def __init__(self):
        GameObject.__init__(self)


        # MOVEMENTS PARAMETERS #
        self.direction = None
        self.speed_x = 6 # 6 pixels per tick
        self.speed_y = 10  # Jumping

        self.velocity_x = 0 # Negative means move left, positive means move right
        self.velocity_y = 0 # Negative means move up, positive means move down


        self.isGrounded = False

        self.isDead = False
Example #37
0
    def __init__(self, screen, direction, start_x):
        images = dict()
 
        for face in ["Left", "Right"]:
            try:
                images[face] = pygame.image.load(Bullet.src.format(face))
            except:
                print("Could not load bullet {0} image".format(face))
                exit(-1)
        
        new_y = screen.get_rect().bottom - images[direction].get_rect().top - 50
        
        if direction == "Left":
            dx = 15
        else:
            dx = -15
        GameObject.__init__(self, screen, images, direction, start_x, new_y, dx, 0, False)
Example #38
0
	def testVectorMoveWithoutCollision(self):
		gameMap = GameMap(1000)
		gameObject = GameObject([0, 0], 'drone', 'owen')
		gameObject.velocity = [1, 2]
		gameObject.acceleration = [-1, -1]
		gameMap.addObject(gameObject)

		gameMap.update()
		self.assertEqual(gameObject.loc, [1,2])

		gameMap.update()
		self.assertEqual(gameObject.loc, [1, 3])

		gameMap.update()
		self.assertEqual(gameObject.loc, [0, 3])

		gameMap.update() #Here, instead of going negative, the vectorMovementWithoutCollision function does nothing
		self.assertEqual(gameObject.loc, [0, 3])
Example #39
0
    def __init__(self, screen):
        images = dict()
 
        for face in ["Left", "Right"]:
            try:
                images[face] = pygame.image.load(Enemy.src.format(face))
            except:
                print("Could not load enemy {0} image".format(face))
                exit(-1)


        screenRect = screen.get_rect()
        imgRect = images["Right"].get_rect()
        new_x = screenRect.right - imgRect.right - 5
        new_y = screenRect.bottom - imgRect.bottom
            
        GameObject.__init__(self, screen, images, "Right", new_x, new_y, -1, 0, False)
        self.dirty = 2
Example #40
0
 def addObject(self, peer, newObject):
     search = True
     objectId = 1
     while search:
         lastId = objectId
         for currentObject in self._gameObjects:
             if currentObject.getId() == objectId:
                 objectId += 1
         if lastId == objectId:
             search = False
     newObject = GameObject(objectId, newObject['name'], newObject['image'], newObject['strength'], newObject['defense'], newObject['reliability'])
     self._gameObjects.append(newObject)
     objects = self._tree.getroot().find('objects')
     newElement = etree.Element('object', { 'id': str(objectId), 'strength': str(newObject.getStrength()), 'defense': str(newObject.getDefense()), 'reliability': str(newObject.getReliability()) })
     newElementName = etree.Element('name')
     newElementName.text = newObject.getName()
     newElementImage = etree.Element('image')
     newElementImage.text = newObject.getImage()
     newElement.append(newElementName)
     newElement.append(newElementImage)
     objects.append(newElement)
     self._tree.write(self._initFile)
     self.sendObjects(peer)
Example #41
0
 def __init__(self, position_x, position_y, texture):
     GameObject.__init__(self, position_x, position_y)
     self.texture = texture
Example #42
0
 def __init__(self, img, position):
      GameObject.__init__(self, img, position)
Example #43
0
 def checkCollision(self, other):
     if self.opacity > 20:
         return GameObject.checkCollision(self, other)
     else: return False
Example #44
0
 def initGame(self, game):
     GameObject.initGame(self, game)
     self.active = False
     self.countdown = 0
     self.animation = random.randint(0,300)*.01
     self.anim_size = 0
Example #45
0
File: laby.py Project: kelvan/laby
def main():

    esize = 16
    lvl = level("level0.lvl", esize)

    l = glob.glob("data/*.lvl")
    lvl_anz = len(l)

    try:
        pygame.mixer.init()
        music = pygame.mixer.Sound(os.path.join("data", "music.ogg"))
    except:
        print "No Sound avaiable"
    pygame.init()
    screen = pygame.display.set_mode((lvl.esize * len(lvl.lvl[0]), lvl.esize * len(lvl.lvl)))

    img = image(str(esize))

    try:
        music.play(1)
    except:
        pass

    pygame.key.set_repeat(80, 50)
    for i in range(lvl_anz):
        play = player()
        lvl = level("level" + str(i) + ".lvl", esize)
        objects = []
        screen = pygame.display.set_mode((lvl.esize * len(lvl.lvl[0]), lvl.esize * len(lvl.lvl)))
        for y in range(len(lvl.lvl)):
            objects.append([])
            for x in range(len(lvl.lvl[0])):
                o = GameObject(img[lvl.lvl[y][x]], x * lvl.esize, y * lvl.esize, screen)
                objects[y].append(o)
                if lvl.lvl[y][x] == "S":
                    pl = GameObject(img["player"], x * lvl.esize, y * lvl.esize, screen)

        btime = time.time()

        while not play.finish:
            for event in pygame.event.get():
                if event.type == pygame.KEYDOWN:
                    if event.key == pygame.K_q:
                        txt = "Closing ..."
                        centered_txt(screen, lvl, txt, 50)
                        music.fadeout(2100)
                        time.sleep(2)
                        return
                    if event.key == pygame.K_DOWN:
                        pl.move(0, 1, lvl, img, objects, play)
                    if event.key == pygame.K_UP:
                        pl.move(0, -1, lvl, img, objects, play)
                    if event.key == pygame.K_RIGHT:
                        pl.move(1, 0, lvl, img, objects, play)
                    if event.key == pygame.K_LEFT:
                        pl.move(-1, 0, lvl, img, objects, play)
                    if event.key == pygame.K_n:
                        pass
                        play.finish = 1

            for j in range(len(objects)):
                for o in objects[j]:
                    o.draw()
                pl.draw()
            time.sleep(0.08)
            pygame.display.update()

        dtime = time.time() - btime
        sav = save("User")
        sav.write(play.points, pl.moves, dtime)
        print "Ziel erreicht:", play.points, "gesammelt"
        print "Moves:", pl.moves
        print dtime

        won = 1

        try:
            if lvl.conf["moves"] > 0:
                if pl.moves < lvl.conf["moves"]:
                    print "moves OK"
                else:
                    print "too many steps"
                    won = 0
        except:
            print "Maximal moves not given"

        try:
            if lvl.conf["time"] > 0:
                if dtime < lvl.conf["time"]:
                    print "time OK"
                else:
                    print "too slow"
                    won = 0
        except:
            print "Maximal time not given"

        try:
            if lvl.conf["points"] > 0:
                if play.points > lvl.conf["points"]:
                    print "points OK"
                else:
                    print "not enought points"
                    won = 0
        except:
            print "Minimal points not given"

        if won == 1:
            print "You finished this level"

        if i < lvl_anz - 1:
            txt = "Next level ..."
            centered_txt(screen, lvl, txt, 50)
            time.sleep(1)

    txt = "Finished ..."
    centered_txt(screen, lvl, txt, 50)
    music.fadeout(2100)
    time.sleep(2)
Example #46
0
 def __init__(self, x, y, width, height, resources, speed, object_id):
     GameObject.__init__(self, x, y, width, height, resources, object_id)
     self.speed = speed
     self.direction = Direction.STILL
     self.orientation = Direction.STILL
 def __init__(self,width,height,color,grid):
     GameObject.__init__(self,width,height,color,grid)
     #Already initialized at a random position by superclass
     self.reward = 0  
Example #48
0
from MathUtil import Vector2
from random import randrange

# Initialize any modules that pygame uses.
pygame.init()

screen_size = (900, 500)

# Bits per pixel, 8 bits for each RGBA value.
bpp = 32
screen = pygame.display.set_mode(screen_size, pygame.HWSURFACE, bpp)

all_game_objects = list()

# MAKE THE PLAYER
player = GameObject()
player.position.x = screen_size[0] / 2.0
player.position.y = screen_size[1] - 100
player.color = (255, 0, 0)
player.boundingBox = Rect(player.position.to_tuple(), (100, 20))
all_game_objects.append(player)

# MAKE THE BALL
ball = GameObject()
ball.tag = "ball"
ball.position.x = player.position.x
ball.position.y = player.position.y - 50
ball.velocity = Vector2(randrange(-100, 100), -150)
ball.color = (0, 255, 255)
ball.boundingBox = Rect(ball.position.to_tuple(), (10, 10))
all_game_objects.append(ball)
Example #49
0
	def __init__(self):
		GameObject.__init__(self)
		self._spaceAllocs = {}
		self.addTimer(3, 1, 1)
		self.initAlloc()
		KBEngine.globalData["SpaceMgr"] = self
Example #50
0
	def __init__(self):
		GameObject.__init__(self) 
		Combat.__init__(self) 
		Spell.__init__(self) 
Example #51
0
		if(time.time() - currentTime  > tickFreq): #10 ticks per second. This number can be changed as necessary
			tick()
			tickCount += 1
			currentTime = time.time()

		# if currentTime - startTime > 10: break #quick line to time out the code after 10 seconds
	print("Game loop has been terminated.")

def tick():
	gameMap.update()
	#tick process:
		#Take human input
		#Introduce new game pieces
		#update all game pieces

#START TEST CODE
if __name__ == '__main__':
	thr = threading.Thread(target=runGame, args=(), kwargs={})
	thr.start()

	myObject = GameObject([0,0], 'drone', 'owen')
	myObject.velocity = [1, 0]
	gameMap.addObject(myObject)
	while True:
		flatGameMap = []
		for i in gameMap.gameObjects:
			flatGameMap.append(i.__dict__)
		print(flatGameMap)
		time.sleep(.1)
#END TEST CODE
Example #52
0
	def __init__(self):
		GameObject.__init__(self)
Example #53
0
 def initGame(self, game):
     GameObject.initGame(self, game)
     self.snd_play = False
Example #54
0
#!/usr/bin/env python

import sys, pygame
from GameObject import GameObject
from pygame.locals import *

pygame.init()
screen = pygame.display.set_mode((640, 480))
player = pygame.image.load('ball.bmp').convert()
background = pygame.image.load('background.jpg').convert()
screen.blit(background, (0, 0))
objects = []

for x in range(10): 		#create 10 objects
	o = GameObject(player, x, x)
 	objects.append(o)

while 1:
	for event in pygame.event.get():
		if event.type in (QUIT, KEYDOWN):
			sys.exit()

	for o in objects:
		screen.blit(background, o.pos, o.pos)

	for o in objects:
		o.move()
		screen.blit(o.image, o.pos)

	pygame.display.update()
	pygame.time.delay(10)
Example #55
0
def start():
	player = GameObject("Player")
	player.add_component(SpriteRenderer)
	player.add_component(Player)
	player.add_component(PlayerController)
Example #56
0
intersectText = myriadProFont.render("Intersecting!", 1, (255, 0, 255), (0, 0, 0))

# Prepare logo
helloWorldSize = helloWorld.get_size()
helloWorld.fill((0,0,0), None, pygame.BLEND_RGBA_MAX)

x, y = 0, 0
clock = pygame.time.Clock()
directionX, directionY = 1, 1

def playSound():
    sound.stop()
    sound.play()

rectangle = GameObject(100, 100, 400, 400)
logo = GameObject(0, 0, helloWorldSize[0], helloWorldSize[1])

while 1:
    clock.tick(30)

    screen.fill((0,0,0))

    for event in pygame.event.get():
        if event.type == pygame.QUIT: sys.exit()

    mousePosition  = pygame.mouse.get_pos()

    x = mousePosition[0]
    y = mousePosition[1]

    logo.setPosition(x, y)