Skip to content

Commit

Permalink
Text-Display Updates
Browse files Browse the repository at this point in the history
Added: TextDisplay.MoveTo - method
Added: TextDisplay.MoveBy - method
Added: TextDisplay.SetAlpha - method

Added: TileMap.MoveTo - method
Added: TileMap.MoveBy - method
Added: TileMap.SetAlpha - method
Added: TileMap.X(), .Y(), .XY()  - getters
  • Loading branch information
Rocco-Gossmann committed Oct 25, 2023
1 parent 9c229de commit 743a7d9
Show file tree
Hide file tree
Showing 6 changed files with 137 additions and 75 deletions.
3 changes: 3 additions & 0 deletions core/bitmapentity.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ func (b *BitmapEntity) W() uint16 { return b.canvasBlitOpts.Clip.W }
func (b *BitmapEntity) H() uint16 { return b.canvasBlitOpts.Clip.H }
func (b *BitmapEntity) WH() (uint16, uint16) { return b.canvasBlitOpts.Clip.W, b.canvasBlitOpts.Clip.H }

// ------------------------------------------------------------------------------
// Actions
// ------------------------------------------------------------------------------
func (b *BitmapEntity) ToCanvas(ca *Canvas) CanvasCollisionLayers {
if !b.visible {
return CANV_CL_NONE
Expand Down
43 changes: 35 additions & 8 deletions gfx/Text.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,18 @@ type TextDisplay struct {
charsPerLine uint16
lines uint16
ts *TileSet
mp *TileMap

// Internals
mp *TileMap

// Formating
cursorx, cursory uint16
wrap bool
}

func (me *TextDisplay) SetWrap(wrap bool) *TextDisplay {
me.wrap = wrap
return me
}

// ==============================================================================
// Constructors
// ==============================================================================
func InitTextDisplay(ca *core.Canvas) *TextDisplay {

if ca == nil {
Expand All @@ -48,6 +48,9 @@ func InitTextDisplay(ca *core.Canvas) *TextDisplay {
return &text
}

// ==============================================================================
// Setters
// ==============================================================================
func (me *TextDisplay) SetCursor(x, y int32) *TextDisplay {
x = x % int32(me.charsPerLine)
y = y % int32(me.lines)
Expand Down Expand Up @@ -126,9 +129,11 @@ func (me *TextDisplay) Echo(text string) *TextDisplay {
return me
}

func (me *TextDisplay) ToCanvas(ca *core.Canvas) {
me.mp.ToCanvas(ca, nil)
func (me *TextDisplay) SetWrap(wrap bool) *TextDisplay {
me.wrap = wrap
return me
}

func (me *TextDisplay) setFont(ts *TileSet) *TextDisplay {
tw, th := ts.GetTileWidth(), ts.GetTileWidth()

Expand All @@ -140,3 +145,25 @@ func (me *TextDisplay) setFont(ts *TileSet) *TextDisplay {

return me
}

func (me *TextDisplay) MoveTo(x, y int32) *TextDisplay {
me.mp.MoveTo(x*-1, y*-1)
return me
}

func (me *TextDisplay) MoveBy(x, y int32) *TextDisplay {
me.mp.MoveBy(x, y)
return me
}

func (me *TextDisplay) SetAlpha(a byte) *TextDisplay {
me.mp.SetAlpha(a)
return me
}

// ==============================================================================
// Actions
// ==============================================================================
func (me *TextDisplay) ToCanvas(ca *core.Canvas) {
me.mp.ToCanvas(ca)
}
51 changes: 41 additions & 10 deletions gfx/TileMap.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,16 @@ import (
"fmt"

"github.com/rocco-gossmann/GoWas/core"
"github.com/rocco-gossmann/GoWas/types"
)

type tileMapOpts struct {
X, Y int32 // Where to blit it on the screen
Alpha byte
}

type TileMap struct {
init bool
opts tileMapOpts
ts *TileSet
memory []byte
mw, mh uint32
Expand Down Expand Up @@ -62,6 +67,7 @@ func (tm *TileMap) Init(pTs *TileSet, width, height uint32) *TileMap {
// -----------------------------------------------------------------------------
// Setters
// -----------------------------------------------------------------------------
// Tiles
func (me *TileMap) SetTileSetOffset(o int) *TileMap {
var tc = me.ts.TileCount()

Expand Down Expand Up @@ -129,14 +135,39 @@ func (me *TileMap) SetTile(x, y uint32, tileIndex byte) *TileMap {
return me
}

// Display
func (me *TileMap) SetAlpha(a byte) *TileMap {
me.opts.Alpha = a
return me
}
func (me *TileMap) MoveTo(x, y int32) *TileMap {

me.opts.X = x
me.opts.Y = y

return me
}
func (me *TileMap) MoveBy(x, y int32) *TileMap {

me.opts.X += x
me.opts.Y += y

return me
}

// -----------------------------------------------------------------------------
// Getters
// -----------------------------------------------------------------------------
type ToCanvasOpts struct {
Scroll types.Point
}
func (me *TileMap) X() int32 { return me.opts.X }
func (me *TileMap) Y() int32 { return me.opts.Y }
func (me *TileMap) XY() (int32, int32) { return me.opts.X, me.opts.Y }
func (me *TileMap) Alpha() byte { return me.opts.Alpha }

func (me *TileMap) ToCanvas(ca *core.Canvas, opts *ToCanvasOpts) {
// -----------------------------------------------------------------------------
// Actions
// -----------------------------------------------------------------------------

func (me *TileMap) ToCanvas(ca *core.Canvas) {

me.validate()

Expand All @@ -146,10 +177,8 @@ func (me *TileMap) ToCanvas(ca *core.Canvas, opts *ToCanvasOpts) {
offsetX, offsetY := int32(0), int32(0)
startX, startY := uint32(0), uint32(0)

if opts != nil {
offsetX = int32(opts.Scroll.X) * -1
offsetY = int32(opts.Scroll.Y) * -1
}
offsetX = int32(me.opts.X) * -1
offsetY = int32(me.opts.Y) * -1

// Check for overshoots Horizontal
if offsetX < 0 {
Expand All @@ -172,7 +201,9 @@ func (me *TileMap) ToCanvas(ca *core.Canvas, opts *ToCanvasOpts) {

// dstX, dstY := uint16((me.mw+overShootX)*tw), uint16((me.mh+overShootY)*th)

bopts := TilesetBlitOptions{}
bopts := TilesetBlitOptions{
Alpha: me.opts.Alpha,
}

ti, mi := 0, byte(0)
for y := startY; y < startY+mh; y++ {
Expand Down
2 changes: 1 addition & 1 deletion project-template/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ module GoWasProject

go 1.21.1

require github.com/rocco-gossmann/GoWas v0.3.1
require github.com/rocco-gossmann/GoWas v0.4.0

94 changes: 47 additions & 47 deletions project-template/scenes/debug.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,25 @@ import (
"github.com/rocco-gossmann/GoWas/core"
"github.com/rocco-gossmann/GoWas/gfx"
"github.com/rocco-gossmann/GoWas/io"
"github.com/rocco-gossmann/GoWas/types"
)

const validMouseButtons = io.MOUSE_BTN1 |
io.MOUSE_BTN2 |
io.MOUSE_BTN3

type debugScene struct {
tma float64
tma float64
totaltime float64

CursorEntity *core.BitmapEntity
bg2 *core.BitmapEntity

text *gfx.TextDisplay

bgSet *gfx.TileSet
mouseButtonDisplay *gfx.TileSet

bgMap *gfx.TileMap
bgScroll types.Point
bgScroll int32

fpsTime float64
fpsCnt int
Expand All @@ -51,13 +50,13 @@ func (s *debugScene) Load(e *core.EngineState, ca *core.Canvas) {
s.text = gfx.InitTextDisplay(ca) // Initialize a Text-Display (You can have as many as you want)

s.text. //<- Starting the Text change on a Display
SetCursor(0, 0).Echo("@ Test {}()<|>"). //<- Settting a Cursor position and Printing Text, starting from that location
SetCursor(-2, 0).Echo("->"). //<- negative coordinates mean "From the Bottom" and/or "From the Right"
SetCursor(0, 0).Echo("--- start typing ---"). //<- Settting a Cursor position and Printing Text, starting from that location
SetCursor(-15, 2).Echo("<- last key"). //<- negative coordinates mean "From the Bottom" and/or "From the Right"

SetCursor(0, 6).Echo("Hey you!"). //<- Positive coordinate = "From the Top" and/or "From the Left"
Echo(" Move the\nmouse over this\nScreen and press\none of it's Buttons."). // <- If you don't specifiy a location, the text
// continues where the last character was printed
// You can use \n to force a line break and carriage return from within the text
// continues where the last character was printed
// You can use \n to force a line break and carriage return from within the text
SetCursor(5, 13).Echo(fmt.Sprintf("Pressed / Held:"))

// Preparing a part on the bottom line for showing a constantly changing value
Expand All @@ -76,45 +75,48 @@ func (s *debugScene) Load(e *core.EngineState, ca *core.Canvas) {

// > Init Background Map
s.bgMap = &gfx.TileMap{}
s.bgMap.Init(s.bgSet, 22, 22).SetMap([]byte{
12, 7, 12, 7, 12, 7, 12, 7, 12, 7, 12, 7, 12, 7, 12, 7, 12, 7, 12, 7, 12, 7,
7, 12, 7, 12, 7, 12, 7, 12, 7, 12, 7, 12, 7, 12, 7, 12, 7, 12, 7, 12, 7, 12,
12, 7, 12, 7, 12, 7, 12, 7, 12, 7, 12, 7, 12, 7, 12, 7, 12, 7, 12, 7, 12, 7,
7, 12, 7, 12, 7, 12, 7, 12, 7, 12, 7, 12, 7, 12, 7, 12, 7, 12, 7, 12, 7, 12,
12, 7, 12, 7, 12, 7, 12, 7, 12, 7, 12, 7, 12, 7, 12, 7, 12, 7, 12, 7, 12, 7,
7, 12, 7, 12, 7, 12, 7, 12, 7, 12, 7, 12, 7, 12, 7, 12, 7, 12, 7, 12, 7, 12,
12, 7, 12, 7, 12, 7, 12, 7, 12, 7, 12, 7, 12, 7, 12, 7, 12, 7, 12, 7, 12, 7,
7, 12, 7, 12, 7, 12, 7, 12, 7, 12, 7, 12, 7, 12, 7, 12, 7, 12, 7, 12, 7, 12,
12, 7, 12, 7, 12, 7, 12, 7, 12, 7, 12, 7, 12, 7, 12, 7, 12, 7, 12, 7, 12, 7,
7, 12, 7, 12, 7, 12, 7, 12, 7, 12, 7, 12, 7, 12, 7, 12, 7, 12, 7, 12, 7, 12,
12, 7, 12, 7, 12, 7, 12, 7, 12, 7, 12, 7, 12, 7, 12, 7, 12, 7, 12, 7, 12, 7,
7, 12, 7, 12, 7, 12, 7, 12, 7, 12, 7, 12, 7, 12, 7, 12, 7, 12, 7, 12, 7, 12,
12, 7, 12, 7, 12, 7, 12, 7, 12, 7, 12, 7, 12, 7, 12, 7, 12, 7, 12, 7, 12, 7,
7, 12, 7, 12, 7, 12, 7, 12, 7, 12, 7, 12, 7, 12, 7, 12, 7, 12, 7, 12, 7, 12,
12, 7, 12, 7, 12, 7, 12, 7, 12, 7, 12, 7, 12, 7, 12, 7, 12, 7, 12, 7, 12, 7,
7, 12, 7, 12, 7, 12, 7, 12, 7, 12, 7, 12, 7, 12, 7, 12, 7, 12, 7, 12, 7, 12,
12, 7, 12, 7, 12, 7, 12, 7, 12, 7, 12, 7, 12, 7, 12, 7, 12, 7, 12, 7, 12, 7,
7, 12, 7, 12, 7, 12, 7, 12, 7, 12, 7, 12, 7, 12, 7, 12, 7, 12, 7, 12, 7, 12,
12, 7, 12, 7, 12, 7, 12, 7, 12, 7, 12, 7, 12, 7, 12, 7, 12, 7, 12, 7, 12, 7,
7, 12, 7, 12, 7, 12, 7, 12, 7, 12, 7, 12, 7, 12, 7, 12, 7, 12, 7, 12, 7, 12,
12, 7, 12, 7, 12, 7, 12, 7, 12, 7, 12, 7, 12, 7, 12, 7, 12, 7, 12, 7, 12, 7,
7, 12, 7, 12, 7, 12, 7, 12, 7, 12, 7, 12, 7, 12, 7, 12, 7, 12, 7, 12, 7, 12,
})
s.bgMap.
Init(s.bgSet, 22, 22).
SetMap([]byte{
12, 7, 12, 7, 12, 7, 12, 7, 12, 7, 12, 7, 12, 7, 12, 7, 12, 7, 12, 7, 12, 7,
7, 12, 7, 12, 7, 12, 7, 12, 7, 12, 7, 12, 7, 12, 7, 12, 7, 12, 7, 12, 7, 12,
12, 7, 12, 7, 12, 7, 12, 7, 12, 7, 12, 7, 12, 7, 12, 7, 12, 7, 12, 7, 12, 7,
7, 12, 7, 12, 7, 12, 7, 12, 7, 12, 7, 12, 7, 12, 7, 12, 7, 12, 7, 12, 7, 12,
12, 7, 12, 7, 12, 7, 12, 7, 12, 7, 12, 7, 12, 7, 12, 7, 12, 7, 12, 7, 12, 7,
7, 12, 7, 12, 7, 12, 7, 12, 7, 12, 7, 12, 7, 12, 7, 12, 7, 12, 7, 12, 7, 12,
12, 7, 12, 7, 12, 7, 12, 7, 12, 7, 12, 7, 12, 7, 12, 7, 12, 7, 12, 7, 12, 7,
7, 12, 7, 12, 7, 12, 7, 12, 7, 12, 7, 12, 7, 12, 7, 12, 7, 12, 7, 12, 7, 12,
12, 7, 12, 7, 12, 7, 12, 7, 12, 7, 12, 7, 12, 7, 12, 7, 12, 7, 12, 7, 12, 7,
7, 12, 7, 12, 7, 12, 7, 12, 7, 12, 7, 12, 7, 12, 7, 12, 7, 12, 7, 12, 7, 12,
12, 7, 12, 7, 12, 7, 12, 7, 12, 7, 12, 7, 12, 7, 12, 7, 12, 7, 12, 7, 12, 7,
7, 12, 7, 12, 7, 12, 7, 12, 7, 12, 7, 12, 7, 12, 7, 12, 7, 12, 7, 12, 7, 12,
12, 7, 12, 7, 12, 7, 12, 7, 12, 7, 12, 7, 12, 7, 12, 7, 12, 7, 12, 7, 12, 7,
7, 12, 7, 12, 7, 12, 7, 12, 7, 12, 7, 12, 7, 12, 7, 12, 7, 12, 7, 12, 7, 12,
12, 7, 12, 7, 12, 7, 12, 7, 12, 7, 12, 7, 12, 7, 12, 7, 12, 7, 12, 7, 12, 7,
7, 12, 7, 12, 7, 12, 7, 12, 7, 12, 7, 12, 7, 12, 7, 12, 7, 12, 7, 12, 7, 12,
12, 7, 12, 7, 12, 7, 12, 7, 12, 7, 12, 7, 12, 7, 12, 7, 12, 7, 12, 7, 12, 7,
7, 12, 7, 12, 7, 12, 7, 12, 7, 12, 7, 12, 7, 12, 7, 12, 7, 12, 7, 12, 7, 12,
12, 7, 12, 7, 12, 7, 12, 7, 12, 7, 12, 7, 12, 7, 12, 7, 12, 7, 12, 7, 12, 7,
7, 12, 7, 12, 7, 12, 7, 12, 7, 12, 7, 12, 7, 12, 7, 12, 7, 12, 7, 12, 7, 12,
12, 7, 12, 7, 12, 7, 12, 7, 12, 7, 12, 7, 12, 7, 12, 7, 12, 7, 12, 7, 12, 7,
7, 12, 7, 12, 7, 12, 7, 12, 7, 12, 7, 12, 7, 12, 7, 12, 7, 12, 7, 12, 7, 12,
})

s.bg2.MoveBy(-4, -4).Alpha(0x80, false)
}

func (me *debugScene) Tick(e *core.EngineState) bool {

// Update Timer
me.tma += 24 * e.DeltaTime
me.text.SetCursor(7, -1).Echo(fmt.Sprint(me.tma)) // <- update the Text display with the current timer value
// Update Timers
me.fpsTime += e.DeltaTime
me.totaltime += e.DeltaTime
me.tma += 24 * e.DeltaTime // <-background scroll timer

me.text.SetCursor(7, -1).Echo(fmt.Sprint(me.totaltime)) // <- update the Text display with the current timer value

me.text.SetCursor(0, 0).Echo(string(e.Keyboard.HistoryRunes(18))).
SetCursor(0, 1).Clear(8).Echo(fmt.Sprintf("%v", e.Keyboard.History(1)))
me.text.SetCursor(0, 0).Echo(string(e.Keyboard.HistoryRunes(20))).
SetCursor(0, 2).Clear(5).Echo(fmt.Sprintf("%v", e.Keyboard.History(1)))

// Update FPS
me.fpsTime += e.DeltaTime
if me.fpsTime >= 1 {

me.text.
Expand All @@ -127,8 +129,7 @@ func (me *debugScene) Tick(e *core.EngineState) bool {
}

// Update Background-Scroll
me.bgScroll.X = uint16(me.tma)
me.bgScroll.Y = uint16(me.tma)
me.bgScroll = int32(me.tma)

return true
}
Expand All @@ -137,11 +138,9 @@ func (s *debugScene) Draw(e *core.EngineState, ca *core.Canvas) {
// Update FPS Counter
s.fpsCnt++

s.bgMap.ToCanvas(ca, &gfx.ToCanvasOpts{
Scroll: s.bgScroll,
})

//s.bg2.ToCanvas(ca) //<-- disabled bg2 because it looked silly
s.bgMap.
MoveTo(s.bgScroll, s.bgScroll).
ToCanvas(ca)

ca.FillColorA(0x00000000, 0xb0, core.CANV_CL_ALL) // Filling the canvas with a half transparent black
// to darken the backaground a bit
Expand All @@ -154,6 +153,8 @@ func (s *debugScene) Draw(e *core.EngineState, ca *core.Canvas) {

// Draw the Mouse Button Display
//-------------------------------------------------------------------------
// This is not going to stay as it is. It will be replaced by propper sprites, that function similar to
// How BitmapEntitys, Maps and TextDisplays do
s.mouseButtonDisplay.BlitTo(ca, int(e.Mouse.PressedOrHeld&validMouseButtons), &gfx.TilesetBlitOptions{
X: 0, Y: 88,
})
Expand All @@ -177,5 +178,4 @@ func (s *debugScene) Unload(e *core.EngineState) *struct{} {

var Debug = debugScene{
CursorEntity: bmps.BMPcursor.MakeEntity(),
bg2: bmps.BMPoversized.MakeEntity(),
}
19 changes: 10 additions & 9 deletions todo.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ Bugs:
TextDisplay:
================================================================================
[x] Add a clear function, that replaces a number of characters with spaces, but leaves the Cursor-Position unaltered
[ ] Make Text-Display Moveable on Screen Similar to TileMap
[ ] Add Setters and Getters like in BitmapEntity
[ ] ScreenOffset
[ ] Alpha
[x] Make Text-Display Moveable on Screen Similar to TileMap
[x] Add Setters and Getters like in BitmapEntity
[x] ScreenOffset <= @done MoveTo and MoveBy added
[x] Alpha
[ ] Make Bounderies resizeable (right now bounds are always the canvas size)

Rendering:
================================================================================
Expand All @@ -19,20 +20,20 @@ Rendering:

Maps:
================================================================================
[ ] Rework Setters and Getters to Work like BitmapEntities Do @critical
[x] Rework Setters and Getters to Work like BitmapEntities Do @critical
[ ] Test how drawing Maps, that are smaller than the screen behaves @critical
[ ] Maps Collision layers @critical
[ ] Maps Alpha blending
[x] Maps Alpha blending
[ ] Allow to fill columns or rows of Tiles with data @high (Instead of just single tiles or the entire map)
[ ] Maps Clipping-Rect @low
[ ] Allow maps scroll.x any y propperties to be negative @low
[x] Allow maps scroll.x any y propperties to be negative @done Map scroll replaced by x,y coords


Keyboard Input:
================================================================================
[x] Browser side - Key-Statemanagement
[ ] Go Side
[ ] KeyStates
[x] Go Side
[x] KeyStates

Audio:
================================================================================
Expand Down

0 comments on commit 743a7d9

Please sign in to comment.