コード例 #1
0
ファイル: asteroid.py プロジェクト: maxfish/SpaceMadness
    def __init__(
            self,
            world,
            x,
            y,
            speed,
            torque,
            asset='resources/images/asteroides/asteroid_01.png',
            scale=1,
    ):
        super().__init__(world, x, y, 0)
        # Slightly smaller than the image
        texture = Texture.load_from_file(asset)
        image_size = min(texture.width, texture.height)

        radius = ((image_size / PHYSICS_SCALE) / 2) * 0.8

        self._quad = QuadDrawable(x, y, texture.width * scale, texture.height * scale)
        self._quad.anchor_to_center()
        self._quad.texture = texture
        self._quad.shader = ShaderProgram.from_files(vert_file='resources/shaders/base.vert', frag_file='resources/shaders/rgba.frag')

        self._physicAsteroid = PhysicsAsteroid(
            self,
            world.physicsWorld,
            center=Vector2(x / PHYSICS_SCALE, y / PHYSICS_SCALE),
            radius=radius,
            speed=speed,
            torque=torque,
        )
コード例 #2
0
ファイル: shield.py プロジェクト: maxfish/SpaceMadness
    def __init__(self, ship, world):
        super().__init__(ship._world, 0, 0)
        self._ship = ship

        self._quad = QuadDrawable(0, 0, 0, 0)
        self._quad.texture = Texture.load_from_file(
            'resources/images/shield_arc.png')
        self._quad.shader = ShaderProgram.from_files(
            vert_file='resources/shaders/base.vert',
            frag_file='resources/shaders/rgba.frag')
        self._quad.size = Vector2(self._quad.texture.width,
                                  self._quad.texture.height) * 0.67
        self._quad.anchor = Vector2(0, self._quad.size.y / 2)

        self._physicsShield = PhysicsShield(
            self,
            ship._physicsShip,
            world.physicsWorld,
            center=self._ship._physicsShip.body.position,
            radius=(self._quad.size.x / PHYSICS_SCALE) * 1.1,
        )
        self._collision_timer = 0

        self._rad1 = ship._dim.y / 2.9
        self._rad2 = ship._dim.y / 2.9
        self._angle = 0
        self._angle_speed = 1
        self._enable = False
        self._charge = 0
        self.shield_state = ShieldState(self)
        self.update(0, (0.0, 0.0, 0.0))
コード例 #3
0
ファイル: frames_store.py プロジェクト: cklein/mgl2d
    def load(self, path, file_name):
        logger.info("Loading '%s/%s'" % (path, file_name))

        json_data = open(os.path.join(path, file_name))
        data = json.load(json_data)
        json_data.close()

        meta = data.get('meta')
        if meta:
            fps = meta.get('fps')
            if fps:
                self.animation_fps = fps

        for animation_name in data['animations']:
            animation_data = data['animations'][animation_name]
            # Check if this is a clone of another one
            clone_of = animation_data.get('clone_of')
            if clone_of:
                animation_data = data['animations'][clone_of]
                animation_data['clone_of'] = clone_of
            self.animations[animation_name] = Animation(
                animation_data, animation_name)

        # Load images and frames
        for frame_name in data['frames']:
            frame = data['frames'][frame_name]
            if not frame['image_file'] in self.images:
                self.images[frame['image_file']] = frame[
                    'image'] = Texture.load_from_file(
                        os.path.join(path, frame['image_file']))
                self.frames[frame_name] = Frame(frame, frame_name)
コード例 #4
0
 def __init__(self, x, y, length, angle):
     # self.quadb = QuadDrawable(x, y, 36/8, 100/8, angle)
     # self.quadb.texture = Texture.load_from_file('resources/images/burst_b.png')
     self.quadm = QuadDrawable(x + 36 / 8, y, length, 100 / 8, angle)
     self.quadm.texture = Texture.load_from_file('resources/images/burst_m.png')
     # self.quade = QuadDrawable(x+36/8+100-4, y, 64/8, 100/8, angle)
     # self.quade.texture = Texture.load_from_file('resources/images/burst_e.png')
     self.should_be_removed = False
