Example #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)
	}
}
Example #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])
	}

}