package states

import (
	"fmt"
	"math"

	"github.com/hajimehoshi/ebiten/v2"
	geom "src.robn.tv/MrDonuts/RGB/geometry"
	score "src.robn.tv/MrDonuts/RGB/tools"
)

var currentEnd = 1 //used for animating squares
var secondsPerUpdate = 0.02
var ticksPerSecond = 60.0
var deltaSeconds = 1.0 / ticksPerSecond
var secondsCounter = 0.0

type LoadLevelState struct {
}

func (s *LoadLevelState) Enter() {
	fmt.Println("Entering Loading State")
	currentEnd = 1
}

func (s *LoadLevelState) Exit() {
	fmt.Println("Exiting Loading State")
}

func (s *LoadLevelState) Update() {
	secondsCounter += deltaSeconds

	//determine how much to jump by on each draw
	totalSquares := geom.GameGrid.NumSquares()
	jumpAmount := math.Ceil(float64(totalSquares) / ticksPerSecond)
	if secondsCounter >= float64(secondsPerUpdate) {
		secondsCounter = 0
		currentEnd += int(jumpAmount)
	}

	if currentEnd > geom.GameGrid.NumSquares() {
		SM.Transition("play")

	}

}

func (s *LoadLevelState) Draw(screen *ebiten.Image) {

	geom.GameGrid.DrawUpTo(currentEnd, screen)
	score.ScoreMngr.Draw(screen)
}
