Skip to content

Commit

Permalink
bugs arreglados + ejemplo + ejemplo compilado
Browse files Browse the repository at this point in the history
  • Loading branch information
Troxsoft committed Nov 29, 2023
1 parent 574d609 commit 274c2f9
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 7 deletions.
20 changes: 13 additions & 7 deletions engine/physics.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,30 @@ package engine

import "fmt"

func _newGameObjectUnregister(pos Position, siz Size) *GameObject {
return &GameObject{
name: fmt.Sprintf("%s_'un_register_______________________________'", len(gameObjects)),
func _newGameObjectUnregister(pos Position, siz Size, shape Shape, id int) *GameObject {
j := &GameObject{
name: fmt.Sprintf("%s_'un_register_______________________________'", len(gameObjects)),
size: siz,
position: pos,
shape: shape,
id: id,
}
j.collision = NewCollisionRectagle(j)
return j
}

/*
physics type: Colliders and collisions[ON]
*/
func (g *GameObject) MoveTo(npos Position) bool {
func (g *GameObject) MoveTo(npos Position) (*GameObject, bool) {

coll2 := _newGameObjectUnregister(npos, NewSize(g.size.W, g.size.H))
coll2 := _newGameObjectUnregister(npos, NewSize(g.size.W, g.size.H), g.shape, g.id)
if h, _ := coll2.collision.OnCollision(); h != nil {

return false
return h, false
} else {
g.SetPosition(npos)
return true
return nil, true
}

}
Binary file added example_physics_simply.exe
Binary file not shown.
36 changes: 36 additions & 0 deletions examples/example_physics_simply.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package main

import (
e "github.com/Troxsoft/Furia2D-Engine/engine"
)

var obj *e.GameObject
var obj2 *e.GameObject

func main() {
e.InitGame("welcome to Furia2D-Engine :)", e.NewSize(600, 600), func(ge *e.GameEvent) {
obj, _ = e.CreateGameObject("you", e.SHAPE_RECTANGLE, e.NewSize(30, 30), e.NewPosition(200, 30))
obj2, _ = e.CreateGameObject("you not is enemy", e.SHAPE_RECTANGLE, e.NewSize(50, 50), e.NewPosition(300, 30))
obj.SetUpdate(func(g *e.GameObject, goe *e.GameObjectEvent) {
g.SetPosition(e.ClampPos(g.Position(), e.NewPosition(600, 600), e.NewPosition(0, 0)))
if ge.IsKeyDown(ge.KeyRight) {
objetoColision, _ := g.MoveTo(e.NewPosition(g.Position().X+10, g.Position().Y))
if objetoColision != nil {
g.SetColor3(255, 0, 0)
} else {
g.SetColor3(0, 0, 0)
}
}
if ge.IsKeyDown(ge.KeyLeft) {
g.MoveTo(e.NewPosition(g.Position().X-10, g.Position().Y))
}

})
obj.Instance(nil)
obj2.Instance(nil)
//fmt.Println(obj.F)
},
func(ge *e.GameEvent) {

})
}

0 comments on commit 274c2f9

Please sign in to comment.