Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lighting last update #13

Open
wants to merge 14 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified src/.vs/slnx.sqlite
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified src/.vs/src/v17/.wsuo
Binary file not shown.
63 changes: 63 additions & 0 deletions src/Lighting.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import math
def LightAlgorithm(colors, x, y, playerX, playerY, TimeOfDay):
PlayerPos = [(TimeOfDay * 25), 0]
blockPos = [x, y]
Darken = round(math.dist(blockPos, PlayerPos))
Darken = Darken * TimeOfDay
num1 = 100
num2 = 139
num3 = 69
num4 = 19
num5 = 115
num6 = 85
num7 = 34
num8 = 0
num9 = 128
num10 = 211
num11 = 255
num12 = 223
num13 = 135
num14 = 206
num15 = 235
if num1 - Darken < 0:
num1 = Darken + 0
if num2 - Darken < 0:
num2 = Darken + 0
if num3 - Darken < 0:
num3 = Darken + 0
if num4 - Darken < 0:
num4 = Darken + 0
if num5 - Darken < 0:
num5 = Darken + 0
if num6 - Darken < 0:
num6 = Darken + 0
if num7 - Darken < 0:
num7 = Darken + 0
if num8 - Darken < 0:
num8 = Darken + 0
if num9 - Darken < 0:
num9 = Darken + 0
if num10 - Darken < 0:
num10 = Darken + 0
if num11 - Darken < 0:
num11 = Darken + 0
if num12 - Darken < 0:
num12 = Darken + 0
if num13 - Darken < 0:
num13 = Darken + 0
if num14 - Darken < 0:
num14 = Darken + 0
if num15 - Darken < 0:
num15 = Darken + 0
colorslist = [
(num1 - Darken, num1 - Darken, num1 - Darken),
(num2 - Darken, num3 - Darken, num4 - Darken),
(num2 - Darken, num5 - Darken, num6 - Darken),
(num7 - Darken, num2 - Darken, num7 - Darken),
(num8 - Darken, num9 - Darken, num8 - Darken),
(num10 - Darken, num10 - Darken, num10 - Darken),
(num11 - Darken, num12 - Darken, num8 - Darken),
(num9 - Darken, num9 - Darken, num9 - Darken),
(num13 - Darken, num14 - Darken, num15- Darken),
(num11 - Darken, num11 - Darken, num11 - Darken),]
return colorslist
Binary file modified src/__pycache__/Character_creation.cpython-310.pyc
Binary file not shown.
Binary file added src/__pycache__/MainMen.cpython-310.pyc
Binary file not shown.
Binary file modified src/__pycache__/collision.cpython-310.pyc
Binary file not shown.
Binary file modified src/__pycache__/inventory.cpython-310.pyc
Binary file not shown.
Binary file modified src/__pycache__/logo.cpython-310.pyc
Binary file not shown.
Binary file modified src/__pycache__/player.cpython-310.pyc
Binary file not shown.
Binary file modified src/__pycache__/render.cpython-310.pyc
Binary file not shown.
Binary file modified src/__pycache__/terrain_gen.cpython-310.pyc
Binary file not shown.
8 changes: 5 additions & 3 deletions src/logo.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,14 @@ def extract_frames(video_file: str, image_folder: str) -> None:
clip.audio.write_audiofile(image_folder + "/audio.wav")


def play_intro_video(image_folder, not_skipped, screen):
def play_intro_video(image_folder, not_skipped, screen, intro):
clock: object = pig.time.Clock()

# Load the images from the specified folder
image_files: str = sorted(glob.glob(image_folder + "/frame*.png"))

