Compare commits
No commits in common. "5eb2079da181a8d47a0340f5ca590a8cedf63e9e" and "b80a5afc4aed874e53e7f83464846bf6779b86ce" have entirely different histories.
5eb2079da1
...
b80a5afc4a
22
main.py
22
main.py
@ -1,10 +1,9 @@
|
||||
import pygame
|
||||
import time
|
||||
import sys
|
||||
import random
|
||||
|
||||
from world.world import World, Position
|
||||
from world.render_objects import DebugRenderObject, FoodObject
|
||||
from world.render_objects import DebugRenderObject
|
||||
from world.simulation_interface import Camera
|
||||
|
||||
# Initialize Pygame
|
||||
@ -18,19 +17,17 @@ DARK_GRAY = (64, 64, 64)
|
||||
GRAY = (128, 128, 128)
|
||||
WHITE = (255, 255, 255)
|
||||
RENDER_BUFFER = 50
|
||||
SPEED = 700 # Pixels per second
|
||||
|
||||
# Grid settings
|
||||
GRID_WIDTH = 20 # Number of cells horizontally
|
||||
GRID_HEIGHT = 15 # Number of cells vertically
|
||||
CELL_SIZE = 20 # Size of each cell in pixels
|
||||
|
||||
DEFAULT_TPS = 20 # Number of ticks per second for the simulation
|
||||
FOOD_SPAWNING = False
|
||||
DEFAULT_TPS = 5 # Amount of ticks per second for the simulation
|
||||
|
||||
|
||||
def draw_grid(screen, camera, showing_grid=True):
|
||||
# Fill the screen with black
|
||||
# Fill screen with black
|
||||
screen.fill(BLACK)
|
||||
|
||||
# Calculate effective cell size with zoom
|
||||
@ -144,9 +141,6 @@ def main():
|
||||
world.add_object(DebugRenderObject(Position(0, 0)))
|
||||
world.add_object(DebugRenderObject(Position(20, 0)))
|
||||
|
||||
# sets seed to 67 >_<
|
||||
random.seed(67)
|
||||
|
||||
running = True
|
||||
while running:
|
||||
deltatime = clock.get_time() / 1000.0 # Convert milliseconds to seconds
|
||||
@ -231,14 +225,6 @@ def main():
|
||||
total_ticks += 1
|
||||
# Add your tick-specific logic here
|
||||
|
||||
# gets every object in the world and returns amount of FoodObjects
|
||||
objects = world.get_objects()
|
||||
print(objects)
|
||||
food = len([obj for obj in objects if isinstance(obj, FoodObject)])
|
||||
print(f"Food count: {food}")
|
||||
if food < 10 and FOOD_SPAWNING == True:
|
||||
world.add_object(FoodObject(Position(random.randint(-200, 200), random.randint(-200, 200))))
|
||||
|
||||
print("Tick logic executed")
|
||||
world.tick_all()
|
||||
|
||||
@ -312,7 +298,7 @@ def main():
|
||||
for each in selected_objects:
|
||||
obj = each
|
||||
obj_text = font.render(
|
||||
f"Object: {str(obj)}", True, WHITE
|
||||
f"Object: {str(obj)}, Neighbors: {obj.neighbors}", True, WHITE
|
||||
)
|
||||
obj_rect = obj_text.get_rect()
|
||||
obj_rect.topleft = (10, 30 + i * 20)
|
||||
|
||||
@ -1,12 +1,6 @@
|
||||
from world.world import Position, BaseEntity
|
||||
import pygame
|
||||
|
||||
# returns desired yellow value for food decay
|
||||
def food_decay_yellow(decay):
|
||||
if decay < 128:
|
||||
return decay
|
||||
else:
|
||||
return 255 - decay
|
||||
|
||||
class DebugRenderObject(BaseEntity):
|
||||
def __init__(self, position: Position, radius=5):
|
||||
@ -39,39 +33,3 @@ class DebugRenderObject(BaseEntity):
|
||||
|
||||
def __repr__(self):
|
||||
return f"DebugRenderObject({self.position}, neighbors={self.neighbors})"
|
||||
|
||||
class FoodObject(BaseEntity):
|
||||
def __init__(self, position: Position):
|
||||
super().__init__(position)
|
||||
|
||||
self.max_visual_width = 10
|
||||
self.decay = 0
|
||||
self.interaction_radius = 50
|
||||
self.flags = {
|
||||
"death": False,
|
||||
"can_interact": True,
|
||||
}
|
||||
|
||||
def tick(self, interactable=None):
|
||||
if interactable is None:
|
||||
interactable = []
|
||||
|
||||
self.decay += 1
|
||||
|
||||
if self.decay > 255:
|
||||
self.decay = 255
|
||||
self.flag_for_death()
|
||||
|
||||
return self
|
||||
|
||||
def render(self, camera, screen):
|
||||
if camera.is_in_view(*self.position.get_position()):
|
||||
pygame.draw.circle(
|
||||
screen,
|
||||
(255-self.decay,food_decay_yellow(self.decay),0),
|
||||
camera.world_to_screen(*self.position.get_position()),
|
||||
5 * camera.zoom
|
||||
)
|
||||
|
||||
def __repr__(self):
|
||||
return f"FoodObject({self.position}, decay={self.decay})"
|
||||
@ -101,12 +101,6 @@ class World:
|
||||
closest_obj = obj
|
||||
return closest_obj
|
||||
|
||||
def get_objects(self):
|
||||
all_objects = []
|
||||
for obj_list in self.buffers[self.current_buffer].values():
|
||||
all_objects.extend(obj_list)
|
||||
print("All objects: ", all_objects)
|
||||
return all_objects
|
||||
|
||||
class BaseEntity(ABC):
|
||||
def __init__(self, position: "Position"):
|
||||
@ -130,8 +124,9 @@ class BaseEntity(ABC):
|
||||
def flag_for_death(self):
|
||||
self.flags["death"] = True
|
||||
|
||||
|
||||
class Position:
|
||||
def __init__(self, x: int, y: int):
|
||||
def __init__(self, x, y):
|
||||
self.x = x
|
||||
self.y = y
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user