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,20 +13,22 @@ type Debug struct {
}
func (d *Debug) Update(c *Context) {
for _, e := range c.Events { switch ec := e.(type) {
case *gg.KeyDown :
switch ec.Key {
case gg.KeyF11 :
d.Visible = !d.Visible
for _, e := range c.Events {
switch ec := e.(type) {
case *gg.KeyDown:
switch ec.Key {
case gg.KeyF11:
d.Visible = !d.Visible
}
}
}}
}
}
func (d *Debug) Draw(c *Context) []gg.EVertex {
e := c.Engine
relTri := tri.Rel()
relPlayer := player.Rel()
keyStrs := []string{}
keyStrs = append(keyStrs, fmt.Sprintf(
"counter: %d", counter,
@ -94,7 +96,6 @@ func (d *Debug) Draw(c *Context) []gg.EVertex {
e.DebugPrint(c.Image,
strings.Join(keyStrs, "\n"))
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 :
grid.Cage /= 10
grid.Width /= 5
case gg.Key0 :
grid.Cage *= 10
grid.Width *= 5
}}}
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:
grid.Cage *= 10
grid.Width *= 5
}
}
}
}
func (grid *Grid) Draw(c *Context) []gg.EVertex {
@ -58,19 +62,19 @@ const (
var (
playerAnimations gg.AnimationSet
playerImg *gg.Image
player *Player
rectMove gg.Rectangle
rect *Rect
tri *Tri
playerImg *gg.Image
player *Player
rectMove gg.Rectangle
rect *Rect
tri *Tri
)
func main() {
e := gg.NewEngine(&gg.WindowConfig{
Title: "Test title",
Width: 720,
Height: 480,
VSync: true,
Title: "Test title",
Width: 720,
Height: 480,
VSync: true,
Fullscreen: false,
})
@ -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
@ -160,8 +164,8 @@ func main() {
txt.Face, err = gg.MakeFaceFromTtf(
bytes.NewReader(fonts.MPlus1pRegular_ttf),
&gg.TtfFaceOptions{
Size: 32,
DPI: 72,
Size: 32,
DPI: 72,
Hinting: gg.FontHintingNone,
},
)

View file

@ -6,13 +6,13 @@ import (
"time"
)
import "vultras.su/core/gg"
import "surdeus.su/core/gg"
type Player struct {
gg.AnimatedSprite
MoveSpeed gg.Float
ScaleSpeed gg.Float
Spawned bool
Spawned bool
}
func NewPlayer() *Player {
@ -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:
@ -136,26 +135,27 @@ func (p *Player) Update(c *Context) {
}
for _, event := range c.Events {
switch ec := event.(type) {
case *gg.KeyDown:
switch {
case ec.Key == gg.KeyB:
if p.Layer != PlayerL {
p.Layer = PlayerL
} else {
p.Layer = HighestL
switch ec := event.(type) {
case *gg.KeyDown:
switch {
case ec.Key == gg.KeyB:
if p.Layer != PlayerL {
p.Layer = PlayerL
} else {
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),
)
}
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))
_, collides := gg.Collide(p, col.With)
if !collides {
break LOOP
for {
p.Move(gg.Y(-1))
_, collides := gg.Collide(p, col.With)
if !collides {
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 {
case gg.KeyArrowUp:
r.Move(gg.Y(-10* dt))
case gg.KeyArrowDown:
r.Move(gg.Y(10 * dt))
case gg.KeyArrowLeft:
r.Move(gg.X(-10*dt))
case gg.KeyArrowRight:
r.Move(gg.X(10* dt))
}}
for _, v := range c.Keys() {
switch v {
case gg.KeyArrowUp:
r.Move(gg.Y(-10 * dt))
case gg.KeyArrowDown:
r.Move(gg.Y(10 * dt))
case gg.KeyArrowLeft:
r.Move(gg.X(-10 * dt))
case gg.KeyArrowRight:
r.Move(gg.X(10 * dt))
}
}
}
func (r *Rect) Event(c *Context) {

View file

@ -1,24 +1,24 @@
package main
import (
"vultras.su/core/gg"
"surdeus.su/core/gg"
//"fmt"
)
type Objecter interface{
type Objecter interface {
}
type Wrap[V Objecter] struct {
O V
}
//func (w *Wrap)
//func (w *Wrap)
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 (
@ -38,7 +38,7 @@ func (t *Tri) Update(c *Context) {
//tedges := t.Edges()
//crosses, ok := tedges.CrossWithEdges(redges)
//fmt.Println("shit:", crosses, ok)
if false {
//fmt.Println("edges:", tedges)
}
@ -63,45 +63,49 @@ 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))
case gg.KeyN:
t.Move(gg.X(100*dt*d))
case gg.KeyM:
t.Move(gg.Y(100 * dt * d))
case gg.KeyN:
t.Move(gg.X(100 * dt * d))
case gg.KeyV:
t.Rotate(d * gg.Pi * 0.3 * dt)
case gg.Key2 :
if t.Spawned {
break
case gg.KeyV:
t.Rotate(d * gg.Pi * 0.3 * dt)
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)),
})
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 {
switch e := event.(type) { case *gg.KeyDown:
switch e.Key {
case gg.Key1 :
if t.Connected() {
t.Disconnect()
} else {
t.Connect(player)
switch e := event.(type) {
case *gg.KeyDown:
switch e.Key {
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/