Files
Prism/ExampleApp/Src/PlayerCube.cs

55 lines
1.6 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Prism;
namespace Example
{
class PlayerCube : Entity
{
public float HorizontalForce = 10.0f;
public float VerticalForce = 10.0f;
private RigidBody2DComponent m_PhysicsBody;
private MaterialInstance m_MeshMaterial;
void OnCreate()
{
m_PhysicsBody = GetComponent<RigidBody2DComponent>();
MeshComponent meshComponent = GetComponent<MeshComponent>();
m_MeshMaterial = meshComponent.Mesh.GetMaterial(0);
m_MeshMaterial.Set("u_Metalness", 0.0f);
}
void OnUpdate(float ts)
{
if (Input.IsKeyPressed(KeyCode.D))
m_PhysicsBody.ApplyLinearImpulse(new Vec2(HorizontalForce, 0), new Vec2(), true);
else if (Input.IsKeyPressed(KeyCode.A))
m_PhysicsBody.ApplyLinearImpulse(new Vec2(-HorizontalForce, 0), new Vec2(), true);
if (Input.IsKeyPressed(KeyCode.Space))
m_PhysicsBody.ApplyLinearImpulse(new Vec2(0, VerticalForce), new Vec2(0, -10), true);
Vec3 color = new Vec3(0.8f, 0.8f, 0.8f);
if (Input.IsKeyPressed(KeyCode.Q))
color = new Vec3(0.0f, 1.0f, 0.0f);
m_MeshMaterial.Set("u_AlbedoColor", color);
if (Input.IsKeyPressed(KeyCode.R))
{
Mat4 transform = GetTransform();
transform.Translation = new Vec3(0.0f);
SetTransform(transform);
}
}
}
}