diff --git a/.pylintrc b/.pylintrc index 233b6c0..5d824b8 100644 --- a/.pylintrc +++ b/.pylintrc @@ -1,3 +1,3 @@ [MESSAGES CONTROL] # temporary, until documentation is complete -disable=C0114, C0115, C0116, C0103, W0511, R0902, E1121, W0613, R0801 +disable=C0114, C0115, C0116, C0103, W0511, R0902, E1121, W0613, R0801, E1101, C0301, W0231 diff --git a/game/torch.py b/game/torch.py new file mode 100644 index 0000000..61b06b4 --- /dev/null +++ b/game/torch.py @@ -0,0 +1,53 @@ +from arcade.experimental import Shadertoy +from pyglet.math import Vec2 + +from game.config import SCREEN_WIDTH, SCREEN_HEIGHT + + +class Torch(Shadertoy): + """ShaderToy program to create a torch with shadow effect.""" + + def __init__(self, size, main_source): + # super().__init__(size, main_source) + print("Torch init") + print(size) + print(main_source) + self.shadertoy = None + # self.channel0 = None + # self.channel1 = None + self.load_shader(size, main_source) + print("Torch init") + + def load_shader(self, size, main_source): + shader_file_path = main_source + window_size = size + self.shadertoy = Shadertoy.create_from_file(window_size, shader_file_path) + # self.channel0 = self.shadertoy.ctx.framebuffer( + # color_attachments=[self.shadertoy.ctx.texture(window_size, components=4)] + # ) + # self.channel1 = self.shadertoy.ctx.framebuffer( + # color_attachments=[self.shadertoy.ctx.texture(window_size, components=4)] + # ) + # self.shadertoy.channel_0 = self.channel0.color_attachments[0] + # self.shadertoy.channel_1 = self.channel1.color_attachments[0] + print("Torch load_shader") + + def draw(self, angle): + print(angle) + + # self.channel0.use() + # self.channel0.clear() + # + # self.channel1.use() + # self.channel1.clear() + # # Draw everything that can be hidden in shadows bur does not cast shadow + # # self.walls.draw() + # + # # self.use() + # # self.clear() + self.shadertoy.program["lightPosition"] = Vec2( + SCREEN_WIDTH / 2, SCREEN_HEIGHT / 2 + ) + self.shadertoy.program["lightSize"] = 300 + self.shadertoy.program["angle"] = angle + self.shadertoy.render() diff --git a/game/views/game_view.py b/game/views/game_view.py index e11dc7a..eaa5882 100644 --- a/game/views/game_view.py +++ b/game/views/game_view.py @@ -11,6 +11,8 @@ from game.views import change_views, return_to_view from game.views.inventory import Item, get_inventory_ui +from game.torch import Torch + arcade.enable_timings() @@ -52,6 +54,12 @@ def __init__(self, level): # select the level self.select_level(level) + # create instance of TorchShaderToy and assign to torch attribute + self.torch = Torch( + size=(self.player.width, self.player.height), + main_source=assets.sprites.resolve("shadow.glsl"), + ) + def select_level(self, level: int = 1): """Select the level and set up the game view""" @@ -214,6 +222,7 @@ def on_draw(self): self.clear() self.scene_camera.use() + if self.floor is not None: self.floor.draw() self.walls.draw() @@ -223,11 +232,13 @@ def on_draw(self): self.pickables.draw() self.entities_list.draw() + self.torch.draw(self.player.angle) + # Add GUI self.gui_camera.use() arcade.Text( f"Health: 100, Time: " - f"{':'.join(map(lambda x: f'{int(x):02d}',divmod(time.time()-self.start_time, 60)))}", + f"{':'.join(map(lambda x: f'{int(x):02d}', divmod(time.time() - self.start_time, 60)))}", self.window.width - 200, self.window.height - 25, ).draw()