-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
CollisionArea agregado para facilitar la deteccion de colisiones en u…
…na area especifica sin cambiar la posicion de el mismo 🤦♀️
- Loading branch information
Showing
3 changed files
with
117 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package engine | ||
|
||
type CollisionArea struct { | ||
position Position | ||
size Size | ||
gob *GameObject | ||
sc *Scene | ||
onCollision func(*CollisionArea, *GameObject, *GameObjectEvent) | ||
debugColor *Color | ||
} | ||
|
||
func (p *CollisionArea) Scene() *Scene { | ||
return p.sc | ||
} | ||
func (p *CollisionArea) Size() Size { | ||
return p.size | ||
} | ||
func (p *CollisionArea) Position() Position { | ||
return p.position | ||
} | ||
func NewCollisionArea(scene *Scene, pos Position, siz Size) *CollisionArea { | ||
p := &CollisionArea{ | ||
position: pos, | ||
size: siz, | ||
gob: _newGameObjectUnregister(pos, siz, SHAPE_RECTANGLE, len(scene.GameObjectsObjects())+1), | ||
sc: scene, | ||
onCollision: func(coll *CollisionArea, g *GameObject, goe *GameObjectEvent) { | ||
|
||
}, | ||
debugColor: nil, | ||
} | ||
scene.areas = append(scene.areas, p) | ||
return p | ||
} | ||
func (p *CollisionArea) SetDebugColor(color Color) { | ||
p.debugColor = &color | ||
} | ||
func (p *CollisionArea) QuitDebugColor() { | ||
p.debugColor = nil | ||
} | ||
func (p *CollisionArea) SetOnCollision(c func(*CollisionArea, *GameObject, *GameObjectEvent)) { | ||
p.onCollision = c | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
|
||
e "github.com/Troxsoft/Furia2D-Engine/engine" | ||
) | ||
|
||
var obj *e.GameObject | ||
var area *e.CollisionArea | ||
|
||
func main() { | ||
e.InitGame("welcome to Furia2D-Engine :)", e.NewSize(500, 400), func(ge *e.GameEvent) { | ||
area = e.NewCollisionArea(e.GetCurrentScene(), e.NewPos(100, 100), e.NewSize(200, 200)) | ||
area.SetDebugColor(e.BROWN) | ||
area.SetOnCollision(func(a *e.CollisionArea, g *e.GameObject, goe *e.GameObjectEvent) { | ||
if g != nil { | ||
fmt.Println("aña") | ||
} | ||
}) | ||
obj, _ = e.CreateGameObject("you", e.SHAPE_RECTANGLE, e.NewSize(100, 100), e.NewPosition(0, 0)) | ||
e.NewCamera(e.NewPosition(0, 0), e.NewPosition(0, 0)) | ||
h, _ := e.CreateGameObject("j", e.SHAPE_RECTANGLE, e.NewSize(20, 20), e.NewPosition(240, 100)) | ||
h.Instance(e.GetCurrentScene(), nil) | ||
obj = obj.Instance(e.GetCurrentScene(), nil) | ||
e.GetCurrentScene().SetCamera(e.NewCamera(e.NewPosition(0, 0), e.NewPosition(0, 0))) | ||
|
||
}, | ||
func(ge *e.GameEvent) { | ||
e.GetCurrentScene().Camera().SetTarget(e.NewPosition(obj.Position().X-250, obj.Position().Y-200)) | ||
if ge.IsKeyDown(ge.KeyRight) { | ||
obj.MoveTo(e.NewPosition(obj.Position().X+5, obj.Position().Y)) | ||
} | ||
if ge.IsKeyDown(ge.KeyDown) { | ||
obj.MoveTo(e.NewPosition(obj.Position().X, obj.Position().Y+5)) | ||
} | ||
if ge.IsKeyDown(ge.KeyUp) { | ||
obj.MoveTo(e.NewPosition(obj.Position().X, obj.Position().Y-5)) | ||
} | ||
if ge.IsKeyDown(ge.KeyLeft) { | ||
obj.MoveTo(e.NewPosition(obj.Position().X-5, obj.Position().Y)) | ||
} | ||
}) | ||
} |