Mozaik effekt

This commit is contained in:
markojozsef
2026-09-25 10:31:07 +02:00
parent 8e060ce43f
commit 7a62dc6ae0
6 changed files with 37 additions and 17 deletions

View File

@@ -9,13 +9,13 @@ gamestates = {
}
gamestate = "none"
def switch_gamestate(state):
def switch_gamestate(game, state):
global gamestate
gamestate = state
gamestates[gamestate].switch()
gamestates[gamestate].switch(game)
def update(dt):
gamestates[gamestate].update(dt)
def update(game, dt):
gamestates[gamestate].update(game, dt)
def draw(game):
gamestates[gamestate].draw(game)

View File

@@ -1,5 +1,5 @@
import gamestate
# Azért létezik ez a "none" gamestate hogy meghívja az elsö gamestate init() funkcióját
def update(dt):
gamestate.switch_gamestate("overworld")
def update(game, dt):
gamestate.switch_gamestate(game, "title")

View File

@@ -26,8 +26,6 @@ OVERWORLD_MAP = [
[0,0,0,0],
]
class BalthasarController:
def __init__(self):
self.direction = DIR_UP
@@ -95,10 +93,10 @@ class OverworldMap:
controller = BalthasarController()
overworld = OverworldMap()
def switch():
def switch(game):
pass
def update(dt):
def update(game, dt):
controller.update()
if controls.is_control_pressed(0): # Fel

View File

@@ -10,18 +10,24 @@ panel = renderers.NineSlicesPanel(0,100,230,100)
m = []
def switch():
def mos_1x(g):
g.mosaic = 1
def mos_2x(g):
g.mosaic = 2
def switch(game):
global m
m = [
menu.MenuItem("1", 100, 90, None, None, None, None, None, None),
menu.MenuItem("2", 100, 70 , None, None, None, None, None, None)
menu.MenuItem("1", 100, 90, None, None, None, None, mos_1x, game),
menu.MenuItem("2", 100, 70 , None, None, None, None, mos_2x, game)
]
m[0].down = m[1]
m[1].up = m[0]
m[0].select()
def update(dt):
def update(game, dt):
controltext = ""
for c in controls.controls:

View File

@@ -19,6 +19,8 @@ class Game(arcade.Window):
self.screen_width = SCREEN_WIDTH
self.screen_height = SCREEN_HEIGHT
self.mosaic = 1
self.mos_enabled = False
self.game_texture = self.ctx.texture(
(SCREEN_WIDTH, SCREEN_HEIGHT),
@@ -33,7 +35,7 @@ class Game(arcade.Window):
self.renderer = renderers.TextureRenderer(self.ctx)
def on_update(self, dt):
gamestate.update(dt)
gamestate.update(game, dt)
controls.update()
def on_key_press(self, symbol, modifiers):
@@ -73,6 +75,8 @@ class Game(arcade.Window):
y,
scaled_width,
scaled_height,
self.mosaic,
self.mos_enabled
)
game = Game()

View File

@@ -34,24 +34,36 @@ class TextureRenderer:
""",
fragment_shader="""
#version 330
#define INV_RESOLUTION_X (1. / screen_size.x)
#define INV_RESOLUTION_Y (1. / screen_size.y)
uniform vec2 screen_size;
uniform sampler2D tex;
uniform float mosaic;
uniform bool mos_enabled;
in vec2 uv;
out vec4 color;
void main() {
color = texture(tex, uv);
vec2 new_uv = vec2(
(floor((uv.x / INV_RESOLUTION_X) / mosaic) * INV_RESOLUTION_X) * mosaic,
(floor((uv.y / INV_RESOLUTION_Y) / mosaic) * INV_RESOLUTION_Y) * mosaic
);
color = texture(tex, mos_enabled ? new_uv : uv);
}
""",
)
self.quad = arcade.gl.geometry.quad_2d_fs()
def render(self, texture, x, y, width, height):
def render(self, texture, x, y, width, height, mosaic, mos_enabled):
self.program["screen_size"] = (self.ctx.screen.width,
self.ctx.screen.height)
self.program["bounds"] = (x, y, width, height)
self.program["mosaic"] = mosaic
self.program["mos_enabled"] = mos_enabled
texture.use(0)
self.program["tex"] = 0