Skip to content

Commit

Permalink
getters agregados a los gameObjects
Browse files Browse the repository at this point in the history
bastantes cosas para escribirlas.
  • Loading branch information
Troxsoft committed Nov 29, 2023
1 parent 7cd150a commit 9086f79
Show file tree
Hide file tree
Showing 7 changed files with 120 additions and 56 deletions.
1 change: 0 additions & 1 deletion LICENCE
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

Copyright (c) 2023 troxsoft.

Copyright (c) 2023 troxsoft.
Expand Down
63 changes: 10 additions & 53 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,63 +9,20 @@ Un motor de videojuego escrito usando Golang 100% usando la poderosa libreria Ra
```go
package main

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

var (
playerG *e.GameObject
enemigoG *e.GameObject
aliadoG *e.GameObject
)
var obj *e.GameObject

func main() {
e.InitGame("controlador basico :)", e.NewSize(600, 400), func(eg *e.GameEvent) {
//init
playerG, _ = e.CreateGameObject("player", e.SHAPE_IMAGE, e.NewSize(200, 200), e.NewPosition(30, 30))
enemigoG, _ = e.CreateGameObject("enemigo", e.SHAPE_RECTANGLE, e.NewSize(30, 30), e.NewPosition(100, 100))
aliadoG, _ = e.CreateGameObject("aliado", e.SHAPE_RECTANGLE, e.NewSize(50, 50), e.NewPosition(40, 80))
//playerG.Hide()
aliadoG.SetColor(e.NewColor2(0, 0, 255))
enemigoG.SetColor(e.NewColor2(255, 0, 0))
playerG.SetImage(e.NewImage("sapo.jpg"))
enemigoG.AddToGroup("ene")
playerG.SetStart(func(g *e.GameObject, a any) {
g.SetPosition(e.NewPosition(0, a.(int32)))
})
playerG.SetUpdate(func(g *e.GameObject, a *e.GameObjectEvent) {
if collisi, _ := a.OnCollisionInTheGroup("ene"); collisi != nil {
g.SetColor3(255, 0, 0)
} else {
g.SetColor3(255, 255, 255)
if a.IsMouseDown(a.MouseButtonRight) {
g.SetColor3(255, 0, 0)
} else {
g.SetColor3(255, 255, 255)
}
}
if eg.IsKeyDown(eg.KeyLeft) {
g.SetPosition2(g.Position().X-2, g.Position().Y)
}
if eg.IsKeyDown(eg.KeyRight) {
g.SetPosition2(g.Position().X+2, g.Position().Y)
}
if eg.IsKeyDown(eg.KeyUp) {
g.SetPosition2(g.Position().X, g.Position().Y-2)
}
if eg.IsKeyDown(eg.KeyDown) {
g.SetPosition2(g.Position().X, g.Position().Y+2)
}
})
e.InstanceGameObject("enemigo", nil)
e.InstanceGameObject("player", int32(30))
e.InstanceGameObject("player", int32(300))
e.InstanceGameObject("aliado", nil)
}, func(eg *e.GameEvent) {
//update
e.InitGame("welcome to Furia2D-Engine :)", e.NewSize(500, 400), func(ge *e.GameEvent) {
obj, _ = e.CreateGameObject("you", e.SHAPE_RECTANGLE, e.NewSize(30, 30), e.NewPosition(30, 30))
e.InstanceGameObject("you", nil)
},
func(ge *e.GameEvent) {

})
})
}

```

- mas ejemplos en 'examples'
## Furia2D esta escrito en ingles ,pero el github,documentacion NO. ªjolote
89 changes: 89 additions & 0 deletions engine/gameObject.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,18 @@ var (
ErrShapeInvalid = errors.New("the shape is invalid")
)

func (g *GameObject) Vars() map[string]any {
//hhhhhhhhhhhhhhhhhhhhhhhhhhhh
newV := make(map[string]any)
for k, v := range g.vars {
newV[k] = v
}
return newV

}
func (g *GameObject) Id() int {
return g.id
}
func (g *GameObject) CollisionRect() CollisionRectangle {
return g.collision
}
Expand Down Expand Up @@ -130,9 +142,65 @@ func (g *GameObject) SetImage(img *FuriaImage) {
panic("the image not is valid")
}
}
func (g *GameObject) Image() *FuriaImage {
if g.shape == SHAPE_IMAGE {
switch any(g.GetVar("image")).(type) {
case *FuriaImage:
return g.GetVar("image").(*FuriaImage)
break
}

} else {
panic("the image not is valid")
}
return nil
}

