mirror of
https://github.com/celisej567/gm_construct_port.git
synced 2026-09-13 20:12:39 +03:00
44 lines
970 B
C#
44 lines
970 B
C#
using Sandbox;
|
|
using System;
|
|
|
|
[Library( "ent_bouncyball", Title = "Bouncy Ball", Spawnable = true )]
|
|
public partial class BouncyBallEntity : Prop, IUse
|
|
{
|
|
public float MaxSpeed { get; set; } = 1000.0f;
|
|
public float SpeedMul { get; set; } = 1.2f;
|
|
|
|
public override void Spawn()
|
|
{
|
|
base.Spawn();
|
|
|
|
SetModel( "models/ball/ball.vmdl" );
|
|
SetupPhysicsFromModel( PhysicsMotionType.Dynamic, false );
|
|
Scale = Rand.Float( 0.5f, 2.0f );
|
|
RenderColor = Color.Random.ToColor32();
|
|
}
|
|
|
|
protected override void OnPhysicsCollision( CollisionEventData eventData )
|
|
{
|
|
var speed = eventData.PreVelocity.Length;
|
|
var direction = Vector3.Reflect( eventData.PreVelocity.Normal, eventData.Normal.Normal ).Normal;
|
|
Velocity = direction * MathF.Min( speed * SpeedMul, MaxSpeed );
|
|
}
|
|
|
|
public bool IsUsable( Entity user )
|
|
{
|
|
return true;
|
|
}
|
|
|
|
public bool OnUse( Entity user )
|
|
{
|
|
if ( user is Player player )
|
|
{
|
|
player.Health += 10;
|
|
|
|
Delete();
|
|
}
|
|
|
|
return false;
|
|
}
|
|
}
|