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

water #12

Open
wants to merge 1 commit 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/__pycache__/render.cpython-311.pyc
Binary file not shown.
Binary file added src/__pycache__/water.cpython-311.pyc
Binary file not shown.
4 changes: 2 additions & 2 deletions src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,10 @@
terrain_gen.camera_x,
terrain_gen.camera_y,
)
result = player.move(infoObject.current_h, screen, infoObject,tile)
result = player.move(infoObject.current_h, screen, infoObject,tile)
if result != None:
reset_terrain = result[0]
clicked = result[1]
clicked = result[1]
tile = [-1,0]
if clicked:
tile = player.delete_tile(terrain_gen.terrain,tile)
Expand Down
11 changes: 9 additions & 2 deletions src/render.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
import typing as tp
import player
import random


#import water as phwater
water=[]
def render_terrain(
screen: pig.Surface,
width: float | int,
Expand All @@ -19,6 +19,7 @@ def render_terrain(
r"terraria_styled_game\Textures\grass.jpg",
r"terraria_styled_game\Textures\stone.jpg",
]
global water
colors = [
(100, 100, 100), # Stone
(139, 69, 19), # Dirt
Expand All @@ -30,6 +31,8 @@ def render_terrain(
(128, 128, 128), # Diamond
(135, 206, 235), # Sky (Blue)
(255, 255, 255), # Clouds (White)
(100,170,190), #water blue
(242,209,107),#sand yellow
] # Color palette for blocks
colliders = []
for x in range(width[0], width[1]):
Expand All @@ -48,6 +51,9 @@ def render_terrain(
color = (255, 255, 255)
else:
color = (211, 211, 211)
# if color == (100,170,190):
#addwater

pig.draw.rect(
screen,
color,
Expand All @@ -62,6 +68,7 @@ def render_terrain(
and color != (139, 115, 85)
and color != (255, 255, 255)
and color != (211, 211, 211)
and color != (100,170,190)
):
colliders.append(currentblock)
return colliders
Expand Down
29 changes: 24 additions & 5 deletions src/terrain_gen.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,26 @@ def __init__(self, width, height, pos_x=0, pos_y=0):

def generate_terrain(self):
self.terrain = [[0 for _ in range(self.width[1])] for _ in range(self.height)]

ground_levels = [int(self.height / 1.5)] * self.width[1]
# Set sky blocks
for x in range(self.width[0], self.width[1]):
for y in range(ground_levels[x]):
self.terrain[y][x] = 8 # Sky

# Generate natural water features in dips (lakes)
for x in range(self.width[0], self.width[1]):
dip_chance = random.randint(0, 100)
if dip_chance < 5: # Adjust the chance as needed for less frequent lakes
lake_width = random.randint(10, 30) # Random width of the lake
lake_depth = random.randint(5, 15) # Random depth of the lake
lake_start_y = ground_levels[x] # Start the lake at the ground level
for y in range(lake_start_y, lake_start_y + lake_depth):
for dx in range(-lake_width // 2, lake_width // 2 + 1):
if 0 <= x + dx < self.width[1] and 0 <= y < self.height:
self.terrain[y][x + dx] = 10 # Water

# Generate random ground
ground_levels = [self.height // 2] * self.width[1]
ground_levels = [int(self.height / 1.5)] * self.width[1]
for x in range(self.width[0], self.width[1]):
ground_levels[x] = ground_levels[x - 1] + random.randint(-2, 2)
ground_levels[x] = max(0, min(self.height - 1, ground_levels[x]))
Expand All @@ -27,10 +44,11 @@ def generate_terrain(self):
for y in range(ground_levels[x], self.height):
self.terrain[y][x] = random.choice([0, 1]) # Stone or Dirt

# Set sky blocks
# sand
for x in range(self.width[0], self.width[1]):
for y in range(ground_levels[x]):
self.terrain[y][x] = 8 # Sky
for y in range(ground_levels[x], self.height):
if self.terrain[y - 1][x] == 10:
self.terrain[y][x] = 11 # Replace empty space with dirt

# Generate trees
tree_count = self.width[1] // 10
Expand All @@ -53,6 +71,7 @@ def generate_terrain(self):
):
if abs(dx) + abs(dy) <= leaf_radius:
self.terrain[tree_y + dy][tree_x + dx] = 3 # Leaves


# Generate ore deposits
ore_count = self.width[1] // 100
Expand Down
Loading
Loading