-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
66 lines (56 loc) · 1.62 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package main
import (
"log"
"github.com/KeithClinard/go-particle-simulator/internal/logic"
"github.com/KeithClinard/go-particle-simulator/internal/models"
"github.com/KeithClinard/go-particle-simulator/internal/rendering"
"github.com/hajimehoshi/ebiten/v2"
)
var tickCounter uint64 = 0
// Only calculate gravity every N ticks
// Particles still move between calculations
// Increase to improve performance at the cost of accuracy
var gravityFrequencyConstant uint64 = 1
type Game struct {
gameState *models.GameState
}
func (game *Game) Update() error {
logic.HandleUserInputs(game.gameState)
if tickCounter%gravityFrequencyConstant == 0 {
logic.ApplyGravity(game.gameState)
}
for _, particle := range game.gameState.Particles {
particle.Move()
}
logic.DetectOutOfBounds(game.gameState)
//logic.HandleCollision(game.gameState)
logic.DestroyParticles(game.gameState)
tickCounter++
return nil
}
func (game *Game) Draw(screen *ebiten.Image) {
rendering.DrawParticles(game.gameState, screen)
rendering.DrawDebugInfo(game.gameState, screen)
}
func (game *Game) Layout(outsideWidth, outsideHeight int) (int, int) {
return outsideWidth, outsideHeight
}
func InitializeGameObject() *Game {
ebiten.SetWindowSize(800, 600)
ebiten.SetWindowTitle("Particle Simulation")
ebiten.SetWindowResizable(true)
return &Game{
gameState: &models.GameState{
ShowDebugInfo: true,
Planets: make([]*models.Particle, 0),
Particles: make([]*models.Particle, 0),
Controller: new(models.Controller),
},
}
}
func main() {
game := InitializeGameObject()
if err := ebiten.RunGame(game); err != nil {
log.Fatal(err)
}
}