home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 23 / IOPROG_23.ISO / SOFT / RAYCAST.ZIP / BULLET.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1995-10-19  |  2.9 KB  |  102 lines

  1. #include "assert.h"
  2. #include "ray.h"
  3. #include "globals.h"
  4. #include "rayspr.h"
  5. #include "sprfunc.h"
  6. #include "sfvars.h"
  7. #include "maxmins.h"
  8. #include "sprinter.h"
  9. #include "fixed.h"
  10. #include "collisio.h"
  11. #include "sound.h"
  12. #include "voxinter.h"
  13. #include "ground.h"
  14. #include "sprtypes.h"
  15. #include "sprswtch.h"
  16. #include "message.h"
  17. #include "defobj.h"
  18. #include "objcol.h"
  19. #include "damage.h"
  20.  
  21. #define BULLET_SPEED 20
  22. #define BULLET_DAMAGE 10
  23.  
  24. long bmin_x, bmin_y, bmax_x, bmax_y;
  25. long sound_id;
  26.  
  27. void Bullet_Create(pobject cur_object, long offset);
  28. void Bullet_Update(pobject cur_object, long update_num);
  29. void Bullet_Update_Z(pobject cur_object, psector new_sec);
  30. ULONG Bullet_Message(pobject send_obj, pobject receive_obj, ULONG message, pdata extra_data);
  31.  
  32. void Init_Bullets(func_index index) {
  33.    sound_id=Load_Sound("shoot.wav");
  34.    update_funcs[index]=Bullet_Update;
  35.    update_z_funcs[index]=Bullet_Update_Z;
  36.    load_extra_funcs[index]=Bullet_Create;
  37.    message_funcs[index]=Bullet_Message;
  38.    bmin_x=0x7FFFFFFF;
  39. }
  40.  
  41. BOOL Is_Hittable(pobject the_obj) {
  42. if (the_obj->stats.current_health>0) {
  43.    return TRUE;
  44. }  else {
  45.    return FALSE;
  46. }
  47.  
  48. }
  49.  
  50. void Bullet_Update(pobject cur_object, long update_num) {
  51.    long orig_alt;
  52.    pobject orig_obj;
  53.    orig_alt=cur_object->z+Ground_Height(cur_object);
  54.    Move_Object_Vec(cur_object, (pvector2)(cur_object->extra_data));
  55.    cur_object->z=orig_alt-Ground_Height(cur_object);
  56.    if (cur_object->z <= 0) {
  57.       Switch_Object_Types(cur_object, Obj_Type_List+EXPLOSION_TYPE);
  58.    }
  59. }
  60.  
  61. void Bullet_Update_Z(pobject cur_object, psector new_sec) {
  62. }
  63.  
  64. void Bullet_Create(pobject cur_object, long offset) {
  65.    Play_Sound(sound_id);
  66.    if (bmin_x==0x7FFFFFFF)
  67.       Get_Map_Max_Mins(bmin_x, bmin_y, bmax_x, bmax_y);
  68.  
  69.    pvector2 delta_vec;
  70.    delta_vec=(pvector2)NewPtr(sizeof(vector2));
  71.    delta_vec->x=(rcos_table[cur_object->angle]*cur_object->type->stats.base_speed);
  72.    delta_vec->y=(rsin_table[cur_object->angle]*cur_object->type->stats.base_speed);
  73.    cur_object->extra_data=(pdata)delta_vec;
  74. }
  75.  
  76. ULONG Bullet_Message(pobject send_obj, pobject receive_obj, ULONG message, pdata extra_data)
  77. {
  78.    switch (message) {
  79.       case WALL_SLIDE_CONFIRM:
  80.       if (*((BOOL *)extra_data)==TRUE) {
  81.          Switch_Object_Types(receive_obj, Obj_Type_List+EXPLOSION_TYPE);
  82.          return OPERATION_STOP;
  83.       } else {
  84.          return STOP_SLIDE;
  85.       }
  86.      case HIT_BY_OBJ:
  87.      case HIT_OBJ:
  88.          if (Is_Hittable(send_obj)&&(send_obj!=receive_obj->owner)) {
  89.             Stop_Obj(receive_obj, (pobj_collision)extra_data);
  90.             Switch_Object_Types(receive_obj, Obj_Type_List+EXPLOSION_TYPE);
  91.             Give_Damage(send_obj, BULLET_DAMAGE);
  92.             return OPERATION_STOP;
  93.          }
  94.          return NORMAL_MESSAGE;
  95.       default:
  96.          break;
  97.    }
  98. return Default_Message(send_obj, receive_obj, message, extra_data);
  99. }
  100.  
  101.  
  102.