2025-01-21 16:40:46 -05:00
|
|
|
"""
|
2025-01-22 11:23:11 -05:00
|
|
|
miniopolis.py
|
2025-01-21 16:40:46 -05:00
|
|
|
|
|
|
|
author: Caleb Scott
|
|
|
|
|
2025-01-22 11:23:11 -05:00
|
|
|
First attempt to make a tile-based colony-sim game.
|
2025-01-21 16:40:46 -05:00
|
|
|
"""
|
|
|
|
|
|
|
|
# IMPORTS -----------------------------------------------------------
|
|
|
|
|
|
|
|
import arcade
|
2025-01-22 12:34:51 -05:00
|
|
|
|
2025-02-04 14:43:54 -05:00
|
|
|
from lib.scene.scene_config import *
|
2025-01-21 16:40:46 -05:00
|
|
|
|
|
|
|
# CLASSES -----------------------------------------------------------
|
|
|
|
|
|
|
|
class GameBoard(arcade.Window):
|
|
|
|
|
|
|
|
def __init__(self, width, height, title):
|
|
|
|
|
|
|
|
# Basic setup for size of window + default background
|
|
|
|
super().__init__(width, height, title)
|
|
|
|
arcade.set_background_color(arcade.color.BLACK)
|
|
|
|
|
|
|
|
def setup(self):
|
|
|
|
"""
|
|
|
|
Used for starting up the game board
|
|
|
|
"""
|
|
|
|
# Obtain world tilemap
|
|
|
|
self.tile_map = arcade.load_tilemap(
|
|
|
|
TEST_MAP,
|
|
|
|
scaling=TILE_SCALE,
|
2025-02-05 15:33:07 -05:00
|
|
|
layer_options=LAYER_OPTIONS
|
2025-01-21 16:40:46 -05:00
|
|
|
)
|
|
|
|
self.scene = arcade.Scene.from_tilemap(self.tile_map)
|
|
|
|
|
2025-02-05 15:33:07 -05:00
|
|
|
for layer in self.scene.keys():
|
|
|
|
print(layer)
|
|
|
|
|
2025-01-21 16:40:46 -05:00
|
|
|
# Tiles selection
|
|
|
|
self.selected_struct_tile = "[Nothing]"
|
2025-01-22 12:34:51 -05:00
|
|
|
self.selected_env_tile = GROUND
|
|
|
|
|
|
|
|
# Structure build state
|
|
|
|
self.pressed_key = None
|
|
|
|
self.build_mode = ""
|
2025-01-21 16:40:46 -05:00
|
|
|
|
2025-01-22 14:51:13 -05:00
|
|
|
# Errors
|
|
|
|
self.error_msg = ""
|
|
|
|
|
2025-01-21 16:40:46 -05:00
|
|
|
# Render text for the game
|
|
|
|
self.structs_text = arcade.Text(
|
|
|
|
"STRUCTURES: [L]ogger [C]rops [W]ater Power [H]ousing [M]iner [F]actory [J]unction",
|
2025-01-26 19:24:10 -05:00
|
|
|
x=TEXT_X, y=TEXT_Y
|
2025-01-21 16:40:46 -05:00
|
|
|
)
|
|
|
|
self.commands_text = arcade.Text(
|
2025-01-22 11:33:20 -05:00
|
|
|
"COMMANDS: [LMB] - Check Tile [LMB+X] - Delete [LMB+KEY] - Put Structure",
|
2025-01-26 19:24:10 -05:00
|
|
|
x=TEXT_X, y=TEXT_Y - TEXT_Y_WIDTH
|
2025-01-21 16:40:46 -05:00
|
|
|
)
|
|
|
|
self.resources_text = arcade.Text(
|
2025-01-22 11:23:11 -05:00
|
|
|
"RESOURCES: People: 0, Iron: 0, Wood: 0, Food: 0",
|
2025-01-26 19:24:10 -05:00
|
|
|
x=TEXT_X, y=TEXT_Y - 2*TEXT_Y_WIDTH
|
2025-01-21 16:40:46 -05:00
|
|
|
)
|
|
|
|
self.tile_text = arcade.Text(
|
|
|
|
f"SELECTED: {self.selected_struct_tile}",
|
2025-01-26 19:24:10 -05:00
|
|
|
x=TEXT_X, y=TEXT_Y - 3*TEXT_Y_WIDTH
|
2025-01-21 16:40:46 -05:00
|
|
|
)
|
2025-01-22 12:34:51 -05:00
|
|
|
self.mode_text = arcade.Text(
|
|
|
|
f"MODE: {self.build_mode}",
|
2025-01-26 19:24:10 -05:00
|
|
|
x=TEXT_X, y=TEXT_Y - 4*TEXT_Y_WIDTH,
|
2025-01-22 14:51:13 -05:00
|
|
|
color=arcade.color.YELLOW
|
|
|
|
)
|
|
|
|
self.error_text = arcade.Text(
|
|
|
|
f"{self.error_msg}",
|
2025-01-26 19:24:10 -05:00
|
|
|
x=TEXT_X, y=TEXT_Y - 5*TEXT_Y_WIDTH,
|
2025-01-22 14:51:13 -05:00
|
|
|
color=arcade.color.RED_ORANGE
|
2025-01-22 12:34:51 -05:00
|
|
|
)
|
2025-01-21 16:40:46 -05:00
|
|
|
|
2025-01-22 12:34:51 -05:00
|
|
|
# Initialize the Game Logic class
|
2025-02-05 15:33:07 -05:00
|
|
|
# self.game_logic = GameLogic(self.scene, None)
|
2025-01-22 11:35:16 -05:00
|
|
|
|
2025-01-22 12:34:51 -05:00
|
|
|
def on_key_release(self, symbol, modifiers):
|
|
|
|
if symbol == arcade.key.ESCAPE:
|
|
|
|
self.pressed_key = None
|
|
|
|
self.build_mode = ""
|
2025-01-21 16:40:46 -05:00
|
|
|
else:
|
2025-01-22 12:34:51 -05:00
|
|
|
self.pressed_key = symbol
|
|
|
|
if self.pressed_key == arcade.key.X:
|
|
|
|
self.build_mode = "Delete Structure"
|
|
|
|
elif self.pressed_key == arcade.key.L:
|
|
|
|
self.build_mode = "Place Logger (must be on trees tile)"
|
|
|
|
elif self.pressed_key == arcade.key.C:
|
|
|
|
self.build_mode = "Place Crops"
|
|
|
|
elif self.pressed_key == arcade.key.W:
|
|
|
|
self.build_mode = "Place Hydro Power (must be adjacent to water)"
|
|
|
|
elif self.pressed_key == arcade.key.H:
|
|
|
|
self.build_mode = "Place Housing"
|
|
|
|
elif self.pressed_key == arcade.key.M:
|
|
|
|
self.build_mode = "Place Miner (must be on iron tile)"
|
|
|
|
elif self.pressed_key == arcade.key.F:
|
|
|
|
self.build_mode = "Place Factory"
|
|
|
|
elif self.pressed_key == arcade.key.J:
|
|
|
|
self.build_mode = "Place Junction"
|
|
|
|
else:
|
|
|
|
self.pressed_key = None
|
|
|
|
self.build_mode = ""
|
2025-01-21 16:40:46 -05:00
|
|
|
|
2025-01-22 12:34:51 -05:00
|
|
|
def on_mouse_release(self, x, y, button, modifiers):
|
2025-01-22 14:57:58 -05:00
|
|
|
res = ""
|
2025-01-22 12:34:51 -05:00
|
|
|
if self.pressed_key == arcade.key.X:
|
2025-01-22 14:51:13 -05:00
|
|
|
res = self.game_logic.delete_structure(x, y)
|
2025-01-22 12:34:51 -05:00
|
|
|
elif self.pressed_key == arcade.key.L:
|
2025-01-22 14:51:13 -05:00
|
|
|
res = self.game_logic.place_structure(LOGGER, x, y)
|
2025-01-22 12:34:51 -05:00
|
|
|
elif self.pressed_key == arcade.key.C:
|
2025-01-22 14:51:13 -05:00
|
|
|
res = self.game_logic.place_structure(CROPS, x, y)
|
2025-01-22 12:34:51 -05:00
|
|
|
elif self.pressed_key == arcade.key.W:
|
2025-01-22 14:51:13 -05:00
|
|
|
res = self.game_logic.place_structure(HYDROPOWER, x, y)
|
2025-01-22 12:34:51 -05:00
|
|
|
elif self.pressed_key == arcade.key.H:
|
2025-01-22 14:51:13 -05:00
|
|
|
res = self.game_logic.place_structure(HOUSING, x, y)
|
2025-01-22 12:34:51 -05:00
|
|
|
elif self.pressed_key == arcade.key.M:
|
2025-01-22 14:51:13 -05:00
|
|
|
res = self.game_logic.place_structure(MINER, x, y)
|
2025-01-22 12:34:51 -05:00
|
|
|
elif self.pressed_key == arcade.key.F:
|
2025-01-22 14:51:13 -05:00
|
|
|
res = self.game_logic.place_structure(FACTORY, x, y)
|
2025-01-22 12:34:51 -05:00
|
|
|
elif self.pressed_key == arcade.key.J:
|
2025-01-22 14:51:13 -05:00
|
|
|
res = self.game_logic.place_structure(JUNCTION, x, y)
|
2025-01-21 16:40:46 -05:00
|
|
|
else:
|
2025-01-22 12:34:51 -05:00
|
|
|
# Checking structure tile type
|
|
|
|
s_tiles = arcade.get_sprites_at_point((x,y), self.scene[LAYER_STRUCTURES])
|
|
|
|
if len(s_tiles) == 1:
|
2025-01-26 19:31:16 -05:00
|
|
|
self.selected_struct_tile = s_tiles[0].properties['class']
|
2025-01-22 12:34:51 -05:00
|
|
|
else:
|
|
|
|
self.selected_struct_tile = "[Nothing]"
|
|
|
|
|
|
|
|
# Checking environment tile type
|
|
|
|
e_tiles = arcade.get_sprites_at_point((x,y), self.scene[LAYER_ENVIRONMENT])
|
|
|
|
if len(e_tiles) == 1:
|
2025-01-26 19:31:16 -05:00
|
|
|
self.selected_env_tile = e_tiles[0].properties['class']
|
2025-01-22 12:34:51 -05:00
|
|
|
else:
|
|
|
|
self.selected_env_tile = GROUND
|
2025-01-21 16:40:46 -05:00
|
|
|
|
2025-01-22 14:51:13 -05:00
|
|
|
# Display error if placement was invalid
|
|
|
|
self.error_msg = res
|
|
|
|
|
|
|
|
# Reset key mode
|
|
|
|
self.pressed_key = None
|
|
|
|
self.build_mode = ""
|
|
|
|
|
2025-01-21 16:40:46 -05:00
|
|
|
def on_draw(self):
|
|
|
|
"""
|
|
|
|
Screen rendering
|
|
|
|
"""
|
|
|
|
# Refresh
|
|
|
|
self.clear()
|
|
|
|
|
|
|
|
# Draw the world tiles
|
|
|
|
self.scene.draw()
|
|
|
|
|
|
|
|
# Draw updated text
|
|
|
|
self.structs_text.draw()
|
|
|
|
self.commands_text.draw()
|
|
|
|
|
|
|
|
self.tile_text.text = f"SELECTED: {self.selected_struct_tile} on {self.selected_env_tile}"
|
|
|
|
self.tile_text.draw()
|
|
|
|
|
2025-01-22 11:33:20 -05:00
|
|
|
self.resources_text.text = f"RESOURCES: People: 0, Iron: 0, Wood: 0, Food: 0"
|
2025-01-22 11:23:11 -05:00
|
|
|
self.resources_text.draw()
|
|
|
|
|
2025-01-22 12:34:51 -05:00
|
|
|
self.mode_text.text = f"MODE: {self.build_mode}"
|
|
|
|
self.mode_text.draw()
|
|
|
|
|
2025-01-22 14:51:13 -05:00
|
|
|
self.error_text.text = f"{self.error_msg}"
|
2025-01-22 14:57:58 -05:00
|
|
|
self.error_text.draw()
|
2025-01-22 14:51:13 -05:00
|
|
|
|
2025-01-21 16:40:46 -05:00
|
|
|
# MAIN --------------------------------------------------------------
|
|
|
|
|
|
|
|
def main():
|
|
|
|
window = GameBoard(SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_TITLE)
|
|
|
|
window.setup()
|
|
|
|
arcade.run()
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
main()
|