#include <acknex.h>
#include <default.c>
void Barrel()
{
//Just a placeholder
set(my,FLAG8);
my.skill1=100;
while(my.skill1>0)
{
wait(1);
}
safe_remove(me);
}
void create_barrel()
{
VECTOR to;
vec_set(to,mouse_dir3d);
vec_scale(to,1000); // set a range
vec_add(to,mouse_pos3d);
c_trace(mouse_pos3d,to,0);
if(trace_hit)
//This wonīt work, because entity is too high!
//ent_create(CUBE_MDL,vector(target.x,target.y,target.z+20),Barrel);
//This will work
ent_create(CUBE_MDL,vector(target.x,target.y,target.z+10),Barrel);
}
var RocketRange=100;
var RocketScanHeight=10;
void HitEvent()
{
//If hit something
if(event_type==EVENT_IMPACT||event_type==EVENT_ENTITY)
{
//The Problem is here. If you comment out this line, then youīll see that the scan-circle
//is rotated into the ground, so you got like no chance to scan anything. To really have the
//full scan-range, you need to reset itīs rotation
vec_set(my.pan,nullvector);
//Scan around
c_scan(my.x,my.pan,vector(360,0,RocketRange),IGNORE_PASSABLE|IGNORE_ME);
//And tell the rocket you hit something
my.skill2=1;
//You can remove this line, itīs just to show you the range of the rockets
// wait(-1);
//Now we can remove everything
my.skill2=2;
}
//If scanned something
if(event_type==EVENT_DETECT)
{
//And you are marked as enemy
if(is(you,FLAG8))
{
//And you are withing the height between -10 and 10
VECTOR temp;
vec_set(temp.x,you.x);
vec_to_ent(temp.x,my);
if(abs(temp.z)<RocketScanHeight)
{
//set you health to 0
you.skill1=0;
}
}
}
}
void shoot_rocket(VECTOR* targetVec)
{
//We have to save the parameter in order not to lose it
VECTOR RocketTarget;
vec_set(RocketTarget,targetVec);
//No create the rocket
ENTITY* RocketEnt=ent_create(CUBE_MDL,vector(player.x,player.y,player.z+50),NULL);
//scale it down
vec_scale(RocketEnt.scale_x,0.2);
//Make it react to touches and detected entites
RocketEnt.emask|=ENABLE_ENTITY|ENABLE_IMPACT|ENABLE_DETECT;
RocketEnt.event=HitEvent;
//The variable for acceleration
var RocketSpeed=0;
//The range indicator
ENTITY* range=ent_create(SPHERE_MDL,my.x,NULL);
//Scale it to the range of the rocket
vec_scale(range.scale_x,RocketRange/8);
range.scale_z=RocketScanHeight/8;
//make it transparent
set(range,TRANSLUCENT|PASSABLE);
range.alpha=50;
//Fly as long as we hit nothing
while(RocketEnt.skill2==0)
{
//Target our destination
vec_to_angle(RocketEnt.pan,vec_diff(NULL,RocketTarget.x,RocketEnt.x));
//Accelerate to get the "rocket effect"
accelerate(RocketSpeed,0.5,0);
c_move(RocketEnt,vector(RocketSpeed,0,0),nullvector,IGNORE_PASSABLE|USE_POLYGON);
//set the range indicator to rockets position and orientation
vec_set(range.x,RocketEnt.x);
vec_set(range.pan,RocketEnt.pan);
//You can uncomment this line to really see how the rotation makes a difference
//RocketEnt.roll+=5*time_step;
wait(1);
}
//When we hit something, wait until we can remove it
while(RocketEnt.skill2==1)wait(1);
//Reset the event and remove everything
RocketEnt.event=NULL;
safe_remove(range);
safe_remove(RocketEnt);
}
void playerEnt()
{
player=me;
VECTOR to;
var RocketTime=0;
while(1)
{
draw_text("Shoot with [mouse_left]\ncreate barrels with [mouse_right]\nmove with WASD",0,0,COLOR_WHITE);
//Mark our target
vec_set(to,mouse_dir3d);
vec_scale(to,1000); // set a range
vec_add(to,mouse_pos3d);
c_trace(mouse_pos3d,to,0);
if(trace_hit)
draw_point3d(vector(target.x,target.y,target.z+10),COLOR_RED,100,10);
//Shoot 2 rockets every second
if(mouse_left&&RocketTime>0.5)
{
shoot_rocket(target.x);
RocketTime=0;
}
RocketTime+=time_step/16;
//Rotate to the mouse pointer
vec_to_angle(my.pan,vec_diff(NULL,target.x,my.x));
c_move(my,vector(3*(key_w-key_s),3*(key_a-key_d),0),vector(0,0,-1),GLIDE);
wait(1);
}
}
void main()
{
fps_max=60;
level_load("");
//Let the mouse have influence
mouse_mode=4;
//Create the playground
you=ent_create(CUBE_MDL,nullvector,NULL);
you.scale_x=50;
you.scale_y=50;
set(you,POLYGON);
//set camera position
vec_set(camera.x,vector(0,0,500));
camera.tilt=-90;
//Create the player
ent_create(CUBE_MDL,vector(0,0,10),playerEnt);
on_mouse_right=create_barrel;
}