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
import (
"vultras.su/core/gg"
"surdeus.su/core/gg"
"fmt"
"encoding/json"
)
type Float = gg.Float
func EdgesFromVals(vals ...Float) gg.Edges {
ret := gg.Edges{}
for i:=0 ; i<len(vals) ; i += 4 {
for i := 0; i < len(vals); i += 4 {
ret = append(
ret,
gg.Edge{

View file

@ -1,6 +1,6 @@
package main
import "vultras.su/core/gg"
import "surdeus.su/core/gg"
import (
"strings"
@ -13,13 +13,15 @@ type Debug struct {
}
func (d *Debug) Update(c *Context) {
for _, e := range c.Events { switch ec := e.(type) {
case *gg.KeyDown :
for _, e := range c.Events {
switch ec := e.(type) {
case *gg.KeyDown:
switch ec.Key {
case gg.KeyF11 :
case gg.KeyF11:
d.Visible = !d.Visible
}
}}
}
}
}
func (d *Debug) Draw(c *Context) []gg.EVertex {
@ -97,4 +99,3 @@ func (d *Debug) Draw(c *Context) []gg.EVertex {
return nil
}

View file

@ -1,7 +1,7 @@
package main
import (
"vultras.su/core/gg"
"surdeus.su/core/gg"
"github.com/hajimehoshi/ebiten/v2/examples/resources/images"
"github.com/hajimehoshi/ebiten/v2/examples/resources/fonts"
//_ "github.com/silbinarywolf/preferdiscretegpu"
@ -19,15 +19,19 @@ type Grid struct {
func (grid *Grid) Update(c *Context) {
//d := c.IsPressed(gg.KeyShift)
for _, ev := range c.Events { switch e := ev.(type){
case *gg.KeyDown : switch e.Key {
case gg.Key9 :
for _, ev := range c.Events {
switch e := ev.(type) {
case *gg.KeyDown:
switch e.Key {
case gg.Key9:
grid.Cage /= 10
grid.Width /= 5
case gg.Key0 :
case gg.Key0:
grid.Cage *= 10
grid.Width *= 5
}}}
}
}
}
}
func (grid *Grid) Draw(c *Context) []gg.EVertex {
@ -142,7 +146,7 @@ func main() {
grid.Images[0] = gg.NewImage(720, 480)
grid.Images[0].Fill(gg.Rgba(1, 1, 1, 1))
grid.Shader = bgShader
grid.Uniforms = map[string] any{}
grid.Uniforms = map[string]any{}
//bg.Floating = true
grid.Visible = true
grid.Floating = true

View file

@ -6,7 +6,7 @@ import (
"time"
)
import "vultras.su/core/gg"
import "surdeus.su/core/gg"
type Player struct {
gg.AnimatedSprite
@ -23,7 +23,7 @@ func NewPlayer() *Player {
ret.MoveSpeed = 40.
ret.ScaleSpeed = .2
ret.Animations = playerAnimations
ret.TimeBetweenFrames = time.Second/10
ret.TimeBetweenFrames = time.Second / 10
ret.Shader = gg.SolidWhiteColorShader
ret.Visible = true
@ -32,7 +32,6 @@ func NewPlayer() *Player {
//ret.Collidable = true
//ret.Resolvable = true
return ret
}
@ -74,11 +73,11 @@ func (p *Player) Update(c *Context) {
case gg.KeyQ:
p.SetScale(
p.Scale().Add(
gg.X(p.ScaleSpeed*dt),
gg.X(p.ScaleSpeed * dt),
),
)
case gg.KeyW:
p.Move(gg.Y(-p.MoveSpeed * dt ))
p.Move(gg.Y(-p.MoveSpeed * dt))
walking = true
p.Animate(Walk)
case gg.KeyA:
@ -155,7 +154,8 @@ func (p *Player) Update(c *Context) {
c.Camera.AddScale(gg.V2(
ec.Offset.Y * dt * p.ScaleSpeed * 40,
))
}}
}
}
}
@ -173,8 +173,9 @@ func (p *Player) Resolve(c *Context) {
c.Frame(), len(c.Collisions), col.What, col.With, len(col.Crosses), len(col.Points),
)
}
for _, col := range c.Collisions {switch col.Type{
case gg.CollisionStaticPhysics :
for _, col := range c.Collisions {
switch col.Type {
case gg.CollisionStaticPhysics:
LOOP:
for {
p.Move(gg.Y(-1))
@ -183,6 +184,6 @@ func (p *Player) Resolve(c *Context) {
break LOOP
}
}
}}
}
}
}

View file

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

View file

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

View file

@ -1,6 +1,6 @@
package main
import "vultras.su/core/gg"
import "surdeus.su/core/gg"
import "fmt"
var (
@ -63,25 +63,26 @@ func (t *Tri) Update(c *Context) {
d = -1
}
for _, key := range keys { switch key {
for _, key := range keys {
switch key {
case gg.KeyM:
t.Move(gg.Y(100*dt*d))
t.Move(gg.Y(100 * dt * d))
case gg.KeyN:
t.Move(gg.X(100*dt*d))
t.Move(gg.X(100 * dt * d))
case gg.KeyV:
t.Rotate(d * gg.Pi * 0.3 * dt)
case gg.Key2 :
case gg.Key2:
if t.Spawned {
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)),
gg.V(0, 10+gg.Float(counter)),
gg.V(100+gg.Float(counter), 0),
gg.V(0, -10-gg.Float(counter)),
})
case gg.Key3 :
case gg.Key3:
if t.Spawned {
break
}
@ -91,17 +92,20 @@ func (t *Tri) Update(c *Context) {
if c.Spawn(&tt) == nil {
counter++
}
}}
}
}
for _, event := range c.Events {
switch e := event.(type) { case *gg.KeyDown:
switch e := event.(type) {
case *gg.KeyDown:
switch e.Key {
case gg.Key1 :
case gg.Key1:
if t.Connected() {
t.Disconnect()
} 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

View file

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