/* ----------------------------------------------- GTASC - GTA adaptation for TI Calculators ----------------------------------------------- Programmed by : Olivier SANGALA Version : 1.2 License : Free under GNU General Public License ( see "gpl.txt" ) Release Date : 05/01/2007 Platform : TI89/TI92+/V200 Website : http://olivier.sangala.free.fr Email : olivier_sangala@hotmail.com ---------- License ---------- Copyright (C) 2002-2007 Olivier SANGALA This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ //----------------------------------------------------------------------------- /* Code for managing objects motions (vehs and peds) */ #include // Include All Header Files #include "defines.h" #include "tmde.h" //--------------------------------------------------------------------------- extern TCamera Camera; extern int scx; extern int scy; //-------------------------------------------------------------------------- // extern extern TGame*Game; //-------------------------------------------------------------------------- int cos_table[16]={16,14,11,6,0,-6,-11,-14,-16,-14,-11,-6,0,6,11,14}; int sin_table[16]={0,6,11,14,16,14,11,6,0,-6,-11,-14,-16,-14,-11,-6}; //--------------------------------------------------------------------------- /* function called once each frame refresh ticks position for all objects method : - backup motion data for all objects - consider keys strokes for main ped/veh , and modify user motion data - modify computer motion data - call events routines for new angle / tile pattern - tick move all objects - flag collisions - step back objects that collide (using push motion data) - flag other collisions (eg : items on map) - flip objects */ void Motion_Tick(void) { TVeh*V=NULL; TPed*P=NULL; TBullet*B=NULL; // save motion data int a=0; V=Game->Vehs; for (a=0;aMD2 = V->MD; P=Game->Peds; for (a=0;aMD2 = P->MD; // ACTIONS : angle / speed / shoot / veh out / veh in // MainP / MainV KB_ProcessGame(); // Computer - Peds P=Game->Peds; for (a=0;aenable) if (P->health) if (P!=Game->MainPed) Ped_CC(P); // Computer - Vehs V=Game->Vehs; for (a=0;aenable) if (V->health) if (V!=Game->MainVeh) Veh_CC(V); // new angle P=Game->Peds; for (a=0;aMD.angle!=P->MD2.angle || P->MD.speed_way!=P->MD2.speed_way) Ped_OnNewAngle(P); V=Game->Vehs; for (a=0;aMD.angle!=V->MD2.angle || V->MD.speed_way!=V->MD2.speed_way) Veh_OnNewAngle(V); // veh tiledata V=Game->Vehs; for (a=0;aMD.angle!=V->MD2.angle) Veh_LoadTD(V); // Motion - Peds P=Game->Peds; for (a=0;aenable) if (P->health) if (!(P==Game->MainPed && Game->MainVeh)) // not ped in veh MD_TickLCD(&P->MD); // Motion - Vehs V=Game->Vehs; for (a=0;aenable) if (V->health) MD_TickLCD(&V->MD); // Motion - Bullets B=Game->Bullets; for (a=0;aenable) MD_TickLCD(&B->MD); // TEST COLLISION - STEPBACK TC_TestALL(); TC_StepBack(); // main ped in veh if (Game->MainVeh) { Game->MainPed->MD.Pos.x=Game->MainVeh->MD.Pos.x+4; Game->MainPed->MD.Pos.y=Game->MainVeh->MD.Pos.y+4; } // OTHER COLLISION TC_Bullet_ALL(); TC_Secret(); TC_Target(); // flags OBJ_ProcessFlags(); // FLIPPING Flip_Objects(); } //--------------------------------------------------------------------------- /* processed tasks : - bullet hit -> remove - ped hurt by bullet - ped runover - veh hurt by bullet - veh hurt by obstacle - veh xplode flag */ void OBJ_ProcessFlags(void) { // bullets int a=0; TBullet*B=Game->Bullets; for (a=0;aenable) { if (B->flag_hit) { B->enable=0; B->flag_hit=0; } } // peds TPed*P=Game->Peds; for (a=0;aenable) { if (P->flag_bullet) { P->flag_bullet=0; Ped_Hurt(P); } if (P->flag_runover) { P->flag_runover=0; Ped_Kill(P); } } // vehs TVeh*V=Game->Vehs; for (a=0;aenable) { if (V->flag_damage) { Veh_Hurt(V,V->flag_damage); V->flag_damage=0; } else if (V->flag_bullet) { V->flag_bullet=0; Veh_Hurt(V,1); } if (V->flag_explode) { V->flag_explode=0; Veh_Blow(V); } } } //--------------------------------------------------------------------------- // tick object, considering number of pixel ticks depending on speed void MD_TickLCD (TMotionData *MD) { MD_GetSPEED23(MD); int a=0; for (a=0;aspeed3;a++) { MD_MoveOnePixel(MD); } } //--------------------------------------------------------------------------- // move one pixel along line with slope (dx,dy) void MD_MoveOnePixel (TMotionData *MD) { // LOAD DATA int dx = MD->dx; int dy = MD->dy; int x=MD->Pos.x; int y=MD->Pos.y; int sc=MD->slope_counter; // PROCESS if (dx==0 && dy==0) return; if (abs(dx) > abs(dy)) { (dx>0) ? x++ : x-- ; sc += abs(dy); if (sc >= abs(dx)) { (dy>0) ? y++ : y-- ; sc -= abs(dx); } } else { (dy>0) ? y++ : y-- ; sc += abs(dx); if (sc >= abs(dy)) { (dx>0) ? x++ : x-- ; sc -= abs(dy); } } // SAVE DATA MD->Pos.x=x; MD->Pos.y=y; MD->slope_counter=sc; } //--------------------------------------------------------------------------- void MD_GetSPEED23(TMotionData *MD) { // speed2 = take care of angle int dist_center_square[16]={16,18,23,18,16,18,23,18,16,18,23,18,16,18,23,18}; MD->speed2 = MD->speed*16/dist_center_square[MD->angle]; // speed3 = move ticks / lcd tick MD->speed3=0; MD->speed_counter += MD->speed2; while (MD->speed_counter >= SPEED_LCD) { MD->speed_counter -= SPEED_LCD; MD->speed3++; } } //--------------------------------------------------------------------------- void MD_OnNewAngle(TMotionData *MD) { MD->speed_counter = 0; MD->slope_counter = 0; int angle2=((4-MD->angle)&15); MD->dx = cos_table[angle2]; MD->dy = -sin_table[angle2]; // speed_way if (MD->speed_way) { MD->dx = -MD->dx; MD->dy = -MD->dy; } } //---------------------------------------------------------------------------