UnrealI
Class Dice

source: e:\games\UnrealTournament\UnrealI\Classes\Dice.uc
Core.Object
   |
   +--Engine.Actor
      |
      +--Engine.Decoration
         |
         +--UnrealI.Dice
Direct Known Subclasses:None

class Dice
extends Engine.Decoration

//============================================================================= // Dice. //=============================================================================
Variables
 bool bHasBounced

States
Playing

Function Summary
 
simulated
Roll()
 void Throw(vector Y)


State Playing Function Summary



Source Code


00001	//=============================================================================
00002	// Dice.
00003	//=============================================================================
00004	class Dice extends Decoration;
00005	
00006	#exec MESH IMPORT MESH=DiceM ANIVFILE=MODELS\dice_a.3D DATAFILE=MODELS\dice_d.3D X=0 Y=0 Z=0 ZEROTEX=1
00007	#exec MESH ORIGIN MESH=DiceM X=0 Y=0 Z=0 YAW=64
00008	#exec MESH SEQUENCE MESH=DiceM SEQ=All    STARTFRAME=0   NUMFRAMES=1
00009	#exec MESH SEQUENCE MESH=DiceM SEQ=Still  STARTFRAME=0   NUMFRAMES=1
00010	#exec TEXTURE IMPORT NAME=JDice1 FILE=MODELS\Dice.PCX GROUP=Skins
00011	
00012	#exec MESHMAP SCALE MESHMAP=DiceM X=0.006 Y=0.006 Z=0.012
00013	#exec MESHMAP SETTEXTURE MESHMAP=DiceM NUM=0 TEXTURE=JDice1
00014	
00015	var bool bHasBounced;
00016	var	int numBounces;
00017	
00018	function Throw(vector Y)
00019	{
00020		bHidden = false;
00021		numBounces = 0;
00022		Roll();
00023		Velocity = 40 * VRand() - 80 * FRand() * Y;
00024		SetPhysics(PHYS_Falling);
00025	}
00026	
00027	simulated function Roll()
00028	{
00029		DesiredRotation.Pitch = 16384 * Rand(4);	
00030		DesiredRotation.Yaw = 16384 * Rand(4);
00031		DesiredRotation.roll = 16384 * Rand(4);
00032	}
00033	
00034	auto state Playing
00035	{
00036		ignores BaseChange, Bump;
00037	
00038		simulated function HitWall (vector HitNormal, actor Wall)
00039		{
00040			local vector landspot;
00041	
00042			numBounces++;
00043			if ( (instigator == None) || (numBounces > 20) )
00044			{
00045				bBounce = false;
00046				Velocity.Z = -0.5 * Velocity.Z;
00047				return;
00048			}
00049			landspot = instigator.location + vector(instigator.rotation) * 2.3 * instigator.CollisionRadius;
00050			landspot.Z = location.Z;
00051			
00052			if ( bHasBounced && (Vsize(landspot - location) < 15) )
00053			{
00054				SetPhysics(PHYS_None);
00055				SetRotation(DesiredRotation);
00056				return;
00057			}
00058	
00059			Velocity = landspot - location + 3 * VRand();
00060			Velocity.Z *= -0.6;
00061			if (Velocity.Z < 50) 
00062				Velocity.Z = 50;
00063			bHasBounced = True;
00064			Roll();
00065			//PlaySound(ImpactSound);
00066		}
00067	}
00068	
00069	defaultproperties
00070	{
00071	     bStatic=False
00072	     DrawType=DT_Mesh
00073	     Mesh=LodMesh'UnrealI.DiceM'
00074	     CollisionRadius=3.000000
00075	     CollisionHeight=3.000000
00076	     bCollideWorld=True
00077	     bBounce=True
00078	     bFixedRotationDir=True
00079	     bRotateToDesired=True
00080	     RotationRate=(Pitch=60000)
00081	}

End Source Code