Posted By: M4sterm1nd
kollisionsprobleme - 02/17/10 18:23
hallo Com,
ich habe ein paar codeprobleme mit der kollision.
hoffentlich könnt Ihr mir weiterhelfen.
also mein raumschiff prallt zwar etwas von dem Asteroiden ab aber es färbt sich nicht rot
desweiteren werden die asteroiden unverwundbar nach dem gegenfliegen wenn ich 2 asteroiden durch gegenfliegen schon zerstört habe
danke für´s drüberschauen schonmal
ich habe ein paar codeprobleme mit der kollision.
hoffentlich könnt Ihr mir weiterhelfen.
also mein raumschiff prallt zwar etwas von dem Asteroiden ab aber es färbt sich nicht rot
desweiteren werden die asteroiden unverwundbar nach dem gegenfliegen wenn ich 2 asteroiden durch gegenfliegen schon zerstört habe
Code:
///////////////////////////////
#include <acknex.h>
#include <default.c>
///////////////////////////////
function starfield(PARTICLE *p);
function fade_stars(PARTICLE *p);
function fire_effect(PARTICLE *p);
function fade_fire(PARTICLE *p);
function players_laser();
function move_plaser();
function remove_plaser();
function asteroid();
function schusstreffer_event();
function asteroid_destroy();
function asteroid_explodes();
function player_collisions();
///////////////////////////////
STRING* explosion_pcx = "explo+9.pcx" ; // explosion sprite
///////////////////////////////
BMAP* star_tga = "star.tga";
BMAP* fire_tga = "fire.tga";
ENTITY* Raumschiff;
///////////////////////////////
action player1() // attach this action to the ship model
{
var init_z;
player = my; // I'm the player
init_z = my.z;
//c_setminmax(me);
set (my, POLYGON); // use polygon-based collision detection
my.ambient = 100; // make the ship look brighter
#define schaden skill2
#define health skill1
my.health = 100;
my.schaden = 10;
VECTOR player_speed, star_pos, temp, jet_offset, jet2_offset, jet3_offset, jet4_offset, jet5_offset, jet6_offset;
var temp_x = 0, temp_y = 0;
while (1)
{
if((key_a == 0) || (key_s == 0) || (key_w == 0) || (key_d == 0))
{
temp_x = 0;
temp_y = 0;
}
if(key_w == 1)
{
temp_x += 20 * time_step;
wait(1);
}
if(key_s == 1)
{
temp_x -= 20 * time_step;
wait(1);
}
if(key_a == 1)
{
temp_y += 20 * time_step;
wait(1);
}
if(key_d == 1)
{
temp_y -= 20 * time_step;
wait(1);
}
player_speed.x = temp_x;
player_speed.y = temp_y;
player_speed.z = init_z;
if(my.y <= -2000)
my.y = 1999;
if(my.y >= 2000)
my.y = -1999;
if(my.x <= -2000)
my.x = 1999;
if(my.x >= 2000)
my.x = -1999;
vec_set(temp.x,mouse_pos3d.x);
vec_sub(temp.x,my.x);
temp.z = init_z;
if((my.y <= 1998) && (my.y >= -1998) && (my.x <= 1998) && (my.x >= -1998))
vec_to_angle(my.pan,temp);
c_move(my,player_speed,NULLVECTOR,IGNORE_PASSABLE | GLIDE);
// Triebwerkseffekt
vec_set(jet_offset.x, vector(-40, 50, 0));
vec_set(jet2_offset.x, vector(-40, -50, 0));
vec_set(jet3_offset.x, vector(10, 50, 0));
vec_set(jet4_offset.x, vector(10, -50, 0));
vec_set(jet5_offset.x, vector(-15, -65, 0));
vec_set(jet6_offset.x, vector(-15, 65, 0));
vec_rotate(jet_offset.x, my.pan);
vec_rotate(jet2_offset.x, my.pan);
vec_rotate(jet3_offset.x, my.pan);
vec_rotate(jet4_offset.x, my.pan);
vec_rotate(jet5_offset.x, my.pan);
vec_rotate(jet6_offset.x, my.pan);
vec_add(jet_offset.x, my.x);
vec_add(jet2_offset.x, my.x);
vec_add(jet3_offset.x, my.x);
vec_add(jet4_offset.x, my.x);
vec_add(jet5_offset.x, my.x);
vec_add(jet6_offset.x, my.x);
if(key_w)
{
effect(fire_effect, 10, jet_offset.x, nullvector); // generate 10 fire particles each frame
effect(fire_effect, 10, jet2_offset.x, nullvector);
}
if(key_s)
{
effect(fire_effect, 10, jet3_offset.x, nullvector); // generate 10 fire particles each frame
effect(fire_effect, 10, jet4_offset.x, nullvector);
}
if(key_a)
effect(fire_effect, 5, jet5_offset.x, nullvector);
if(key_d)
effect(fire_effect, 5, jet6_offset.x, nullvector);
// Ende Triebwerkseffekt
my.emask |= (ENABLE_BLOCK | ENABLE_ENTITY | ENABLE_IMPACT); // the player is sensitive to collisions with level blocks and entities
my.event = player_collisions; // and runs this event function if it collides with something
star_pos.x = my.x - 800 + random(1600); // x = -800...+1300
star_pos.y = my.y - 800 + random(1600); // y = -800...+1300
star_pos.z = 0;
effect(starfield, 1, star_pos.x, nullvector);
wait (1);
}
}
function player_collisions() // this is player's event function
{
my.health -= you.schaden; // verringere players health
vec_set(my.blue,vector(0,0,200));
vec_add(my.x, bounce);
}
///////////////////////////////
function main()
{
vec_set(sky_color, vector(1, 1, 1));
fps_max = 80;
video_screen = 1;
level_load("spaceshooter.WMB");
wait(2);
player = ent_create("player.mdl",NULLVECTOR,player1);
// Asteroiden erstellen
ent_create("asteroid.mdl", vector(500, 500, player.z), asteroid);
ent_create("asteroid.mdl", vector(-500, 500, player.z), asteroid);
ent_create("asteroid.mdl", vector(150, 250, player.z), asteroid);
ent_create("asteroid.mdl", vector(-500, -150, player.z), asteroid);
ent_create("asteroid.mdl", vector(500, 750, player.z), asteroid);
ent_create("asteroid.mdl", vector(500, -500, player.z), asteroid);
mouse_mode = 2;
BMAP* Maus_tga = bmap_create("Maus.tga");
mouse_map = Maus_tga;
mouse_spot.x = bmap_width(Maus_tga)/2;
mouse_spot.y = bmap_height(Maus_tga)/2;
while(1)
{
vec_set(camera.x,player.x);
vec_add(camera.x,vector(0,0,1200));
vec_set(camera.pan,vector(0,-90,0));
mouse_pos.x = mouse_cursor.x;
mouse_pos.y = mouse_cursor.y;
on_mouse_left = players_laser;
wait(1);
}
}
function starfield(PARTICLE *p)
{
p.alpha = 5 + random(50);
p.bmap = star_tga;
p.size = 2 + random(1); // generate stars with random sizes
p.flags |= (BRIGHT | TRANSLUCENT);
p.event = fade_stars;
}
function fade_stars(PARTICLE *p)
{
p.alpha -= 0.5 * time_step; // fade out the stars
if (p.alpha < 0)
{
p.lifespan = 0;
}
}
// Triebwerk
function fire_effect(PARTICLE *p)
{
p->vel_x = (1 - random(2)) / 5; // set a random particle speed on the x and y axis
p->vel_y = (1 - random(2)) / 5;
p->vel_z = 0;
p.alpha = 25 + random(50); // and a random transparency
p.bmap = fire_tga;
p.size = 10; // gives the size of the fire particles
p.flags |= (BRIGHT | MOVE);
p.event = fade_fire;
}
function fade_fire(PARTICLE *p)
{
p.alpha -= 25 * time_step; // fade out the fire particles quickly
if (p.alpha < 0)
p.lifespan = 0; // and remove them completely when they become invisble
}
// Schießen (Laser)
function players_laser()
{
VECTOR plaser_offset;
vec_set(plaser_offset.x, vector(20, 0, 0));
vec_rotate(plaser_offset.x, player.pan);
vec_add(plaser_offset.x, player.x);
ent_create("laser1.mdl", plaser_offset.x, move_plaser);
wait (-1);
}
function move_plaser()
{
c_setminmax(me);
set(my, PASSABLE);
set(my, POLYGON);
my.pan = player.pan;
my.skill100 = 15;
my.emask |= (ENABLE_BLOCK | ENABLE_ENTITY);
my.event = remove_plaser;
#define schaden skill1
my.schaden = 10;
while (my)
{
if (vec_dist(my.x, player.x) > 70)
reset(my, PASSABLE);
c_move(my, vector(75 * time_step, 0, 0), nullvector, IGNORE_YOU | IGNORE_PASSABLE);
wait (1);
}
}
function remove_plaser()
{
wait (1);
ent_remove(my);
}
function asteroid()
{
c_setminmax(me);
set(my, POLYGON);
while (!player) {wait (1);}
my.z = player.z; // align the power source entity at the same height with the player
my.pan = random(360); // start with a random set of angles
my.tilt = random(360); // this way, the boxes won't look all the same
my.roll = random(360);
#define health skill1
#define schaden skill2
my.health = 30;
my.schaden = 10;
my.emask |= (ENABLE_BLOCK | ENABLE_ENTITY | ENABLE_IMPACT);
my.event = schusstreffer_event;
while (my)
{
my.z = player.z;
my.pan += 1 * time_step; // rotate slowly
my.tilt += 1 * time_step;
my.roll += 1 * time_step;
if(my.health <= 0)
{
asteroid_destroy();
}
wait (1);
}
}
function schusstreffer_event()
{
my.health -= you.schaden;
}
function asteroid_destroy()
{
vec_add(my.x, vector(0,0,5));
my.event = NULL; // then the enemy is going to die
ent_create (explosion_pcx, my.x, asteroid_explodes); // create the explosion sprite
wait (-0.2);
ent_remove(my);
}
function asteroid_explodes() // drives the explosion sprite
{
set (my, PASSABLE); // the explosion sprite is passable
my.scale_x = 0.4;
my.scale_y = my.scale_x;
my.scale_z = my.scale_x;
set (my, BRIGHT); // set its bright flag
my.ambient = 100; // give it an ambient of 100
set (my, TRANSLUCENT); // and make it transparent
my.alpha = 100; // but we set it to be completely opaque for now
my.roll = random(360);
while (my.frame < 9) // go through all the animation frames
{
if (my.frame > 2) // a part of the explosion animation was played?
{
if (you) // if the enemy ship hasn't been removed yet
set(you, INVISIBLE); // then make it invisible (the ship and the explosion sprite have overlapped during the 2 animation frames)
}
my.frame += 0.7 * time_step; // 0.7 gives the animation speed
wait (1);
}
while (my.alpha > 0) // now fade the last frame quickly
{
my.alpha -= 50 * time_step; // 50 = fading speed
wait (1);
}
ent_remove (my); // time to remove the explosion sprite
}
danke für´s drüberschauen schonmal