Skip to content

Commit

Permalink
노이즈 추가 (#10)
Browse files Browse the repository at this point in the history
Co-authored-by: AkiaCode <[email protected]>
  • Loading branch information
MineEric64 and AkiaCode committed Sep 4, 2023
1 parent d354629 commit c929468
Show file tree
Hide file tree
Showing 8 changed files with 67 additions and 16 deletions.
3 changes: 1 addition & 2 deletions characters/__init__.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import pygame
from abc import ABC

from components.config import CONFIG, CONST, debug
from components.config import CONFIG, CONST

from components.text.text_collection import TextCollection
from components.events.grace_period import GracePeriod

from components.sprites.sprite_collection import SpriteCollection
from components.sprites.sprite_handler import SpriteHandler
from components.sprites.sprite import Sprite

class Character(ABC):
Expand Down
7 changes: 1 addition & 6 deletions characters/enemy.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
import pygame
from threading import Timer

from characters.player import Player
from characters.texture import Texture

from components.config import CONFIG, CONST, debug
from components.sprites.sprite import Sprite
from components.config import CONFIG

class Enemy(Player):
def follow_player(self, obstacles: list[Texture]):
Expand Down
2 changes: 1 addition & 1 deletion characters/player.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from characters import Character

from components.config import CONST, CONFIG, debug
from components.config import CONST, CONFIG

from components.sprites.sprite_collection import SpriteCollection
from components.sprites.sprite_handler import SpriteHandler
Expand Down
50 changes: 50 additions & 0 deletions components/events/noise.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import pygame
import numpy as np

import time

from components.config import CONFIG, debug

class NoiseEvent:
"""노이즈 생성 및 관리 클래스"""

level = 1.0
"""노이즈 강도 (1 ~ 3)"""

width = 960
"""노이즈 이미지 너비 (기본값: 960)"""

height = 540
"""노이즈 이미지 높이 (기본값: 540)"""

@classmethod
def make_noise(cls) -> pygame.Surface:
"""
노이즈 이미지를 생성합니다.
:return: 노이즈 이미지
"""

noise = pygame.Surface((cls.width, cls.height), pygame.SRCALPHA, 32)
# noise2 = np.random.normal(0, 0.3, (cls.width, cls.height, 3))

x = np.zeros(cls.width * cls.height * 3)
x = x.reshape((cls.width, cls.height, 3)) # flat view

for ii in range(cls.width):
x[ii] += CONFIG.random.randint(0, 50)

pygame.surfarray.blit_array(noise, x)
return noise.convert()

@classmethod
def multiply(cls, noise: pygame.Surface, background: pygame.Surface) -> pygame.Surface:
"""
노이즈 이미지와 배경 이미지를 곱합성합니다.
:noise: 노이즈 이미지
:background: 기존 배경 이미지
:return: 곱합성된 새로운 이미지
"""

surface = background.copy().convert()
surface.blit(noise, (0, 0), None, pygame.BLEND_RGBA_SUB)
return surface
4 changes: 1 addition & 3 deletions components/events/text.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import pygame
from threading import Timer

from components.config import CONFIG, CONST, debug
from components.config import CONFIG

from components.text import Text
from components.text.text_collection import TextCollection
from components.text.mutual_text import MutualText

from characters.player import Player

Expand Down
4 changes: 2 additions & 2 deletions components/events/time.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from collections import deque
from characters.player import Player
from components.config import CONFIG, debug
from components.config import CONFIG

class CharacterValue:
"""시간 관리를 위한 캐릭터 값 관리 클래스"""
Expand Down Expand Up @@ -48,7 +48,7 @@ def rewind(cls) -> list[CharacterValue]:
@classmethod
def update(cls, characters: list[Player]):
"""
플레이어의 위치를 업데이트합니다.
캐릭터의 위치를 업데이트합니다.
:param characters: 현재 캐릭터 모음
"""
positions: list[CharacterValue] = [CharacterValue(character, character.x, character.y) for character in characters] # 캐릭터 값 각각 저장
Expand Down
2 changes: 1 addition & 1 deletion components/sfx_collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def init(cls):
def control_mute(cls):
"""음소거 되어있으면 해제하고, 되어있지 않으면 음소거합니다."""
cls.muted = not cls.muted
cls.volume = 0.0 if cls.muted else 1.0 # 음소거면 음량을 0으로 조절
cls.volume = 0.0 if cls.muted else cls.volume # 음소거면 음량을 0으로 조절

cls.set_volume(cls.volume) # 음량 저장

Expand Down
11 changes: 10 additions & 1 deletion maps/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
from components.config import CONFIG, debug
from components.world import World

from components.events.time import TimeEvent
from components.events.noise import NoiseEvent

from characters.player import Player
from characters.enemy import Enemy
from characters.texture import Texture
Expand Down Expand Up @@ -82,7 +85,13 @@ def render(self, frame_count: int):
"""
self.background.set_pos(CONFIG.camera_x, self.background.y)

CONFIG.surface.blit(self.background.image.convert(), self.background.get_pos())
background_image = self.background.image.convert()

if TimeEvent.is_rewind:
noise = NoiseEvent.make_noise()
background_image = NoiseEvent.multiply(noise, background_image)

CONFIG.surface.blit(background_image.convert(), self.background.get_pos())
CONFIG.surface.blit(self.floor.image, self.floor.get_pos())

World.process_gravity(self.enemies + [self.player], self.floor.y) # 중력 구현
Expand Down

0 comments on commit c929468

Please sign in to comment.