Exemple #1
0
func TestEntityCreate(t *testing.T) {
	tick := message.Tick(42)
	entity := message.NewEntity()
	entity.Id = 69
	entity.Position.X = 22
	entity.Position.Y = 67
	entity.Speed.Angle = 67
	entity.Speed.Norm = 78
	entity.Sprite = 12
	// TODO: populate other attributes

	testMessage(t, message.Types["entity_create"], func(w io.Writer) error {
		return builder.SendEntityCreate(w, tick, entity)
	}, func(conn *message.Conn, t *testing.T) {
		rt, e := handler.ReadEntityCreate(conn)
		if rt != tick {
			t.Fatal("Sent tick", tick, "but received", rt)
		}
		if !entity.Equals(e) {
			t.Fatal("Sent entity", entity, "but received", e)
		}
	})
}
Exemple #2
0
		err = conn.Write(func(w io.Writer) error {
			return builder.SendChunksUpdate(w, ctx.Clock.GetRelativeTick(), blks)
		})
		if err != nil {
			return err
		}

		// Send initial entities
		log.Println("Sending initial entities")
		for _, e := range ctx.Entity.List() {
			if e.Id == session.Entity.Id {
				continue
			}

			err := conn.Write(func(w io.Writer) error {
				return builder.SendEntityCreate(w, ctx.Clock.GetRelativeTick(), e)
			})
			if err != nil {
				return err
			}
		}

		// Send current players
		for _, s := range ctx.Auth.List() {
			if s.Id == session.Id {
				continue
			}

			err := conn.Write(func(w io.Writer) error {
				return builder.SendPlayerJoined(w, ctx.Clock.GetRelativeTick(), s.Entity.Id, s.Username)
			})