Another night of .obj failure

This commit is contained in:
2018-03-21 05:08:24 +00:00
parent 4db78f52fa
commit c4598590c2
4 changed files with 254 additions and 142 deletions

View File

@@ -2,8 +2,9 @@ package main
import (
"flag"
"image/color"
// "image/color"
"log"
"math"
"os"
"path/filepath"
@@ -30,6 +31,7 @@ type env struct {
type state struct {
env *env
step int
objIdx int
spriteIdx int
@@ -89,10 +91,17 @@ func (e *env) run() {
oldState := *state
state = state.runStep(pWin)
if oldState != *state {
if oldState != *state || oldState.step == 0 {
log.Printf(
"new state: numObj=%d object=%d (%s) numFrames=%d frame=%d", // FIXME: rename to sprite throughout
state.env.set.Count(), state.objIdx, state.env.set.Palette[state.objIdx], state.curObject().NumFrames, state.spriteIdx)
"new state: numObj=%d object=%d (%s) numFrames=%d sprite=%d zoom=%.2f",
state.env.set.Count(),
state.objIdx,
state.env.set.Palette[state.objIdx],
state.curObject().NumSprites,
state.spriteIdx,
state.zoom,
)
state.step += 1
state.present(pWin)
}
@@ -107,22 +116,21 @@ func (s *state) runStep(pWin *pixelgl.Window) *state {
}
func (s *state) present(pWin *pixelgl.Window) {
obj := s.curObject()
frame := obj.Frames[s.spriteIdx] // FIXME: Rename Frame to Sprite throughout
// obj := s.curObject()
// sprite := obj.Sprites[s.spriteIdx]
log.Printf("%#v", frame)
center := pWin.Bounds().Center()
pic := pixel.MakePictureData(pixel.R(0, 0, float64(frame.Width), float64(frame.Height)))
// FIXME: how do I convert? Do I even have the right data here?
for i, b := range frame.PixelData {
pic.Pix[i] = color.RGBA{b, b, b, 255}
}
sprite := pixel.NewSprite(pic, pic.Bounds())
cam := pixel.IM
// cam = cam.ScaledXY(pixel.ZV, pixel.Vec{1.0, -1.0}) // invert the Y axis
cam = cam.Scaled(center, s.zoom) // apply current zoom factor
//cam = cam.Moved(center.Sub(s.camPos)) // Make it central
//cam = cam.Rotated(center, -0.785) // Apply isometric angle
s.cam = cam
pWin.SetMatrix(s.cam)
pWin.Clear(colornames.White)
sprite.Draw(pWin, pixel.IM.Moved(pWin.Bounds().Center()))
// pixel.NewSprite(pic, pic.Bounds()).Draw(pWin, pixel.IM.Moved(center))
}
func (s *state) handleKeys(pWin *pixelgl.Window) {
@@ -147,10 +155,13 @@ func (s *state) handleKeys(pWin *pixelgl.Window) {
}
if pWin.JustPressed(pixelgl.KeyUp) {
if s.spriteIdx < int(s.curObject().NumFrames)-1 {
if s.spriteIdx < int(s.curObject().NumSprites)-1 {
s.spriteIdx += 1
}
}
// Zoom in and out with the mouse wheel
s.zoom *= math.Pow(1.2, pWin.MouseScroll().Y)
}
func (s *state) curObject() *data.Object {