source: golgotha/src/golg/objs/flak.cc @ 80

Last change on this file since 80 was 80, checked in by Sam Hocevar, 11 years ago
  • Adding the Golgotha source code. Not sure what's going to be interesting in there, but since it's all public domain, there's certainly stuff to pick up.
File size: 2.6 KB
Line 
1/********************************************************************** <BR>
2  This file is part of Crack dot Com's free source code release of
3  Golgotha. <a href="http://www.crack.com/golgotha_release"> <BR> for
4  information about compiling & licensing issues visit this URL</a>
5  <PRE> If that doesn't help, contact Jonathan Clark at
6  golgotha_source@usa.net (Subject should have "GOLG" in it)
7***********************************************************************/
8
9#include "objs/flak.hh"
10#include "map.hh"
11#include "map_man.hh"
12#include "objs/light_o.hh"
13#include "g1_render.hh"
14#include "time/profile.hh"
15#include "object_definer.hh"
16#include "r1_api.hh"
17#include "math/pi.hh"
18#include "objs/particle_emitter.hh"
19#include "sound_man.hh"
20#include "sound/sfx_id.hh"
21#include "resources.hh"
22#include "g1_rand.hh"
23#include "lisp/li_class.hh"
24#include "draw_context.hh"
25#include "r1_clip.hh"
26
27S1_SFX(flak_sfx, "misc/total_miss_1.wav", S1_3D, 70);
28
29static r1_texture_ref flak("lil_flak");
30
31g1_object_definer<g1_flak_class>
32g1_flak_def("flak", 0);
33
34g1_flak_class::g1_flak_class(g1_object_type id, g1_loader_class *fp)
35  : g1_object_class(id, fp)
36{
37  time = 0;
38  x = -1;
39}
40
41void g1_flak_class::setup(const i4_3d_vector &pos, i4_float _size)
42{
43  x=lx=pos.x;
44  y=ly=pos.y;
45  h=lh=pos.z;
46  size = _size;
47
48  if (!occupy_location())
49    return;
50
51  request_think();
52  flak_sfx.play(x,y,h);
53}
54
55void g1_flak_class::think()
56{
57  time++;
58
59  if (time<4)
60    request_think();
61  else
62  {
63    unoccupy_location();
64    request_remove();
65  }
66}
67
68void g1_flak_class::draw(g1_draw_context_class *context)
69{
70  i4_3d_vector screen_pos;
71  context->transform->transform(i4_3d_point_class(x,y,h), screen_pos);
72
73  i4_float center_x=g1_render.center_x, center_y=g1_render.center_y;
74  i4_float w  = 1 / screen_pos.z;
75  i4_float xs = center_x * w * g1_render.scale_x;
76  i4_float ys = center_y * w * g1_render.scale_y;
77
78  if (screen_pos.z > r1_near_clip_z)
79  {
80    i4_float
81      cx=center_x + screen_pos.x*xs,
82      cy=center_y + screen_pos.y*ys,
83      sz=size * center_x * w;
84    int frame = time;
85    i4_float
86      s = i4_float(frame%2)*0.5,
87      t = i4_float(frame/2)*0.5;
88       
89    r1_clip_render_textured_rect(i4_f_to_i(cx-sz), i4_f_to_i(cy-sz),
90                                 i4_f_to_i(cx+sz), i4_f_to_i(cy+sz),
91                                 screen_pos.z, 0.7,
92                                 i4_f_to_i(center_x*2), i4_f_to_i(center_y*2),
93                                 flak.get(), 0, g1_render.r_api,
94                                 s,t,s+0.5,t+0.5);
95  }
96}
Note: See TracBrowser for help on using the repository browser.