func (this *PlayerController) FixedUpdate() {
	this.GameObject().Physics.Shape.Layer = chipmunk.Layer(this.Player.Map.Layer)
	t := this.JointGameObject.Transform()

	var move engine.Vector = this.Transform().WorldPosition()

	if input.KeyDown('W') {
		move.Y += 100
	}
	if input.KeyDown('S') {
		move.Y += -100
	}
	if input.KeyDown('A') {
		move.X += -100
	}
	if input.KeyDown('D') {
		move.X += 100
	}

	t.SetWorldPosition(move)
}
Example #2
0
func (m *Map) GenerateCollision() {

	var shapes []*chipmunk.Shape

	for x := 0; x < m.Width; x++ {
		for y := 0; y < m.Height; y++ {
			if t, e := m.GetTile(x, y); e {
				if t.Collision() != CollisionNone {
					p, _ := m.GetTilePos(x, y)
					shape := chipmunk.NewBox(vect.Vect{vect.Float(p.X), vect.Float(p.Y)},
						vect.Float(m.TileSize), vect.Float(m.TileSize))

					shape.Layer = chipmunk.Layer(m.Layer)
					shape.SetFriction(0)
					shapes = append(shapes, shape)
				}
			}
		}
	}

	m.GameObject().AddComponent(engine.NewPhysicsShapes(true, shapes))

}