if intro == 1:
image_files: str = sorted(glob.glob(image_folder + "/*.jpg"))
else:
image_files: str = sorted(glob.glob(image_folder + "/frame*.png"))
# Load the audio file
audio_file: str = image_folder + "/audio.wav"
pig.mixer.music.load(audio_file)
Expand Down
169 changes: 92 additions & 77 deletions src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,83 +7,98 @@
import player as pl
from Character_creation import main
tile = [-1,0]
if __name__ == "__main__":
pig.init()
clock: object = pig.time.Clock()
not_skipped: bool = True
reset_terrain: bool = True
clicked: bool = False
# Path to your video file
video_file: str = r"terraria_styled_game\\Company Animated Logo.mov"
infoObject: object = pig.display.Info()
screen: pig.Surface = pig.display.set_mode(
(infoObject.current_w, infoObject.current_h)
)
# pig.display.toggle_fullscreen()
pig.display.set_caption("terraria styledgame")
pig.mouse.set_cursor(pig.SYSTEM_CURSOR_CROSSHAIR)

# Path to the folder to save the extracted frames
image_folder: str = r"terraria_styled_game\\frames"
colliders: list = []
# Extract frames from the video
# logo.extract_frames(video_file, image_folder)
vx, vy = 0, 0 # infoObject.current_w/2, 0#infoObject.current_h /2
# Call the function to play the video
logo.play_intro_video(image_folder, not_skipped, screen)
import MainMen

