Skip to content

Commit

Permalink
added some text
Browse files Browse the repository at this point in the history
  • Loading branch information
rutra8002 committed Jul 17, 2024
1 parent 0346342 commit 4e4320b
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
6 changes: 6 additions & 0 deletions classes/Camera.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ def update(self):
obj.rect = pygame.Rect(obj.rect.x - 10, obj.rect.y, obj.rect.width, obj.rect.height)
for i in range(len(obj.points)):
obj.points[i] = (obj.points[i][0] - 10, obj.points[i][1])
self.x -= 10

if keys[pygame.K_LEFT]: # Left arrow key is held down
for i in range(len(self.game.points)):
Expand All @@ -30,6 +31,7 @@ def update(self):
obj.rect = pygame.Rect(obj.rect.x + 10, obj.rect.y, obj.rect.width, obj.rect.height)
for i in range(len(obj.points)):
obj.points[i] = (obj.points[i][0] + 10, obj.points[i][1])
self.x += 10

if keys[pygame.K_UP]: # Up arrow key is held down
for i in range(len(self.game.points)):
Expand All @@ -40,6 +42,8 @@ def update(self):
for i in range(len(obj.points)):
obj.points[i] = (obj.points[i][0], obj.points[i][1] + 10)

self.y += 10

if keys[pygame.K_DOWN]: # Down arrow key is held down
for i in range(len(self.game.points)):
self.game.points[i] = (self.game.points[i][0], self.game.points[i][1] - 10)
Expand All @@ -49,3 +53,5 @@ def update(self):
obj.rect = pygame.Rect(obj.rect.x, obj.rect.y - 10, obj.rect.width, obj.rect.height)
for i in range(len(obj.points)):
obj.points[i] = (obj.points[i][0], obj.points[i][1] - 10)

self.y -= 10
21 changes: 21 additions & 0 deletions classes/game.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,17 @@ def __init__(self, save, preset):

print(self.objects)

def render_text(self, text, position, color=(255, 255, 255)):
"""
Renders text at the specified position.
:param text: The text to render.
:param position: A tuple (x, y) representing where to render the text.
:param color: The color of the text.
"""
font = pygame.font.Font(None, 24) # You can adjust the font and size
text_surface = font.render(text, True, color)
self.screen.blit(text_surface, position)

def create_cursor_particles(self):
mouse_x, mouse_y = pygame.mouse.get_pos()
self.cursor_particle_system.add_particle(
Expand Down Expand Up @@ -374,6 +385,16 @@ def render(self):

if self.mode == 'default':

camera_coords_text = f"Camera X: {self.camera.x}, Y: {self.camera.y}"
self.render_text(camera_coords_text, (10, 200)) # Adjust position as needed

for i, obj in enumerate(self.objects):
if hasattr(obj, 'x') and hasattr(obj, 'y'):
object_coords_text = f"Obj {i} X: {obj.x}, Y: {obj.y}"
else:
object_coords_text = f"Obj {i} X: N/A, Y: N/A"
self.render_text(object_coords_text, (10, 220 + i * 20)) # Adjust position as needed

sorted_objects = sorted(self.objects, key=lambda obj: getattr(obj, 'layer', 0))
for object in sorted_objects:
if type(object) == settings_screen.Settings_screen:
Expand Down

0 comments on commit 4e4320b

Please sign in to comment.