def __init__(self, resources: Resources) -> None: self.ticks = -1 self.last_finish = -1 self.best_finish = -1 font = FontManager(resources.get_path("DejaVuSans.ttf"), size=28) white = Color(r=255, g=255, b=255) self.timer_textbox = TextBox(font, 50, 100, white) self.best_time_textbox = TextBox(font, 50, 150, white)
def main() -> int: sdl2.ext.init() resources = Resources(__file__, "resources") controller = Controller() # Objective 1: Create and show the Window # YOUR CODE HERE... window = Window(WINDOW_TITLE, WINDOW_SIZE) window.show() # Objective 2: Create the Renderer with a background color # YOUR CODE HERE... renderer = Renderer(window) color = Color(110, 132, 174) renderer.color = color # Objective 3: Set up the game # YOUR CODE HERE... game = Game(resources) # Game Loop, draws each frame last_time = time() lag = 0.0 while True: now = time() lag += now - last_time last_time = now controller.handle_input() if controller.has_input(Input.QUIT): break # Objective 3: Update the game the appropriate number of frames # YOUR CODE HERE... while lag >= SECONDS_PER_UPDATE: game.update(controller) lag -= SECONDS_PER_UPDATE # Objective 2: Draw over all drawings of the last frame with the default color # YOUR CODE HERE... renderer.clear() # Objective 3: Render the game # YOUR CODE HERE... game.render(renderer) # Objective 2: Show the result on screen # YOUR CODE HERE... renderer.present() sdl2.ext.quit() return 0
def load_tile_map(resources: Resources) -> Tuple[List[int], int, int]: tiles = [] width = 0 height = 0 # Objective 5: Load in tilemap path = resources.get_path("default.map") file = open(path, "r") for line in file.readlines(): row_width = 0 for i in line.split(" "): if i == '': continue tiles.append(int(i)) row_width += 1 width = row_width height += 1 return tiles, width, height
def main() -> int: sdl2.ext.init() resources = Resources(__file__, "resources") controller = Controller() window = Window(WINDOW_TITLE, WINDOW_SIZE) window.show() renderer = Renderer(window) color = Color(125, 148, 210) renderer.color = color # Objective 3: Set up the game game = Game(resources) # Game Loop, draws each frame last_time = time() lag = 0.0 while True: now = time() lag += now - last_time last_time = now controller.handle_input() if controller.has_input(Input.QUIT): break # Objective 3: Update the game the appropriate number of frames while lag >= SECONDS_PER_UPDATE: game.update(controller) lag -= SECONDS_PER_UPDATE renderer.clear() # Objective 3: Render the game game.render(renderer) game.update(controller) renderer.present() sdl2.ext.quit() return 0
def main() -> int: sdl2.ext.init() resources = Resources(__file__, "resources") controller = Controller() # Objective 1: Create and show the Window window = Window(WINDOW_TITLE, WINDOW_SIZE) window.show() # Objective 2: Create the Renderer with a background color # YOUR CODE HERE... # Objective 3: Set up the game # YOUR CODE HERE... # Game Loop, draws each frame last_time = time() lag = 0.0 while True: now = time() lag += now - last_time last_time = now controller.handle_input() if controller.has_input(Input.QUIT): break # Objective 3: Update the game the appropriate number of frames # YOUR CODE HERE... # Objective 2: Draw over all drawings of the last frame with the default color # YOUR CODE HERE... # Objective 3: Render the game # YOUR CODE HERE... # Objective 2: Show the result on screen # YOUR CODE HERE... sdl2.ext.quit() return 0
def load_tile_map(resources: Resources) -> Tuple[List[int], int, int]: tiles = [] width = 0 height = 0 # Objective 5: Load in tilemap # YOUR CODE HERE... path = resources.get_path('default.map') map = open(path, "r") for line in map.readlines(): lineWidth = 0 for i in line.split(" "): if i == "": continue tiles.append(int(i)) lineWidth += 1 if width > 0 and width != lineWidth: print("ERROR") width = lineWidth height += 1 return tiles, width, height
def main() -> int: sdl2.ext.init() resources = Resources(__file__, "resources") controller = Controller() # Objective 1: Create and show the Window window = Window(WINDOW_TITLE, WINDOW_SIZE) window.show() # Objective 2: Create the Renderer with a background color renderer = Renderer(window) color = Color(255, 255, 255) renderer.color = color # Objective 3: Set up the game # Game Loop, draws each frame last_time = time() lag = 0.0 while True: now = time() lag += now - last_time last_time = now controller.handle_input() if controller.has_input(Input.QUIT): break # Objective 3: Update the game the appropriate number of frames while lag >= SECONDS_PER_UPDATE: lag -= SECONDS_PER_UPDATE # Objective 2: Draw over all drawings of the last frame with the default color renderer.clear() # Objective 3: Render the game renderer.present()
SDLK_ESCAPE, \ SDLK_UP, \ SDLK_DOWN, \ SDLK_RETURN, \ SDL_Quit from sdl2.ext import Resources, get_events from const import WindowSize, Colors, HorseNames from input import Input from ui import Dialog from game import Game FPS = 60 # units.FPS MAX_FRAME_TIME = int(5 * (1000 / FPS)) RESOURCES = Resources(__file__, 'resources') class Lobby: def __init__(self, window, world, renderer, factory): self.window = window self.renderer = renderer self.world = world self.factory = factory self.rsystem = factory.create_sprite_render_system(window) self.menu_bg = RESOURCES.get_path("wolfe-09-muybridge.jpg") self.menu_cursor = RESOURCES.get_path("menu_cursor.png") self.running = True
def __init__(self, resources: Resources) -> None: self.texture = None # type: Optional[TextureSprite] self.texture_path = resources.get_path("player.png") self.pos = copy(INITIAL_POS) self.vel = copy(ZERO_VEL) self.restart()
def __init__(self, resources: Resources) -> None: self.texture = None # type: Optional[TextureSprite] self.texture_path = resources.get_path("grass.png") self.tiles, self.width, self.height = load_tile_map(resources)
from sdl2.ext.compat import byteify import OpenGL #OpenGL.ERROR_CHECKING = False from OpenGL.GL import * from OpenGL.GLU import * import pym import functools import numpy import ctypes from sdl2.ext import Resources PyBUF_READ = 0x100 PyBUF_WRITE = 0x200 RESOURCES = Resources(__file__, "assets") # From: # http://larsnordeide.com/2014/pysdl2-playing-a-sound-from-a-wav-file.html # class WavSound(object): def __init__(self, file, pcm): super(WavSound, self).__init__() self._buf = POINTER(Uint8)() self._length = Uint32() self._bufpos = 0 self.pcm = pcm self.want_spec = SDL_AudioSpec(freq=48000, aformat=AUDIO_S16,
import sys import os try: import sdl2.ext as sdl2ext except ImportError: import traceback traceback.print_exc() sys.exit(1) from sdl2.ext import Resources RESOURCES = Resources(os.path.dirname(os.path.abspath(__file__)), "resources") sdl2ext.init() window = sdl2ext.Window("Hello World!", size=(640, 480)) window.show() factory = sdl2ext.SpriteFactory(sdl2ext.SOFTWARE) sprite = factory.from_image(RESOURCES.get_path("Hello.png")) sprite_renderer = factory.create_sprite_renderer(window) sprite_renderer.render(sprite) processor = sdl2ext.TestEventProcessor() processor.run(window) sdl2ext.quit()
# --------------------------------------------------------------------------- # Filename: db.py # Created: 03/16/2017 # Author: TurBoss # E-mail: [email protected] # License: GNU GPL 3.0 # --------------------------------------------------------------------------- """ Database Wrapper """ import sqlite3 from sdl2.ext import Resources from utils import dict_factory DB = Resources(__file__, 'resources', 'db') class DataBase: """" Functions to get and set the database """ def __init__(self): """ Get the database path """ self.db_path = DB.get_path('database.sqlite') def get_all_npc(self): """ Get all NPC from the database :rtype dict :returns all npc in the database """
from sdl2 import SDL_CreateRGBSurface, \ SDL_SWSURFACE, \ SDL_BlitSurface, \ SDL_Rect from sdl2.ext import Resources, \ load_image, \ subsurface, \ SoftwareSprite import pyscroll from pytmx.util_pysdl2 import load_pysdl2 from const import WindowSize MAPS = Resources(__file__, 'resources', 'maps') class Background: def __init__(self, filename, renderer): # Load TMX data self.tmx_data = load_pysdl2(filename=filename, renderer=renderer) # Make data source for the map self.map_data = pyscroll.TiledMapData(self.tmx_data) # Make the scrolling layer screen_size = (400, 400) map_layer = pyscroll.BufferedRenderer(self.map_data, screen_size) # make the pygame SpriteGroup with a scrolling map
import sys,os import init try: import sdl2.ext as sdl2ext except ImportError: import traceback traceback.print_exc() sys.exit(1) from sdl2.ext import Resources RESOURCES = Resources(__file__, "resources") sdl2ext.init() window = sdl2ext.Window("Hello World!", size=(640,480)) window.show() factory = sdl2ext.SpriteFactory(sdl2ext.SOFTWARE) sprite = factory.from_image(RESOURCES.get_path("totoro.png")) spriterenderer = factory.create_sprite_renderer(window) spriterenderer.render(sprite) processor = sdl2ext.TestEventProcessor() processor.run(window) sdl2ext.quit()
TTF_OpenFont, \ TTF_CloseFont, \ TTF_GetError, \ TTF_RenderText_Shaded from sdl2.ext import Resources, \ TextureSpriteRenderSystem, \ TextureSprite, \ SoftwareSprite, \ SoftwareSpriteRenderSystem, \ SDLError, \ FontManager, \ load_image, \ subsurface RESOURCES = Resources(__file__, 'resources', 'ui') FONTS = Resources(__file__, 'resources', 'fonts') class SoftSprite(SoftwareSprite): def __init__(self, renderer, font=None, text="", font_size=16, text_color=SDL_Color(255, 255, 255), background_color=SDL_Color(0, 0, 0)): self.renderer = renderer if font is None: font = FONTS.get_path("BebasKai.TTF") else: font = FONTS.get_path(font)
# -*- coding: utf-8 -*- from sdl2 import SDL_Rect,\ SDL_RenderCopy from sdl2.ext import Resources,\ SpriteFactory,\ TEXTURE from const import WindowSize from utils import int_map RESOURCES = Resources(__file__, 'resources', 'spells') class Facing: LEFT = 0 LEFT_UP = 1 UP = 2 RIGHT_UP = 3 RIGHT = 4 RIGHT_DOWN = 5 DOWN = 6 LEFT_DOWN = 7 COUNT = 8 class Spell: def __init__(self, renderer, factory, name, player_facing): self.renderer = renderer self.factory = factory
from db import DataBase from input import Input from map import Map from npc import Npc from player import Player from components.spritesheet import SpriteSheet from systems.player_animation import PlayerAnimationSystem from systems.player_movement import PlayerMovementSystem from systems.npc_animation import NpcAnimationSystem from systems.npc_movement import NpcMovementSystem FPS = 60 # units.FPS MAX_FRAME_TIME = int(5 * (1000 / FPS)) RESOURCES = Resources(__file__, 'resources') MAPS = Resources(__file__, 'resources', 'maps') class Game: def __init__(self, world, window, renderer, factory): self.db = DataBase() self.running = False self.world = world self.window = window self.renderer = renderer self.factory = factory self.background_tiles = []