def __init__(self, x, y, max_life=60, max_particles=200, particles_per_update=5, total_creations=None, particle_class=Particle, random_next=False, dx=0, dy=0):
        self.x = x
        self.y = y
        self.orig_x = x
        self.orig_y = y
        self.dx = dx
        self.dy = dy


        self.particle_class = particle_class
        self.random_next = random_next

        self.particles = list()
        self.particles_per_update = particles_per_update
        self.max_particles = max_particles
        self.max_life = max_life
        self.total_creations = total_creations
        self.creations_remaining = total_creations
        self.stopped = False

        for i in range(0,particles_per_update):
            p = self.particle_class(x,y, emitter=self)
            p.update()
            self.particles.append(p)
        
        if(self.total_creations is not None):
            self.creations_remaining = self.creations_remaining - particles_per_update
        else:
            self.creations_remaining = self.max_particles

        cwd = os.path.dirname(__file__)
        sprImg8 = sdl2_DisplayManager.inst().load_surface(os.path.join(cwd,"exp8.png"))
        sprImg16 = sdl2_DisplayManager.inst().load_surface(os.path.join(cwd,"exp16.png"))

        self.txImg8 = sdl2_DisplayManager.inst().texture_from_surface(sprImg8)
        self.txImg16 = sdl2_DisplayManager.inst().texture_from_surface(sprImg16)

        (self.p8_w,self.p8_h) = self.txImg8.size
        (self.p16_w,self.p16_h) = self.txImg16.size

        sdl2.SDL_SetTextureBlendMode(self.txImg8.texture, sdl2.SDL_BLENDMODE_BLEND)
        sdl2.SDL_SetTextureBlendMode(self.txImg16.texture, sdl2.SDL_BLENDMODE_BLEND)

        del sprImg8
        del sprImg16
Esempio n. 2
0
 def create_texture(self,
                    size,
                    access=sdl2.SDL_TEXTUREACCESS_TARGET,
                    blendmode=COPY_BLENDMODE):
     _create_texture = self.renderer.sprite_factory.create_texture_sprite
     texture = _create_texture(self.renderer.wrapped_object,
                               size,
                               access=access)
     sdl2.SDL_SetTextureBlendMode(texture.texture, blendmode)
     return texture
Esempio n. 3
0
    def __init__(self, x, y, max_life=60, max_particles=200, particles_per_update=5,
            emitter_dx_fn=None, emitter_dy_fn=None, dither_dx_fn=None, dither_dy_fn=None):
        self.x = x
        self.y = y

        self.particles = list()
        self.particles_per_update = particles_per_update
        self.max_particles = max_particles
        self.max_life = max_life

        self.emitter_dx_fn = emitter_dx_fn
        self.emitter_dy_fn = emitter_dy_fn

        self.dither_dx_fn = dither_dx_fn
        self.dither_dy_fn = dither_dy_fn

        for i in range(0,particles_per_update):
            p = Particle(x,y, parent=self)
            p.update()
            self.particles.append(p)
        sprFire = sdl2_DisplayManager.inst().load_surface("assets/dmd/fire.png")
        sprWhite = sdl2_DisplayManager.inst().load_surface("assets/dmd/white.png")
        sprYellow = sdl2_DisplayManager.inst().load_surface("assets/dmd/fire_yellow.png")

        sprSmoke = sdl2_DisplayManager.inst().load_surface("assets/dmd/exp.png")

        self.txFire = sdl2_DisplayManager.inst().texture_from_surface(sprFire)
        self.txWhite = sdl2_DisplayManager.inst().texture_from_surface(sprWhite)
        self.txYellow = sdl2_DisplayManager.inst().texture_from_surface(sprYellow)
        self.txSmoke = sdl2_DisplayManager.inst().texture_from_surface(sprSmoke)

        (self.p_w,self.p_h) = self.txSmoke.size

        sdl2.SDL_SetTextureBlendMode(self.txFire.texture, sdl2.SDL_BLENDMODE_BLEND)
        sdl2.SDL_SetTextureBlendMode(self.txWhite.texture, sdl2.SDL_BLENDMODE_BLEND)
        sdl2.SDL_SetTextureBlendMode(self.txYellow.texture, sdl2.SDL_BLENDMODE_BLEND)

        sdl2.SDL_SetTextureBlendMode(self.txSmoke.texture, sdl2.SDL_BLENDMODE_BLEND)

        del sprFire
        del sprWhite
        del sprYellow
        del sprSmoke
