hello guys all, it is ashame here to put a such post here,but anyway i need your help.
and my wanted help includes,first smooth the game logic, fix up the structure,and then give some advice on the code aspect,and mainly on the first two parts which are mostly interested for me,thx again,you guys.great apprecaitions,and thanks tons.
if i get needy help,when the project is finished,i will post all the project here for your kindness!
regards,
jolley
//road and windows info
#define ROAD_WIDTH 100
#define ROAD_HEIGHT 150
#define WINDOWS_WIDTH 600
#define WINDOWS_HEIGHT 800
//moving objects mass
#define CAR_MASS 2
#define RACINGCAR_MASS 4
#define CANVAS_MASS 4
#define DIFFERENCE_MASS 2//the sustraction between racing car and canvas,or car
#define PEOPLE_MASS 5
//conversion rate
#define ACTUAL_CAR_RATE 0.8 //adjust width of the actual size
#define FULLBLOOD 1000// the full blood
#define FORCE_TO_BLOOD_RATE 0.2 // the rate that force is converted into blood
#define TIME_TO_BLOODLOSS 20 //the time spending outside of the road is converted into blood loss
#include <stdio.h>
#include <time.h>
#include "Draw.h"
#include "Input.h"
#include "Sound.h"
#include "SafeRelease.h"
#include <math.h>
//------------structs-----------------------------
typedef struct
{
int x,y;//position
int speed;
int width,height;//width and height of the car categories
}*racingCarInfo,*WanderingCarInfo;//a structure for racing car and wandering car
typedef struct
{
int x,y;
int speed;
}*peopleInfo;
class CGame
{
public:
CGame();
~CGame();
//console part
void Game_Init(HWND hWnd,HINSTANCE hInstance);//the initialization of some other devices,initialize all resources
void Game_Main(HWND hWnd,UINT message,HINSTANCE hInstance);//the logical handling here
void Game_Shutdown();//the shutdown of some devices after not using it
void Game_Run(HWND hWnd,UINT message,HINSTANCE hInstance);//the run of the game
void Game_Terminate(UINT message,HINSTANCE hInstance);//terminate the game
//timer system
DWORD Record_Used(UINT message);//keep a record of the time elapsed.
DWORD Record_Remaining(UINT message,HINSTANCE hInstance);//record the remaining time for the player,not the state that the key is pressed
void Calculate_acceleration();//the acceleration that the car receives after the collision
int Calculate_Score();//calculate the score received.distance+collison information-peopleHit*100
DWORD Calculate_Distance();//calculate the distance that the car covered.
void Count_PeopleHit();//count the number of people that is hit.
void speedAfterCollision();
DWORD Calculate_Blood();//count the blood.
void Refresh_Blood();//fill the player with full blood.
bool Collide_Car();//detect car collision, and calculate the damage. draw the picture.
bool Collide_People();//detect people collision, and draw the picture.
//void Terminate_Game();//put the game to an end.
void Update_Speed();//update the speed based on a policy of time that is spent on the pressed button
COffScreen* m_pSurfaceBackground;
COffScreen* m_pSurfaceForeword;//foreoword and instruction of the very game
COffScreen* m_pSurfaceSpeedControl[5];
COffScreen* m_pSurfaceClock;
DWORD m_timeNow;//save system time.
DWORD m_dwDistance;
int m_peopleHit;
int m_accWc;//Wandering car's acceleration
int m_accRc;//Racing car's acceleration
int m_rc_speed;//racing car's speed before colliding
int m_wc_speed;//wandering car's speed before colliding
int m_rc_updatedSpeed;
racingCarInfo m_rc;
WanderingCarInfo m_wc1,m_wc2;//information on wandering car and canvasafter colliding
peopleInfo m_ppInfo;//information on people
int m_collisonType;//1:total non-stretch collision and 0: total stretch collision
int m_carType;//the car type
int m_gameState;
HWND m_hWnd;
HINSTANCE m_hInstance;
};
ps:the attached part is a flash model by peers.if finding any time,can u feel the game? thx in advance
regards,
jolley
//load bitmaps to create surfaces. every bitmap corresponds to every surface
void CGame::Game_Init(HWND hWnd,HINSTANCE hInstance)
{
//other devices such as input and sound are not added just for simplicity
m_hWnd = hWnd;
m_pDraw = new CDraw;
if( m_bWindowed )//if it is windowed,then choose windowed screen
{
m_pDraw->CreateWindowedDisplay(m_hWnd,800,600 );
}
//put the bitmaps in surfaces
m_pDraw->CreateOffScr(&m_pSurfaceBackground,800,600);
m_pSurfaceBackground->DrawBitmap(".\\picture\\background.bmp",800,600);
m_pSurfaceBackground->SetColorKey(RGB(255,255,0),RGB(255,255,0));
//handle all games states
void CGame::Game_Main(HWND hWnd,UINT message,HINSTANCE hInstance)
{
int error;
//game logic handling
//if the game is proceeding
while(m_gameState!=GAME_EXIT)
{
//check all the game state one by one
switch(m_gameState)
{
case GAME_INIT://game is initializing
{
//HRESULT Game_Init(HWND hWnd,HINSTANCE hInstance)
Game_Init(hWnd,hInstance);//allocate all memory and resource
//convert to the menu mode
m_gameState = GAME_MENU;
} break;
case GAME_MENU://game is on the menu mode
{
//handling those menus; call the main menu functions, and let the work be done.
//can convert to running state.
}break;
case GAME_START://game is starting
{
//optional, usually is used for preparation
//also some work before clearup.
//prepare for initializing
//can convert to the running state.
//g_gm_situation = GAME_RUNNING;
}break;
case GAME_RUNNING://game is running
{
//in this part, all game logic cycle is included
//clear up the screen Clear()
//read inputs,Get_Input()
//execute logic and AI
//display the next frame
//adjust the synchronization display speed to 30 fps Wait
//the only way to change the way of game is by means of interaction
Game_Run(hWnd,message,hInstance);
}break;
case GAME_RESTART://game id restarting
{
//this is the clearup part
//aiming at clearing up problems before restarting games
//Fixup
//convert to the menu mode
m_gameState = GAME_MENU;
}break;
case GAME_EXIT://game is exiting
{
//if the game is in the state,
//then release all the resources that are occuplied
// Release_And_Cleanup();
//set the variable error
error = 0;
//convert no state here.
}break;
default:
break;
}
}
}
//when on the left/right direction,and between road width and windows width,calcaulate the x/y,and reduce the blood
void CGame::racingCarXYBlood()
{
m_rc->x+=OFFSET;
m_rc->y=Calculate_Distance();
//here the reduced blood is based on current (x-coordination-windows/2)/current speed *TIME_TO_BLOODLOSS
//TIME_TO_BLOODLOSS is a macro which converts used time to blood loss liberally
m_dBlood= FULLBLOOD - (fabs(m_rc->x - WINDOWS_WIDTH/2)/m_rc_updatedSpeed)*TIME_TO_BLOODLOSS;
}
//hanle the right button which directs towards right
void CGame::processRightButtonInput(UINT message,HINSTANCE hInstance)//right button input
{
racingCarXYBlood();//update xy coordination and blood
if(m_dBlood ==0)
{
Game_Terminate(message,hInstance);
}
else
{ //when trying to exceed the window_width/2,then it is told to be unmovable.
if(m_rc->x >=WINDOWS_WIDTH/2)
{
m_bMovable = false;
}
}
}
//hanle the right button which directs towards right
void CGame::ProcessLeftButtonInput(UINT message,HINSTANCE hInstance)//left button input
{
racingCarXYBlood();//update xy coordination and blood
if(m_dBlood ==0)
{
Game_Terminate(message,hInstance);
}
else
{//when trying to exceed -window_width/2,then it is told to be unmovable.
//obviously the window is broken into two parts
if(m_rc->x <=-WINDOWS_WIDTH/2)
{
m_bMovable = false;
}
}
}
//judge whether car and racing car collision happens,and set the flags
void CGame::IsCarCrashed()
{
}
//judge whether people and racing car collision happens,and set the flags
void CGame::IsPeopleCrashed()
{
if(Collide_People())
{
m_bPeopleCrashed = true;
}
else
{
m_bPeopleCrashed = false;
}
}
//the blood rectangle is designed to supply the racing car with full blood
//and only when the distance is 2000,or 4000,it can be updated the blood at a rectangle.
//which the rectangle is limited by the following macros
bool CGame::IsBloodRect()
{
if(Calculate_Distance()%2000 ==0 &&((m_rc->x >BLOOD_RECT_WIDTH_UNDER )&&(m_rc->x<BLOOD_RECT_WIDTH_ABOVE))&&
((m_rc->y>BLOOD_RECT_HEIGHT_UNDER)&&(m_rc->y<BLOOD_RECT_HEIGHT_ABOVE)))
return true;
return false;
}
//provided racing car collision fails to two parts,then it will draw bitmaps respectively
void CGame::drawCarColliding()
{
m_pDraw = new CDraw;
if(m_rc->speed > m_wc1->speed)
{
m_pDraw->BltBitmap(400,500,m_pSurfaceCollidingIntoCar,NULL);//here we should create a surface like collidinginto
}
else
{
m_pDraw->BltBitmap(400,500,m_pSurfaceBeingCrashed,NULL);//here we should create a ".//picture//carCrashed.bmp"
}
}
//the main part of the game,run the game
void CGame::Game_Run(HWND hWnd,UINT message,HINSTANCE hInstance)//the run of the game
{
IsReadyMovable();
//input processing
if(m_bReady)
{
if(m_pInput->IsKeyDown(DIK_RIGHT))//if u are pressing RIGHT arow button down
{ if(m_bMovable)
{
processRightButtonInput( message,hInstance);
}
else//if can not movable,then terminate the game
{
Game_Terminate(message,hInstance);
}
}
else if(m_pInput->IsKeyDown(DIK_LEFT))//if u are pressing RIGHT arow button down
{
if(m_bMovable)
{
ProcessLeftButtonInput( message,hInstance);
}
else
{
Game_Terminate(message,hInstance);
}
}
else if (m_pInput->IsKeyDown(DIK_UP))//if u are pressing RIGHT arow button down
{
if(m_bMovable)
{
m_rc->y+=Calculate_Distance();//record the distance that the racing car covers
while(1)
{
Update_Speed();//update speed by the time spending on pressing the button
Calculate_Distance();//Update distance by updated speed
Record_Used(message);//start to record the time
if(IsBloodRect())//if it comes to the blood rectangle,which can update the blood
{
Refresh_Blood();
}
IsCarCrashed();//judge whether the car is crashed
IsPeopleCrashed();//judge whether the people is crashed
if(m_bCarCrashed)//if car is crashed,then draw the bitmaps.
{
drawCarColliding();
}
else
{
;
}
if(m_bPeopleCrashed)
{ //draw picture that people is killed!
m_pDraw->BltBitmap(229,270,m_pSurfacePeopleAndRacingCar,NULL);
m_pDraw->BltBitmap(229,270,m_pSurfacePeopleAndRacingCarCrashed,NULL);
m_peopleHit++;
m_dBlood = (fabs(m_rc->x - WINDOWS_WIDTH/2)/m_rc->speed)*TIME_TO_BLOODLOSS;
if(m_dBlood ==0)
{
Game_Terminate(message,hInstance);
}
else
{
if(m_rc->x <=-WINDOWS_WIDTH/2)
{
m_bMovable = false;
}
else
{
m_dBlood = (fabs(m_rc->x - WINDOWS_WIDTH/2)/m_rc->speed)*TIME_TO_BLOODLOSS;
}//still can be movable,and continue to reduce blood
}
}
else
{
}//still can not crash
}
}
}
else if(m_pInput->IsKeyDown(DIK_DOWN))
{
if(m_bMovable)
{
m_rc->y-=Calculate_Distance();
while(1)
{
Update_Speed();//update speed by the time spending on pressing the button
Calculate_Distance();//Update distance by updated speed
Record_Used(message);//start to record the time
if(Calculate_Distance()%2000 ==0 && (IsBloodRect()))
{
Refresh_Blood();
}
IsCarCrashed();//judge whether the car is crashed
IsPeopleCrashed();//judge whether the people is crashed
if(m_bCarCrashed)
{
drawCarColliding();
}
else
{
;
}
if(m_bPeopleCrashed)
{
m_pDraw->BltBitmap(229,270,m_pSurfacePeopleAndRacingCar,NULL);
m_pDraw->BltBitmap(229,270,m_pSurfacePeopleAndRacingCarCrashed,NULL);
m_peopleHit++;
m_dBlood = (fabs(m_rc->x - WINDOWS_WIDTH/2)/m_rc->speed)*TIME_TO_BLOODLOSS;
if(m_dBlood ==0)
{
Game_Terminate(message,hInstance);
}
else
{
if(m_rc->x <=-WINDOWS_WIDTH/2)
{
m_bMovable = false;
}
else
{;}
}
}
else
{;}
}//while
}//if(m_bMovable)
}//else if(m_pInput->IsKeyDown(DIK_DOWN))
else
{;}//any other keyboard is left unhandled.
}
else //if not ready,then it should be Initialized
{
Game_Init(hWnd, hInstance);
}
}
}
jolley
April 20th, 2006, 05:24 AM
//judge the conditions and terminate the game accordingly.
void CGame::Game_Terminate(UINT message,HINSTANCE hInstance)
{
//if distance>=11000
if(Calculate_Distance()>=11000)
{
//if score <3000
if(Calculate_Score()<3000)
{
printf("congratulations,but you need more points!:),><");
}
//if blood <FULLBLOOD
else if(Calculate_Blood() < FULLBLOOD)
{
printf("congratulations,but your car is crashed!:) ><");
}
//output the disatance and score,and people hit
else
{
printf("%lf",m_dwDistance);
printf("\n");
printf("%ld",Calculate_Score());
printf("%d",m_peopleHit);
}
}
else
{
//if blood is not enough, and can not move
if(Calculate_Blood() < FULLBLOOD&&!m_bMovable)
{
printf("sorry,the blood is used up,the game is stopped:(")//this can be advanced to print it out in a certain position
}
//if time is up and can not move
else if(Record_Remaining(message,hInstance)==0&&!m_bMovable)
{
printf("sorry,the time is up,the game is stopped:(");
}
else
{
printf("it is crashed!");
}
}
exit(0);
}
//update the speed according to the time that the up arrow key is pressed
//the idea is when u pressing 0<x<10,then your speed increase SPEED_FIRST,
//when the time is 10<x<15,then your speed increase SPEED_SECOND,and the similar things follows that
//however,when the speed exceeds SPEED_FIFTH,it can not exceed any more,and just keep the velocity.
//when the button is released,corresponding actions are taken as follow:
void CGame::Update_Speed(UINT message)
{
switch(message)
{ //if pressed
case WM_KEYDOWN:
{
if(0<fabs(Record_Used(message)) && fabs(Record_Used(message)) < 10 )
//if the time spent on pressing the key button is 0<pressTime<10
{
//set the racing car the FIRST_SPEED
m_rc_updatedSpeed+= SPEED_FIRST;
if(m_rc_speed > SPEED_FIFTH )
{
m_rc_updatedSpeed = SPEED_FIFTH;
}
m_rc->speed = m_rc_updatedSpeed;
}
else if(10<fabs(Record_Used(message)) && fabs(Record_Used(message)) <15)
//if the time spent on pressing the key button is 10<pressTime<15
{
//set the racing car the SECOND_SPEED
m_rc_updatedSpeed+= SPEED_SECOND;
if(m_rc_speed > SPEED_FIFTH )
{
m_rc_updatedSpeed = SPEED_FIFTH;
}
m_rc->speed = m_rc_updatedSpeed;
}
else if(15<fabs(Record_Used(message)) && fabs(Record_Used(message)) < 20)
//see comments above
{
m_rc_updatedSpeed+= SPEED_THIRD;
if(m_rc_speed > SPEED_FIFTH )
{
m_rc_updatedSpeed = SPEED_FIFTH;
}
m_rc->speed = m_rc_updatedSpeed;
}
else if(20<fabs(Record_Used(message)) && fabs(Record_Used(message)) < 25)
{
m_rc_updatedSpeed+= SPEED_FOURTH;
if(m_rc_speed > SPEED_FIFTH )
{
m_rc_updatedSpeed = SPEED_FIFTH;
}
m_rc->speed = m_rc_updatedSpeed;
}
else
{
m_rc_updatedSpeed = SPEED_FIFTH;
m_rc->speed = m_rc_updatedSpeed;
}
}break;
case WM_KEYUP:
{
if(0<fabs(Record_Used(message)) && fabs(Record_Used(message)) < 10 )
//if the time spent on pressing the key button is 0<pressTime<10
{
//set the racing car the FIRST_SPEED
m_rc_updatedSpeed-= SPEED_FIRST;
if(m_rc_speed < SPEED_FIRST )
{
m_rc_updatedSpeed = SPEED_FIRST;
}
m_rc->speed = m_rc_updatedSpeed;
}
else if(10<fabs(Record_Used(message)) && fabs(Record_Used(message)) <15)
//if the time spent on pressing the key button is 10<pressTime<15
{
//set the racing car the SECOND_SPEED
m_rc_updatedSpeed-= SPEED_SECOND;
if(m_rc_speed < SPEED_FIRST)
{
m_rc_updatedSpeed = SPEED_FIRST;
}
m_rc->speed = m_rc_updatedSpeed;
}
else if(15<fabs(Record_Used(message)) && fabs(Record_Used(message)) < 20)
//see comments above
{
m_rc_updatedSpeed-= SPEED_THIRD;
if(m_rc_speed < SPEED_FIRST )
{
m_rc_updatedSpeed = SPEED_FIRST;
}
m_rc->speed = m_rc_updatedSpeed;
}
else if(20<fabs(Record_Used(message)) && fabs(Record_Used(message)) < 25)
{
m_rc_updatedSpeed-= SPEED_FOURTH;
if(m_rc_speed > SPEED_FIRST )
{
m_rc_updatedSpeed = SPEED_FIRST;
}
m_rc->speed = m_rc_updatedSpeed;
}
else
{
m_rc_updatedSpeed = SPEED_FIRST;
m_rc->speed = m_rc_updatedSpeed;
}
}break;
default:
break;
}
}
//accumulate the distance depending on the speed,if the current speed is 0,then record the previous distance,
//if not,add them up to the total distance.
DWORD CGame::Calculate_Distance(UINT message,WPARAM wParam)
{
if(m_rc_updatedSpeed)
{
m_dwDistance += m_rc_updatedSpeed * Record_Used(message,wParam);//accumulated the original distance
return m_dwDistance;
}
else
{
if(m_dwDistance)
{
return m_dwDistance;
}
else
{
return 0;
}
}
}
//record the time when the button is pressed up and down
DWORD CGame::Record_Used(UINT message)
{
DWORD timeOld=0;
DWORD timeNew;
switch(message)
{
case WM_KEYDOWN:
{
timeOld = GetTickCount();
//start to record the time.and donot break out the case.
switch (wParam)
{
case VK_ESCAPE://when clicking the exit button
{
timeOld = 0;//put the time to zero.
PostQuitMessage(0);//terminate the run.
break;
}
default:
break;
}
}
case WM_KEYUP:
{
timeNew = GetTickCount();
break;
//when the key is up at the moment,the time is recorded,
}
default:
break;
}
return (timeNew - timeOld);//return back the elapsed time.
}
//record the time when the game is going on
DWORD CGame::Record_Remaining(UINT message,HINSTANCE hInstance)
{
DWORD timeOld,timeNew;
if(m_dReady==true)//is ready
{
if(m_bMovable==false)//is not movable
{
timeOld = GetTickCount();//record the time before running the game
}
}
Game_Run(message, hInstance);//run the game
if(m_bMovable==false)//is not movable
{
timeNew = GetTickCount();//record the time after running the game
}
return (MAX_TIME_ALLOW - timeNew + timeOld);//return the remaining time.design the time for 2 seconds.
}
//whether the racing car is ready or movable.
//if the game is initialized,then the movable and ready flag is set true.
void CGame::IsReadyMovable()
{
if(m_bInitialised)
{
m_bMovable = true;
m_dReady = true;
}
else
{
m_bMovable = true;
m_dReady = true;
}
// to reduce the loss of precision
//because of width and height of the car does not change,
//so here we use m_wc1 for simplicity.
col_width = m_wc1->width*ACTUAL_CAR_RATE;
col_height = m_wc1->height*ACTUAL_CAR_RATE;
col_x_offset = (m_wc1->width - col_width)/2;
col_y_offset = (m_wc1->height - col_height)/2;
//this is a flaw that the x/y coordination should be
left1 = m_wc1->x + col_x_offset;
left2 = m_rc->x + col_x_offset;
right1 = m_wc1->x + m_wc1->width;
right2 = m_rc->x + m_rc->width;
top1 = m_wc1->y + col_y_offset;
top2 = m_rc->y + col_y_offset;
bottom1 = m_wc1->y + m_wc1->height;
bottom2 = m_rc->y + m_rc->height;
return 1;
}
//the code here is mainly using pixel collision,though the code is needed updating urgently.
bool CGame::Collide_People()
{
HDC hDC,hDC1,hDC2,hDC3,hDCTemp;
hDC = ::CreateCompatibaleDC(NULL);//HDC for background
hDC1 = ::CreateCompatibaleDC(NULL);//HDC for car
hDC2 = ::CreateCompatibaleDC(NULL);//HDC for people
hDC3 = ::CreateCompatibleDC(NULL);//HDC for mask
hDCTemp = ::CreateCompatibleDC(NULL);
//load the car bitmap
HBITMAP car_bitmap = (HBITMAP)::LoadImage(NULL,"car bitmap",
IMAGE_BITMAP,112,64,LR_LOADFROMFILE);
//load the people bitmap
HBITMAP people_bitmap = (HBITMAP)::LoadImage(NULL,"people bitmap",
IMAGE_BITMAP,800,300,LR_LOADFROMFILE);
//load the mask bitmap
HBITMAP mask_bitmap = (HBITMAP)::LoadImage(NULL,"mask bitmap",
IMAGE_BITMAP,800,300,LR_LOADFROMFILE);
//load the background bitmap
HBITMAP background_bitmap = (HBITMAP)::LoadBitmap(NULL,"background bitmap",
IMAGE_BITMAP,800,300,LR_LOADFROMFILE);
//bitmap for dark as default.
HBITMAP dark;
BITMAP bm;
SelectObject(hDC,background_bitmap);//associate background with hDC
//BitBlt(hDC,0,0,width,height,hDC1,0,0,WHITENESS);//see above
SelectObject(hDC1,car_bitmap);//associate car_bitmap with hDC1
//::BitBlt(hDC1,0,0,width,height,hDC2,0,0,SRCCOPY);//see above
SelectObject(hDC2,people_bitmap);//associate people_bitmap with hDChDC2
//::BitBlt(hDC2,0,0,width,height,hDC,0,0,SRCCOPY);
SelectObject(hDC3,mask_bitmap);//associate mask_bitmap with hDC3
SelectObject(hDCTemp,dark);//associate dark with hDCTemp
GetObject(car_bitmap,sizeof(BITMAP),&bm);//get the bitmap information from car_bitmap
unsigned char* px = new unsigned char[bm.bmHeight*bm.bmWidthBytes];//a new array for storing the bitmap
////copies the bitmap bits of a specified device-dependent bitmap into a buffer
GetBitmapBits(car_bitmap,bm.bmHeight*bm.bmWidthBytes,px);
//provided only for compatibility with 16-bit versions of Windows
if(bm.bmBitsPixel == 32)
{
return;
}
CreateCompatibleBitmaps(dark,112,64);//build up Bitmaps compatible with the device context
GetObject(dark,sizeof(BITMAP),&bm);
unsigned char* px1 = new unsigned char[bm.bmHeight*bm.bmWidthBytes];
GetBitmapBits(dark,bm.bmHeight*bm.bmWidthBytes,px1);
}
}
}
delete px;
delete px1;
::BitBlt(hDC,0,0,800,600,hDC1,0,0,SRCCOPY);//put the car in the background
::BitBlt(hDC,0,0,800,600,hDC2,0,0,SRCAND);//put the people in the background and make AND operation
::BitBlt(hDC1,0,0,800,600,hDC2,0,0,SRCINVERT);//run XOR operation and store the difference
::BitBlt(hDCTemp,0,0,800,600,hDC1,0,0,SRCCOPY);// store the difference in hDCTemp Device context.
m_bPeopleCrashed = true;
return true;
}
//every collision speed will be recalculated.
//here we apply the physics equations such as.
//non-stretch collision
//v1=v2=(m1*v10+m2*v20)/(m1+m2)
//stretch-collision
//v1=((m1-m2)*v10+2*m2*v20)/(m1+m2);
//v2=((m2-m1)*v20+2*m1*v10)/(m1+m2);
//here we compare.
//if m1=m2, then v1=v20,v2=v10;
//if m1<<m2,then v1=2*v2-v1,v2=v2;
void CGame::speedAfterCollision()
{
// int wc_NewSpeed,rc_NewSpeed;//here we use member function
if(m_bCarCrashed)//if car collision occurs
{
else if(m_bPeopleCrashed)//if people collision occurs
{
//because after colliding into a man, the man is obvious to be killed,
//the velocity is set 0,so use
//the collision type: total-stretch collision, which the mass between the two is set
//people
m_rc->speed = (RACINGCAR_MASS * m_rc_speed + PEOPLE_MASS * (m_ppInfo->speed))/RACINGCAR_MASS;
m_rc_updatedSpeed=m_rc->speed;
}
else
{
return;
}
return;
}
//blood calculation is using the equation:fullblood- m*a*FORCE_TO_BLOOD_RATE
//m*a is short for the equation:force = mass *acceleration,
//and FORCE_TO_BLOOD_RATE is something that convets from force to blood
DWORD CGame::Calculate_Blood()
{
return FULLBLOOD-RACINGCAR_MASS*m_accRc*FORCE_TO_BLOOD_RATE;
}
//calculate_acceleration is using the equation:
//delta speed = (speed after collision- speed before collision)
//delta time =(used time,a bit flaw though)
void CGame::Calculate_acceleration()
{
/*calculate the acceleration*/
m_accWc = fabs(m_wc->speed - (m_wc_speed))/Record_Used(message);
m_accRc = fabs(m_rc->speed - (m_rc_speed))/Record_Used(message);
return;
}
// update the blood
void CGame::Refresh_Blood()
{
if(m_dBlood==FULLBLOOD)
{
return false;
}
m_dBlood = FULLBLOOD;
return true;
}
//if people collision,then the people hit will adds one.
void CGame::Count_PeopleHit()
{
if(m_bPeopleCrashed)
m_peopleHit++;
}
//calculate the score,the equation:
//distance*10+(fullblood-current blood)*mass*updated velocity-(100*people hit count)
double CGame::Calculate_Score()
{