Exemple #1
0
func SyncSpec(c gospec.Context) {
	c.Specify("Sample sprite loads correctly", func() {
		s1, err := sprite.LoadSprite("test_sprite")
		c.Expect(err, Equals, nil)
		s2, err := sprite.LoadSprite("test_sprite")
		c.Expect(err, Equals, nil)
		sprite.CommandSync([]*sprite.Sprite{s1, s2}, [][]string{[]string{"melee"}, []string{"defend", "damaged"}}, "hit")
		hit := false
		for i := 0; i < 20; i++ {
			s1.Think(50)
			s2.Think(50)
			if s1.Anim() == "melee_01" && s2.Anim() == "damaged_01" {
				hit = true
			}
		}
		c.Expect(hit, Equals, true)
	})
}
Exemple #2
0
func (h *handler) HandleEventGroup(group gin.EventGroup) {
	if group.Events[0].Type != gin.Press {
		return
	}
	if h.box1 == nil || h.box1.sb == nil || h.box1.sb.s == nil {
		return
	}
	for name, key := range action_map {
		if group.Events[0].Key.Id() == key.Id() {
			cmd := commands[name]
			if len(cmd.You) > 0 {
				if h.box2 == nil || h.box2.sb == nil || h.box2.sb.s == nil {
					return
				}
				sprite.CommandSync(
					[]*sprite.Sprite{h.box1.sb.s, h.box2.sb.s},
					[][]string{cmd.Me, cmd.You},
					cmd.Sync)
			} else {
				h.box1.sb.s.CommandN(cmd.Me)
			}
		}
	}
}