0% found this document useful (0 votes)
15 views3 pages

Interface

This document contains Python code for functions related to a turn-based dungeon game interface built with Pygame. It includes functions for ending a turn, getting mouse clicks on tiles, moving a character, handling mouse movement to display tile info, handling menu selections, updating the display, and switching between menus.

Uploaded by

perez0z0
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views3 pages

Interface

This document contains Python code for functions related to a turn-based dungeon game interface built with Pygame. It includes functions for ending a turn, getting mouse clicks on tiles, moving a character, handling mouse movement to display tile info, handling menu selections, updating the display, and switching between menus.

Uploaded by

perez0z0
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 3

import mainhelper

import dungeongenerator
import pygame

###All interface related things

#actions!
def end_turn(dungeon, character):

print('End Turn clicked')

if dungeon.initiative_list[0] != dungeon.initiative_list[-1]:
dungeon.initiative_list.append(dungeon.initiative_list.pop(0)) # Move the
current character to the end of the list
else:
dungeon.initiative_list.insert(0, dungeon.initiative_list.pop()) # Move
the last character to the beginning of the list

#resetting the stuff for the characters


character.current_move = 0
character.current_basicAction = 0
character.current_basicAttack = 0
character.current_special = 0

def get_clicked_tile(room, cell_width, cell_height):


while True:
for event in pygame.event.get():
if event.type == pygame.MOUSEBUTTONDOWN:
if event.button == 1: # Left mouse button
pos = pygame.mouse.get_pos()
clicked_tile = mainhelper.get_tile_at_pos(pos, room, cell_width,
cell_height)
return clicked_tile
else:
continue

#this method should belong to the character class


def move_character(character, room, cell_width, cell_height):
print('move function engaged!')

# Check if the character has already moved this turn


if character.current_move >= character.max_move:
print('Already moved too much this turn!!!!')
return

# Calculate the clicked tile based on the mouse position


clicked_tile = get_clicked_tile(room, cell_width, cell_height)

# Find the current tile where the character is


current_tile = room.find_character_tile(character)

# Calculate the Manhattan distance between the current tile and the clicked tile
distance = room.manhattan_distance((current_tile.i, current_tile.j),
(clicked_tile.i, clicked_tile.j))

# If the clicked tile is within the character's movement range, move the
character to the clicked tile
if distance <= character.movement_rate:
current_tile.character = None
clicked_tile.character = character
character.current_move = character.current_move + 1
else:
print('Cannot move to that location.')

####in here we need to do something for multiline output


def handle_mouse_motion(pos, room, cell_width, cell_height, initiative_list,
current_character, text_output_surface, font):
# Get the tile info for the tile at the mouse position
text = mainhelper.get_tile_info(pos, room, cell_width, cell_height,
initiative_list, current_character)
# Clear the text output surface
text_output_surface.fill((0, 0, 0))
# Render the tile info text onto the surface
text_surface = font.render(text, True, (255, 255, 255))
# Blit the text surface onto the text output surface
text_output_surface.blit(text_surface, (0, 0))

def handle_menu_selection(pos, menu_entries, menu_actions):


for i, entry in enumerate(menu_entries):
if pos[1] > i * 72 and pos[1] < (i + 1) * 72:
menu_actions[entry]()

def update_display(display_surface, text_output_surface, menu_output_surface,


menu_entries, menu_font):
# Draw a rectangle around the text output surface
pygame.draw.rect(text_output_surface, (255, 255, 255), pygame.Rect(0, 0,
text_output_surface.get_width(), text_output_surface.get_height()), 1)
display_surface.blit(text_output_surface, (0, display_surface.get_height() -
text_output_surface.get_height()))

# Draw the menu entries


for i, entry in enumerate(menu_entries):
text_surface = menu_font.render(entry, True, (255, 255, 255)) # Render in
white
menu_output_surface.blit(text_surface, (0, i * 72)) # Adjust the y position
as needed

# Draw a line below each entry


if i < len(menu_entries):
pygame.draw.line(menu_output_surface, (255, 255, 255), (0, (i + 1) * 72
- 5), (menu_output_surface.get_width(), (i + 1) * 72 - 5))

# Blit the menu surface onto the main display surface


display_surface.blit(menu_output_surface, (display_surface.get_width() -
menu_output_surface.get_width(), 0))

# Update the display


pygame.display.flip()
def switch_menu_wrapper(current_menu_actions_var, current_menu_list_var,
target_menu_actions, target_menu_list):
print('Switching menu!')
# Perform the switch by updating the variables
globals()[current_menu_actions_var] = target_menu_actions
print(globals()[current_menu_actions_var])
globals()[current_menu_list_var] = target_menu_list
print(globals()[current_menu_list_var])
print('did we do globals?')

You might also like