|
[Code/ Idea] bullets without entities
#391795
01/15/12 23:49
01/15/12 23:49
|
Joined: Sep 2003
Posts: 6,861 Kiel (Germany)
Superku
OP
Senior Expert
|
OP
Senior Expert
Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
|
When you're creating a shooter (side-scroller, FPS, space shooter), you'd probably most of the time use models for flying bullets. As the (ent_)creation of all those bullets, their removal, rendering and esp. c_move (that includes a USE_BOX trace) gets quite slow, I suggest you don't use models at all and simply run a function that emulates a bullet as follows:
///////////////////////////////
#include <acknex.h>
#include <default.c>
///////////////////////////////
void p_bullet(PARTICLE* p)
{
vec_set(p.blue,vector(random(128),128+random(128),255));
set(p, STREAK | BRIGHT);
p.alpha = 100;
p.size = 10;
p.lifespan = 0.01;
p.event = NULL;
}
void bullet_create(VECTOR* vpos,VECTOR* vang,var speed)
{
var alive = 16;
VECTOR pos,temp,vel;
vec_set(pos,vpos);
vec_set(vel,vector(speed,0,0));
vec_rotate(vel,vang);
while(alive > 0)
{
// calculate new position
vec_set(temp,vel);
vec_scale(temp,time_step);
vec_add(temp,pos);
c_trace(pos,temp,IGNORE_PASSABLE | USE_POLYGON); // optional: SCAN_TEXTURE
if(trace_hit)
{
/*if(you) ... // reduce health, blood effect
else ... // spark effect*/
alive = 0;
}
effect(p_bullet,1,pos,vel); // you may want to shorten vel on impact
vec_set(pos,temp); // move to new position
alive -= time_step;
wait(1);
}
}
void main()
{
fps_max = 60;
video_mode = 9;
level_load(NULL);
ent_create(CUBE_MDL,vector(500,-10,-5),NULL);
def_move();
while(1)
{
if(mouse_left)
{
VECTOR temp;
vec_set(temp,vector(5,-20,-10));
vec_rotate(temp,camera.pan);
vec_add(temp,camera.x);
bullet_create(temp,camera.pan,500);
wait(-0.1);
}
wait(1);
}
}
You can still use c_ignore and most of the events. Additionally, if you really need a lot of bullets, you could handle all of them with just one wait (save the bullets in some array/ linked list).
"Falls das Resultat nicht einfach nur dermassen gut aussieht, sollten Sie nochmal von vorn anfangen..." - Manual Check out my new game: Pogostuck: Rage With Your Friends
|
|
|
Re: [Code/ Idea] bullets without entities
[Re: alibaba]
#391817
01/16/12 09:55
01/16/12 09:55
|
Joined: Feb 2009
Posts: 2,154
Damocles_
Expert
|
Expert
Joined: Feb 2009
Posts: 2,154
|
Why should i use entities? I use c_trace =/ I wonder how you make a blue c_trace ? a c_trace is for gaining information and ent_create is for making something "3d" to get rendered.
|
|
|
|