Setup
Input
Movement
Minimap

We will be taking advantage of the ability to draw graphics to make a minimap

First create a folder called Engine/Game
Move Game.py into the game folder and copy the empty __init__.py file in as well.

Create a minimap.py file in the new folder with the following code

	
import tempfile
import uuid
from PIL import Image

class minimap():
	__imageFile = None
	__imageMem = None

	__height = None
	__width = None

	def __init__(self, height, width):
		self.__imageFile = tempfile.gettempdir() + str(uuid.uuid4()) + ".png"

		self.__height = height
		self.__width = width

		self.__imageMem  = Image.new("RGB", (height, width), 0x000000)
		self.__imageMem.save(self.__imageFile )

	def imageFile(self):
		return self.__imageFile

	def addDot(self, x,y, color):

		if(x < 0 or y < 0 ):
			return

		if(x >= self.__width or y >= self.__height ):
			return

		self.__imageMem.putpixel((x, y), color)
		self.__imageMem.save(self.__imageFile )
		pass


	

In the game.py file copy the code below

	from Engine.Game.minimap import minimap
from Input.keyEnum import keyEnum

from bearlibterminal import terminal


class Game:

	minimap = None

	def __init__(self):
		self.minimap = minimap(40, 40)

		self.minimapFile = self.minimap.imageFile();



		self.player_x = int(terminal.state(terminal.TK_WIDTH)/2)
		self.player_y = int(terminal.state(terminal.TK_HEIGHT)/2)

	def update(self,input_status):


		move = {'x': 0, 'y': 0}

		if (input_status["KeyPress"][keyEnum.MOVE_UP]):
			move["y"] = move["y"] - 1

		if (input_status["KeyPress"][keyEnum.MOVE_DOWN]):
			move["y"] = move["y"] + 1

		if (input_status["KeyPress"][keyEnum.MOVE_LEFT]):
			move["x"] = move["x"] - 1

		if (input_status["KeyPress"][keyEnum.MOVE_RIGHT]):
			move["x"] = move["x"] + 1

		if (input_status["KeyPress"][keyEnum.MOVE_UPLEFT]):
			move["y"] = move["y"] - 1
			move["x"] = move["x"] - 1

		if (input_status["KeyPress"][keyEnum.MOVE_UPRIGHT]):
			move["y"] = move["y"] - 1
			move["x"] = move["x"] + 1

		if (input_status["KeyPress"][keyEnum.MOVE_DOWNLEFT]):
			move["y"] = move["y"] + 1
			move["x"] = move["x"] - 1

		if (input_status["KeyPress"][keyEnum.MOVE_DOWNRIGHT]):
			move["y"] = move["y"] + 1
			move["x"] = move["x"] + 1


		self.player_x = self.player_x + move["x"]
		self.player_y = self.player_y + move["y"]

		self.minimap.addDot(self.player_x, self.player_y, 0xFFFFFF)

		terminalConfig = "0xF0000: '"+ self.minimapFile  + "', size=40x40, spacing=1x1;"

		terminal.set(terminalConfig )

	def render(self):
		terminal.put(self.player_x, self.player_y, "@")
		terminal.put(0, 0, 0xF0000)

	

Finally change engine.py to


class engine():
	engine_state = None
	game_object = None

	def __init__(self):
		self.engine_state = engineState.Game

		self.game_object  = Game()


	def update(self,input_status):

		if(self.engine_state == engineState.Game):
			self.game_object.update(input_status)


	def render(self):


		if(self.engine_state == engineState.Game):
			self.game_object.render()

		pass


	def game_loop(self,input_status):

		self.update(input_status)
		self.render()

If all goes well you should see in the top left of the screen a dot. As you move your character around you should see a line being drawn