did invetory and some prompts
This commit is contained in:
parent
0c1f5224e2
commit
a1e46af961
26
entity.py
26
entity.py
|
@ -1,3 +1,4 @@
|
|||
from typing import Dict
|
||||
from actions import Action, Idle, NA
|
||||
|
||||
class Entity():
|
||||
|
@ -17,13 +18,25 @@ class Creature(Entity):
|
|||
class Player(Creature):
|
||||
def __init__(self):
|
||||
super().__init__("player")
|
||||
self.main_hand = None
|
||||
self.equipment: Dict[str, Dict | None] = {
|
||||
"main_hand": None,
|
||||
"feet": None
|
||||
}
|
||||
|
||||
def equip(self, item, slot) -> None:
|
||||
self.equipment[slot] = ITEMS_DATA[item]
|
||||
|
||||
def total_damage(self) -> int:
|
||||
dmg = self.damage
|
||||
for item in self.equipment.values():
|
||||
if item: dmg += item["damage"]
|
||||
return dmg
|
||||
|
||||
class Enemy(Creature):
|
||||
def __init__(self, codename):
|
||||
super().__init__(codename)
|
||||
|
||||
def calculate_action(self):
|
||||
def calculate_action(self) -> None:
|
||||
self.action: Action = Idle()
|
||||
|
||||
CREATURES_DATA = {
|
||||
|
@ -40,7 +53,12 @@ CREATURES_DATA = {
|
|||
}
|
||||
|
||||
ITEMS_DATA = {
|
||||
"none": {
|
||||
"damage": 1
|
||||
"shiv": {
|
||||
"damage": 3,
|
||||
"name": "Shiv"
|
||||
},
|
||||
"fire_gem": {
|
||||
"damage": 1,
|
||||
"name": "Fire gem"
|
||||
}
|
||||
}
|
2
floor.py
2
floor.py
|
@ -65,7 +65,7 @@ class Floor:
|
|||
self.grid = []
|
||||
for row in range(width):
|
||||
self.grid.append([])
|
||||
for tile in range(height):
|
||||
for _ in range(height):
|
||||
self.grid[row].append(TileType.AIR)
|
||||
self.grid[0][0] = TileType.WALL
|
||||
self.entities = EntityMap()
|
||||
|
|
36
game.py
36
game.py
|
@ -1,5 +1,5 @@
|
|||
from terminal import Terminal
|
||||
from entity import Creature, Player, Enemy
|
||||
from entity import ITEMS_DATA, Creature, Player, Enemy
|
||||
from actions import *
|
||||
from floor import COLLIDABLE, Floor, TileType
|
||||
import sys
|
||||
|
@ -48,6 +48,7 @@ class Game:
|
|||
"""
|
||||
self.instance_creature(3, 3, self.player)
|
||||
self.instance_creature(6, 4, Enemy("slime"))
|
||||
self.player.equip("shiv", "main_hand")
|
||||
self.render()
|
||||
while not self.should_exit:
|
||||
self.step()
|
||||
|
@ -97,12 +98,16 @@ class Game:
|
|||
for y in range(floor_frame_height, term_height):
|
||||
self.term.put_char(x, y, ' ')
|
||||
self.term.put_string(0, floor_frame_height, f"HP: {self.player.hp}/{self.player.max_hp}" )
|
||||
self.term.put_string(0, floor_frame_height + 1, f"MH:{'None' if not self.player.main_hand else 'Item'}; Damage: {self.player.damage}" )
|
||||
self.term.put_string(0, floor_frame_height + 1, f"MH: {'None' if not self.player.equipment['main_hand'] else self.player.equipment['main_hand']['name']}; Damage: {self.player.total_damage()}")
|
||||
|
||||
# Menu
|
||||
for x in range(floor_frame_width, term_width):
|
||||
for y in range(term_height):
|
||||
self.term.put_char(x, y, 'M')
|
||||
self.term.put_char(x, y, ' ')
|
||||
self.term.put_string(floor_frame_width, 0, f"Move: {KEYBINDS['move_left']} {KEYBINDS['move_up']} {KEYBINDS['move_right']} {KEYBINDS['move_down']}")
|
||||
self.term.put_string(floor_frame_width, 1, f"Inventory: {KEYBINDS['inventory']}")
|
||||
self.term.put_string(floor_frame_width, 2, f"Quit: {KEYBINDS['quit']}")
|
||||
|
||||
|
||||
def step(self):
|
||||
"""
|
||||
|
@ -145,17 +150,30 @@ class Game:
|
|||
Waits for a game event to happen, and behaves accordingly
|
||||
"""
|
||||
keycode = self.term.get_key()
|
||||
if keycode == "q":
|
||||
if keycode == KEYBINDS["quit"]:
|
||||
self.should_exit = True
|
||||
elif keycode == "p":
|
||||
elif keycode == KEYBINDS["inventory"]:
|
||||
self.hud += 1
|
||||
print(self.hud, flush=True)
|
||||
self.input_event()
|
||||
elif keycode == "KEY_RIGHT":
|
||||
elif keycode == KEYBINDS["move_right"]:
|
||||
self.player.action = Move(1, 0)
|
||||
elif keycode == "KEY_LEFT":
|
||||
elif keycode == KEYBINDS["move_left"]:
|
||||
self.player.action = Move(-1, 0)
|
||||
elif keycode == "KEY_DOWN":
|
||||
elif keycode == KEYBINDS["move_down"]:
|
||||
self.player.action = Move(0, 1)
|
||||
elif keycode == "KEY_UP":
|
||||
elif keycode == KEYBINDS["move_up"]:
|
||||
self.player.action = Move(0, -1)
|
||||
elif keycode == "KEY_RESIZE":
|
||||
self.render()
|
||||
self.input_event()
|
||||
|
||||
|
||||
KEYBINDS = {
|
||||
"move_right": "→",
|
||||
"move_left": "←",
|
||||
"move_down": "↓",
|
||||
"move_up": "↑",
|
||||
"quit": "q",
|
||||
"inventory": "i",
|
||||
}
|
|
@ -2,10 +2,11 @@ import curses
|
|||
from typing import Tuple
|
||||
|
||||
KEYCODES = {
|
||||
curses.KEY_LEFT: "KEY_LEFT",
|
||||
curses.KEY_RIGHT: "KEY_RIGHT",
|
||||
curses.KEY_UP: "KEY_UP",
|
||||
curses.KEY_DOWN: "KEY_DOWN"
|
||||
curses.KEY_LEFT: "←",
|
||||
curses.KEY_RIGHT: "→",
|
||||
curses.KEY_UP: "↑",
|
||||
curses.KEY_DOWN: "↓",
|
||||
curses.KEY_RESIZE: "KEY_RESIZE"
|
||||
}
|
||||
|
||||
class Terminal:
|
||||
|
|
Loading…
Reference in New Issue