Direction
This commit is contained in:
21
main.go
21
main.go
@@ -2,10 +2,13 @@ package main
|
||||
|
||||
import (
|
||||
"github.com/hajimehoshi/ebiten/v2"
|
||||
"gitlab.com/kbr4/9heroja/configuration"
|
||||
"gitlab.com/kbr4/9heroja/hero"
|
||||
"gitlab.com/kbr4/9heroja/terrain"
|
||||
_ "image/png"
|
||||
"log"
|
||||
"math/rand"
|
||||
"time"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -45,7 +48,7 @@ type Game struct {
|
||||
}
|
||||
|
||||
func (g *Game) Update() error {
|
||||
g.terrain.GoDown()
|
||||
g.terrain.Move()
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -66,7 +69,23 @@ func init() {
|
||||
GameInstance = &Game{}
|
||||
GameInstance.hero = hero.NewHero()
|
||||
GameInstance.terrain = terrain.NewTerrain()
|
||||
GameInstance.hero.ChangeDirection(configuration.North)
|
||||
GameInstance.terrain.ChangeDirection(configuration.North)
|
||||
GameInstance.hero.Walk()
|
||||
|
||||
ticker := time.NewTicker(1500 * time.Millisecond)
|
||||
go func() {
|
||||
for {
|
||||
select {
|
||||
case <-ticker.C:
|
||||
// change terrain direction to random direction
|
||||
randomDirection := configuration.AllDirections[rand.Intn(len(configuration.AllDirections))]
|
||||
GameInstance.terrain.ChangeDirection(randomDirection)
|
||||
GameInstance.hero.ChangeDirection(randomDirection)
|
||||
}
|
||||
}
|
||||
|
||||
}()
|
||||
}
|
||||
|
||||
func main() {
|
||||
|
||||
Reference in New Issue
Block a user