commit 626d8fd5d01b50741d885cf291232bea0dadbcab parent ec1f27b656d72a1de6a57a83656cde18c6308122 Author: bsandro <brian.drosan@gmail.com> Date: Wed, 20 Oct 2021 00:15:02 +0300 Moved tileset pictures and map files into "assets" subdirectory Added stub character at fixed position. Diffstat:
24 files changed, 54 insertions(+), 158 deletions(-)
diff --git a/Zorldo.tiled-session b/Zorldo.tiled-session @@ -1,61 +0,0 @@ -{ - "Map/SizeTest": { - "height": 4300, - "width": 2 - }, - "activeFile": "map0.tmx", - "expandedProjectPaths": [ - "." - ], - "fileStates": { - "": { - "scaleInDock": 1 - }, - "map0.tmx": { - "scale": 1.5, - "selectedLayer": 0, - "viewCenter": { - "x": 261, - "y": 239 - } - }, - "map0.tmx#npc_test": { - "scaleInEditor": 1 - }, - "map0.tmx#overworld": { - "scaleInEditor": 1 - }, - "npc_test.tsx": { - "scaleInDock": 1, - "scaleInEditor": 2 - }, - "overworld.tsx": { - "scaleInDock": 1, - "scaleInEditor": 2 - } - }, - "frame.defaultDuration": 200, - "lastUsedTilesetExportFilter": "JSON tileset files (*.json)", - "map.lastUsedExportFilter": "JSON map files (*.json)", - "map.lastUsedFormat": "tmx", - "map.renderOrder": null, - "map.tileHeight": 16, - "map.tileWidth": 16, - "openFiles": [ - "overworld.tsx", - "map0.tmx" - ], - "project": "Zorldo.tiled-project", - "property.type": "bool", - "recentFiles": [ - "overworld.tsx", - "map0.tmx", - "npc_test.tsx" - ], - "resizeMap.removeObjects": true, - "tileset.lastUsedFormat": "tsx", - "tileset.tileSize": { - "height": 32, - "width": 16 - } -} diff --git a/Inner.png b/assets/Inner.png Binary files differ. diff --git a/NPC_test.png b/assets/NPC_test.png Binary files differ. diff --git a/Overworld.png b/assets/Overworld.png Binary files differ. diff --git a/basictiles.png b/assets/basictiles.png Binary files differ. diff --git a/batch5.png b/assets/batch5.png Binary files differ. diff --git a/cave.png b/assets/cave.png Binary files differ. diff --git a/character.png b/assets/character.png Binary files differ. diff --git a/characters_new.png b/assets/characters_new.png Binary files differ. diff --git a/font.png b/assets/font.png Binary files differ. diff --git a/log.png b/assets/log.png Binary files differ. diff --git a/map0.json b/assets/map0.json diff --git a/objects.png b/assets/objects.png Binary files differ. diff --git a/overworld.json b/assets/overworld.json diff --git a/assets/protag.png b/assets/protag.png Binary files differ. diff --git a/things.png b/assets/things.png Binary files differ. diff --git a/character.go b/character.go @@ -0,0 +1,38 @@ +package main + +import ( + "github.com/hajimehoshi/ebiten/v2" + "github.com/hajimehoshi/ebiten/v2/ebitenutil" + _ "image/png" + "errors" +) + +type Character struct { + Image *ebiten.Image + Options *ebiten.DrawImageOptions + x, y float64 +} + +func (c *Character) Init(filename string) error { + var err error + + c.Image, _, err = ebitenutil.NewImageFromFile(filename) + if err != nil { + return err + } + + c.Options = &ebiten.DrawImageOptions{} + + return nil +} + +func (c *Character) Move(x, y float64) error { + if c.Options == nil { + return errors.New("Character was not initialized") + } + + c.Options.GeoM.Reset() + c.Options.GeoM.Translate(x, y) + + return nil +} diff --git a/gamemap.go b/gamemap.go @@ -120,7 +120,7 @@ func (l *Layer) Init(gamemap *Gamemap) error { func (t *Tileset) Init() error { var err error - t.Atlas, _, err = ebitenutil.NewImageFromFile(t.Image) + t.Atlas, _, err = ebitenutil.NewImageFromFile(assetsDir + t.Image) if err != nil { return err } diff --git a/main.go b/main.go @@ -12,6 +12,7 @@ import ( ) const ( + assetsDir = "assets/" screenW = 1280 screenH = 480 scale = 2 @@ -23,6 +24,7 @@ type Game struct { Map *Gamemap PressedKeys []ebiten.Key Cam Camera + Hero Character } func (g *Game) Init() error { @@ -32,13 +34,17 @@ func (g *Game) Init() error { // init base map g.Map = &Gamemap{} - var err error = g.Map.Init("map0.json") + var err error = g.Map.Init(assetsDir + "map0.json") if err != nil { return err } g.Cam.Init(screenW/scale, screenH/scale, g.Map.RealWidth, g.Map.RealHeight) + g.Hero.Init(assetsDir + "protag.png") + // @todo stub + g.Hero.Move(100, 100) + return nil } @@ -68,7 +74,9 @@ func (g *Game) Update() error { } func (g *Game) Draw(screen *ebiten.Image) { + // iterating through tiles for _, tiles := range g.Map.Tiles { + // iterating through layers on the tile for _, tile := range tiles { if tile.IsOnScreen(&g.Cam, g.Map) { // render options for that tile are being copied into opts so the cam @@ -79,6 +87,12 @@ func (g *Game) Draw(screen *ebiten.Image) { } } } + // @todo character is being rendered on top of the map for the time being + opts := *g.Hero.Options // preserving original draw options like above + opts.GeoM.Translate(-g.Cam.x, -g.Cam.y) // camera compensation + screen.DrawImage(g.Hero.Image, &opts) + + // debug info ebitenutil.DebugPrint(screen, fmt.Sprintf("TPS: %0.2f, screen: %v", ebiten.CurrentTPS(), g.Cam)) } diff --git a/npc_test.json b/npc_test.json @@ -1,95 +0,0 @@ -{ "columns":4, - "image":"NPC_test.png", - "imageheight":128, - "imagewidth":64, - "margin":0, - "name":"npc_test", - "spacing":0, - "tilecount":16, - "tiledversion":"1.4.3", - "tileheight":32, - "tiles":[ - { - "animation":[ - { - "duration":200, - "tileid":0 - }, - { - "duration":200, - "tileid":1 - }, - { - "duration":200, - "tileid":2 - }, - { - "duration":200, - "tileid":3 - }], - "id":0 - }, - { - "animation":[ - { - "duration":200, - "tileid":4 - }, - { - "duration":200, - "tileid":5 - }, - { - "duration":200, - "tileid":6 - }, - { - "duration":200, - "tileid":7 - }], - "id":4 - }, - { - "animation":[ - { - "duration":200, - "tileid":8 - }, - { - "duration":200, - "tileid":9 - }, - { - "duration":200, - "tileid":10 - }, - { - "duration":200, - "tileid":11 - }], - "id":8 - }, - { - "animation":[ - { - "duration":200, - "tileid":12 - }, - { - "duration":200, - "tileid":13 - }, - { - "duration":200, - "tileid":14 - }, - { - "duration":200, - "tileid":15 - }], - "id":12 - }], - "tilewidth":16, - "type":"tileset", - "version":1.4 -} diff --git a/Zorldo.tiled-project b/tiled/Zorldo.tiled-project diff --git a/map0.tmx b/tiled/map0.tmx diff --git a/npc_test.tsx b/tiled/npc_test.tsx diff --git a/overworld.tsx b/tiled/overworld.tsx