-
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.
1 parent
0834605
commit 7e08f53
Showing
5 changed files
with
53 additions
and
3 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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,16 @@ | ||
package components | ||
|
||
import ( | ||
"github.com/co0p/tankism/lib/ecs" | ||
) | ||
|
||
const CollisionType = "Collision" | ||
|
||
// Collision, omponent for filtering collision | ||
type Collision struct { | ||
Target *ecs.Entity | ||
} | ||
|
||
func (t Collision) Type() ecs.ComponentType { | ||
return CollisionType | ||
} |
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,31 @@ | ||
package systems | ||
|
||
import ( | ||
"github.com/co0p/tankism/game/ecs/components" | ||
"github.com/co0p/tankism/lib/ecs" | ||
"github.com/hajimehoshi/ebiten/v2" | ||
) | ||
|
||
type CollisionResolution struct { | ||
EntityManager *ecs.EntityManager | ||
} | ||
|
||
func (s *CollisionResolution) Draw(screen *ebiten.Image) {} | ||
|
||
func (s *CollisionResolution) Update() error { | ||
|
||
entities := s.EntityManager.FindByComponents(components.CollisionType) | ||
|
||
for _, e := range entities { | ||
collision := e.GetComponent(components.CollisionType).(*components.Collision) | ||
// bounce back -- basic resolution for all | ||
// TODO resolve based on other types e.g. Health | ||
if collision.Target.HasComponent(components.VelocityType) { | ||
v := collision.Target.GetComponent(components.VelocityType).(*components.Velocity) | ||
v.Intertia = -1 | ||
} | ||
e.RemoveComponent(components.CollisionType) | ||
} | ||
|
||
return nil | ||
} |