Esempio n. 4
0
    def new_render_target(self, target):
        """Set a context for the render target.

        When done, set it to None.

        Args:
            target (SDL_RENDERER, SDL_TEXTURE): the target of the renderer
            to be used during this context.
        """
        sdlrenderer = self.default_args["renderer"].sdlrenderer
        sdl2.SDL_SetRenderTarget(sdlrenderer, target)
        sdl2.SDL_SetTextureBlendMode(target, sdl2.SDL_BLENDMODE_BLEND)
        yield
        sdl2.SDL_SetRenderTarget(sdlrenderer, None)
Esempio n. 5
0
 def refresh(self):
     """
     Refreshes the graphical representation of stored text.
     """
     surface = ttf.TTF_RenderUTF8_Blended(
         self.font.handle, bytes(self._text, "utf8"),
         sdl2.SDL_Color(255, 255, 255, 255))
     if not surface:
         self.surface_size = (0, 0)
         return
     self.surface_size = (surface.contents.w, surface.contents.h)
     self.texture = sdl2.SDL_CreateTextureFromSurface(
         self.canvas.renderer, surface)
     sdl2.SDL_SetTextureBlendMode(self.texture, sdl2.SDL_BLENDMODE_BLEND)
     sdl2.SDL_FreeSurface(surface)
Esempio n. 6
0
    def draw_text(self, area, text, **kwargs):
        x, y, w, h = area
        assert w, (area, text, kwargs)
        assert "width" in kwargs
        texture = self.sprite_factory.from_text(text,
                                                fontmanager=self.font_manager,
                                                **kwargs)
        _w, _h = texture.size
        if kwargs.get(
                "center_text", False
        ):  # and _w <= (w + 40): # +40? seems to fix scaled text snapping between centered/not
            destination = [(x + (w / 2)) - (_w / 2), (y + (h / 2)) - (_h / 2),
                           _w - 2, _h]
        else:
            destination = (x + 2, y + 2, _w - 2, _h)

        sdl2.SDL_SetTextureBlendMode(texture.texture, TEXT_BLENDMODE)
        self.copy(texture, dstrect=destination)
Esempio n. 7
0
    def render(self, renderer):
        i = 0
        for game in self.currentState.roms:
            currentColor = WHITE
            if self.currentState.getCurrentRom() == game:
                currentColor = RED

            surf = sdl2.sdlttf.TTF_RenderText_Blended(
                self.font, game.name.encode("utf-8"), currentColor).contents
            text = sdl2.SDL_CreateTextureFromSurface(renderer, surf)
            sdl2.SDL_SetTextureBlendMode(text, sdl2.SDL_BLENDMODE_BLEND)
            sdl2.SDL_FreeSurface(surf)

            w, h = c_int(), c_int()
            sdl2.SDL_QueryTexture(text, None, None, byref(w), byref(h))
            sdl2.SDL_RenderCopy(renderer, text, None,
                                sdl2.SDL_Rect(50, 50 + (i * 40), w, h))

            i += 1
Esempio n. 8
0
    def render(self, renderer):
        if self.currentSystem != self.currentState.getCurrentSystem().name:
            image = sdl2.sdlimage.IMG_Load(
                b"images/backdrops/" +
                self.currentState.getCurrentSystem().name.encode('utf-8') +
                b".jpg")
            self.text = sdl2.SDL_CreateTextureFromSurface(renderer, image)
            sdl2.SDL_FreeSurface(image)

            sdl2.SDL_SetTextureBlendMode(self.text, sdl2.SDL_BLENDMODE_BLEND)
            sdl2.SDL_SetTextureAlphaMod(self.text, c_uint8(48))
            sdl2.SDL_QueryTexture(self.text, None, None,
                                  byref(self.imageWidth),
                                  byref(self.imageHeight))

            self.currentSystem = self.currentState.getCurrentSystem().name

        percent = 720 / self.imageHeight.value
        sdl2.SDL_RenderCopy(
            renderer, self.text, None,
            sdl2.SDL_Rect(0, 0, int(self.imageWidth.value * percent),
                          int(self.imageHeight.value * percent)))
