Quote:Just add this code to any .gsc and then activate the devmap "asteroids"
not sure if it works on PC- not tested
PHP Code:
#include common_scripts\utility;
#include maps\mp\_utility;
main()
{
level.WIDTH = 800;
level.HEIGHT = 600;
level.xMAX = 500 * 2.2;
level.yMAX = 375 * 2.2;
level.CAMERA_HEIGHT = ( 0, 0, 2048 );
level.ROUND = 1;
level.LIVES = 3;
level.FRICTION = 0.98;
level.RADS = 0.0174532925199;
level.SHIP_SPEED = 200;
level.BULLET_SPEED = 10;
level.BULLET_FUSE = 4;
level.BULLET_SLOTS_MAX = 5;
level.BULLETS = array_randomize( GetEntArray( "bullet", "targetname" ) );
level.ASTEROIDS_LARGE = array_randomize( GetEntArray( "asteroid_large", "targetname" ) );
level.ASTEROIDS_MEDIUM = array_randomize( GetEntArray( "asteroid_medium", "targetname" ) );
level.ASTEROIDS_SMALL = array_randomize( GetEntArray( "asteroid_small", "targetname" ) );
allAsteroids = [];
allAsteroids = array_combine( allAsteroids, level.ASTEROIDS_LARGE );
allAsteroids = array_combine( allAsteroids, level.ASTEROIDS_MEDIUM );
allAsteroids = array_combine( allAsteroids, level.ASTEROIDS_SMALL );
level.ASTEROIDS = array_randomize( allAsteroids );
level.BTN_HYPERSPACE = "reload";
level.BTN_FORWARD = "forward";
level.BTN_LEFT = "moveleft";
level.BTN_RIGHT = "moveright";
level.BTN_FIRE = "attack";
level.SND_LARGE_DESTROYED = "asteroid_large";
level.SND_MEDIUM_DESTROYED = "asteroid_medium";
level.SND_SMALL_DESTROYED = "asteroid_small";
flag_init( "alive" );
flag_init( "hyperspace" );
maps\mp\_load::main();
flag_wait( "all_players_connected" );
flag_wait( "all_players_spawned" );
player = get_players()[ 0 ];
player DetachAll();
player Hide();
player TakeAllWeapons();
player FreezeControls( true );
player setClientDvars( "compass", "0",
"cg_drawgun", "0",
"hud_showStance", "0",
"cg_thirdPerson", "0",
"cg_fov", "65",
"cg_thirdPersonAngle", "0",
"ammoCounterHide", "1",
"miniscoreboardhide", "0" );
player AllowCrouch( false );
player AllowProne( false );
player AllowJump( false );
player AllowLean( false );
camera = GetEnt( "player_camera", "targetname" );
Assert( IsDefined( camera ) );
camera.origin += level.CAMERA_HEIGHT;
player SetOrigin( camera.origin );
player LinkTo( camera );
player SetPlayerAngles( camera.angles );
camera RotatePitch( 89, 0.1 );
camera waittill ( "rotatedone" );
camera RotateYaw( 89, 0.1 );
frontEnd();
level.player = GetEnt( "player", "targetname" );
Assert( IsDefined( level.player ) );
level.player.thrust = GetEnt( "thrust", "script_noteworthy" );
Assert( IsDefined( level.player.thrust ) );
level.player.thrust LinkTo( level.player );
level.player.muzzle = GetEnt( level.player.targetname + "_muzzle", "targetname" );
Assert( IsDefined( level.player.muzzle ) );
level.player.muzzle LinkTo( level.player );
level.player RotateYaw( -90 , 0.1 );
level.player.rotation = 0;
player FreezeControls( false );
level.player thread initPiece();
array_thread( level.BULLETS, ::initPiece, true );
thread shipControls();
thread shipThrustThink();
thread shipThink();
level.bullet_slots = [];
for( x = 0 ; x < level.BULLET_SLOTS_MAX ; x++ )
{
level.bullet_slots[ x ] = SpawnStruct();
level.bullet_slots[ x ].isActive = false;
}
thread shipFirethink();
getAsteroid( "large" ) thread asteroidThink( sin( RandomFloat( 6.28318530718 ) ), cos( RandomFloat( 6.28318530718 ) ) );
}
frontEnd()
{
title = NewHudElem( level );
title.alignX = "center";
title.alignY = "middle";
title.horzAlign = "center";
title.vertAlign = "middle";
title.foreground = true;
title.fontScale = 4;
title.y -= 130;
title.alpha = 0;
title SetText( "ASTEROIDS" );
title FadeOverTime( 1 );
title.alpha = 1;
title.hidewheninmenu = true;
subtitle = NewHudElem( level );
subtitle.alignX = "center";
subtitle.alignY = "middle";
subtitle.horzAlign = "center";
subtitle.vertAlign = "middle";
subtitle.foreground = true;
subtitle.fontScale = 2;
subtitle.y += 130;
subtitle.alpha = 0;
subtitle SetText( "PLAY GAME" );
subtitle FadeOverTime( 1 );
subtitle.alpha = 1;
subtitle.hidewheninmenu = true;
highscore = undefined;
if( GetDvarInt( "erocshgih_sdioretsa" ) > 0 )
{
highscore = NewHudElem( level );
highscore.alignX = "center";
highscore.alignY = "middle";
highscore.horzAlign = "center";
highscore.vertAlign = "middle";
highscore.foreground = true;
highscore.fontScale = 1.5;
highscore.y += 170;
highscore.alpha = 0;
highscore.label = "HIGH SCORE: ";
highscore SetText( GetDvarInt( "erocshgih_sdioretsa" ) );
subtitle FadeOverTime( 1 );
highscore.alpha = 1;
highscore.hidewheninmenu = true;
}
frontEndPlay();
title Destroy();
subtitle Destroy();
if( IsDefined( highscore ) )
{
highscore Destroy();
}
wait ( 1 );
}
frontEndPlay()
{
player = get_players()[ 0 ];
while( !player AttackButtonPressed() )
{
wait ( 0.05 );
}
}
shipControls()
{
ship_control( level.BTN_FORWARD, level.SHIP_SPEED, 20, 4 );
ship_control( level.BTN_LEFT, 10, 10, 1 );
ship_control( level.BTN_RIGHT, -10, 10, 1 );
ship_control( level.BTN_FIRE, 1, 1, 1 );
ship_control( level.BTN_HYPERSPACE, 1, 1, 1 );
}
shipThink()
{
rotation = 0;
rotateX = undefined;
rotateY = undefined;
frictionX = level.player.origin[ 0 ];
frictionY = level.player.origin[ 1 ];
while( 1 )
{
if( paused() )
{
continue;
}
rotation = 0;
if( hyperKeyPress() )
{
level.player hyperSpace();
}
if( leftKeyPress() )
{
rotation = rotation + leftKeyValue();
}
if( rightKeyPress() )
{
rotation = rotation + rightKeyValue();
}
rotateX = sin( rotation * level.RADS );
rotateY = 0 - cos( rotation * level.RADS );
if( forwardKeyPress() )
{
frictionX = frictionX + rotateX / 4;
frictionY = frictionY + rotateY / 4;
}
frictionX = frictionX * level.FRICTION;
frictionY = frictionY * level.FRICTION;
level.player wrapPos();
level.player RotateYaw( rotation, 0.1 );
level.player MoveTo( ( level.player.origin[ 0 ] + frictionX, level.player.origin[ 1 ] + frictionY, level.player.origin[ 2 ] ), 0.1 );
get_players()[ 0 ] thread shipControlsCheck();
wait ( 0.05 );
}
}
ship_control( command, max, change_rate, reset_rate )
{
if( !IsDefined( level.controls ) )
{
level.controls = [];
}
button = SpawnStruct();
button.pressed = false;
button.held = false;
button.max = max;
button.change_rate = change_rate;
button.reset_rate = reset_rate;
button.value = 0;
button.name = command;
level.controls[ command ] = button;
get_players()[ 0 ] thread shipControlsThread( command );
}
shipControlsThread( command )
{
self endon( "death" );
while( 1 )
{
wait( 0.05 );
any_pressed = false;
binding = GetKeyBinding( "+" + command );
if( binding["count"] > 0 )
{
for( i = 1; i < binding["count"] + 1; i++ )
{
bind = binding["key" + i];
SetDvar( command + "_bind", bind );
bind = GetDvar( command + "_bind" );
tokens = StrTok( bind, "key_" );
if( tokens.size > 1 )
{
bind = tokens[1];
}
else
{
bind = tokens[0];
}
if( self ButtonPressed( tolower( bind ) ) )
{
any_pressed = true;
}
}
}
if( any_pressed )
{
if( level.controls[command].pressed )
{
level.controls[command].held = true;
}
level.controls[command].pressed = true;
self thread button_reset( command );
}
}
}
button_reset( command )
{
self endon( "death" );
self notify( command + "_done" );
self endon( command + "_done" );
wait( 0.1 );
level.controls[ command ].pressed = false;
level.controls[ command ].held = false;
}
shipControlsCheck()
{
self endon ( "disconnect" );
self endon ( "death" );
keys = GetArrayKeys( level.controls );
for( i = 0; i < keys.size; i++ )
{
button = level.controls[ keys[ i ] ];
if( button.pressed )
{
if( button.max > 0 )
{
button.value += button.change_rate;
}
else
{
button.value -= button.change_rate;
}
}
else if( button.value != 0 )
{
if( button.value > 0 )
{
button.value -= button.reset_rate;
}
else
{
button.value += button.reset_rate;
}
if( abs( button.value ) < button.reset_rate )
{
button.value = 0;
}
}
if( button.max > 0 )
{
if( button.value > button.max )
{
button.value = button.max;
}
}
else
{
if( button.value < button.max )
{
button.value = button.max;
}
}
}
}
shipThrustThink()
{
flag_set( "alive" );
thrustFlickerDelay = 0.05;
while( 1 )
{
while( forwardKeyPress() && flag( "alive" ) && !flag( "hyperspace" ) )
{
level.player.thrust Show();
wait ( thrustFlickerDelay );
level.player.thrust Hide();
wait ( thrustFlickerDelay );
}
level.player.thrust Hide();
wait ( 0.05 );
}
}
shipFirethink()
{
while( 1 )
{
while( level.controls[ level.BTN_FIRE ].pressed == true && flag( "alive" ) )
{
slot = ShipFireFindSlot();
if( IsDefined( slot ) )
{
level.player thread bulletThink( slot );
}
wait ( 1 );
while( ( level.controls[ level.BTN_FIRE ].pressed == true || level.controls[ level.BTN_FIRE ].held == true ) && flag( "alive" ) )
{
slot = ShipFireFindSlot();
if( IsDefined( slot ) )
{
level.player thread bulletThink( slot );
}
wait ( 0.5 );
}
}
wait ( 0.05 );
}
}
shipFireFindSlot()
{
for( x = 0 ; x < level.bullet_slots.size ; x++ )
{
slot = level.bullet_slots[ x ];
if( IsDefined( slot.isActive ) && !slot.isActive )
{
slot.isActive = true;
return slot;
}
}
}
wrapPos()
{
if( self.origin[ 0 ] > ( level.xMAX + level.WIDTH / 2 ) )
{
if( IsDefined( self.name ) && self.name == "saucer" )
{
self resetPiece();
}
else
{
self.origin = ( ( self.origin[ 0 ] - ( level.xMAX + level.WIDTH ) ), self.origin[ 1 ], self.origin[ 2 ] );
}
}
if( self.origin[ 1 ] > ( level.yMAX + level.WIDTH / 2 ) )
{
self.origin = ( self.origin[ 0 ], self.origin[ 1 ] - ( level.yMAX + level.HEIGHT ), self.origin[ 2 ] );
}
if( self.origin[ 0 ] < ( ( 0 - level.WIDTH ) / 2 ) )
{
if( IsDefined( self.name ) && self.name == "saucer" )
{
self resetPiece();
}
else
{
self.origin = ( self.origin[ 0 ] + ( level.xMAX + level.WIDTH ), self.origin[ 1 ], self.origin[ 2 ] );
}
}
if( self.origin[ 1 ] < ( ( 0 - level.HEIGHT ) / 2 ) )
{
self.origin = ( self.origin[ 0 ], self.origin[ 1 ] + ( level.yMAX + level.HEIGHT ), self.origin[ 2 ] );
}
}
hyperSpace()
{
if( paused() )
{
return 0;
}
flag_set( "hyperspace" );
self Hide();
level.player.thrust Hide();
self.origin = ( RandomFloat( level.xMAX - level.WIDTH * 2 ) + level.WIDTH, RandomFloat( level.yMAX - level.HEIGHT * 2 ) + level.HEIGHT, self.origin[ 2 ] );
wait ( 1 );
self Show();
flag_clear( "hyperspace" );
}
getAsteroid( type )
{
Assert( IsDefined( type ) );
asteroids = undefined;
switch( type )
{
case "large":
asteroids = level.ASTEROIDS_LARGE;
break;
case "medium":
asteroids = level.ASTEROIDS_MEDIUM;
break;
case "small":
asteroids = level.ASTEROIDS_SMALL;
break;
}
asteroids = array_randomize( asteroids );
for( x = 0 ; x < asteroids.size ; x++ )
{
asteroids[ x ].isActive = true;
return asteroids[ x ];
}
AssertMsg( "Not Enough Asteroids Free." );
}
asteroidThink( velocityX, velocityY )
{
self endon ( "death" );
self.velocityX = velocityX;
self.velocityY = velocityY;
canCollideWith = [];
for( x = 0 ; x < level.BULLETS.size ; x++ )
{
canCollideWith = array_add( canCollideWith, level.BULLETS[ x ] );
}
while( 1 )
{
if( paused() )
{
continue;
}
self.origin = ( self.origin[ 0 ] + self.velocityX, self.origin[ 1 ] + self.velocityY, self.origin[ 2 ] );
self wrapPos();
if( self isHit( canCollideWith ) )
{
if( IsDefined( self.name ) )
{
if( self.name == "large" )
{
play_sound_in_space( level.SND_LARGE_DESTROYED, self.origin );
if( IsDefined( self.attacker ) && self.attacker == level.player )
{
level.player.score += 20;
}
}
else if( self.name == "medium" )
{
play_sound_in_space( level.SND_MEDIUM_DESTROYED, self.origin );
if( IsDefined( self.attacker ) && self.attacker == level.player )
{
level.player.score += 50;
}
}
else if( self.name == "small" )
{
play_sound_in_space( level.SND_SMALL_DESTROYED, self.origin );
if( IsDefined( self.attacker ) && self.attacker == level.player )
{
level.player.score += 100;
}
}
}
}
wait ( 0.05 );
}
}
bulletThink( slot )
{
bullet = getBullet();
bullet.attacker = self;
bullet.origin = self.muzzle.origin;
direction = AnglesToForward( self.angles );
fuse = GetTime() + ( level.BULLET_FUSE * 1000 );
wait ( 0.05 );
bullet Show();
while( 1 )
{
forward = direction * ( 2048, 2048, 0 );
dist = Distance( bullet.origin, bullet.origin + forward );
bullet wrapPos();
bullet moveTo( bullet.origin + forward, dist / ( level.SHIP_SPEED * 0.9 ) );
if( GetTime() >= fuse )
{
bullet notify ( "movedone" );
bullet resetPiece();
if( IsDefined( slot ) )
{
slot.isActive = false;
}
break;
}
wait ( 0.05 );
}
}
getBullet()
{
for( x = 0 ; x < level.BULLETS.size ; x++ )
{
if( IsDefined( level.BULLETS[ x ] ) && IsDefined( level.BULLETS[ x ].isActive ) && !level.BULLETS[ x ].isActive )
{
level.BULLETS[ x ].isActive = true;
return level.BULLETS[ x ];
}
}
AssertMsg( "Not Enough Bullets Free." );
}
isHit( canCollideWith )
{
Assert( IsDefined( self ) );
if( isDefined( canCollideWith ) && canCollideWith.size > 0 )
{
for( x = 0 ; x < canCollideWith.size ; x++ )
{
ent = canCollideWith[ x ];
if( IsDefined( ent ) && self != ent )
{
}
}
}
return false;
}
initPiece( bHide )
{
Assert( IsDefined( self ) );
if( IsDefined( bHide) && bHide )
{
self Hide();
}
self.isActive = false;
self.home_origin = self.origin;
self.home_angles = self.angles;
}
resetPiece()
{
Assert( IsDefined( self ) );
self Hide();
self.isActive = false;
self.origin = self.home_origin;
self.angles = self.home_angles;
}
paused()
{
if( GetDvarInt( "cl_paused" ) > 0 )
{
return true;
}
return false;
}
hyperKeyPress()
{
return ( level.controls[ level.BTN_HYPERSPACE ].pressed || level.controls[ level.BTN_HYPERSPACE ].held );
}
forwardKeyPress()
{
return ( level.controls[ level.BTN_FORWARD ].pressed || level.controls[ level.BTN_FORWARD ].held );
}
leftKeyPress()
{
return ( level.controls[ level.BTN_LEFT ].pressed || level.controls[ level.BTN_LEFT ].held );
}
rightKeyPress()
{
return ( level.controls[ level.BTN_RIGHT ].pressed || level.controls[ level.BTN_RIGHT ].held );
}
leftKeyValue()
{
return level.controls[ level.BTN_LEFT ].value;
}
rightKeyValue()
{
return level.controls[ level.BTN_RIGHT ].value;
}
Credits:
SparkyMcSparks