示例#1
0
    def __init__(self, address, port):
        self.address = address
        self.port = port

        self.socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

        self.create_layers()

        self.window = pyglet.window.Window(width=1280,
                                           height=720,
                                           caption="Entity Test 2",
                                           resizable=True)
        self.window.set_minimum_size(*c.VIEWPORT_SIZE)
        self.window.push_handlers(self)

        self.fps_display = pyglet.window.FPSDisplay(window=self.window)
        self.fps_display.label.color = (255, 255, 255, 200)

        self.key_handler = key.KeyStateHandler()
        self.mouse_handler = mouse.MouseStateHandler()
        self.window.push_handlers(self.key_handler, self.mouse_handler)

        self.world_batch = pyglet.graphics.Batch()
        self.world_camera = source.camera.Camera(scroll_speed=0,
                                                 min_zoom=0,
                                                 max_zoom=float("inf"))
        self.debug_draw_options = pymunk.pyglet_util.DrawOptions()

        self.ui_batch = pyglet.graphics.Batch()
        self.fps_display.label.batch = self.ui_batch

        self.debug_mode = False

        self.physics_space = pymunk.Space()

        self.position_label = pyglet.text.Label(text="X: 0, Y: 0",
                                                batch=self.ui_batch,
                                                font_size=10,
                                                x=5,
                                                y=40)

        self.entities = []
        self.player = None

        self.chunks = {}
        self.chunk_buffer = {}
        self.to_request = []
        self.to_unload = []
示例#2
0
    def __init__(self, board, batch, *args, **kwargs):
        self.board = board
        self.pieces_location = [[None for i in range(8)] for i in range(8)]

        # Handlers
        self.mouse_handler = mouse.MouseStateHandler()

        #batch
        self.batch = batch

        #Squares that change of color when user clicks in a piece
        self.square_selected = {
            'square_selected': None,
            'possible_squares': {}
        }

        self.previous_move = 'black'
    def __init__(
        self,
        caption: str = None,
        default_size: tuple = (1000, 800),
        minimum_size: tuple = (100, 100),
        world_layers: list = [],
        ui_layers: list = [],
        resizable: bool = True,
        fps_counter: bool = False
    ):
        self.create_layers(world_layers, ui_layers)

        self.default_size = default_size
        self.window = pyglet.window.Window(
            width=self.default_size[0],
            height=self.default_size[1],
            caption=caption,
            resizable=resizable
        )
        self.window.set_minimum_size(*minimum_size)
        self.window.push_handlers(self)

        if fps_counter:
            self._fps_display = pyglet.window.FPSDisplay(window=self.window)
            self._fps_display.label.color = (255, 255, 255, 200)

        self.key_handler = key.KeyStateHandler()
        self.mouse_handler = mouse.MouseStateHandler()
        self.window.push_handlers(self.key_handler, self.mouse_handler)

        self.world_batch = pyglet.graphics.Batch()
        self.world_camera = Camera(
            scroll_speed=0,
            min_zoom=0,
            max_zoom=float("inf")
        )
        self.position_camera()

        self.ui_batch = pyglet.graphics.Batch()
        if fps_counter:
            self._fps_display.label.batch = self.ui_batch

        self.physics_space = pymunk.Space()
        self.entities = []
示例#4
0
    def __init__(self,
                 config: Config = Config(),
                 windowless: bool = False,
                 debug_mode: bool = False,
                 show_fps: bool = False):
        self._handlers = []

        jank.set_app(self)
        self.config = config

        if not self.config.bilinear_filtering:
            jank.pyglet.image.Texture.default_mag_filter = jank.pyglet.gl.GL_NEAREST
            jank.pyglet.image.Texture.default_min_filter = jank.pyglet.gl.GL_NEAREST

        self.windowless = windowless
        self.debug_mode = debug_mode
        self.show_fps = show_fps

        self.physics_space = pymunk.Space()

        if self.windowless:
            return

        self.create_layers(self.config.world_layers, self.config.ui_layers)

        self.window = self.create_window(self.config)

        self.push_handlers(self)

        self.fps_display = jank.pyglet.window.FPSDisplay(window=self.window)
        if self.config.fps_label is not None:
            self.fps_display.label = self.config.fps_label

        self.key_handler = key.KeyStateHandler()
        self.mouse_handler = mouse.MouseStateHandler()
        self.push_handlers(self.key_handler, self.mouse_handler)

        self.world_batch = jank.graphics.Batch()
        self.ui_batch = jank.graphics.Batch()
        self.camera = Camera()
        self.camera.set_active()
