1 /*
2 Copyright (C) 2000 Xavier Hosxe <xhosxe@free.fr>
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 */
18
19
20
21 #include "sprite.hpp"
22
Sprite(List * list)23 Sprite::Sprite(List *list)
24 : Elem(list)
25 {
26 type_ = TYPE_UNDEF;
27 sizex_ = sizez_ = dx_ = x_ = y_ = dy_ = z_ = dz_ = 0;
28 dead_=0;
29 bRealEnemy=false;
30 for (int i=0; i<MAX_LISTENING; i++) {
31 listeningSprite[i]=NULL;
32 }
33 nListeningSprite=0;
34 }
Sprite(List * list,type_sprites type,float x,float y,float z)35 Sprite::Sprite(List *list, type_sprites type, float x, float y, float z)
36 : Elem(list)
37 {
38 type_= type;
39 x_=x;
40 y_=y;
41 z_=z;
42 sizex_ = sizez_ = dx_=dy_=dz_=0;
43 dead_=0;
44 bRealEnemy=false;
45 for (int i=0; i<MAX_LISTENING; i++) {
46 listeningSprite[i]=NULL;
47 }
48 nListeningSprite=0;
49 }
50
move()51 void Sprite::move()
52 {
53 x_+=dx_*GLvar->global_timeadjustment;
54 y_+=dy_*GLvar->global_timeadjustment;
55 z_+=dz_*GLvar->global_timeadjustment;
56 }
57
58
59 #ifdef HAVE_LIBSDL_MIXER
SpritePlaySample(type_samples sampleToPlay,int volume)60 void Sprite::SpritePlaySample(type_samples sampleToPlay,int volume) {
61 if (z_<63) {
62 int v=Mix_PlayChannel(-1,GLvar->samples[sampleToPlay], 0);
63 Mix_Volume(v, (int)((63-z_)*2)*volume/128);
64 }
65 }
PlaySample(type_samples sampleToPlay,int volume)66 void Sprite::PlaySample(type_samples sampleToPlay,int volume) {
67 if (GLvar->samples[sampleToPlay])
68 {
69 int v=Mix_PlayChannel(-1,GLvar->samples[sampleToPlay], 0);
70 Mix_Volume(v, volume);
71 }
72 }
73 #else
74 /* must exist because it has one or two parameters...
75 so no defined is possible. */
SpritePlaySample(type_samples sampleToPlay,int volume)76 void Sprite::SpritePlaySample(type_samples sampleToPlay,int volume) {
77 }
PlaySample(type_samples sampleToPlay,int volume)78 void Sprite::PlaySample(type_samples sampleToPlay,int volume) {
79 }
80 #endif
81
82
addListeningSprite(Sprite * toAdd)83 bool Sprite::addListeningSprite(Sprite*toAdd) {
84 bool ok=false;
85 int i=0;
86 do {
87 if (listeningSprite[i]==NULL) {
88 listeningSprite[i]=toAdd;
89 ok=true;
90 nListeningSprite++;
91 // printf("++ I'm 0x%x and i ADD 0x%x to my list position [%d]\n", this, toAdd,i);
92 }
93 i++;
94 } while (i<MAX_LISTENING && !ok);
95 return ok;
96 }
97
removeListeningSprite(Sprite * toRemove)98 void Sprite::removeListeningSprite(Sprite*toRemove) {
99 for (int i=0; i<MAX_LISTENING; i++) {
100 if (listeningSprite[i]==toRemove) {
101 // printf("-- I'm 0x%x and i REMOVE 0x%x from my list position [%d]\n", this, toRemove,i);
102 listeningSprite[i]=NULL;
103 nListeningSprite--;
104 i=MAX_LISTENING;
105 }
106 }
107 }
108
iJustDied()109 void Sprite::iJustDied() {
110 if (nListeningSprite==0) {
111 return;
112 }
113 for (int i=0; i<MAX_LISTENING; i++) {
114 if (listeningSprite[i]!=NULL) {
115 // printf("##### I'm 0x%x and i Tell 0x%x i'm dead\n", this,listeningSprite[i]);
116 listeningSprite[i]->receiveEvent(this);
117 }
118 }
119 }
120
receiveEvent(Sprite * sprite)121 void Sprite::receiveEvent(Sprite*sprite) {
122 }
123
124
125
126
127
128
129