Esempio n. 9
0
def run_raw():
    global renderer, bg_texture, maze, vmp, walls_texture

    sdl2.SDL_Init(sdl2.SDL_INIT_VIDEO)
    window = sdl2.SDL_CreateWindow(b"Eye of the Beholder 2",
                                   sdl2.SDL_WINDOWPOS_CENTERED, sdl2.SDL_WINDOWPOS_CENTERED,
                                   800, 600, sdl2.SDL_WINDOW_SHOWN | sdl2.SDL_WINDOW_RESIZABLE)

    renderer = sdl2.SDL_CreateRenderer(window, -1,
                                       sdl2.SDL_RENDERER_ACCELERATED + sdl2.SDL_RENDERER_TARGETTEXTURE + sdl2.SDL_RENDERER_PRESENTVSYNC)
    sdl2.SDL_SetRenderDrawBlendMode(renderer, sdl2.SDL_BLENDMODE_BLEND)

    render_target = sdl2.SDL_CreateTexture(renderer, sdl2.SDL_PIXELFORMAT_RGB888, sdl2.SDL_TEXTUREACCESS_TARGET,
                                           VP_WIDTH_PIXELS,
                                           VP_HEIGHT_PIXELS)

    sdl2.SDL_SetTextureBlendMode(render_target, sdl2.SDL_BLENDMODE_BLEND)

    sdl2.sdlimage.IMG_Init(sdl2.sdlimage.IMG_INIT_PNG)

    maze = load_maze('build/level1.maz')

    vmp = load_vmp('build/dung.vmp.json')

    bg_texture = get_vmp_bg_texture()
    walls_texture = get_vmp_wall_texture()

    party_position = (5, 28)
    party_direction = Direction.North

    running = True
    event = sdl2.SDL_Event()
    while running:
        while sdl2.SDL_PollEvent(byref(event)) != 0:
            if event.type == sdl2.SDL_QUIT:
                running = False
                break
            elif event.type == sdl2.SDL_KEYDOWN:
                if event.key.keysym.sym == KEY_W:
                    party_position = party_direction.update_pos(party_position)
                elif event.key.keysym.sym == KEY_S:
                    party_position = party_direction.opposite().update_pos(party_position)
                elif event.key.keysym.sym == KEY_A:
                    party_position = party_direction.previous_dir().update_pos(party_position)
                elif event.key.keysym.sym == KEY_D:
                    party_position = party_direction.next_dir().update_pos(party_position)
                elif event.key.keysym.sym == KEY_Q:
                    party_direction = party_direction.previous_dir()
                elif event.key.keysym.sym == KEY_E:
                    party_direction = party_direction.next_dir()

                print(f'position: {party_position[0]}, {party_position[1]}, direction: {party_direction.symbol}')

        sdl2.SDL_SetRenderTarget(renderer, render_target)
        sdl2.SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255)
        sdl2.SDL_RenderClear(renderer)

        draw_bg()

        draw_walls(party_position, party_direction)

        sdl2.SDL_SetRenderTarget(renderer, None)

        sdl2.SDL_RenderCopy(renderer, render_target, None, None)
        sdl2.SDL_RenderPresent(renderer)

    sdl2.SDL_DestroyWindow(window)
    sdl2.SDL_Quit()
    return 0
Esempio n. 10
0
def get_vmp_wall_texture():
    surface = sdl2.sdlimage.IMG_Load(bytes(f'build/vcn_{vmp["name"]}_walls.png', 'utf-8'))
    sdl2.SDL_SetColorKey(surface, sdl2.SDL_TRUE, 0)
    texture = sdl2.SDL_CreateTextureFromSurface(renderer, surface)
    sdl2.SDL_SetTextureBlendMode(texture, sdl2.SDL_BLENDMODE_BLEND)
    return texture
