YT-Physics/main.go
2024-05-27 14:31:32 -04:00

47 lines
763 B
Go

// Package
package main
import (
"math/rand"
)
// Libraries
// Varaibles
var squares = []*Square{}
// Functions
func onCollide(s *Square) {
var nSquare Square
nSquare.Init()
nSquare.x = s.x - (s.vx * 0.5)
nSquare.y = s.y - (s.vy * 0.5)
nSquare.vx = s.vx * (rand.Float32() * 1.2)
nSquare.vy = s.vy * (rand.Float32() * 1.2)
squares = append(squares, &nSquare)
}
func onUpdate(w *Window) {
for _, square := range squares {
go square.Update(onCollide)
square.Draw()
}
}
// Entry Point
func main() {
// Creating the Window
var window Window
// Starting the window
window.Init("YT Physics", 1024, 1024)
// Creating objects
var nSquare Square
nSquare.Init()
squares = append(squares, &nSquare)
// Running the app
window.Run(onUpdate)
}