コード例 #5
0
ファイル: world.py プロジェクト: maxfish/SpaceMadness
    def __init__(self, bounds, controllers, stage, debug=0):
        self.scene = self.SCENE_TITLE
        self.game_over_timer = 0
        self.stage = stage

        self.game_over_quad = QuadDrawable(
            SCREEN_WIDTH / 2 - 496 / 2,
            SCREEN_HEIGHT / 2 - 321 / 2,
            496,
            321,
        )
        self.game_over_quad.texture = Texture.load_from_file(
            'resources/images/game_over.png')

        self.bounds = bounds
        self.debug = debug

        self.window_x = 0
        self.window_y = 0

        self.physicsWorld = b2World(gravity=(0, 0),
                                    contactListener=ContactListener())
        # Physical bodies should be deleted outside the simulation step.
        self.physics_to_delete = []
        self._shapes = Shapes()

        self.controllers = controllers

        self.bullet_mgr = bullet_mgr = BulletManager(self)

        self.players = []
        self.entities = [bullet_mgr]

        def batch(iterable, n=1):
            l = len(iterable)
            for ndx in range(0, l, n):
                yield iterable[ndx:min(ndx + n, l)]

        quadrant = 0
        for cs in batch(controllers, 3):
            x = 300 + (SCREEN_WIDTH -
                       600) * (quadrant & 1) + 100 * random.uniform(-1, 1)
            y = 200 + (SCREEN_HEIGHT -
                       400) * (quadrant >> 1 & 1) + 50 * random.uniform(-1, 1)
            ship = Ship(
                self,
                bullet_mgr,
                controllers=cs,
                x=x,
                y=y,
                # angle=math.degrees(math.atan2(y, x)) - 180
                color=SHIP_TEXTURES[list(SHIP_TEXTURES.keys())[quadrant]],
            )
            self.players.append(ship)
            self.entities.append(ship)
            quadrant += 1

        self.asteroids = []
コード例 #6
0
ファイル: cloud.py プロジェクト: maxfish/SpaceMadness
def create_cloud_quad(cloud, size, cloud_list, cloud_picked):
    cloud.quad = QuadDrawable(cloud.pos.x,
                              cloud.pos.y,
                              size,
                              size,
                              angle=random.random() * math.pi * 2)
    cloud.quad.texture = Texture.load_from_file('resources/images/clouds/' +
                                                cloud_list[cloud_picked - 1])
    cloud.quad.shader = ShaderProgram.from_files(
        vert_file='resources/shaders/base.vert',
        frag_file='resources/shaders/rgba.frag')
    cloud.quad.anchor_to_center()
コード例 #7
0
    def __init__(
            self,
            world,
            bullet_mgr,
            controllers,
            x,
            y,
            z=0,
            angle=0,
            color='standard',
    ):
        super().__init__(world, x, y, z)
        self.world = world

        self._dim = Vector2(130 * SCALE, 344 * SCALE)
        self._angle = angle
        self._physicsShip = PhysicsShip(
            self,
            world.physicsWorld,
            x / config.PHYSICS_SCALE,
            y / config.PHYSICS_SCALE,
            angle=angle,
        )

        # Used by ship components to scale themselves
        self.size = SCALE

        self._quad = QuadDrawable(0, 0, self._dim.x, self._dim.y)
        self._quad.pos = self._position
        self._quad.anchor = self._dim.__div__(2.0)

        texture_file = SHIP_TEXTURES.get(color, SHIP_TEXTURES['standard'])
        self._quad.texture = Texture.load_from_file(texture_file)
        self._quad.shader = ShaderProgram.from_files(vert_file='resources/shaders/base.vert', frag_file='resources/shaders/rgba.frag')

        self.controllers = controllers
        self.pilotController = controllers[0] if len(controllers) else None
        self.shieldController = controllers[1] if len(controllers) > 1 else None
        self.turretController = controllers[2] if len(controllers) > 2 else None

        self.shields = [
            Shield(self, world),
            Shield(self, world),
        ]

        self.turret_right = Turret(self, bullet_mgr, offset_x=-59 * SCALE, offset_y=2 * SCALE)
        self.turret_left = Turret(self, bullet_mgr, offset_x=59 * SCALE, offset_y=2 * SCALE)

        self.ship_state = ShipState(self)

        self.trail = Trail(self, 0, 0)
        self.side_trail_left = SideTrail(self, 28 * SCALE, 40 * SCALE, -45)
        self.side_trail_right = SideTrail(self, -25 * SCALE, 40 * SCALE, 225)
コード例 #8
0
ファイル: planet.py プロジェクト: maxfish/SpaceMadness
def create_planet_quad(planet, size, planet_list, planet_picked):
    planet.quad = QuadDrawable(planet.pos.x,
                               planet.pos.y,
                               size,
                               size,
                               angle=random.random() * math.pi * 2)
    planet.quad.texture = Texture.load_from_file('resources/images/planets/' +
                                                 planet_list[planet_picked -
                                                             1])
    planet.quad.shader = ShaderProgram.from_files(
        vert_file='resources/shaders/base.vert',
        frag_file='resources/shaders/rgba.frag')
    planet.quad.anchor_to_center()
コード例 #9
0
ファイル: bullet.py プロジェクト: maxfish/SpaceMadness
 def __init__(self, bullet_mgr, world):
     super().__init__(world, 0, 0, 0)
     # The visual representation of the bullet.
     self.owner = None
     self._world = world
     self._quad = QuadDrawable()
     self._quad.texture = Texture.load_from_file(
         'resources/images/bullet.png')
     self._quad.size = Vector2(self._quad.texture.width,
                               self._quad.texture.height)
     self._quad.anchor_to_center()
     # Attach physics only in the initialize method
     self.bullet_radius = min(self._quad.size.x,
                              self._quad.size.y) / PHYSICS_SCALE / 2
     self._angle = None
     self.bullet_mgr = bullet_mgr
