generated from mwc/project_game
Monsters have a weighting on how many to spawn and roll which specific monster to spawn from the pool. I have not added the ability to advance levels yet, though that should work to add monsters if the Floor number advances. I did notice a bug where the player cannot be harmed by the monsters unless the player moves into them, not the other way around. The monsters seem to treat the player as a wall that cannot be passed through. This is confusing because the code for the player and monsters match as far as their ability to move into each other...
70 lines
2.1 KiB
Python
70 lines
2.1 KiB
Python
from retro.game import Game
|
|
from random import sample
|
|
from player import Player
|
|
from wall import Wall
|
|
from random import randint
|
|
|
|
def board_edges(board_size):
|
|
"""The outline of the generated board. Used in angband to surround
|
|
the level with immovable objects to keep the enemies and player inside
|
|
"""
|
|
x,y = board_size
|
|
positions = []
|
|
top = [(i,0) for i in range(x)]
|
|
bottom = [(i,y-1) for i in range(x)]
|
|
left = [(0,j) for j in range(1,y-1)]
|
|
right = [(x-1,j) for j in range(1,y-1)]
|
|
return top + bottom + left + right
|
|
|
|
def inner_board(board_size):
|
|
x,y = board_size
|
|
positions = []
|
|
for i in range(1,x-1):
|
|
for j in range(1,y-1):
|
|
positions.append((i,j))
|
|
return positions
|
|
|
|
def random_empty_position(game):
|
|
"""Returns a random empty position.
|
|
"""
|
|
agents_by_position = game.get_agents_by_position()
|
|
while True:
|
|
x, y = game.board_size
|
|
i = randint(1, x-2)
|
|
j = randint(1, y-2)
|
|
if not agents_by_position[(i,j)]:
|
|
return (i,j)
|
|
|
|
def level_one(board_size):
|
|
x,y = board_size
|
|
positions = []
|
|
for i in range(1,x-1):
|
|
for j in range(1,y//4):
|
|
if i <= x // 4 or i >= x - (x // 4):
|
|
positions.append((i,j))
|
|
for i in range(1,x//4):
|
|
for j in range((y - (y // 4)), y-1):
|
|
positions.append((i,j))
|
|
|
|
# Introduce randomness within predefined pattern
|
|
for _ in range(10): # Example: Add 10 random obstacles
|
|
rand_i = randint(1, x - 2)
|
|
rand_j = randint(1, y - 2)
|
|
positions.append((rand_i, rand_j))
|
|
|
|
# for i in range(1,x-1):
|
|
# for j in range(1,y-1):
|
|
# if i >=4 and i <= 7 or i >= 13 and i <= 16:
|
|
# if j >= 4 and j <= 7 or j >= 13 and j <= 16:
|
|
# positions.append((i,j))
|
|
return positions
|
|
|
|
def level_two(board_size):
|
|
x,y = board_size
|
|
positions = []
|
|
for i in range(1,x-1):
|
|
for j in range(1,y-1):
|
|
if i >=4 and i <= 7 or i >= 13 and i <= 16:
|
|
if j >= 4 and j <= 7 or j >= 13 and j <= 16:
|
|
positions.append((i,j))
|
|
return positions |