This commit is contained in:
anton.gurov
2019-10-25 18:47:10 +03:00
parent ad6fb0c03e
commit ed5a425dab
11 changed files with 413 additions and 13 deletions

43
ui/mainwindow/camera.go Normal file
View File

@ -0,0 +1,43 @@
package mainwindow
type GameCamera struct {
X int
Y int
Width int
Height int
}
func (c *GameCamera) MoveCamera(targetX int, targetY int, mapWidth int, mapHeight int) {
// Update the camera coordinates to the target coordinates
x := targetX - c.Width/2
y := targetY - c.Height/2
if x < 0 {
x = 0
}
if y < 0 {
y = 0
}
if x > mapWidth - c.Width {
x = mapWidth - c.Width
}
if y > mapHeight - c.Height {
y = mapHeight - c.Height
}
c.X, c.Y = x, y
}
func (c *GameCamera) ToCameraCoordinates(mapX int, mapY int) (cameraX int, cameraY int) {
// Convert coordinates on the gamemap, to coordinates on the viewport
x, y := mapX-c.X, mapY-c.Y
if x < 0 || y < 0 || x >= c.Width || y >= c.Height {
return -1, -1
}
return x, y
}

View File

@ -1,12 +0,0 @@
package mainwindow
//Console is a pair of layers (BG and FG) used to render something
// All because of lack of background colors in libbearterminal
type Console struct {
x,y,w,h int
FgLayer *Layer
BgLayer *Layer
}
func NewConsole

View File

@ -26,6 +26,7 @@ func (mw *MainWindow) Open() {
fmt.Sprintf(
//"window: size=%dx%d, title='%s v%s'; font: ./resources/fonts-bitmap/ibmnew8x12.png, size=8x12;",
"window: size=%dx%d, title='%s v%s'; font: %s, size=8x16;",
//"window: size=%dx%d, title='%s v%s'",
config.MainWindowSizeX,
config.MainWindowSizeY,
config.Title,