You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

82 lines
2.5 KiB
C#

using Duality;
using Duality.Components;
using Duality.Components.Renderers;
using Duality.Resources;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace BackGroundScroller_Example
{
[RequiredComponent(typeof(Camera))]
//LevelHandler is used for maintaining anything level related like backgrounds (tileMaps, character- and objectspawner in future)
public class LevelHandler : Component, ICmpUpdatable
{
// Basicspeed-Multiplikator of the current ground (speed the ground should be multiplied with)
// [1 = basic, in the scroller defined speed]
private float horSpeedMultiplicator;
private float horSpeed;
private Camera mainCamera;
public Camera MainCamera
{
get { return this.mainCamera; }
set { this.mainCamera = value; }
}
public float CamSpeedMultiplier
{
get { return this.horSpeedMultiplicator; }
set { this.horSpeedMultiplicator = value; }
}
public float CamSpeed
{
get { return this.horSpeed; }
set { this.horSpeed = value; }
}
private BackgroundScroller bgScroller;
public BackgroundScroller BackgroundScroller
{
get { return this.bgScroller; }
set { this.bgScroller = value; }
}
public void OnUpdate()
{
if(DualityApp.Keyboard.KeyPressed(Duality.Input.Key.D))
{
Vector3 deltaPos = new Vector3();
deltaPos.X = CamSpeed * horSpeedMultiplicator;
deltaPos.X *= Time.MsPFMult * Time.TimeMult / 1000;
MainCamera.GameObj.Transform.MoveBy(deltaPos);
}
if (DualityApp.Keyboard.KeyPressed(Duality.Input.Key.A))
{
Vector3 deltaPos = new Vector3();
deltaPos.X = -CamSpeed;
deltaPos.X *= Time.MsPFMult * Time.TimeMult / 1000;
MainCamera.GameObj.Transform.MoveBy(deltaPos);
}
//Calls update-logic of the scroller to generate and move the different layers
//At this point a logic to change the defined prefabs can be introduced to enable a dynamic layer change
this.bgScroller.Update(horSpeed, mainCamera);
}
}
}