예제 #1
0
    def init(self):
        self.title_img = sf.Texture.load_from_file(
            bytes(os.path.join("assets", "title.png"), 'UTF-8'))
        self.logo_img = sf.Texture.load_from_file(
            bytes(os.path.join("assets", "logo.png"), 'UTF-8'))
        self.title = sf.Sprite(self.title_img)
        self.logo = sf.Sprite(self.logo_img)
        self.logo.position = (575, 0)
        self.title.position = (740, 8)
        self.logo.color = sf.Color(255, 255, 255, 1)
        self.title.color = sf.Color(255, 255, 255, 1)
        self.fadein = True

        self.titletime = 0
        self.logoalpha = 1

        self.done = False

        self.player_img = sf.Texture.load_from_file(
            bytes(os.path.join("assets", "you.png"), 'UTF-8'))
        self.player_sprite = sf.Sprite(self.player_img)
        self.player_sprite.origin = (self.player_sprite.width / 2,
                                     self.player_sprite.height)
        self.player_sprite.position = (60, 500)

        self.to_render = [self.title, self.logo, self.player_sprite]
예제 #2
0
class SpriteBasedEntity(Entity):
    """Base class for sprite-based entities"""

    show_collision_boxes = False  # Draw collision boxes (used by pixel perfect test)
    collision_boxes_color = sf.Color(255, 175, 200, 150)

    def __init__(self, engine, id, pos=sf.Vector2f(), angle=90):
        Entity.__init__(self, id, pos, angle)
        subclass = self.__class__  # provides access to subclass static variables
        if not isinstance(subclass.texture, sf.Texture):
            subclass.texture = loadTexture(subclass.texture_path, engine)
        self.sprite = sf.Sprite(subclass.texture)
        self.collision_table = CollisionTable(
            self.sprite.getTexture().copyToImage())
        if SpriteBasedEntity.show_collision_boxes:
            self.collision_rect = sf.RectangleShape()
            self.collision_rect.setFillColor(
                SpriteBasedEntity.collision_boxes_color)
        else:  # avoid unnecessary memory consumption
            self.collision_rect = None

    def draw(self, target, states):
        if self.collision_rect != None:
            rect = self.getGlobalBounds()
            self.collision_rect.setSize(sf.Vector2f(rect.width, rect.height))
            self.collision_rect.setPosition(rect.left, rect.top)
            target.draw(self.collision_rect)
        states.transform *= self.getTransform()
        target.draw(self.sprite, states)

    def getLocalBounds(self):
        return self.sprite.getLocalBounds()
예제 #3
0
    def render(self, target):
        target.setView(globals.camera)

        target.clear(sf.Color(100, 200, 100))
        self.entities_mgr.drawAll(target)

        target.setView(target.getDefaultView())
예제 #4
0
파일: core.py 프로젝트: klavdijv/pug2d
 def draw(self, window):
     offscreen = self.window
     offscreen.clear(sf.Color(0, 0, 0, 0))
     super(OffscreenLayer, self).draw(offscreen)
     offscreen.display()
     container = self.container.object
     container.texture = offscreen.texture
     window.draw(container, self.container.shader)
예제 #5
0
    def init(self):
        self.paused = False
        self.engine.getRenderWindow().setFramerateLimit(0)
        self.engine.getRenderWindow().setVerticalSyncEnabled(False)

        # particle emitter
        self.emitter = thor.UniversalEmitter.create()
        self.emitter.setEmissionRate(30)
        self.emitter.setLifetime(sf.seconds(5))
        self.emitter.setPositionCallback(self.mousePosition)

        # particle system
        particle = loadTexture("data/particle.png", self.engine)
        self.particle_system = thor.ParticleSystem(thor.noDeletePtr(particle))
        self.particle_system.addEmitter(self.emitter)

        # particle affectors
        gradient = thor.createGradient(sf.Color(0, 150, 0), [
            1,
            sf.Color(0, 150, 100),
            1,
            sf.Color(0, 0, 150),
        ])
        self.particle_system.addAffector(thor.ColorAffector.create(gradient))
        self.particle_system.addAffector(thor.FadeInAffector.create(0.1))
        self.particle_system.addAffector(thor.FadeOutAffector.create(0.1))
        self.particle_system.addAffector(thor.TorqueAffector.create(500))
        self.particle_system.addAffector(
            thor.ForceAffector.create(sf.Vector2f(0, 100)))

        # particle parameters
        self.velocity = thor.PolarVector2f(200, -90)
        # text
        from script.entities_tools import loadFont
        self.font = loadFont("data/Crimson-Roman.otf", self.engine)
        self.text = sf.Text(
            "Left click: Enable/disable glow effect\n"
            "Right click: Pause\n"
            "Mouse wheel: Change direction\n", self.font)
        self.text.setCharacterSize(14)
        self.text.setColor(sf.Color(255, 255, 255))

        return True
예제 #6
0
    def draw(self, window):
        """Draw the bullet as a straight green line."""

        if self.life < 5:
            alpha = int(255 * float(self.life) / 5.0)
        else:
            alpha = 255

        line = sf.Shape.line(0, -5, 0, 5, 1, sf.Color(0, 255, 0, alpha))
        line.position = self.loc
        line.rotation = self.angle
        window.draw(line)
예제 #7
0
    def draw(self, window):
        """Draws the ship in the provided window."""

        # Draw a red triangle of thrust behind the ship if we're accelerating.
        if self.THRUST and self.alive:
            thrustshape = sf.Shape()
            thrustshape.add_point(-3, -6, sf.Color.BLACK, sf.Color.RED)
            thrustshape.add_point(3, -6, sf.Color.BLACK, sf.Color.RED)
            thrustshape.add_point(0, -10, sf.Color.BLACK, sf.Color.RED)
            thrustshape.outline_thickness = 1
            thrustshape.outline_enabled = True
            thrustshape.fill_enabled = False
            thrustshape.position = self.loc
            thrustshape.rotate(self.angle)
            window.draw(thrustshape)

        # Pick the ship's colors
        if self.is_clone:
            dark = 0.3
        else:
            dark = 1
        if self.alive:
            color = sf.Color(255 * dark, 255 * dark, 255 * dark)
        else:
            color = sf.Color(255 * dark, 0, 0)

        # Draw the shape of the ship.
        shipshape = sf.Shape()
        for c in self.corners:
            shipshape.add_point(c.x, c.y, sf.Color.BLACK, color)
        shipshape.outline_thickness = 1
        shipshape.outline_enabled = True
        shipshape.fill_enabled = False
        shipshape.position = self.loc
        shipshape.rotation = self.angle
        window.draw(shipshape)
예제 #8
0
 def fadeout(self, target, *args):
     self.faderect.color = sf.Color(0, 0, 0, 0)
     self.fade = "out"
     cantbelievethereisntaneasierwaytodothis = [target]
     cantbelievethereisntaneasierwaytodothis.extend(list(args))
     self.fadetarget = tuple(cantbelievethereisntaneasierwaytodothis)
예제 #9
0
 def render(self, target):
     target.clear(sf.Color(30, 30, 30))
     self.particle_system.draw(target)
     target.draw(self.text)
예제 #10
0
 def show(self, name):
     self.issues[name].color = sf.Color(255, 255, 255, 150)
예제 #11
0
 def hide(self, name):
     self.issues[name].color = sf.Color(255, 255, 255, 0)