diff --git a/core/bitmapentity.go b/core/bitmapentity.go index 6c933be..fbb36c0 100644 --- a/core/bitmapentity.go +++ b/core/bitmapentity.go @@ -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 diff --git a/gfx/Text.go b/gfx/Text.go index 83e3dfb..0ef5d0b 100644 --- a/gfx/Text.go +++ b/gfx/Text.go @@ -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 { @@ -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) @@ -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() @@ -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) +} diff --git a/gfx/TileMap.go b/gfx/TileMap.go index 42e9246..f1cbafd 100644 --- a/gfx/TileMap.go +++ b/gfx/TileMap.go @@ -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 @@ -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() @@ -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() @@ -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 { @@ -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++ { diff --git a/project-template/go.mod b/project-template/go.mod index 79c8727..186e9db 100644 --- a/project-template/go.mod +++ b/project-template/go.mod @@ -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 diff --git a/project-template/scenes/debug.go b/project-template/scenes/debug.go index e0bd623..c9492e7 100644 --- a/project-template/scenes/debug.go +++ b/project-template/scenes/debug.go @@ -7,7 +7,6 @@ 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 | @@ -15,10 +14,10 @@ const validMouseButtons = io.MOUSE_BTN1 | io.MOUSE_BTN3 type debugScene struct { - tma float64 + tma float64 + totaltime float64 CursorEntity *core.BitmapEntity - bg2 *core.BitmapEntity text *gfx.TextDisplay @@ -26,7 +25,7 @@ type debugScene struct { mouseButtonDisplay *gfx.TileSet bgMap *gfx.TileMap - bgScroll types.Point + bgScroll int32 fpsTime float64 fpsCnt int @@ -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 @@ -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. @@ -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 } @@ -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 @@ -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, }) @@ -177,5 +178,4 @@ func (s *debugScene) Unload(e *core.EngineState) *struct{} { var Debug = debugScene{ CursorEntity: bmps.BMPcursor.MakeEntity(), - bg2: bmps.BMPoversized.MakeEntity(), } diff --git a/todo.md b/todo.md index 27c65cf..2f2bf2a 100644 --- a/todo.md +++ b/todo.md @@ -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: ================================================================================ @@ -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: ================================================================================