Exemplo n.º 1
0
    def __init__(self, screen_size, gravity=(
            0.0, -9.0), ppm=100.0, renderer='pygame'):
        """ Init the world with boundaries and gravity, and init colors.

            Parameters:
              screen_size .. (w, h) -- screen size in pixels [int]
              gravity ...... (x, y) in m/s^2  [float] default: (0.0, -9.0)
              ppm .......... pixels per meter [float] default: 100.0
              renderer ..... which drawing method to use (str) default: 'pygame'

            Return: class Elements()
        """
        self.set_screenSize(screen_size)
        self.set_drawingMethod(renderer)

        # Create Subclasses
        self.add = add_objects.Add(self)
        self.callbacks = callbacks.CallbackHandler(self)
        self.camera = camera.Camera(self)

        # Gravity + Bodies will sleep on outside
        self.gravity = gravity
        self.doSleep = True

        # Create the World
        self.world = box2d.b2World(self.gravity, self.doSleep)
        bodyDef = box2d.b2BodyDef()
        self.world.groundBody = self.world.CreateBody(bodyDef)

        # Init Colors
        self.init_colors()

        # Set Pixels per Meter
        self.ppm = ppm
Exemplo n.º 2
0
    def initializeWorld(self):
        global contactList
        contactList = []
        worldAABB = box2d.b2AABB()
        worldAABB.lowerBound.Set(- 100, - 100)
        worldAABB.upperBound.Set(100, 100)
        gravity = box2d.b2Vec2(0, - 10)
        doSleep = True
        self.world = box2d.b2World(worldAABB, gravity, doSleep)
        self.levelSwitchCountingDown = False
        self.levelSwitchCounter = 0

        # make sun
        BodySprite(self.world.GetGroundBody(), 'Rollcats_Sun.png', 20, 20, -10, -10, self.worldToScreen, self.screenToWorld)

        self.contactListener = myContactListener()
        self.world.SetContactListener(self.contactListener)
Exemplo n.º 3
0
 def __init__(self):
     global SCREENHEIGHT
     SCREENHEIGHT = Globals.game.screen.get_size()[1]
     
     # set up box2D    
     worldAABB=box2d.b2AABB()
     worldAABB.lowerBound.Set(-100, -100)
     worldAABB.upperBound.Set(100, 100)
     gravity = box2d.b2Vec2(0, -10)
     self.world = box2d.b2World(worldAABB, gravity, True)
     
     self.timeStep = 1.0/60
     self.run = True
     
     self.contactListener = X2OContactListener()
     self.world.SetContactListener(self.contactListener)
     
     self.makeBoundingBox()
Exemplo n.º 4
0
    def __init__(self,
                 screen_size,
                 gravity=(0.0, -9.0),
                 ppm=100.0,
                 renderer='pygame'):
        """ Init the world with boundaries and gravity, and init colors.
        
            Parameters:
              screen_size .. (w, h) -- screen size in pixels [int]
              gravity ...... (x, y) in m/s^2  [float] default: (0.0, -9.0)
              ppm .......... pixels per meter [float] default: 100.0
              renderer ..... which drawing method to use (str) default: 'pygame'

            Return: class Elements()
        """
        self.set_screenSize(screen_size)
        self.set_drawingMethod(renderer)

        # Create Subclasses
        self.add = add_objects.Add(self)
        self.callbacks = callbacks.CallbackHandler(self)
        self.camera = camera.Camera(self)

        # Set Boundaries
        self.worldAABB = box2d.b2AABB()
        self.worldAABB.lowerBound.Set(-100.0, -100.0)
        self.worldAABB.upperBound.Set(100.0, 100.0)

        # Gravity + Bodies will sleep on outside
        gx, gy = gravity
        self.gravity = box2d.b2Vec2(gx, gy)
        self.doSleep = True

        # Create the World
        self.world = box2d.b2World(self.worldAABB, self.gravity, self.doSleep)

        # Init Colors
        self.init_colors()

        # Set Pixels per Meter
        self.ppm = ppm