zorldo

Goofing around with Ebiten
git clone git://bsandro.tech/zorldo
Log | Files | Refs | README

character.go (646B)


      1 package main
      2 
      3 import (
      4 	"errors"
      5 	"github.com/hajimehoshi/ebiten/v2"
      6 	"github.com/hajimehoshi/ebiten/v2/ebitenutil"
      7 	_ "image/png"
      8 )
      9 
     10 type Character struct {
     11 	Image   *ebiten.Image
     12 	Options *ebiten.DrawImageOptions
     13 	x, y    float64
     14 }
     15 
     16 func (c *Character) Init(filename string) error {
     17 	var err error
     18 
     19 	c.Image, _, err = ebitenutil.NewImageFromFile(filename)
     20 	if err != nil {
     21 		return err
     22 	}
     23 
     24 	c.Options = &ebiten.DrawImageOptions{}
     25 
     26 	return nil
     27 }
     28 
     29 func (c *Character) Move(x, y float64) error {
     30 	if c.Options == nil {
     31 		return errors.New("Character was not initialized")
     32 	}
     33 
     34 	c.Options.GeoM.Reset()
     35 	c.Options.GeoM.Translate(x, y)
     36 
     37 	return nil
     38 }