00001
00002
00003
00004
00005 #include <memory.h>
00006 #include <ALL.H>
00007 #include <GAMEDEF.H>
00008 #include <OMISC.H>
00009 #include <ORECT.H>
00010 #include <OSPRITE.H>
00011 #include <OSPRTRES.H>
00012 #include <OWORLD.H>
00013 #include <OWORLDMT.H>
00014 #include <OMATRIX.H>
00015
00016
00017 #include <OVGA.H>
00018
00019
00020
00021
00022 Sprite::Sprite() {
00023
00024 memset( (char *)this + sizeof(void *), 0, sizeof(Sprite) - sizeof(void *) );
00025 }
00026
00027
00028
00029
00030 Sprite::~Sprite() {
00031 deinit();
00032 }
00033
00034
00035
00036
00037 void Sprite::init(short spriteId, short startXLoc, short startYLoc, char startSubXLoc, char startSubYLoc) {
00038 sprite_id = spriteId;
00039
00040 go_x = next_x = cur_x = startXLoc;
00041 go_y = next_y = cur_y = startYLoc;
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052 sprite_id = 1;
00053 err_here();
00054
00055
00056 sprite_info->load_bitmap_res();
00057
00058
00059
00060 set_abs(ZOOM_SMALL , MAP_LOC_WIDTH , MAP_LOC_HEIGHT);
00061 set_abs(ZOOM_MEDIUM, ZOOM1_LOC_WIDTH, ZOOM1_LOC_HEIGHT);
00062 set_abs(ZOOM_LARGE , ZOOM2_LOC_WIDTH, ZOOM2_LOC_HEIGHT);
00063
00064 will_not_move_next_process = 0;
00065 }
00066
00067
00068
00069
00070 void Sprite::deinit() {
00071 world.get_loc(cur_x, cur_y)->remove_sprite();
00072 }
00073
00074
00075
00076
00078
00079 }
00080
00081
00082
00083
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098 return NULL;
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167 }
00168
00169
00170
00171
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189 }
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211
00212
00213
00214
00215
00216
00217
00218
00219
00220
00221
00222
00223
00224
00225
00226
00227
00228
00232
00233
00234
00235
00236
00237
00238
00239
00240
00241 int zoomLevel = matrixPtr->zoom_level;
00242 int bmpWidth = sprite_info->bitmap_width[zoomLevel];
00243 int bmpHeight = sprite_info->bitmap_height[zoomLevel];
00244
00245
00246 err_when( !sprite_info->res_bitmap[zoomLevel].init_flag );
00247 char* bmpPtr = sprite_info->bitmap_ptr[zoomLevel];
00248
00249
00250
00251 int x1 = abs_rect[zoomLevel].x1 - matrixPtr->abs_top_x;
00252
00253
00254 if( x1 <= -bmpWidth || x1 >= matrixPtr->win_width )
00255 return;
00256
00257 int y1 = abs_rect[zoomLevel].y1 - matrixPtr->abs_top_y;
00258
00259 if( y1 <= -bmpHeight || y1 >= matrixPtr->win_height )
00260 return;
00261
00262 int x2 = abs_rect[zoomLevel].x2 - matrixPtr->abs_top_x;
00263 int y2 = abs_rect[zoomLevel].y2 - matrixPtr->abs_top_y;
00264
00265 if( x2 < 0 || y2 < 0 )
00266 return;
00267
00268
00269
00270 if( x1 < 0 || x2 >= matrixPtr->win_width || y1 < 0 || y2 >= matrixPtr->win_height ) {
00271 vga_back.put_bitmap_area_trans_decompress( x1+matrixPtr->win_x1, y1+matrixPtr->win_y1, bmpPtr,
00272 max(0,x1)-x1, max(0,y1)-y1, min(matrixPtr->win_width-1,x2)-x1, min(matrixPtr->win_height-1,y2)-y1);
00273 }
00274
00275
00276
00277 else {
00278 vga_back.put_bitmap_trans_decompress( x1+matrixPtr->win_x1, y1+matrixPtr->win_y1, bmpPtr);
00279
00280
00281
00282
00283
00284
00285
00286
00287
00288
00289
00290
00291
00292
00293
00294
00295 }
00296 }
00297
00298
00299
00300
00301 void Sprite::process() {
00302 if ( will_not_move_next_process ) {
00303 will_not_move_next_process = (will_not_move_next_process+1)%10;
00304 return;
00305 }
00306 else
00307 will_not_move_next_process = 1;
00308
00309
00310
00311 go_x = cur_x;
00312 go_y = cur_y;
00313
00314 go_x += m.random(3) - 1;
00315 go_y += m.random(3) - 1;
00316
00317 Location* locPtr = world.get_valid_loc(go_x, go_y);
00318
00319 if ( !locPtr || !locPtr->is_walkable() || locPtr->has_sprite() )
00320 return;
00321
00322 world.get_loc(cur_x, cur_y)->remove_sprite();
00323 cur_x = go_x; cur_y = go_y;
00324 locPtr->set_sprite(sprite_recno);
00325
00326 set_abs(ZOOM_SMALL , MAP_LOC_WIDTH , MAP_LOC_HEIGHT);
00327 set_abs(ZOOM_MEDIUM, ZOOM1_LOC_WIDTH, ZOOM1_LOC_HEIGHT);
00328 set_abs(ZOOM_LARGE , ZOOM2_LOC_WIDTH, ZOOM2_LOC_HEIGHT);
00329
00330 }
00331
00332