func sparkParticles() *effects.ParticleSystem { img, _ := assets.ImportImageCached("TestAssets/Spark.png") smoke := effects.CreateParticleSystem(effects.ParticleSettings{ MaxParticles: 7, ParticleEmitRate: 7, BaseGeometry: renderer.CreateBox(float32(1), float32(1)), TotalFrames: 1, FramesX: 1, FramesY: 1, MaxLife: 1.0, MinLife: 0.7, StartColor: color.NRGBA{255, 220, 180, 255}, EndColor: color.NRGBA{255, 155, 55, 255}, StartSize: mgl32.Vec3{1, 1, 1}.Mul(0.008), EndSize: mgl32.Vec3{1, 1, 1}.Mul(0.005), MinTranslation: mgl32.Vec3{1, 1, 1}.Mul(-0.04), MaxTranslation: mgl32.Vec3{1, 1, 1}.Mul(0.04), MinStartVelocity: mgl32.Vec3{-0.5, 0.0, -0.5}, MaxStartVelocity: mgl32.Vec3{0.5, 1.0, 0.5}, Acceleration: mgl32.Vec3{0.0, -1.0, 0.0}, OnParticleUpdate: func(p *effects.Particle) { p.Scale[0] = p.Scale[0] * (1 + p.Velocity.Len()*3.5) p.Orientation = mgl32.QuatBetweenVectors(mgl32.Vec3{1, 0, 0}, p.Velocity) }, }) smoke.Node.Material = renderer.NewMaterial(renderer.NewTexture("diffuseMap", img, false)) return smoke }
func fireParticles() *effects.ParticleSystem { img, _ := assets.ImportImageCached("TestAssets/Fire.png") fire := effects.CreateParticleSystem(effects.ParticleSettings{ MaxParticles: 12, ParticleEmitRate: 3, BaseGeometry: renderer.CreateBox(float32(1), float32(1)), TotalFrames: 36, FramesX: 6, FramesY: 6, MaxLife: 0.8, MinLife: 1.5, StartColor: color.NRGBA{255, 180, 80, 255}, EndColor: color.NRGBA{255, 60, 20, 255}, StartSize: mgl32.Vec3{1, 1, 1}.Mul(0.16), EndSize: mgl32.Vec3{1, 1, 1}.Mul(0.23), MinTranslation: mgl32.Vec3{1, 1, 1}.Mul(-0.01), MaxTranslation: mgl32.Vec3{1, 1, 1}.Mul(0.01), MinStartVelocity: mgl32.Vec3{-0.02, 0, -0.02}, MaxStartVelocity: mgl32.Vec3{0.02, 0.08, 0.02}, MinRotation: 3.0, MaxRotation: 3.6, }) fire.Node.Material = renderer.NewMaterial(renderer.NewTexture("diffuseMap", img, false)) return fire }
func sparkParticles() *effects.ParticleGroup { img, _ := assets.ImportImageCached("resources/spark.png") material := renderer.NewMaterial(renderer.NewTexture("diffuseMap", img, false)) particleSystem := effects.CreateParticleSystem(effects.ParticleSettings{ MaxParticles: 80, ParticleEmitRate: 400, BaseGeometry: renderer.CreateBox(float32(1), float32(1)), TotalFrames: 1, FramesX: 1, FramesY: 1, MaxLife: 3.3, MinLife: 1.7, StartColor: color.NRGBA{254, 160, 90, 254}, EndColor: color.NRGBA{254, 160, 90, 254}, StartSize: mgl32.Vec2{2, 2}.Vec3(0), EndSize: mgl32.Vec2{2, 2}.Vec3(0), MinTranslation: mgl32.Vec2{-5, -5}.Vec3(0), MaxTranslation: mgl32.Vec2{5, 5}.Vec3(0), MinStartVelocity: mgl32.Vec2{-100, -100}.Vec3(0), MaxStartVelocity: mgl32.Vec2{100, 100}.Vec3(0), Acceleration: mgl32.Vec2{0, 400}.Vec3(0), OnParticleUpdate: func(p *effects.Particle) { p.Scale[0] = p.Scale[0] * (1 + p.Velocity.Len()*0.05) p.Orientation = mgl32.QuatBetweenVectors(mgl32.Vec3{1, 0, 0}, p.Velocity) }, }) particleSystem.FaceCamera = false particleGroup := effects.NewParticleGroup(nil, particleSystem) particleGroup.Node.Material = material return particleGroup }
func majicParticles() *effects.ParticleGroup { img, _ := assets.ImportImageCached("resources/majic.png") material := renderer.NewMaterial(renderer.NewTexture("diffuseMap", img, false)) particleSystem := effects.CreateParticleSystem(effects.ParticleSettings{ MaxParticles: 300, ParticleEmitRate: 700, BaseGeometry: renderer.CreateBox(float32(1), float32(1)), TotalFrames: 9, FramesX: 3, FramesY: 3, MaxLife: 1.3, MinLife: 0.7, StartColor: color.NRGBA{254, 254, 254, 254}, EndColor: color.NRGBA{254, 254, 254, 254}, StartSize: mgl32.Vec2{10, 10}.Vec3(0), EndSize: mgl32.Vec2{10, 10}.Vec3(0), MinTranslation: mgl32.Vec2{-1, -1}.Vec3(0), MaxTranslation: mgl32.Vec2{1, 1}.Vec3(0), MinStartVelocity: mgl32.Vec2{-170, -170}.Vec3(0), MaxStartVelocity: mgl32.Vec2{170, 170}.Vec3(0), MaxRotation: -3.14, MinRotation: 3.14, }) particleSystem.FaceCamera = false particleGroup := effects.NewParticleGroup(nil, particleSystem) particleGroup.Node.Material = material return particleGroup }
func dustParticles() *effects.ParticleGroup { img, _ := assets.ImportImageCached("resources/smoke.png") material := renderer.NewMaterial(renderer.NewTexture("diffuseMap", img, false)) particleSystem := effects.CreateParticleSystem(effects.ParticleSettings{ MaxParticles: 5, ParticleEmitRate: 20, BaseGeometry: renderer.CreateBox(float32(1), float32(1)), TotalFrames: 64, FramesX: 8, FramesY: 8, MaxLife: 3.3, MinLife: 2.7, StartColor: color.NRGBA{254, 254, 254, 120}, EndColor: color.NRGBA{254, 254, 254, 0}, StartSize: mgl32.Vec2{40, 40}.Vec3(0), EndSize: mgl32.Vec2{180, 180}.Vec3(0), MinTranslation: mgl32.Vec2{-2, -2}.Vec3(0), MaxTranslation: mgl32.Vec2{2, 2}.Vec3(0), MinStartVelocity: mgl32.Vec2{-5.0, -5.0}.Vec3(0), MaxStartVelocity: mgl32.Vec2{5.0, 5.0}.Vec3(0), MaxRotation: -3.14, MinRotation: 3.14, }) particleSystem.FaceCamera = false particleGroup := effects.NewParticleGroup(nil, particleSystem) particleGroup.Node.Material = material return particleGroup }
func htmlContent(content *ui.Container) []ui.Activatable { html := bytes.NewBufferString(` <body> <div class=content> <h1 id=heading>UI EXAMPLE!</h1> <img src=testImage></img> <input type=text placeholder="this is a placeholder"></input> <input type=password></input> <button onclick=clickButton></button> <div> </body> `) css := bytes.NewBufferString(` .content img { width: 200; } .content input { background-color: #fff; margin: 10 0 0 0; } .content button { padding: 20; margin: 10 0 0 0; background-color: #a00; } .content button:hover { background-color: #e99; } `) // create assets htmlAssets := ui.NewHtmlAssets() // image img, _ := assets.ImportImageCached("resources/cubemap.png") htmlAssets.AddImage("testImage", img) // button click callback htmlAssets.AddCallback("clickButton", func(element ui.Element, args ...interface{}) { if len(args) >= 2 && !args[1].(bool) { // on release content.TextElementById("heading").SetText("release").SetTextColor(color.NRGBA{254, 0, 0, 254}).ReRender() } else { content.TextElementById("heading").SetText("press").SetTextColor(color.NRGBA{0, 254, 0, 254}).ReRender() } }) // Render the html/css code to the content container activatables, err := ui.LoadHTML(content, html, css, htmlAssets) if err != nil { fmt.Println("Error loading html: ", err) } return activatables }
func populateContent(content *ui.Container) []ui.Activatable { // example text title textElement := ui.NewTextElement("UI EXAMPLE!", color.Black, 16, nil) // example image element img, _ := assets.ImportImageCached("resources/cubemap.png") imageElement := ui.NewImageElement(img) imageElement.SetWidth(200) // example text field tf := ui.NewTextField("", color.Black, 16, nil) tf.SetPlaceholder("this is a placeholder") tf.SetBackgroundColor(255, 255, 255, 255) tf.SetMargin(ui.Margin{10, 0, 10, 0}) // example hidden text field passwordTf := ui.NewTextField("", color.Black, 16, nil) passwordTf.SetHidden(true) passwordTf.SetBackgroundColor(255, 255, 255, 255) passwordTf.SetMargin(ui.Margin{0, 0, 10, 0}) // example button button := ui.NewContainer() button.SetBackgroundColor(160, 0, 0, 254) button.SetPadding(ui.NewMargin(20)) // button on click event button.Hitbox.AddOnClick(func(button int, release bool, position mgl32.Vec2) { if release { textElement.SetText("release").SetTextColor(color.NRGBA{254, 0, 0, 254}).ReRender() } else { textElement.SetText("click").SetTextColor(color.NRGBA{0, 254, 0, 254}).ReRender() } }) // button on hover event button.Hitbox.AddOnHover(func() { button.SetBackgroundColor(210, 100, 100, 254) }) button.Hitbox.AddOnUnHover(func() { button.SetBackgroundColor(160, 0, 0, 254) }) // add everything to the content container content.AddChildren(textElement, imageElement, tf, passwordTf, button) // return everything that should be included in the Tabs order return []ui.Activatable{tf, passwordTf} }
func NewCharacter() *Character { characterImg, _ := assets.ImportImageCached("resources/stickman.png") characterMat := renderer.NewMaterial(renderer.NewTexture("diffuseMap", characterImg, false)) sprite := effects.CreateSprite(4, 4, 1, characterMat) sprite.FaceCamera = false sprite.SetScale(mgl32.Vec2{characterSize, characterSize}.Vec3(0)) sprite.SetTranslation(mgl32.Vec2{400, 400}.Vec3(0)) body := chipmunkPhysics.NewChipmunkBody(1, 1) circle := chipmunk.NewCircle(vect.Vector_Zero, float32(characterSize*0.5)) body.Body.AddShape(circle) return &Character{ body: body, sprite: sprite, } }