Esempio n. 11
0
	def load(self, renderer):
		# Player
		self.textures[TextureType.PLAYER] = self.create(
			renderer, b'textures/player.png')

		# Characters
		self.textures[TextureType.CIVILIAN] = self.create(
			renderer, b'textures/civilian.png')
		self.textures[TextureType.STOCKER] = self.create(
			renderer, b'textures/stocker.png')

		# Locations
		self.textures[TextureType.HOUSE_INTERIOR] = self.create(
			renderer, b'textures/house_interior.png')
		self.textures[TextureType.GROCERY_STORE_INTERIOR] = self.create(
			renderer, b'textures/grocery_store_interior.png')
		self.textures[TextureType.GAS_STATION_INTERIOR] = self.create(
			renderer, b'textures/gas_station_interior.png')
		self.textures[TextureType.HOUSE_EXTERIOR] = self.create(
			renderer, b'textures/house_exterior.png')
		self.textures[TextureType.HOUSE_EXTERIOR_REAR] = self.create(
			renderer, b'textures/house_exterior_rear.png')
		self.textures[TextureType.GROCERY_STORE_EXTERIOR] = self.create(
			renderer, b'textures/grocery_store_exterior.png')
		self.textures[TextureType.GAS_STATION_EXTERIOR] = self.create(
			renderer, b'textures/gas_station_exterior.png')

		# Supplies
		self.textures[TextureType.FOOD] = self.create(
			renderer, b'textures/food.png')
		self.textures[TextureType.SOAP] = self.create(
			renderer, b'textures/soap.png')
		self.textures[TextureType.HAND_SANITIZER] = self.create(
			renderer, b'textures/hand_sanitizer.png')
		self.textures[TextureType.TOILET_PAPER] = self.create(
			renderer, b'textures/toilet_paper.png')
		self.textures[TextureType.MASK] = self.create(
			renderer, b'textures/mask.png')
		self.textures[TextureType.PET_SUPPLIES] = self.create(
			renderer, b'textures/pet_supplies.png')

		# Items
		self.textures[TextureType.VEHICLE] = self.create(
			renderer, b'textures/vehicle.png')
		self.textures[TextureType.SINK] = self.create(
			renderer, b'textures/sink.png')
		self.textures[TextureType.KITCHEN] = self.create(
			renderer, b'textures/kitchen.png')
		self.textures[TextureType.BED] = self.create(
			renderer, b'textures/bed.png')
		self.textures[TextureType.COMPUTER] = self.create(
			renderer, b'textures/computer.png')
		self.textures[TextureType.SHOPPING_CART] = self.create(
			renderer, b'textures/cart.png')
		self.textures[TextureType.DOOR] = self.create(
			renderer, b'textures/door.png')
		self.textures[TextureType.SELF_CHECKOUT] = self.create(
			renderer, b'textures/self_checkout.png')
		self.textures[TextureType.CLOSET] = self.create(
			renderer, b'textures/closet.png')
		self.textures[TextureType.FUEL_DISPENSER] = self.create(
			renderer, b'textures/fuel_dispenser.png')

		# Pets
		self.textures[TextureType.DOG] = self.create(
			renderer, b'textures/dog.png')

		# Map Elements
		self.textures[TextureType.AISLE] = self.create(
			renderer, b'textures/aisle.png')
		self.textures[TextureType.ROAD] = self.create(
			renderer, b'textures/road.png')
		self.textures[TextureType.SIDEWALK] = self.create(
			renderer, b'textures/sidewalk.png')
		self.textures[TextureType.DRIVEWAY] = self.create(
			renderer, b'textures/driveway.png')
		self.textures[TextureType.PARKING_LOT] = self.create(
			renderer, b'textures/parking_lot.png')
		self.textures[TextureType.COUNTER] = self.create(
			renderer, b'textures/counter.png')
		self.textures[TextureType.DESK] = self.create(
			renderer, b'textures/desk.png')

		# World
		self.textures[TextureType.GRASS] = self.create(
			renderer, b'textures/grass.png')

		# User Interface
		self.textures[TextureType.SPLASH_SCREEN] = self.create(
			renderer, b'textures/splash_screen.jpg')
		self.textures[TextureType.LOSE_SCREEN] = self.create(
			renderer, b'textures/lose_screen.jpg')
		self.textures[TextureType.MINI_MAP] = self.create(
			renderer, b'textures/mini_map.png')
		
		# Increase transparency on mini-map texture
		sdl2.SDL_SetTextureBlendMode(self.textures[TextureType.MINI_MAP],
			sdl2.SDL_BLENDMODE_BLEND)
		sdl2.SDL_SetTextureAlphaMod(self.textures[TextureType.MINI_MAP], 75)