u/KillerQueenOriginal

package main

import "fmt"

type Game interface {
	Init()
	Update(dt float64)
	Draw(dt float64)
}

func RunGame(g Game) {
	g.Init()
	for range 10 {
		dt := 1.0 //calculate dt
		g.Update(dt)
		g.Draw(dt)
	}
}

type MyGame struct {
	Data int
}

func (g *MyGame) Init() {
	g.Data = 0
}

func (g *MyGame) Update(dt float64) {
	g.Data += 1

}

func (g *MyGame) Draw(dt float64) {
	fmt.Println(g.Data)
}

func main() {
	var myGame MyGame
	RunGame(&myGame)
}

how to simulate this go code in odin: i want to create a game interface where users can override update and draw function while being able to access game variables (Data in this example).

you can run the above code in go playground

u/KillerQueenOriginal — 10 days ago