filmov
tv
Chasing Cubes - An UnrealScript Example Application (+Source Code)

Показать описание
Source Code:
There are 3 classes,
-------------------------------------------------------------------
-------------------------------------------------------------------
class FarrisGameInfo extends GameInfo;
DefaultProperties
{
PlayerControllerClass=class'CubeSpawnerPlayerController'
DefaultPawnClass=class'UDKBase.SimplePawn'
bDelayedStart=false
}
--------------------------------------------------------------------
--------------------------------------------------------------------
class CubeSpawnerPlayerController extends PlayerController;
DefaultProperties
{
}
exec function StartFire( optional byte FireModeNum )
{
MouseClicked(FireModeNum == 0, FireModeNum == 1);
}
function MouseClicked (bool bLeftMousePressed, bool bRightMousePressed){
local vector end, norm, loc, pawnLocal;
local TraceHitInfo hitInfo;
local Actor traceHit;
pawnLocal = Pawn.Location;
pawnLocal.Z += 60; // The height of the Camera
end = pawnLocal + normal(vector(Rotation))*32768; // trace to "infinity"
traceHit = trace(loc, norm, end, pawnLocal, true,, hitInfo); // Find where the Camera is pointing at (Further Read: "trace")
if (traceHit != none){
if(bRightMousePressed)
spawnCube(loc); // Spawn Cube at loc
else
traceHit.Destroy(); // Delete the Cube we are pointing it
}
}
function spawnCube(vector loc){
local CubeCompanion cc;
ClientPlaySound(SoundCue'A_Vehicle_Cicada.SoundCues.A_Vehicle_Cicada_TargetLock'); // Makes a sound
loc.z += 150; // So that the Cube starts a bit above the ground
cc = Spawn(class'CubeCompanion',,,loc,Rot(0,0,0)); // class, location, and no rotation
}
/**
* Draw a crosshair. This function is called by the Engine.HUD class.
*/
function DrawHUD( HUD H )
{
local float CrosshairSize;
super.DrawHUD(H);
H.Canvas.SetDrawColor(0,255,0,255);
CrosshairSize = 10;
H.Canvas.SetPos(H.CenterX - CrosshairSize, H.CenterY);
H.Canvas.DrawRect(2*CrosshairSize + 1, 1);
H.Canvas.SetPos(H.CenterX, H.CenterY - CrosshairSize);
H.Canvas.DrawRect(1, 2*CrosshairSize + 1);
}
------------------------------------------------
------------------------------------------------
//copied from BrentFarris
class CubeCompanion extends Actor
placeable;
var() int Speed;
function Tick(float delta)
{
local Vector dir;
super.Tick(delta);
dir = GetALocalPlayerController().Pawn.Location - Location;
velocity = Normal(dir) * speed;
}
DefaultProperties
{
Speed = 150
begin object Class=DynamicLightEnvironmentComponent Name=MyLightEnvironment
end object
LightEnvironment = MyLightEnvironment
Components(0) = MyLightEnvironment
begin object Class=StaticMeshComponent Name=BlockMesh
LightEnvironment = MyLightEnvironment
StaticMesh = StaticMesh'EngineMeshes.Cube'
Scale = .3
end object
Components(1) = BlockMesh
DisplayMesh = BlockMesh
CollisionComponent = BlockMesh
bCollideActors = true
bCollideWorld = true
bStatic = false
bMovable = true
bBlockActors = true
Physics = PHYS_Projectile
}
Thank you.
Комментарии