Esempio n. 1
0
func (m *MouseDebugger) Update() {
	if input.MouseDown(glfw.MouseLeft) {

		mousePosition := m.Transform().WorldPosition()

		sprite3 := engine.NewGameObject("Sprite")
		sprite3.AddComponent(engine.NewSprite(cir))
		sprite3.Transform().SetParent2(GameSceneGeneral.Layer2)
		sprite3.Transform().SetWorldPosition(mousePosition)

		sprite3.Transform().SetScale(engine.NewVector2(30, 30))

		phx := sprite3.AddComponent(engine.NewPhysicsShape(false, chipmunk.NewCircle(vect.Vect{0, 0}, 15))).(*engine.Physics)
		phx.Shape.SetFriction(0.5)
		//phx.Shape.Group = 1
		phx.Shape.SetElasticity(0.5)
	}
	if input.MouseDown(glfw.MouseRight) {

		mousePosition := m.Transform().WorldPosition()

		sprite3 := engine.NewGameObject("Sprite")
		sprite3.AddComponent(engine.NewSprite(box))
		sprite3.Transform().SetParent2(GameSceneGeneral.Layer2)
		sprite3.Transform().SetWorldPosition(mousePosition)

		sprite3.Transform().SetScale(engine.NewVector2(30, 30))
		phx := sprite3.AddComponent(engine.NewPhysics(false)).(*engine.Physics)
		phx.Shape.SetFriction(0.5)
		//phx.Shape.Group = 2
		phx.Shape.SetElasticity(0.5)
	}
}
Esempio n. 2
0
func (m *Map) Draw() {
	if m.Layer < MainPlayer.Map.Layer {
		return
	}
	camera := engine.GetScene().SceneBase().Camera
	cameraPos := camera.Transform().WorldPosition()
	w, h := camera.ScreenSize()
	cameraPos.X -= w / 2
	cameraPos.Y -= h / 2

	//calculate max tiles on screen
	width := int(float32(engine.Width)/(m.TileSize-1)) + 2
	height := int(float32(engine.Height)/(m.TileSize-1)) + 2

	index := 0
	for x := -1; x < width; x++ {
		for y := -1; y < height; y++ {
			var tilePos engine.Vector

			//Try to find tiles on screen
			tilePos.X = cameraPos.X + float32((x * int(m.TileSize-1)))
			tilePos.Y = cameraPos.Y + float32((y * int(m.TileSize-1)))

			//Get tile
			tileType, tx, ty := m.PositionToTile(tilePos)

			//Check if visible/exists
			if tileType.Type() != 0 {
				//Add to draw list
				m.uvs[index] = m.Sprite.UVs[tileType.Type()-1]
				pos, e := m.GetTilePos(tx, ty)
				if !e {
					panic("Does not exists")
				}
				m.positions[index] = pos
				m.rotations[index] = tileType.Angle() + m.Disco
				m.scales[index] = engine.NewVector2(m.TileSize+float32(int(m.Disco)%52), m.TileSize+float32(int(m.Disco)%52))
				index++
				//engine.DrawSprite(m.Sprite.Texture, m.Sprite.UVs[int(m.Tiles[tileIndex])], tilePos, engine.NewVector2(m.TileSize, m.TileSize), 0, engine.AlignCenter, engine.One)
			}
			if tileType.Type2() != 0 {
				//Add to draw list
				m.uvs[index] = m.Sprite.UVs[tileType.Type2()-1]
				pos, e := m.GetTilePos(tx, ty)
				if !e {
					panic("Does not exists")
				}
				m.positions[index] = pos
				m.rotations[index] = tileType.Angle2() + m.Disco
				m.scales[index] = engine.NewVector2(m.TileSize+float32(int(m.Disco)%52), m.TileSize+float32(int(m.Disco)%52))
				index++
				//engine.DrawSprite(m.Sprite.Texture, m.Sprite.UVs[int(m.Tiles[tileIndex])], tilePos, engine.NewVector2(m.TileSize, m.TileSize), 0, engine.AlignCenter, engine.One)
			}
		}
	}

	if m.EnableDisco {
		if m.DiscoStyle == 1 {
			m.Disco++
		} else {
			m.Disco--
		}
		if m.Disco > 50 {
			m.DiscoStyle = 0
		}
		if m.Disco < 0 {
			m.DiscoStyle = 1
		}
	}

	if index > 0 {
		engine.DrawSprites(m.Sprite.Texture, m.uvs[:index], m.positions[:index], m.scales[:index], m.rotations[:index], m.alings[:index], m.colors[:index])
	}

}
Esempio n. 3
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")
	}

}