Example #1
0
    def add_tank(self, position, image, keys=()):
        """Add new tank to the game.
        Args:
            position (tuple of int): List of x-coordinate and y-coordinate of the tank.
            image (pygame.Surface): Tank image as a pygame.Surface instance.
            keys (tuple of int): Tuple with size of 4 contains keys for controlling the tank.
                The order of keys should be (LEFT, RIGHT, UP, DOWN).
        """
        self.num_tanks += 1

        tank = Tank(position, image, keys)
        tank._id = self.num_tanks

        self.tank_group.add(tank)
Example #2
0
 def __init__(self):
     Tank.__init__(self)
Example #3
0
def addBot(type, clan, position=(100, 100), rotation=0, add_moving_handler=False, id=None):
    tank = Tank()
    tank.id = self.getNextId()
    tank.bot = True
    tank.setPosition(position)
    tank.rotation = rotation
    tank.clan = clan
    tank.type = type
    tank.gun_rotation = random.randrange(1, 360)

    #moving_handler = BotTankMovingHandlers(tank)
    #moving_handler.setDaemon(True)
    #moving_handler.start()
    tank.moving_handler = BotTankMovingHandlers(tank)

    Global.GameObjects.addTank(tank)

    self.sendAllTanksToClients()

    return tank.id
Example #4
0
 def add_random_bot(self):
     x, y = randint(0, 1400), randint(0, 1400)
     rotate = randint(0, 360)
     self.add_tank(Tank(x, y, rotate))
Example #5
0
def createInterface():
    #director.director.init(width=3000, height=960, autoscale=True, resizable=True)
    director.director.init(width=2048,
                           height=960,
                           resizable=True,
                           autoscale=False)

    # initGlobalParams()

    # Create a scene and set its initial layer.

    MainLayer = MainSceneLayer()
    set_main_layer(MainLayer)
    main_scene = scene.Scene(MainLayer)
    main_scene.schedule(MainLayer.buttonsHandler)

    MainLayer.register_event_type('add_tank')
    MainLayer.register_event_type('tank_destroy')
    MainLayer.register_event_type('add_random_bot')
    MainLayer.register_event_type('add_animation')
    MainLayer.register_event_type('add_bullet')
    MainLayer.register_event_type('remove_animation')

    # game_layers = Layers(MainLayer)
    # init_global_variables(game_layers)

    # @MainLayer.event
    # def on_clicked(clicks):
    #     print('ovverided', clicks)
    #     pass

    # for i in range(30):
    #     MainLayer.dispatch_event('add_random_bot')
    MainLayer.dispatch_event('add_tank', Tank(100, 100, 0), True)
    MainLayer.dispatch_event('add_tank', Tank(200, 300, 120))
    # MainLayer.dispatch_event('add_tank', Tank(330, 250, 30))
    # MainLayer.dispatch_event('add_tank', Tank(70, 550, 40))
    # MainLayer.dispatch_event('add_tank', Tank(500, 550, 50))
    # MainLayer.dispatch_event('add_tank', Tank(600, 300, 60))
    # MainLayer.dispatch_event('add_tank', Tank(300, 600, 70))

    # load_map()
    #
    # if ip is None:
    #     playerId = addGamePlayer(type=tanktype, clan=clan, position=(150, 150), add_moving_handler=True)
    #     setCurrentPlayerStats(playerId)
    #
    #     thread = Thread(target = Game.callUpdatePositions)
    #     thread.setDaemon(True)
    #     thread.start()
    #
    #     # thread = Thread(target = Game.callCheckCollisions)
    #     # thread.setDaemon(True)
    #     # thread.start()
    #
    #     #proc = Process(target=connectionsListenersPump, args=(addGamePlayer,))
    #     #proc.start()
    #     #proc.join()
    #
    #     # thread = Thread(target = connectionsListenersPump)
    #     # thread.setDaemon(True)
    #     # thread.start()
    #
    #     thread = Thread(target = Game.sendDataToPlayers)
    #     thread.setDaemon(True)
    #     thread.start()
    #
    # else:
    #     #main_scene_layer.connections_listener = NetworkListener(ip, 1332, tanktype)
    #     Global.TankNetworkListenerConnection = NetworkListener(ip, 1332, tanktype, clan)

    director.director.on_resize = MainLayer.resize
    director.director.window.push_handlers(CurrentKeyboard)
    director.director.run(main_scene)