Пример #1
0
func HandlePacketCreateGame(c *Client, rawPacket Packet) { // c *Client,
	//var p PacketGameCreate = rawPacket.(PacketGameCreate)
	g, id := CreateGame(c)

	floor := NewGameObject("ground")
	floor.AddComponent(NewPhysicsShape(true, g.Space, chipmunk.NewBox(vect.Vector_Zero, 200, 0.3)))
	////floor.Physics.Body.SetMoment(Inf)
	//floor.Physics.Shape.SetFriction(0)
	//floor.Physics.Shape.SetElasticity(0)
	//floor.Transform().SetPositionf(0, -0.15)
	g.AddGameObject(floor)

	//wallLeft := NewGameObject("wall left")
	//wallLeft.AddComponent(NewPhysicsShape(true, g.Space, chipmunk.NewBox(vect.Vector_Zero, 1, 100)))
	////floor.Physics.Body.SetMoment(Inf)
	//wallLeft.Physics.Shape.SetFriction(0)
	//wallLeft.Physics.Shape.SetElasticity(0)
	//wallLeft.Transform().SetPositionf(-9.4, 0)
	//g.AddGameObject(wallLeft)

	//wallRight := NewGameObject("wall right")
	//wallRight.AddComponent(NewPhysicsShape(true, g.Space, chipmunk.NewBox(vect.Vector_Zero, 1, 100)))
	////floor.Physics.Body.SetMoment(Inf)
	//wallRight.Physics.Shape.SetFriction(0)
	//wallRight.Physics.Shape.SetElasticity(0)
	//wallRight.Transform().SetPositionf(9.4, 0)
	//g.AddGameObject(wallRight)

	//platform := NewGameObject("platform 1")
	//platform.AddComponent(NewPhysicsShape(true, g.Space, chipmunk.NewBox(vect.Vector_Zero, 2.7, 0.1)))
	////platform.Physics.Body.SetMoment(Inf)
	//platform.Physics.Shape.SetFriction(0)
	//platform.Physics.Shape.SetElasticity(0)
	//platform.Transform().SetPositionf(1.05, 0.95)
	////platform.Transform().SetScalef(1, 0.1)
	//g.AddGameObject(platform)

	//platform = NewGameObject("platform 2")
	//platform.AddComponent(NewPhysicsShape(true, g.Space, chipmunk.NewBox(vect.Vector_Zero, 2.7, 0.1)))
	////platform.Physics.Body.SetMoment(Inf)
	//platform.Physics.Shape.SetFriction(0)
	//platform.Physics.Shape.SetElasticity(0)
	//platform.Transform().SetPositionf(-1.75, 1.75)
	////platform.Transform().SetScalef(1, 0.1)
	//g.AddGameObject(platform)
	//platform = NewGameObject("platform 3")
	//platform.AddComponent(NewPhysicsShape(true, g.Space, chipmunk.NewBox(vect.Vector_Zero, 2.7, 0.1)))
	////platform.Physics.Body.SetMoment(Inf)
	//platform.Physics.Shape.SetFriction(0)
	//platform.Physics.Shape.SetElasticity(0)
	//platform.Transform().SetPositionf(1.75, 2.15)
	////platform.Transform().SetScalef(1, 0.1)
	//g.AddGameObject(platform)

	answer := PacketResultJoinGame{id, 0}
	answer.Write(c.TCPWriter)
}
Пример #2
0
func NewPhysics(static bool, space *chipmunk.Space) *Physics {
	var body *chipmunk.Body

	box := chipmunk.NewBox(vect.Vect{0, 0}, vect.Float(1), vect.Float(1))

	if static {
		body = chipmunk.NewBodyStatic()
	} else {
		body = chipmunk.NewBody(1, box.Moment(1))
	}

	p := &Physics{BaseComponent: NewComponent(), Space: space, Body: body, Box: box.GetAsBox(), Shape: box}
	body.AddShape(box)
	return p
}
Пример #3
0
func HandlePacketInstanceGO(c *Client, rawPacket Packet) {
	var (
		p      PacketInstanceGO = rawPacket.(PacketInstanceGO)
		id     uint32           = 0
		result byte             = 1
		x      float32          = 0
		y      float32          = 0
	)
	if p.GameObjectType == 0 && Games[c.GameID] != nil {
		pName := fmt.Sprintf("Player(%i)", c.ID)
		character := NewGameObject(pName)
		//physics := character.AddComponent( NewPhysicsShape(false, Games[c.GameID].Space, chipmunk.NewCircle(vect.Vector_Zero, float32(0.06)))).(* Physics) //chipmunk.NewBox(vect.Vector_Zero, 0.12, 0.12)))
		physics := character.AddComponent(NewPhysicsShape(false, Games[c.GameID].Space, chipmunk.NewBox(vect.Vector_Zero, 0.04, 0.12))).(*Physics) //
		cc := character.AddComponent(NewCharacterController(Games[c.GameID], c.ID)).(*CharacterController)
		c.Character = cc
		physics.Body.SetMoment(Inf)
		physics.Shape.SetFriction(1)
		physics.Shape.SetElasticity(0)
		character.Transform().SetPositionf(0, 1)
		x = character.Transform().Position().X
		y = character.Transform().Position().Y
		Games[c.GameID].AddGameObject(character)
		id = character.GOID
		result = 0
	}
	answer := PacketResultInstanceGO{id, uint32(c.ID), x, y, result}
	Games[c.GameID].Broadcast2AllPlayersTCP(answer)

	if result == 0 {
		Games[c.GameID].Packages.PushBack(answer)
		//var i int = 0
		//for e := Games[c.GameID].Packages.Front(); e != nil; e = e.Next() {
		//i++
		//}
		//log.Panicf("Count %d", i)
	}
}