Exemplo n.º 1
0
func (s *Item) Start() {
	engine.StartCoroutine(func() {
		engine.CoSleep(2)
		s.takeable = true
		engine.CoSleep(10)
		s.GameObject().Destroy()
	})

}
Exemplo n.º 2
0
func (pl *Player) Hit() {
	if pl.Hitted.State == engine.Ended {
		pl.Hitted = engine.StartCoroutine(func() {
			pl.hit = true
			pl.LastFloor = nil
			pl.Hitable = false
			pl.Attack = false
			pl.able = false
			pl.GameObject().Physics.Body.AddForce(0, pl.jumpPower)
			pl.SubLife(5)
			engine.CoSleep(3)
			pl.hit = false
			pl.able = true
			pl.GameObject().Sprite.SetAnimation("player_stand")
			engine.CoSleep(2)
			pl.Hitable = true
		})
	}
}
Exemplo n.º 3
0
func (pl *Player) OnCollisionEnter(arbiter engine.Arbiter) bool {

	if arbiter.GameObjectB().Tag == "lader" {
		pl.pLader = arbiter.GameObjectB()
		if pl.GameObject().Sprite.CurrentAnimation() != "player_climb" {
			pl.GameObject().Sprite.SetAnimation("player_climb")
		}
		pl.GameObject().Physics.Body.IgnoreGravity = true
		pl.OnGround = false
	}
	if pl.Hitable && arbiter.GameObjectB().Tag == "splinter" {
		pl.pSplint = arbiter.GameObjectB()
		engine.StartCoroutine(func() {
			for pl.pSplint != nil {
				pl.Hit()
				engine.CoYieldCoroutine(pl.Hitted)
			}
		})
	}
	return true
}
Exemplo n.º 4
0
func (s *Enemy) Hit() {
	if s.Hitted.State == engine.Ended {
		s.Hitted = engine.StartCoroutine(func() {
			s.hit = true
			s.Attack = false
			s.LastFloor = nil
			s.hitable = false
			s.able = false
			if s.GameObject() != nil {
				s.GameObject().Physics.Body.AddForce(0, s.jumppower)
			}
			s.SubLife(50)
			engine.CoSleep(3)
			s.hit = false
			s.able = true
			s.hitable = true
			if s.GameObject() != nil {
				s.GameObject().Sprite.SetAnimation("enemy_stand")
			}
		})

	}
}
Exemplo n.º 5
0
func (s *Enemy) Update() {
	plpc := Player.Pl.Transform().WorldPosition()
	if plpc.Distance(s.Transform().WorldPosition()) < 200 {
		s.target = plpc
		s.speed = 60
		s.isClose = false
	} else {
		if !s.isClose && s.speed != 0 {
			s.target = s.Transform().WorldPosition()
			r := float32(rand.Int()%200) - 100
			if r > 0 {
				r += 20
			} else {
				r -= 20
			}
			s.target = s.target.Add(engine.NewVector2(r, 0))

			s.isClose = true
		}
		if s.isClose {
			if s.target.Distance(s.Transform().WorldPosition()) < 60 {

				s.isClose = false

				engine.StartCoroutine(func() {
					s.speed = 0
					engine.CoSleep(float32(rand.Int()%2) + 3)
					if plpc.Distance(s.Transform().WorldPosition()) >= 200 {
						s.speed = 60
						s.isClose = true
						r := float32(rand.Int()%200) - 100
						if r > 0 {
							r += 60
						} else {
							r -= 60
						}
						s.target = s.Transform().WorldPosition()
						s.target = s.target.Add(engine.NewVector2(r, 0))
					}
				})

				return
			}
		}
	}
	ph := s.GameObject().Physics.Body
	s.GameObject().Sprite.SetAlign(engine.AlignTopCenter)
	if float32(math.Abs(float64(ph.Velocity().X))) > 3 {
		if s.GameObject().Sprite.CurrentAnimation() == "enemy_stand" {
			s.GameObject().Sprite.SetAnimation("enemy_walk")
		}
	} else if !s.Attack {
		s.GameObject().Sprite.SetAnimation("enemy_stand")
	}
	if s.OnGround == false {
		s.frames++
	} else {
		s.frames = 0
	}
	d := s.Transform().WorldPosition()
	s.HpB.Transform().SetWorldPosition(d.Add(engine.NewVector2(0, -10)))
	if s.able {
		if s.target.X > s.Transform().WorldPosition().X {
			ph.AddForce(s.speed, 0)
			s.GameObject().Transform().SetScalef(s.width, s.height)

		} else {
			ph.AddForce(-s.speed, 0)
			s.GameObject().Transform().SetScalef(-s.width, s.height)
		}
		d = Player.PlComp.Transform().WorldPosition()
		if d.Distance(s.Transform().WorldPosition()) < 50 {
			s.Attack = true

			s.GameObject().Sprite.SetAnimation("enemy_attack")
			s.GameObject().Sprite.AnimationEndCallback = func(sprite *engine.Sprite) {
				s.Attack = false
				s.GameObject().Sprite.SetAnimation("enemy_stand")
			}

		}
		if s.jump && s.OnGround {
			s.GameObject().Physics.Body.AddForce(0, s.jumppower)
		}
	}
	if s.hit {
		s.GameObject().Sprite.SetAnimation("enemy_hit")
	}
	if (s.GameObject().Sprite.CurrentAnimation() == "enemy_stand" || s.GameObject().Sprite.CurrentAnimation() == "enemy_walk") && !s.OnGround && s.frames > 15 {
		s.GameObject().Sprite.SetAnimation("enemy_jump")
	}

}
Exemplo n.º 6
0
func NewEnemy(Hp *GUI.Bar) *Enemy {
	return &Enemy{engine.NewComponent(), 0, 100, 100, Hp, false, false, true, false, false, true, false, 60, 0, 0, 3000, nil, engine.Vector{0, 0, 0}, engine.StartCoroutine(func() {})}

}
Exemplo n.º 7
0
func NewPlayer() *Player {
	return &Player{engine.NewComponent(), 0, 0, 1, 0, 100, 100, 100, 100, 100, 50, stand_height, 60, 7000, false, false, false, 1, true, false, true, nil, nil, nil, engine.StartCoroutine(func() {}), nil}
}