#include <default.c>
#include <ackphysx.h>
#define DEBUG_POS_LINES
BMAP* bmpDecal1 = "target2e.dds";
BMAP* bmpDecal2 = "target2d.dds";
BMAP* bmpDecal3 = "target2h.dds";
BMAP* bmpDecal4 = "target2b.dds";
BMAP* bmpGround = "ground0.dds";
BMAP* bmpCrosshair = "tg.dds";
VECTOR vSpeed, vAngularSpeed, vForce, vMove, explode, posUp, posDown;
ENTITY *ground;
var handleEntity;
function animExplode()
{
set(my, UNLIT|BRIGHT|LIGHT);
vec_set(me.x,you.x);
me.z = you.z+you.max_z;
vec_fill(my.scale_x,2.5);
ptr_remove(you); wait(1);
my.frame = 1; // Start frame
while (my.frame < 7)
{
my.frame += 3*time_step;
wait(1);
}
ptr_remove(me);
}
function mouse_events()
{
switch (event_type)
{
case EVENT_TOUCH:
handleEntity = handle(me); // Store Entity Pointer
set(me,TRANSLUCENT);
my.alpha = 80;
set(my.material,PASS_SOLID);
c_ignore(22);
while(handleEntity == handle(me))
{
vec_set(posUp,me.x);
vec_set(posDown,me.x);
posUp.z = my.z+my.max_z+10;
posDown.z = ground.z-10;
#ifdef DEBUG_POS_LINES
draw_line(vector(posUp.x,posUp.y,0),NULL,100);
draw_line3d(posUp, COLOR_WHITE,50);
draw_line3d(posDown, COLOR_WHITE,50);
draw_line(vector(posUp.x,posUp.y,0),NULL,100);
draw_point3d(posUp, COLOR_RED, 100, 10);
draw_point3d(posDown, COLOR_RED , 100, 10);
#endif
if (c_trace (posUp, posDown, IGNORE_ME | IGNORE_PASSABLE | SCAN_TEXTURE))
{
PARTICLE* p1 = ent_decal(NULL,bmpDecal1,my.scale_x*100,my.skill2 += 15*time_step); p1.lifespan = .01;
PARTICLE* p2 = ent_decal(NULL,bmpDecal2,my.scale_x*100,my.skill3 -= 15*time_step); p2.lifespan = .01;
PARTICLE* p3 = ent_decal(NULL,bmpDecal3,cycle(my.skill4 -= time_step*80, 0, my.scale_x*100),my.skill5 -= 30*time_step); p3.lifespan = .01;
PARTICLE* p4 = ent_decal(NULL,bmpDecal4,cycle(my.skill6 += time_step*60, 0, my.scale_x*100),0); p4.lifespan = .01;
if (mouse_left) ent_create("explo+7.pcx", 0, animExplode);
}
wait(1);
}
return;
case EVENT_RELEASE:
handleEntity = NULL;
reset(my,TRANSLUCENT);
return;
}
}
function actor(hull)
{
my.material = mtl_metal;
set(my,LIGHT|CAST|SHADOW);
vec_fill(my.scale_x,2.6+random(2.4));
c_setminmax(me);
pXent_settype(my,PH_RIGID,hull);
pXent_setbodyflag (my, NX_BF_FROZEN_ROLL|NX_BF_FROZEN_TILT,1);
pXent_setmass(my, 0);
pXent_addforcecentral( my, vector(2000,2000,0));
pXent_setdamping (my, 0, 0);
pXent_setelasticity(my,100);
pXent_setfriction(my, 101);
me.emask |= ENABLE_TOUCH | ENABLE_RELEASE;
me.event = mouse_events;
}
function ball()
{
vec_set(my.blue,vector(random(150),random(150),random(200)));
actor(PH_SPHERE);
}
function cube()
{
vec_set(my.blue,vector(random(20),random(20),random(250)));
actor(PH_BOX);
}
function main()
{
fps_max = 60; // Limit the frame rate
mouse_map = bmpCrosshair ;mouse_range = 5000; mouse_mode = 4; //mouse_pointer = 3;
mouse_spot.x = bmap_width(bmpCrosshair)/2; // hot spot in the bmap center
mouse_spot.y = bmap_height(bmpCrosshair)/2;
vec_set(sky_color,vector(76,51,25)); // Background color
video_set(sys_metrics(0), sys_metrics(1), 32, 1);
//video_mode = 8;
shadow_stencil = 1;
physX_open(); // Physic simulation
pX_setgravity(vector(0,0,-.001));
pX_setautodisable ( 0, 0);
level_load(NULL); // No level
pXent_settype(NULL, PH_STATIC, PH_PLANE);
vec_set(camera.x,vector(2700,2700,1700)); // Camera position
vec_set(camera.pan,vector(225,-25,0));
camera.arc = 100;
ground = ent_createterrain(bmap_fill(bmap_createblack(32,32,24),vector(76,51,25),100),vector(0,0,0),30,30,125); // Ground plane
ent_setskin(ground,bmpGround,1);
//pXent_settype(ground, PH_STATIC, PH_POLY);
// BACK
you = ent_create(CUBE_MDL,vector(1800, 0, 0),NULL);
vec_set(you.scale_x, vector(1,1000,1000));
c_setminmax(you);
pXent_settype(you,PH_STATIC,PH_BOX);
set(you, INVISIBLE); //wait(1);
// FRONT
you = ent_create(CUBE_MDL,vector(-1800, 0, 0),NULL);
vec_set(you.scale_x, vector(1,1000,1000));
c_setminmax(you);
pXent_settype(you,PH_STATIC,PH_BOX);
set(you, INVISIBLE); //wait(1);
// RIGHT
you = ent_create(CUBE_MDL,vector(0, -1800, 0),NULL);
vec_set(you.scale_x, vector(1000,1,1000));
c_setminmax(you);
pXent_settype(you,PH_STATIC,PH_BOX);
set(you, INVISIBLE); //wait(1);
// LEFT
you = ent_create(CUBE_MDL,vector(0, 1800, 0),NULL);
vec_set(you.scale_x, vector(1000,1,1000));
c_setminmax(you);
pXent_settype(you,PH_STATIC,PH_BOX);
set(you, INVISIBLE); //wait(1);
// TOP
you = ent_create(CUBE_MDL,vector(0, 0, 1500),NULL);
vec_set(you.scale_x, vector(1000,1000,1));
c_setminmax(you);
pXent_settype(you,PH_STATIC,PH_BOX);
set(you, INVISIBLE); //wait(1);
while(num_entities < 99) // Create some models
{
ent_create("EnemyA.mdl",vector(random(-500),random(500),600), cube);
ent_create(SPHERE_MDL,vector(random(-500),random(500),400), ball);
wait(1);
}
def_debug(); // Debug Panel
while(1)
{
draw_text("Animated Decals Sample by Robert Judycki 2014",440,15,COLOR_BLUE);
draw_text("Hold RMB and use [Q|W|E|A|S|D] keys to move the camera",440,35,COLOR_WHITE);
draw_text("[Left Mouse Button] - Terminate certain Entity",440,55,COLOR_WHITE);
if(mouse_right) // Move the camera if the right mouse button was pressed
{
vForce.x =-25*(key_force.x + mouse_force.x); // pan angle
vForce.y = 25*(key_force.y + mouse_force.y); // tilt angle
vForce.z = 0; // roll angle
vec_accelerate(vMove,vAngularSpeed,vForce,0.8);
vec_add(camera.pan,vMove);
vForce.x = 25 * (key_w - key_s); // forward
vForce.y = 25 * (key_a - key_d); // sideward
vForce.z = 25 * (key_e - key_q); // upward
vec_accelerate(vMove,vSpeed,vForce,0.5);
vec_rotate(vMove,camera.pan);
vec_add(camera.x,vMove);
}
wait(1);
}
}