Files
loading/loader.go
2023-10-27 09:59:01 -04:00

109 lines
2.8 KiB
Go

package main
import (
"fmt"
"image/color"
c "loading/character"
"loading/objects"
"log"
"math/rand"
"github.com/hajimehoshi/ebiten/v2"
"github.com/hajimehoshi/ebiten/v2/examples/resources/fonts"
"github.com/hajimehoshi/ebiten/v2/text"
"golang.org/x/image/font"
"golang.org/x/image/font/opentype"
)
func init() {
//tt, err := opentype.Parse(fonts.MPlus1pRegular_ttf)
tt, err := opentype.Parse(fonts.PressStart2P_ttf)
if err != nil {
log.Fatal(err)
}
const dpi = 72
mplusNormalFont, err = opentype.NewFace(tt, &opentype.FaceOptions{
Size: 24,
DPI: dpi,
Hinting: font.HintingVertical,
})
if err != nil {
log.Fatal(err)
}
mplusBigFont, err = opentype.NewFace(tt, &opentype.FaceOptions{
Size: 48,
DPI: dpi,
Hinting: font.HintingFull, // Use quantization to save glyph cache images.
})
if err != nil {
log.Fatal(err)
}
mplusTinyFont, err = opentype.NewFace(tt, &opentype.FaceOptions{
Size: 10,
DPI: dpi,
Hinting: font.HintingVertical,
})
if err != nil {
log.Fatal(err)
}
// Adjust the line height.
mplusBigFont = text.FaceWithLineHeight(mplusBigFont, 54)
}
func loading() {
game := &Game{}
whiteImage.Fill(color.White)
ebiten.SetWindowSize(screenWidth, screenHeight)
ebiten.SetWindowTitle(bsofttext)
fmt.Println(bsofttext)
//loadCharacters(game)
loadBobbles(game)
// Call ebiten.RunGame to start your game loop.
if err := ebiten.RunGame(game); err != nil {
log.Fatal(err)
}
}
func loadBobbles(game *Game) {
// generate bobbles
gridWidth := bubbleGridSpacing * bubbleGridCols
gridHeight := bubbleGridSpacing * bubbleGridRows
gridStartX := float32((screenWidth - gridWidth - bubbleGridSpacing) / 2)
gridStartY := float32((screenHeight - gridHeight - bubbleGridSpacing) / 2)
for i := 0; i < totalBobbles; i++ {
game.bobbles = append(game.bobbles, objects.NewBobble())
ix := float32(i%bubbleGridRows*bubbleGridSpacing + i%bubbleGridRows*bubbleGridSpacing)
iy := float32(i/bubbleGridCols*bubbleGridSpacing + i/bubbleGridCols*bubbleGridSpacing)
game.bobbles[i].Color = color.RGBA{0xFF, 0x00, 0x00, 0xFF}
game.bobbles[i].Bordercolor = color.RGBA{0x80, 0x00, 0x00, 0xFF}
game.bobbles[i].SetPose(gridStartX+ix, gridStartY+iy)
}
}
func loadCharacters(game *Game) {
// generate player character
game.player = c.NewCharacter()
game.player.SetPose(float32(rand.Intn(screenWidth)), float32(rand.Intn(screenHeight)))
// generate enemies
for i := 0; i < enemyCount; i++ {
//create new enemy, slip 'em in
game.enemies = append(game.enemies, c.NewCharacter())
//set random position based on screen dimensions
game.enemies[i].SetPose(float32(rand.Intn(screenWidth)), float32(rand.Intn(screenHeight)))
//distinguish them from the player character
game.enemies[i].Color = color.RGBA{0xFF, 0x00, 0x00, 0xFF}
}
}