Finished Part 2

This commit is contained in:
2019-06-22 22:44:41 -04:00
parent a582009210
commit 2e7d121be3
6 changed files with 123 additions and 25 deletions

View File

@@ -1,29 +1,41 @@
import tcod
import tcod as tc
from entity import Entity
from render_functions import *
from game_map import *
from input_handlers import handle_keys
def main():
screen_width = 80
screen_height = 50
map_width = 80
map_height = 50
player_x = int(screen_width/2)
player_y = int(screen_height/2)
colors = {
'dark_wall': tc.Color(0, 0, 100),
'dark_ground': tc.Color(50, 50, 150)
}
tcod.console_set_custom_font('arial10x10.png', tcod.FONT_TYPE_GREYSCALE | tcod.FONT_LAYOUT_TCOD)
player = Entity(int(screen_width/2), int(screen_height/2), '@', tc.white)
npc = Entity(int(screen_width/2), int(screen_height/2), '@', tc.yellow)
entities = [npc, player]
tcod.console_init_root(screen_width, screen_height, 'tutorial revised', False)
con = tcod.console_new(screen_width, screen_height)
tc.console_set_custom_font('arial10x10.png', tc.FONT_TYPE_GREYSCALE | tc.FONT_LAYOUT_TCOD)
key = tcod.Key()
mouse = tcod.Mouse()
tc.console_init_root(screen_width, screen_height, 'tutorial revised', False)
con = tc.console_new(screen_width, screen_height)
while not tcod.console_is_window_closed():
tcod.sys_check_for_event(tcod.EVENT_KEY_PRESS, key, mouse)
tcod.console_set_default_foreground(con, tcod.white)
tcod.console_put_char(con, player_x, player_y, '@', tcod.BKGND_NONE)
tcod.console_blit(con, 0,0, screen_width, screen_height, 0,0,0)
tcod.console_flush()
game_map = GameMap(map_width, map_height)
tcod.console_put_char(con, player_x, player_y, ' ', tcod.BKGND_NONE)
key = tc.Key()
mouse = tc.Mouse()
while not tc.console_is_window_closed():
tc.sys_check_for_event(tc.EVENT_KEY_PRESS, key, mouse)
render_all(con, entities, game_map, screen_width, screen_height, colors)
tc.console_flush()
clear_all(con, entities)
action = handle_keys(key)
@@ -33,14 +45,15 @@ def main():
if move:
dx, dy = move
player_x += dx
player_y += dy
if not game_map.is_blocked(player.x + dx, player.y + dy):
player.move(dx, dy)
if exit:
return True
if fullscreen:
tcod.console_set_fullscreen(not tcod.console_is_fullscreen())
tc.console_set_fullscreen(not tc.console_is_fullscreen())
if __name__ == '__main__':
main()