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, )
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))
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
def __init__(self): self._font_faces = {} self._page_textures = {} self._character_program = ShaderProgram.from_sources( vert_source=self.vert_shader_base, frag_source=self.frag_shader_texture) self._quad = QuadDrawable() self._quad.shader = self._character_program
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 = []
def __init__(self, filename): self._tmx_data = pytmx.TiledMap(filename, invert_y=True, image_loader=self._image_loader) self._size = self._tmx_data.width * self._tmx_data.tilewidth, self._tmx_data.height * self._tmx_data.tileheight self._layer_offsets = [ Vector2(0, 0) for _ in range(0, len(self._tmx_data.layers)) ] self._drawable = QuadDrawable()
def __init__(self, width, height, flip_y=True): super().__init__() self._fbo = FrameBuffer(width, height) self._drawable = QuadDrawable() self._drawable.size = Vector2(width, height) self._drawable.flip_y = flip_y self._drawable.pos = Vector2(0, height) self._drawable.invalidate_matrices() self._drawable.texture = self._fbo.texture
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)
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()
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()
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
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)
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)
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)
def __init__(self, frames_store): self._frames_store = frames_store self._x = 0 self._y = 0 self._flags = 0 self._angle = 0 self._scale = Vector2(1, 1) # Collision detection self._attack_box = None self._hit_box = None # Frames and animations self._frame = None self._animation = None self._animation_name = None self._animation_frame_index = None self._animation_frame_delay = 0 self._animation_speed = 1 self._animating = False # Drawing self._drawable = QuadDrawable()
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)
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')
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 app = App() main_screen = Screen(800, 600, 'Quad drawable') main_screen.print_info() quads = [] for y in range(3): for x in range(4): quad = QuadDrawable(100 + x * 200, 100 + y * 200, size_x=120, size_y=120) quad.texture = Texture.load_from_file('data/texture.png') quad.anchor_to_center() quads.append(quad) # Flipped horizontally quads[1].flip_x = True # Flipped vertically quads[2].flip_y = True # Flipped in both directions quads[3].flip_x = quads[3].flip_y = True # Scaled smaller quads[4].scale = Vector2(0.8, 0.8) # Scaled bigger quads[5].scale = Vector2(1.2, 1.2)
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')
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