MainMen.mainfunc()
pig.init()
clock: object = pig.time.Clock()
not_skipped: bool = True
reset_terrain: bool = False
clicked: bool = False
# Path to your video file
video_file: str = r"terraria_styled_game\\Company Animated Logo.mov"
infoObject: object = pig.display.Info()
screen: pig.Surface = pig.display.set_mode(
(infoObject.current_w, infoObject.current_h)
)
pygame_icon = pig.image.load(r'terraria_styled_game\program recources\Screenshot 2023-09-21 181742.png')
pig.display.set_icon(pygame_icon)
# pig.display.toggle_fullscreen()
pig.display.set_caption("terraria styledgame")
pig.mouse.set_cursor(pig.SYSTEM_CURSOR_CROSSHAIR)
# Path to the folder to save the extracted frames
image_folder: str = r"terraria_styled_game\\frames"
colliders: list = []
# Extract frames from the video
# logo.extract_frames(video_file, image_folder)
vx, vy = 0, 0 # infoObject.current_w/2, 0#infoObject.current_h /2
# Call the function to play the video
logo.play_intro_video(image_folder, not_skipped, screen, 0)
image_folder: str = r"terraria_styled_game\\NewHorizonsFrames"
logo.play_intro_video(image_folder, not_skipped, screen, 1)
import MainMen
MainMen.mainfunc()
# Rest of game code goes here...
terrain_gen = tgen.TerrainGenerator(
width=(0, infoObject.current_w // 10), height=infoObject.current_h // 15
)
terrain_gen.run(screen)
player_sprite = main()
player = pl.Player(vx, vy)
DayTime = 0
Morning = 0

# Rest of game code goes here...
terrain_gen = tgen.TerrainGenerator(
width=(0, infoObject.current_h // 5), height=infoObject.current_h // 10
)
terrain_gen.run(screen)
player_sprite = main()
player = pl.Player(vx, vy)
# world:object = tgen.generate()
# for square in world.tiles:
# render.draw(screen, square)
# print(terrain_gen.terrain)
# quit()
# rect=pig.Rect((0,0),(infoObject.current_w,infoObject.current_h))
running = True
while running:
clicked=False
if reset_terrain:
terrain_gen.run(screen)
# pig.draw.rect(screen,(100,100,100,50),rect)
screen.fill(
(
0,
0,
0,
)
# world:object = tgen.generate()
# for square in world.tiles:
# render.draw(screen, square)
# print(terrain_gen.terrain)
# quit()
# rect=pig.Rect((0,0),(infoObject.current_w,infoObject.current_h))
running = True
while running:
clicked=False
if reset_terrain:
terrain_gen.run(screen)
# pig.draw.rect(screen,(100,100,100,50),rect)
screen.fill(
(
0,
0,
0,
)
colliders = render.render_terrain(
screen,
terrain_gen.width,
terrain_gen.height,
terrain_gen.terrain,
terrain_gen.pos_x,
terrain_gen.pos_y,
terrain_gen.camera_x,
terrain_gen.camera_y,
)
result = player.move(infoObject.current_h, screen, infoObject,tile)
if result != None:
reset_terrain = result[0]
clicked = result[1]
tile = [-1,0]
if clicked:
tile = player.delete_tile(terrain_gen.terrain,tile)
player.update(
infoObject.current_h, infoObject.current_w, colliders
) # terrain_gen.colliders)
terrain_gen.camera_x += vx
terrain_gen.camera_y += vy
player.draw(screen, player_sprite)
# player.draw_trail(screen)
pig.display.flip()
clock.tick(60)
)
if Morning == 0:
DayTime = DayTime + 0.005
else:
DayTime = DayTime - 0.005
if DayTime <= 0:
Morning = 0
colliders = render.render_terrain(
screen,
terrain_gen.width,
terrain_gen.height,
terrain_gen.terrain,
terrain_gen.pos_x,
terrain_gen.pos_y,
terrain_gen.camera_x,
terrain_gen.camera_y,
player,
DayTime,
Morning
)
if DayTime > 6.5:
Morning = 1
result = player.move(infoObject.current_h, screen, infoObject,tile)
if result != None:
reset_terrain = result[0]
clicked = result[1]
tile = [-1,0]
if clicked:
tile = player.delete_tile(terrain_gen.terrain,tile)
player.update(
infoObject.current_h, infoObject.current_w, colliders
) # terrain_gen.colliders)
terrain_gen.camera_x += vx
terrain_gen.camera_y += vy
player.draw(screen, player_sprite)
# player.draw_trail(screen)
pig.display.flip()
clock.tick(60)
39 changes: 33 additions & 6 deletions src/render.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import pygame as pig
import typing as tp
import player
import Lighting as Lit
import random
import math


def render_terrain(
Expand All @@ -13,8 +15,11 @@ def render_terrain(
pos_y: float | int,
camera_x: float | int,
camera_y: float | int,
playerpos,
DayTime,
morning
) -> list:
tile_size = 10
tile_size = 15
block_images = [
r"terraria_styled_game\Textures\grass.jpg",
r"terraria_styled_game\Textures\stone.jpg",
Expand All @@ -31,6 +36,7 @@ def render_terrain(
(135, 206, 235), # Sky (Blue)
(255, 255, 255), # Clouds (White)
] # Color palette for blocks
NewColors = [] #stores colors with lighting applied, blank and a placeholder at this point in the script
colliders = []
for x in range(width[0], width[1]):
for y in range(height):
Expand All @@ -48,22 +54,43 @@ def render_terrain(
color = (255, 255, 255)
else:
color = (211, 211, 211)
pig.draw.rect(
screen,
color,
(currentblock),
)
NewColors = Lit.LightAlgorithm(colors, x, y, (playerpos.x*15), (playerpos.y*15), DayTime)
if not color == (211, 211, 211):
color = NewColors[block_type]
else:
PlayerPos = [(DayTime * 25), 0]
blockPos = [x, y]
Darken = round(math.dist(blockPos, PlayerPos))
Darken = Darken * DayTime
color = (211 - Darken, 211 - Darken, 211 - Darken)
try:
pig.draw.rect(
screen,
color,
(currentblock),
)
except:
pig.draw.rect(
screen,
(0, 0, 0),
(currentblock),
)
## Load and blit the corresponding block image
# if block_type < len(block_images):
# block_image = block_images[block_type]
# screen.blit(pig.image.load(block_image), currentblock)
color = colors[block_type]
if (
color != (135, 206, 235)
and color != (139, 115, 85)
and color != (255, 255, 255)
and color != (211, 211, 211)
):
colliders.append(currentblock)
if morning == 0:
pig.draw.rect(
screen, (255, 255, 51), ((DayTime * 250) + 300, 10, 100, 100)
)
return colliders


Expand Down
Loading
Loading