This commit is contained in:
Andrey Parhomenko 2024-05-19 23:11:58 +05:00
parent e78a0d9881
commit e697383867
10 changed files with 136 additions and 128 deletions

3
btest.sh Executable file
View file

@ -0,0 +1,3 @@
#!/bin/sh
#
go build -o ./exe/ ./cmd/test/

View file

@ -1,15 +1,16 @@
package main package main
import ( import (
"vultras.su/core/gg" "surdeus.su/core/gg"
"fmt" "fmt"
"encoding/json" "encoding/json"
) )
type Float = gg.Float type Float = gg.Float
func EdgesFromVals(vals ...Float) gg.Edges { func EdgesFromVals(vals ...Float) gg.Edges {
ret := gg.Edges{} ret := gg.Edges{}
for i:=0 ; i<len(vals) ; i += 4 { for i := 0; i < len(vals); i += 4 {
ret = append( ret = append(
ret, ret,
gg.Edge{ gg.Edge{

View file

@ -1,6 +1,6 @@
package main package main
import "vultras.su/core/gg" import "surdeus.su/core/gg"
import ( import (
"strings" "strings"
@ -13,20 +13,22 @@ type Debug struct {
} }
func (d *Debug) Update(c *Context) { func (d *Debug) Update(c *Context) {
for _, e := range c.Events { switch ec := e.(type) { for _, e := range c.Events {
case *gg.KeyDown : switch ec := e.(type) {
switch ec.Key { case *gg.KeyDown:
case gg.KeyF11 : switch ec.Key {
d.Visible = !d.Visible case gg.KeyF11:
d.Visible = !d.Visible
}
} }
}} }
} }
func (d *Debug) Draw(c *Context) []gg.EVertex { func (d *Debug) Draw(c *Context) []gg.EVertex {
e := c.Engine e := c.Engine
relTri := tri.Rel() relTri := tri.Rel()
relPlayer := player.Rel() relPlayer := player.Rel()
keyStrs := []string{} keyStrs := []string{}
keyStrs = append(keyStrs, fmt.Sprintf( keyStrs = append(keyStrs, fmt.Sprintf(
"counter: %d", counter, "counter: %d", counter,
@ -94,7 +96,6 @@ func (d *Debug) Draw(c *Context) []gg.EVertex {
e.DebugPrint(c.Image, e.DebugPrint(c.Image,
strings.Join(keyStrs, "\n")) strings.Join(keyStrs, "\n"))
return nil return nil
} }

View file

@ -1,7 +1,7 @@
package main package main
import ( import (
"vultras.su/core/gg" "surdeus.su/core/gg"
"github.com/hajimehoshi/ebiten/v2/examples/resources/images" "github.com/hajimehoshi/ebiten/v2/examples/resources/images"
"github.com/hajimehoshi/ebiten/v2/examples/resources/fonts" "github.com/hajimehoshi/ebiten/v2/examples/resources/fonts"
//_ "github.com/silbinarywolf/preferdiscretegpu" //_ "github.com/silbinarywolf/preferdiscretegpu"
@ -19,15 +19,19 @@ type Grid struct {
func (grid *Grid) Update(c *Context) { func (grid *Grid) Update(c *Context) {
//d := c.IsPressed(gg.KeyShift) //d := c.IsPressed(gg.KeyShift)
for _, ev := range c.Events { switch e := ev.(type){ for _, ev := range c.Events {
case *gg.KeyDown : switch e.Key { switch e := ev.(type) {
case gg.Key9 : case *gg.KeyDown:
grid.Cage /= 10 switch e.Key {
grid.Width /= 5 case gg.Key9:
case gg.Key0 : grid.Cage /= 10
grid.Cage *= 10 grid.Width /= 5
grid.Width *= 5 case gg.Key0:
}}} grid.Cage *= 10
grid.Width *= 5
}
}
}
} }
func (grid *Grid) Draw(c *Context) []gg.EVertex { func (grid *Grid) Draw(c *Context) []gg.EVertex {
@ -58,19 +62,19 @@ const (
var ( var (
playerAnimations gg.AnimationSet playerAnimations gg.AnimationSet
playerImg *gg.Image playerImg *gg.Image
player *Player player *Player
rectMove gg.Rectangle rectMove gg.Rectangle
rect *Rect rect *Rect
tri *Tri tri *Tri
) )
func main() { func main() {
e := gg.NewEngine(&gg.WindowConfig{ e := gg.NewEngine(&gg.WindowConfig{
Title: "Test title", Title: "Test title",
Width: 720, Width: 720,
Height: 480, Height: 480,
VSync: true, VSync: true,
Fullscreen: false, Fullscreen: false,
}) })
@ -142,7 +146,7 @@ func main() {
grid.Images[0] = gg.NewImage(720, 480) grid.Images[0] = gg.NewImage(720, 480)
grid.Images[0].Fill(gg.Rgba(1, 1, 1, 1)) grid.Images[0].Fill(gg.Rgba(1, 1, 1, 1))
grid.Shader = bgShader grid.Shader = bgShader
grid.Uniforms = map[string] any{} grid.Uniforms = map[string]any{}
//bg.Floating = true //bg.Floating = true
grid.Visible = true grid.Visible = true
grid.Floating = true grid.Floating = true
@ -160,8 +164,8 @@ func main() {
txt.Face, err = gg.MakeFaceFromTtf( txt.Face, err = gg.MakeFaceFromTtf(
bytes.NewReader(fonts.MPlus1pRegular_ttf), bytes.NewReader(fonts.MPlus1pRegular_ttf),
&gg.TtfFaceOptions{ &gg.TtfFaceOptions{
Size: 32, Size: 32,
DPI: 72, DPI: 72,
Hinting: gg.FontHintingNone, Hinting: gg.FontHintingNone,
}, },
) )

View file

@ -6,13 +6,13 @@ import (
"time" "time"
) )
import "vultras.su/core/gg" import "surdeus.su/core/gg"
type Player struct { type Player struct {
gg.AnimatedSprite gg.AnimatedSprite
MoveSpeed gg.Float MoveSpeed gg.Float
ScaleSpeed gg.Float ScaleSpeed gg.Float
Spawned bool Spawned bool
} }
func NewPlayer() *Player { func NewPlayer() *Player {
@ -23,7 +23,7 @@ func NewPlayer() *Player {
ret.MoveSpeed = 40. ret.MoveSpeed = 40.
ret.ScaleSpeed = .2 ret.ScaleSpeed = .2
ret.Animations = playerAnimations ret.Animations = playerAnimations
ret.TimeBetweenFrames = time.Second/10 ret.TimeBetweenFrames = time.Second / 10
ret.Shader = gg.SolidWhiteColorShader ret.Shader = gg.SolidWhiteColorShader
ret.Visible = true ret.Visible = true
@ -32,7 +32,6 @@ func NewPlayer() *Player {
//ret.Collidable = true //ret.Collidable = true
//ret.Resolvable = true //ret.Resolvable = true
return ret return ret
} }
@ -74,11 +73,11 @@ func (p *Player) Update(c *Context) {
case gg.KeyQ: case gg.KeyQ:
p.SetScale( p.SetScale(
p.Scale().Add( p.Scale().Add(
gg.X(p.ScaleSpeed*dt), gg.X(p.ScaleSpeed * dt),
), ),
) )
case gg.KeyW: case gg.KeyW:
p.Move(gg.Y(-p.MoveSpeed * dt )) p.Move(gg.Y(-p.MoveSpeed * dt))
walking = true walking = true
p.Animate(Walk) p.Animate(Walk)
case gg.KeyA: case gg.KeyA:
@ -136,26 +135,27 @@ func (p *Player) Update(c *Context) {
} }
for _, event := range c.Events { for _, event := range c.Events {
switch ec := event.(type) { switch ec := event.(type) {
case *gg.KeyDown: case *gg.KeyDown:
switch { switch {
case ec.Key == gg.KeyB: case ec.Key == gg.KeyB:
if p.Layer != PlayerL { if p.Layer != PlayerL {
p.Layer = PlayerL p.Layer = PlayerL
} else { } else {
p.Layer = HighestL p.Layer = HighestL
}
} }
case *gg.MouseMove:
if !c.IsButtoned(gg.MouseButtonRight) {
break
}
c.Camera.Move(ec.Abs)
case *gg.WheelChange:
c.Camera.AddScale(gg.V2(
ec.Offset.Y * dt * p.ScaleSpeed * 40,
))
} }
case *gg.MouseMove: }
if !c.IsButtoned(gg.MouseButtonRight) {
break
}
c.Camera.Move(ec.Abs)
case *gg.WheelChange:
c.Camera.AddScale(gg.V2(
ec.Offset.Y * dt * p.ScaleSpeed * 40,
))
}}
} }
@ -173,16 +173,17 @@ func (p *Player) Resolve(c *Context) {
c.Frame(), len(c.Collisions), col.What, col.With, len(col.Crosses), len(col.Points), c.Frame(), len(c.Collisions), col.What, col.With, len(col.Crosses), len(col.Points),
) )
} }
for _, col := range c.Collisions {switch col.Type{ for _, col := range c.Collisions {
case gg.CollisionStaticPhysics : switch col.Type {
case gg.CollisionStaticPhysics:
LOOP: LOOP:
for { for {
p.Move(gg.Y(-1)) p.Move(gg.Y(-1))
_, collides := gg.Collide(p, col.With) _, collides := gg.Collide(p, col.With)
if !collides { if !collides {
break LOOP break LOOP
}
} }
} }
}} }
} }

View file

@ -1,6 +1,6 @@
package main package main
import "vultras.su/core/gg" import "surdeus.su/core/gg"
type Rect struct { type Rect struct {
gg.DrawableRectangle gg.DrawableRectangle
@ -32,16 +32,18 @@ func (r *Rect) Update(c *Context) {
//r.R += 0.3 * e.DT() //r.R += 0.3 * e.DT()
dt := c.Dt().Seconds() dt := c.Dt().Seconds()
//r.Position = c.AbsCursorPosition() //r.Position = c.AbsCursorPosition()
for _, v := range c.Keys() { switch v { for _, v := range c.Keys() {
case gg.KeyArrowUp: switch v {
r.Move(gg.Y(-10* dt)) case gg.KeyArrowUp:
case gg.KeyArrowDown: r.Move(gg.Y(-10 * dt))
r.Move(gg.Y(10 * dt)) case gg.KeyArrowDown:
case gg.KeyArrowLeft: r.Move(gg.Y(10 * dt))
r.Move(gg.X(-10*dt)) case gg.KeyArrowLeft:
case gg.KeyArrowRight: r.Move(gg.X(-10 * dt))
r.Move(gg.X(10* dt)) case gg.KeyArrowRight:
}} r.Move(gg.X(10 * dt))
}
}
} }
func (r *Rect) Event(c *Context) { func (r *Rect) Event(c *Context) {

View file

@ -1,24 +1,24 @@
package main package main
import ( import (
"vultras.su/core/gg" "surdeus.su/core/gg"
//"fmt" //"fmt"
) )
type Objecter interface{ type Objecter interface {
} }
type Wrap[V Objecter] struct { type Wrap[V Objecter] struct {
O V O V
} }
//func (w *Wrap) //func (w *Wrap)
type Context2 struct { type Context2 struct {
*gg.Context *gg.Context
} }
type Text struct{ type Text struct {
gg.Text gg.Text
} }

View file

@ -1,6 +1,6 @@
package main package main
import "vultras.su/core/gg" import "surdeus.su/core/gg"
import "fmt" import "fmt"
var ( var (
@ -38,7 +38,7 @@ func (t *Tri) Update(c *Context) {
//tedges := t.Edges() //tedges := t.Edges()
//crosses, ok := tedges.CrossWithEdges(redges) //crosses, ok := tedges.CrossWithEdges(redges)
//fmt.Println("shit:", crosses, ok) //fmt.Println("shit:", crosses, ok)
if false { if false {
//fmt.Println("edges:", tedges) //fmt.Println("edges:", tedges)
} }
@ -63,45 +63,49 @@ func (t *Tri) Update(c *Context) {
d = -1 d = -1
} }
for _, key := range keys { switch key { for _, key := range keys {
switch key {
case gg.KeyM: case gg.KeyM:
t.Move(gg.Y(100*dt*d)) t.Move(gg.Y(100 * dt * d))
case gg.KeyN: case gg.KeyN:
t.Move(gg.X(100*dt*d)) t.Move(gg.X(100 * dt * d))
case gg.KeyV: case gg.KeyV:
t.Rotate(d * gg.Pi * 0.3 * dt) t.Rotate(d * gg.Pi * 0.3 * dt)
case gg.Key2 : case gg.Key2:
if t.Spawned { if t.Spawned {
break break
}
t.Triangles = append(t.Triangles, gg.Triangle{
gg.V(0, 10+gg.Float(counter)),
gg.V(100+gg.Float(counter), 0),
gg.V(0, -10-gg.Float(counter)),
})
case gg.Key3:
if t.Spawned {
break
}
tt := *t
tt.Spawned = true
tt.Disconnect()
if c.Spawn(&tt) == nil {
counter++
}
} }
t.Triangles = append(t.Triangles, gg.Triangle{ }
gg.V(0, 10 + gg.Float(counter)),
gg.V(100 + gg.Float(counter), 0),
gg.V(0, -10 - gg.Float(counter)),
})
case gg.Key3 :
if t.Spawned {
break
}
tt := *t
tt.Spawned = true
tt.Disconnect()
if c.Spawn(&tt) == nil {
counter++
}
}}
for _, event := range c.Events { for _, event := range c.Events {
switch e := event.(type) { case *gg.KeyDown: switch e := event.(type) {
switch e.Key { case *gg.KeyDown:
case gg.Key1 : switch e.Key {
if t.Connected() { case gg.Key1:
t.Disconnect() if t.Connected() {
} else { t.Disconnect()
t.Connect(player) } else {
t.Connect(player)
}
} }
}}} }
}
} }

2
go.mod
View file

@ -1,4 +1,4 @@
module vultras.su/core/gg module surdeus.su/core/gg
go 1.21 go 1.21

View file

@ -1,8 +0,0 @@
version: 3
tasks:
btest:
cmds:
- go build ./cmd/test/
bmath:
cmds:
- go build ./cmd/math/