func (g *GameObject) AddToGroup(groupName string) {
g.groups[groupName] = true
}
func (g *GameObject) Groups() []string {
keys := []string{}
values := []bool{}
arr := []string{}
for k, v := range g.groups {
keys = append(keys, k)
values = append(values, v)
}
for i, v := range values {
if v == true {
arr = append(arr, keys[i])
}
}
return arr

}
func (g *GameObject) Instance(params any) *GameObject {
i := g
vars__ := make(map[string]any)
for k, v := range i.vars {
vars__[k] = v
}
funcs__ := make(map[string]func(*GameObject, any))
for k, v := range i.funcs {
funcs__[k] = v
}
k := &GameObject{
name: i.name,
size: i.size,
position: i.position,
shape: i.shape,
funcs: funcs__,
hide: i.hide,
vars: vars__,
id: len(instancesGameObjects) + 1,
groups: i.groups,
}
k.collision = NewCollisionRectagle(k)
k.Execute("start", params)
instancesGameObjects = append(instancesGameObjects, k)
return k
}
func InstanceGameObject(name string, params any) *GameObject {
i := gameObjects[name]
vars__ := make(map[string]any)
Expand Down Expand Up @@ -163,6 +231,13 @@ func InstanceGameObject(name string, params any) *GameObject {
func (g *GameObject) SetFunction(nameFunction string, function func(*GameObject, any)) {
g.funcs[nameFunction] = function
}
func (g *GameObject) Functions() map[string]func(*GameObject, any) {
newV := make(map[string]func(*GameObject, any))
for k, v := range g.funcs {
newV[k] = v
}
return newV
}
func (g *GameObject) Execute(nameFunction string, params any) {
g.funcs[nameFunction](g, params)
}
Expand All @@ -176,6 +251,9 @@ func (g3 *GameObject) SetColor3(r, g, b uint8) {
func (g3 *GameObject) SetColor2(r, g, b, a uint8) {
g3.SetVar("color", NewColor(r, g, b, a))
}
func (g *GameObject) Color() Color {
return g.GetVar("color").(Color)
}
func (g *GameObject) Draw() {
if IsRunning() == false {
panic("the rufi and raylib not working")
Expand Down Expand Up @@ -210,6 +288,17 @@ func (g *GameObject) SetAnimationImage(ani *AnimationImage) {
g.SetVar("animationImage", ani)
}
}
func (g *GameObject) AnimationImage() *AnimationImage {
if g.shape != SHAPE_ANIMATION_IMAGE {
panic("the shape not is 'animationImage' :(")
}
switch any(g.GetVar("animationImage")).(type) {
case *AnimationImage:
return g.GetVar("animationImage").(*AnimationImage)
break
}
return nil
}
func CreateGameObject(name string, shape Shape, size Size, position Position) (*GameObject, error) {
if IsRunning() == false {
return nil, ErrGameNotRunning
Expand Down
Binary file modified example_animations.exe
Binary file not shown.
Binary file added example_hello_object.exe
Binary file not shown.
4 changes: 2 additions & 2 deletions examples/example_animations.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ var animacion *e.GameObject

func main() {
e.InitGame("animaciones", e.NewSize(500, 500), func(ge *e.GameEvent) {
animacion, _ = e.CreateGameObject("ani", e.SHAPE_ANIMATION_IMAGE, e.NewSize(100, 100), e.NewPosition(50, 50))
animacion, _ = e.CreateGameObject("ani", e.SHAPE_ANIMATION_IMAGE, e.NewSize(500, 500), e.NewPosition(0, 0))
animacion.SetAnimationImage(e.NewAnimationImage([]*e.FuriaImage{
e.NewImage("sapo.jpg"),
e.NewImage("sapo.jpg"),
Expand All @@ -17,7 +17,7 @@ func main() {
e.NewImage("petro.jpg"),
e.NewImage("petro.jpg"),
e.NewImage("petro.jpg"),
}, 100))
}, 200))
e.InstanceGameObject("ani", nil)
}, func(ge *e.GameEvent) {

Expand Down
19 changes: 19 additions & 0 deletions examples/example_hello_object.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package main

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

var obj *e.GameObject

func main() {
e.InitGame("welcome to Furia2D-Engine :)", e.NewSize(500, 400), func(ge *e.GameEvent) {
obj, _ = e.CreateGameObject("you", e.SHAPE_RECTANGLE, e.NewSize(30, 30), e.NewPosition(30, 30))
obj.Instance(nil)

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

})
}

0 comments on commit 9086f79

Please sign in to comment.