source: abuse/trunk/src/extend.cpp @ 528

Last change on this file since 528 was 512, checked in by Sam Hocevar, 11 years ago

imlib: use vec2i for image::size and unroll all necessary changes
everywhere else in the code.

File size: 3.0 KB
Line 
1/*
2 *  Abuse - dark 2D side-scrolling platform game
3 *  Copyright (c) 1995 Crack dot Com
4 *  Copyright (c) 2005-2011 Sam Hocevar <sam@hocevar.net>
5 *
6 *  This software was released into the Public Domain. As with most public
7 *  domain software, no warranty is made or implied by Crack dot Com or
8 *  Jonathan Clark.
9 */
10
11#include "config.h"
12
13#include "common.h"
14
15#include "extend.h"
16#include "view.h"
17#include "objects.h"
18#include "lisp.h"
19
20/*
21
22
23
24  Simple object             (power ups, non-moving objects)
25    int32_t x,y;
26    int8_t direction;
27    uint16_t otype,state
28    uint16_t current_frame;
29    extension *
30
31
32  Moving object             (simple lisp controlled characters)
33     uint8_t flags;
34     int32_t xvel,yvel,xacel,yacel;
35     uint8_t fx,fy,fxvel,fyvel,fxacel,fyacel,aitype;
36     uint16_t aistate,aistate_time;
37     uint16_t hp,mp,
38     extension *
39
40
41  Complex objects          (can controll lights, other characters, and have a neural net ai)
42    uint8_t tobjs,tlights;
43    object_list *
44    light_list *
45    nnet_info *
46    int8_t fade_dir, frame_dir;
47    uint8_t fade_count,fade_max;
48    morph_char *morph_status;
49
50
51*/
52
53void simple_object::add_light(light_source *ls)
54{
55  if (!ls) return ;
56  ls->known=1;
57  for (int i=0; i<tlights; i++) if (lights[i]==ls) return;
58  tlights++;
59  lights=(light_source **)realloc(lights,sizeof(light_source *)*tlights);
60  lights[tlights-1]=ls;
61}
62
63void simple_object::add_object(game_object *o)
64{
65  if (!o) return ;
66  for (int i=0; i<tobjs; i++) if (objs[i]==o) return;
67  o->set_flags(o->flags()|KNOWN_FLAG);
68  if(_team != -1)
69    o->set_team(_team);
70  if(_tint != -1)
71    o->set_tint(_tint);
72  tobjs++;
73  objs=(game_object **)realloc(objs,sizeof(game_object *)*tobjs);
74  objs[tobjs-1]=o;
75}
76
77
78void simple_object::remove_light(light_source *ls)
79{
80  for (int i=0; i<tlights; i++)
81  {
82    if (lights[i]==ls)
83    {
84      tlights--;
85      for (int j=i; j<tlights; j++)     // don't even think about it :)
86        lights[j]=lights[j+1];
87      lights=(light_source **)realloc(lights,sizeof(light_source *)*tlights);
88      return ;
89    }
90  }
91}
92
93void simple_object::remove_object(game_object *o)
94{
95  for (int i=0; i<tobjs; i++)
96  {
97    if (objs[i]==o)
98    {
99      tobjs--;
100      for (int j=i; j<tobjs; j++)     // don't even think about it :)
101        objs[j]=objs[j+1];
102      objs=(game_object **)realloc(objs,sizeof(game_object *)*tobjs);
103      return ;
104    }
105  }
106}
107
108
109simple_object::simple_object()
110{
111
112  x=y=0;
113  direction=1;
114  otype=0;
115  state=stopped;
116  current_frame=0;
117
118  Fade_dir=0;
119  Fade_count=0;
120  Fade_max=16;
121
122
123  tobjs=tlights=0;
124  objs=NULL;
125  lights=NULL;
126  Frame_dir=1;
127  mc=NULL;
128  Controller=NULL;
129
130  Flags=0;
131  Xvel=Yvel=Xacel=Yacel=0;
132  Fx=Fy=Fxvel=Fyvel=Fxacel=Fyacel=Aitype=0;
133  Aistate=Aistate_time=0;
134  Hp=Mp=Fmp=0;
135  _tint = -1;
136  _team = -1;
137  grav_on=1;
138  targetable_on=1;
139}
140
141
142
143void simple_object::set_morph_status(morph_char *Mc)
144{
145  mc=Mc;
146}
147
148void simple_object::clean_up()
149{
150  if (tlights) free(lights);
151  if (tobjs)   free(objs);
152  if (Controller)
153    Controller->focus=NULL;
154}
155
156
157simple_object default_simple;
158
159
Note: See TracBrowser for help on using the repository browser.