示例#5
0
    def __init__(self):
        self.window = pyglet.window.Window(caption="Arkius",
                                           resizable=True,
                                           vsync=True,
                                           width=1400,
                                           height=800)
        self.window.set_minimum_size(*c.MIN_SIZE)

        self.debug_mode = False

        self.key_handler = key.KeyStateHandler()
        self.mouse_handler = mouse.MouseStateHandler()

        self.fps_display = pyglet.window.FPSDisplay(window=self.window)

        self.world_camera = source.camera.Camera(0, 0, 1000)
        self.lock_to_player = False
        self.camera_movement_x = 0
        self.camera_movement_y = 0
        self.zoom = 1

        self.world_batch = pyglet.graphics.Batch()
        self.ui_batch = pyglet.graphics.Batch()

        self.particles = []
        self.handlers = []
        self.trigger_ids = []

        self.push_handlers(self, self.key_handler, self.mouse_handler)

        self.create_layers()
        self.load_resources()

        self.transition = source.ui.transition.Transition(self)
        # self.world = source.hub_world.HubWorld(self)
        self.world = source.dungeon.Dungeon(self, c.HUB)
        self.player = source.player.Player(self)
示例#6
0
    def __init__(self):
        self.createLayers()
        self.loadResources()
        self.window = pyglet.window.Window(
            width=1280,
            height=720,
            caption="Test",
            resizable=True
        )
        self.window.push_handlers(self)

        self.debug_mode = False

        self.fps_display = pyglet.window.FPSDisplay(window=self.window)

        self.space = pymunk.Space()
        self.space.damping = 0

        self.createCollisionHandlers()

        self.world_batch = pyglet.graphics.Batch()
        self.world_camera = source.camera.Camera(
            scroll_speed=0,
            min_zoom=0,
            max_zoom=float("inf")
        )

        self.key_handler = key.KeyStateHandler()
        self.mouse_handler = mouse.MouseStateHandler()
        self.mouse_handler["x"] = 0
        self.mouse_handler["y"] = 0
        self.window.push_handlers(self.key_handler, self.mouse_handler)

        self.projectiles = []
        self.enemies = []

        self.player = source.player.Player(self)

        self.enemy_timer = 0

        self.floor = {}
        for x in range(-c.WORLD_DIMENSIONS[0]//200, c.WORLD_DIMENSIONS[0]//200+1):
            for y in range(-c.WORLD_DIMENSIONS[1]//200, c.WORLD_DIMENSIONS[1]//200+1):
                self.floor[(x, y)] = pyglet.sprite.Sprite(
                    img=self.resources["floor"],
                    x=x*100, y=y*100,
                    batch=self.world_batch,
                    group=self.layers["floor"]
                )

        self.borders = {
            "top": source.basic.Basic(
                self,
                -c.WORLD_DIMENSIONS[0]//2,
                c.WORLD_DIMENSIONS[1]//2,
                collider={
                    "type": "rect",
                    "x": 0, "y": 0,
                    "width": c.WORLD_DIMENSIONS[0]+100,
                    "height": 100,
                    "radius": 0,
                    "id": c.COLLISION_TYPES["obstacle"]
                },
                sprite=pyglet.shapes.Rectangle(
                    x=0, y=0,
                    width=c.WORLD_DIMENSIONS[0]+100,
                    height=100,
                    batch=self.world_batch,
                    group=self.layers["obstacle"]
                )
            ),
            "bottom": source.basic.Basic(
                self,
                -c.WORLD_DIMENSIONS[0]//2 - 100,
                -c.WORLD_DIMENSIONS[1]//2 - 100,
                collider={
                    "type": "rect",
                    "x": 0, "y": 0,
                    "width": c.WORLD_DIMENSIONS[0]+100,
                    "height": 100,
                    "radius": 0,
                    "id": c.COLLISION_TYPES["obstacle"]
                },
                sprite=pyglet.shapes.Rectangle(
                    x=0, y=0,
                    width=c.WORLD_DIMENSIONS[0]+100,
                    height=100,
                    batch=self.world_batch,
                    group=self.layers["obstacle"]
                )
            ),
            "left": source.basic.Basic(
                self,
                -c.WORLD_DIMENSIONS[0]//2 - 100,
                -c.WORLD_DIMENSIONS[1]//2,
                collider={
                    "type": "rect",
                    "x": 0, "y": 0,
                    "width": 100,
                    "height": c.WORLD_DIMENSIONS[1]+100,
                    "radius": 0,
                    "id": c.COLLISION_TYPES["obstacle"]
                },
                sprite=pyglet.shapes.Rectangle(
                    x=0, y=0,
                    width=100,
                    height=c.WORLD_DIMENSIONS[1]+100,
                    batch=self.world_batch,
                    group=self.layers["obstacle"]
                )
            ),
            "right": source.basic.Basic(
                self,
                c.WORLD_DIMENSIONS[0]//2,
                -c.WORLD_DIMENSIONS[1]//2 - 100,
                collider={
                    "type": "rect",
                    "x": 0, "y": 0,
                    "width": 100,
                    "height": c.WORLD_DIMENSIONS[1]+100,
                    "radius": 0,
                    "id": c.COLLISION_TYPES["obstacle"]
                },
                sprite=pyglet.shapes.Rectangle(
                    x=0, y=0,
                    width=100,
                    height=c.WORLD_DIMENSIONS[1]+100,
                    batch=self.world_batch,
                    group=self.layers["obstacle"]
                )
            )
        }
        self._position_camera()
示例#7
0
    def __init__(self, recent_files, drawing_specs, **kwargs):

        super().__init__(**kwargs,
                         caption="Oldpaint",
                         resizable=True,
                         vsync=False)

        self.drawings = Drawings(
            [Drawing.from_spec(s) for s in drawing_specs or []])

        self.tools = Selectable2({
            tool: tool
            for tool in [
                PencilTool, InkTool, PointsTool, SprayTool, LineTool,
                RectangleTool, EllipseTool, FillTool, SelectionTool, PickerTool
            ]
        })
        self.brushes = Selectable([
            RectangleBrush(1, 1),
            RectangleBrush(2, 2),
            RectangleBrush(3, 3),
            CircleBrush(8),
            EllipseBrush(20, 35),
            SquareBrush(20),
        ])
        self.highlighted_layer = None
        # self.show_selection = False

        # Some gl setup
        self.copy_program = Program(VertexShader("glsl/copy_vert.glsl"),
                                    FragmentShader("glsl/copy_frag.glsl"))
        self.line_program = Program(VertexShader("glsl/triangle_vert.glsl"),
                                    FragmentShader("glsl/triangle_frag.glsl"))
        self.vao = VertexArrayObject()

        # All the drawing will happen in a thread, managed by this executor
        self.executor = ThreadPoolExecutor(max_workers=1)

        # Current stroke, if any
        self.stroke = None

        # Mouse cursor setup
        self.mouse_texture = ImageTexture(*load_png("icons/cursor.png"))
        self.mouse_position = None
        self.brush_preview_dirty = None  # A hacky way to keep brush preview dirt away

        # Background texture
        #self.background_texture = ImageTexture(*load_png("icons/background.png"))

        # UI stuff
        self.icons = {
            name: ImageTexture(*load_png(f"icons/{name}.png"))
            for name in [
                "selection", "ellipse", "floodfill", "line", "spray", "pencil",
                "picker", "points", "rectangle", "ink"
            ]
        }

        self.border_vao = VertexArrayObject(vertices_class=SimpleVertices)
        self.border_vertices = self.border_vao.create_vertices([((0, 0, 0), ),
                                                                ((0, 0, 0), ),
                                                                ((0, 0, 0), ),
                                                                ((0, 0, 0), )])

        self.selection_vao = VertexArrayObject(vertices_class=SimpleVertices)
        self.selection_vertices = self.selection_vao.create_vertices([
            ((0, 0, 0), ), ((0, 0, 0), ), ((0, 0, 0), ), ((0, 0, 0), )
        ])

        self._new_drawing = None  # Set when configuring a new drawing
        self.unsaved_drawings = None
        self._error = None
        self.recent_files = OrderedDict((k, None) for k in recent_files)

        self.window_visibility = {
            "edits": False,
            "colors": False,
            "color_editor": False,
            "metrics": False
        }

        # TODO this works, but figure out a way to exit automatically when the application closes.
        # @contextmanager
        # def blah():
        #     yield self.overlay
        #     rect = self.overlay.dirty
        #     self.drawing.update(self.overlay, rect)
        #     self.overlay.clear(rect, frame=0)
        # Thread(target=start_ipython,
        #        kwargs=dict(colors="neutral", user_ns={"drawing": self.drawing, "blah": blah})).start()

        self.plugins = {}
        init_plugins(self)

        # ways to directly access current keys and mouse buttons
        self.keys = key.KeyStateHandler()
        self.push_handlers(self.keys)
        self.mousebuttons = mouse.MouseStateHandler()
        self.push_handlers(self.mousebuttons)
        # Setup pressure sensitive drawing tablet (if available)
        self.tablet = TabletStateHandler(self)

        self._mru_cycling = False  # Whether Alt+Tabbing through drawings
示例#8
0
import pyglet
import Resources
import Functions


import math
from pyglet.window import key
from pyglet.window import mouse
import random



global_key_handler = key.KeyStateHandler()
global_mouse_handler = mouse.MouseStateHandler()


class Camera(object):
    def __init__(self, screen_width, screen_height):
        self.x = self.y = 0.0
        self.screen_width = screen_width
        self.screen_height = screen_height
        self.zoom = 1.0



    def zoom_in(self):
        self.zoom += .1

    def zoom_out(self):
        self.zoom -= .1
示例#9
0
Mousex = 0
MouseY = 0
Point = 0
label = pyglet.text.Label('points:' + str(Point),
                          x=5,
                          y=550,
                          color=(0, 128, 0, 255))
# Window

WINDOW = pyglet.window.Window(caption='noodle-game', width=600, height=600)
WINDOW.set_location(WINDOW.screen.width // 2 - WINDOW.width // 2,
                    WINDOW.screen.height // 2 - WINDOW.height // 2)
WINDOW.set_icon(pyglet.image.load('ramen.png'))

KeyHandler = key.KeyStateHandler()
MouseHandler = mouse.MouseStateHandler()

WINDOW.push_handlers(KeyHandler)
WINDOW.push_handlers(MouseHandler)

pyglet.gl.glClearColor(0.2, 0.2, 0.2, 1)
gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT)

glEnable(GL_BLEND)
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)

# Start menu


class Start():
    ButtonImage = pyglet.image.load('StartButton.png')