Walking
This commit is contained in:
@@ -13,17 +13,21 @@ var (
|
||||
)
|
||||
|
||||
type Terrain struct {
|
||||
positionX float64
|
||||
positionY float64
|
||||
}
|
||||
|
||||
func (t *Terrain) DrawTerrain(screen *ebiten.Image) {
|
||||
screenWidth := screen.Bounds().Max.X
|
||||
screenHeight := screen.Bounds().Max.Y
|
||||
offsetX := int(t.positionX) % 64
|
||||
offsetY := int(t.positionY) % 64
|
||||
op := &ebiten.DrawImageOptions{}
|
||||
for i := 0; i <= screenWidth/64; i++ {
|
||||
for j := 0; j <= screenHeight/64; j++ {
|
||||
for i := -1; i <= screenWidth/64+1; i++ {
|
||||
for j := -1; j <= screenHeight/64+1; j++ {
|
||||
// ground
|
||||
op.GeoM.Reset()
|
||||
op.GeoM.Translate(float64(i*64), float64(j*64))
|
||||
op.GeoM.Translate(float64(i*64+offsetX), float64(j*64+offsetY))
|
||||
screen.DrawImage(grassImage.SubImage(image.Rect(32, 160, 32+64, 160+64)).(*ebiten.Image), op)
|
||||
}
|
||||
|
||||
@@ -37,3 +41,14 @@ func init() {
|
||||
}
|
||||
grassImage = ebiten.NewImageFromImage(img)
|
||||
}
|
||||
|
||||
func NewTerrain() *Terrain {
|
||||
return &Terrain{
|
||||
positionX: 0,
|
||||
positionY: 0,
|
||||
}
|
||||
}
|
||||
|
||||
func (t *Terrain) GoDown() {
|
||||
t.positionY += 1
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user