示例#1
0
    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 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
示例#3
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
示例#4
0
 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()
示例#5
0
 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)
示例#6
0
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()
示例#7
0
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()