Ejemplo n.º 1
0
    help="stage to initiate the game with. Defaults to the default stage.py")
parser.add_argument("--width",
                    default=SCREEN_WIDTH,
                    type=int,
                    help="screen width. Defaults to 1920")
parser.add_argument("--height",
                    default=SCREEN_HEIGHT,
                    type=int,
                    help="screen height. Defaults to 1080.")
parser.add_argument("--fullscreen",
                    default=False,
                    type=bool,
                    help="Do fullscreen, baby!")
args = parser.parse_args()

app = App()

controllerManager = GameControllerManager()
controllerManager.load_joysticks_database('resources/gamecontrollerdb.txt')
# debug: add keyboard
num_joysticks = max(controllerManager.num_joysticks, 1)
controllers = [
    controllerManager.grab_controller() for n in range(num_joysticks)
]

screen = Screen(args.width, args.height, 'Space Madness')
if args.fullscreen:
    screen.full_screen = True
screen.print_info()

world = World(bounds=screen.viewport,
Ejemplo n.º 2
0
#!/usr/bin/env python
import logging

from mgl2d.app import App
from mgl2d.graphics.screen import Screen

logging.basicConfig(level=logging.INFO)

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


def draw_frame(screen):
    pass


def update_frame(delta_ms):
    pass


app.run(screen, draw_frame, update_frame)
Ejemplo n.º 3
0
import sdl2
import sdl2.ext
from Box2D import b2World
from mgl2d.app import App
from mgl2d.input.game_controller_manager import GameControllerManager
from mgl2d.math.vector2 import Vector2
from physics.contact import ContactListener

from physics.physics_asteroid import PhysicsAsteroid
from physics.physics_shield import PhysicsShield
from physics.physics_ship import PhysicsShip

GAME_FPS = 50
GAME_FRAME_MS = 1000 / GAME_FPS

app = App()


class MockCollidable:
    def __init__(self, name):
        self.name = name

    def collide(self, other, began=False, **kwargs):
        state = 'began' if began else 'ended'


def draw_line(surface, x1, y1, x2, y2):
    color = sdl2.ext.Color(255, 255, 255)
    sdl2.ext.line(surface, color, (x1, y1, x2, y2))

Ejemplo n.º 4
0
#!/usr/bin/env python
import random

from mgl2d.app import App
from mgl2d.graphics.color import Color
from mgl2d.graphics.screen import Screen
from mgl2d.graphics.shapes import Shapes

app = App()
main_screen = Screen(800, 600, 'Shapes')
main_screen.print_info()

shapes = Shapes()

line_x1 = line_y1 = line_x2 = line_y2 = 0
center_x = center_y = radius = 0
color = Color()


def get_new_parameters():
    global line_x1, line_x2, line_y1, line_y2, center_x, center_y, radius, color
    color = Color(r=random.random(), g=random.random(), b=random.random(), a=1)

    line_x1 = random.randint(0, main_screen.width)
    line_y1 = random.randint(0, main_screen.height)
    line_x2 = random.randint(0, main_screen.width)
    line_y2 = random.randint(0, main_screen.height)

    center_x = random.randint(0, main_screen.width)
    center_y = random.randint(0, main_screen.height)
    radius = random.randint(10, 150)