コード例 #10
0
    def __init__(self, width, height):
        super().__init__(width, height)
        self.quad = QuadDrawable(0, 0, width, height)
        self.quad.texture = Texture.load_from_file('resources/images/bg.png')
        number_of_planets = 9
        self.planets = []
        number_of_clouds_background = 5
        number_of_clouds_foreground = 5

        self.clouds_background = []
        self.clouds_foreground = []

        # Generate the list of planets
        self.generate_planets(number_of_planets, width, height)
        # Generate the list of clouds
        self.generate_clouds_background(number_of_clouds_background, width, height)
        self.generate_clouds_foreground(number_of_clouds_foreground, width, height)
コード例 #11
0
    def __init__(self, ship, offset_x, offset_y, offset_angle):
        self._ship = ship
        self.offset_x = offset_x
        self.offset_y = offset_y
        self.offset_angle = offset_angle

        self.side_trail_dimensions = Vector2(56 * self._ship.size,
                                             11 * self._ship.size)
        self.side_trail = QuadDrawable(0, 0, self.side_trail_dimensions.x,
                                       self.side_trail_dimensions.y)
        self.side_trail.texture = Texture.load_from_file(
            'resources/images/ship/side_trail.png')
        self.side_trail.anchor = Vector2(56 * self._ship.size,
                                         5 * self._ship.size)
        self.side_trail.angle = offset_angle

        self.update(0, 0)
コード例 #12
0
ファイル: trail.py プロジェクト: maxfish/SpaceMadness
    def __init__(self, ship, offset_x, offset_y):
        self._isBoosting = False
        self._ship = ship
        self.offset_x = offset_x
        self.offset_y = offset_y

        self.engine_trail_dimensions = Vector2(130 * self._ship.size,
                                               344 * self._ship.size)
        self.engine_trail = QuadDrawable(0, 0, self.engine_trail_dimensions.x,
                                         self.engine_trail_dimensions.y)
        self.engine_trail.texture = Texture.load_from_file(
            'resources/images/ship/trail.png')
        # Don't ask why 173...
        self.engine_trail.anchor = Vector2(65 * self._ship.size,
                                           173 * self._ship.size)
        self.engine_trail.shader = ShaderProgram.from_files(
            vert_file='resources/shaders/base.vert',
            frag_file='resources/shaders/rgba.frag')

        self.update(0, 0, False)
コード例 #13
0
ファイル: tmx_map.py プロジェクト: maxfish/mgl2d
    def _image_loader(filename, colorkey, **kwargs):
        if colorkey:
            logger.error('colorkey not implemented')

        image = Texture.load_from_file(filename)

        def load_image(rect=None, flags=None):
            if rect:
                try:
                    x, y, w, h = rect
                    y = image.height - y - h
                    tile = image.get_region(x, y, w, h)
                except:
                    logger.error('cannot get region %s of image', rect)
                    raise
            else:
                tile = image

            if flags:
                logger.error('tile flags are not implemented')

            return tile

        return load_image
コード例 #14
0
import logging

from mgl2d.app import App
from mgl2d.graphics.quad_drawable import QuadDrawable
from mgl2d.graphics.screen import Screen
from mgl2d.graphics.texture import Texture
from mgl2d.math.vector2 import Vector2

logging.basicConfig(level=logging.INFO)

app = App()
screen = Screen(800, 600, 'Quad drawable')
screen.print_info()

# Textured quad centered
quad = QuadDrawable(400, 300, 200, 200)
quad.texture = Texture.load_from_file('data/texture.png')
quad.anchor = Vector2(100, 100)


def draw_frame(screen):
    quad.draw(screen)


def update_frame(delta_ms):
    quad.angle += 0.1
    pass


app.run(screen, draw_frame, update_frame)
コード例 #15
0
ファイル: stage_1.py プロジェクト: maxfish/SpaceMadness
    def __init__(self, width, height):
        super().__init__(width, height)

        self.quad = QuadDrawable(0, 0, width, height)
        self.quad.texture = Texture.load_from_file('resources/images/bg.png')
コード例 #16
0
ファイル: healthbar.py プロジェクト: maxfish/SpaceMadness
 def __init__(self, ship, world):
     super().__init__(world, ship.position.x, ship.position.y)
     self._ship = ship
     self._quad = QuadDrawable(0, 0, ship._dim.x, 5)
     self._quad.texture = Texture.load_from_file(
         'resources/images/health.png')
コード例 #17
0
ファイル: stage_demo.py プロジェクト: maxfish/SpaceMadness
 def __init__(self, width, height):
     super().__init__(width, height)
     texture = Texture.load_from_file('resources/images/logo.png')
     self._logo = QuadDrawable(0, 0, texture.width, texture.height)
     self._logo.anchor = Vector2(texture.width / 2, texture.height / 2)
     self._logo.texture = texture