A dungeon delver roguelike using Pathfinder 2nd edition rules
at g3n 81 lines 2.3 kB view raw
1package main 2 3import ( 4 "time" 5 6 "github.com/g3n/engine/app" 7 "github.com/g3n/engine/camera" 8 "github.com/g3n/engine/core" 9 "github.com/g3n/engine/geometry" 10 "github.com/g3n/engine/gls" 11 "github.com/g3n/engine/graphic" 12 "github.com/g3n/engine/gui" 13 "github.com/g3n/engine/light" 14 "github.com/g3n/engine/material" 15 "github.com/g3n/engine/math32" 16 "github.com/g3n/engine/renderer" 17 "github.com/g3n/engine/util/helper" 18 "github.com/g3n/engine/window" 19) 20 21func main() { 22 // Create application and scene 23 a := app.App() 24 scene := core.NewNode() 25 26 // Set the scene to be managed by the gui manager 27 gui.Manager().Set(scene) 28 29 // Create perspective camera 30 cam := camera.New(1) 31 cam.SetPosition(0, 0, 3) 32 scene.Add(cam) 33 34 // Set up orbit control for the camera 35 camera.NewOrbitControl(cam) 36 37 // Set up callback to update viewport and camera aspect ratio when the window is resized 38 onResize := func(evname string, ev any) { 39 // Get framebuffer size and update viewport accordingly 40 width, height := a.GetSize() 41 a.Gls().Viewport(0, 0, int32(width), int32(height)) 42 // Update the camera's aspect ratio 43 cam.SetAspect(float32(width) / float32(height)) 44 } 45 46 a.Subscribe(window.OnWindowSize, onResize) 47 onResize("", nil) 48 49 // Create a blue torus and add it to the screen 50 geom := geometry.NewTorus(1, 0.4, 12, 32, math32.Pi*2) 51 mat := material.NewStandard(math32.NewColor("DarkBlue")) 52 mesh := graphic.NewMesh(geom, mat) 53 scene.Add(mesh) 54 55 // Create and add a button to the scene 56 btn := gui.NewButton("Make Red") 57 btn.SetPosition(100, 40) 58 btn.SetSize(40, 40) 59 btn.Subscribe(gui.OnClick, func(name string, ev any) { 60 mat.SetColor(math32.NewColor("DarkRed")) 61 }) 62 scene.Add(btn) 63 64 // Create and add lights to the scene 65 scene.Add(light.NewAmbient(&math32.Color{1.0, 1.0, 1.0}, 8.0)) 66 pointLight := light.NewPoint(&math32.Color{1.0, 1.0, 1.0}, 5.0) 67 pointLight.SetPosition(1, 0, 2) 68 scene.Add(pointLight) 69 70 // Create and add an axis helper to the scene 71 scene.Add(helper.NewAxes(0.5)) 72 73 // Set background color to gray 74 a.Gls().ClearColor(0.5, 0.5, 0.5, 1.0) 75 76 // Run the application 77 a.Run(func(renderer *renderer.Renderer, deltaTime time.Duration) { 78 a.Gls().Clear(gls.DEPTH_BUFFER_BIT | gls.STENCIL_BUFFER_BIT | gls.COLOR_BUFFER_BIT) 79 renderer.Render(scene, cam) 80 }) 81}