Initial commit
This commit is contained in:
commit
b3f3a77fc7
8 changed files with 242 additions and 0 deletions
57
main.go
Normal file
57
main.go
Normal file
|
@ -0,0 +1,57 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"github.com/hajimehoshi/ebiten/v2"
|
||||
|
||||
"github.com/ChaoticByte/xels/simulation"
|
||||
)
|
||||
|
||||
|
||||
type Application struct {
|
||||
simulation simulation.Simulation
|
||||
}
|
||||
|
||||
func (a *Application) Update() error {
|
||||
a.simulation.Update()
|
||||
return nil
|
||||
}
|
||||
|
||||
func (a *Application) Draw(screen *ebiten.Image) {
|
||||
// create image from xel grid
|
||||
pixels := make([]byte, 4 * screen.Bounds().Dx() * screen.Bounds().Dy())
|
||||
for i := range len(a.simulation.Grid.Xels) {
|
||||
xel := a.simulation.Grid.Xels[i]
|
||||
var v byte = 0
|
||||
if xel.Energy > 0 {
|
||||
v = byte(max(0, min(255, xel.Energy * 2 + 38)))
|
||||
}
|
||||
// r
|
||||
pixels[i * 4] = v
|
||||
// g
|
||||
pixels[(i*4) + 1] = v
|
||||
// b
|
||||
pixels[(i*4) + 2] = v
|
||||
// a
|
||||
pixels[(i*4) + 3] = 255
|
||||
}
|
||||
screen.WritePixels(pixels)
|
||||
}
|
||||
|
||||
func (a *Application) Layout(outsideWidth int, outsideHeight int) (int, int) {
|
||||
return CanvasWidth, CanvasHeight
|
||||
}
|
||||
|
||||
|
||||
func main() {
|
||||
ebiten.SetWindowSize(CanvasWidth, CanvasHeight)
|
||||
ebiten.SetWindowTitle("Pixels - Main Window")
|
||||
ebiten.SetWindowResizingMode(ebiten.WindowResizingModeEnabled)
|
||||
ebiten.MaximizeWindow()
|
||||
ebiten.SetTPS(MaxTps)
|
||||
app := &Application{
|
||||
simulation: *simulation.NewSimulation(CanvasWidth, CanvasHeight),
|
||||
}
|
||||
InitGrid(app.simulation.Grid)
|
||||
err := ebiten.RunGame(app)
|
||||
if err != nil { panic(err) }
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue