void Koopa::Move(float TPF,list<Object*>* staObjs)
{
	Object* obj;
	//Theo phương x
	x+=vx*TPF;
	ResetRect();
	list<Object*>::iterator i;
	for(i=staObjs->begin();i!=staObjs->end();i++)
	{
		obj=*i;
		if(obj->ID>=20&&obj->ID<=29) //Nếu là thùng, đá , gạch...
			if(Collision::RectVsRect(rect,obj->rect)==true
				&&obj->GetVar("state")!=TS_BREAKING&&obj->GetVar("state")!=TS_BREAKED)
			{
				vx=-vx;
				x=xOld;
			}
	}
	//Theo phương y
	ay=G;
	vy+=ay*TPF;
	y+=vy*TPF+1.0/2*ay*TPF*TPF;
	oldRect=rect;
	ResetRect();
	collisionList->clear();
	for(i=staObjs->begin();i!=staObjs->end();i++)
	{
		obj=*i;
		if(obj->ID>=20&&obj->ID<=29)				//Nếu là thùng, đá , gạch...
			if(Collision::RectVsRect(rect,obj->rect)==true
				&&obj->GetVar("state")!=TS_BREAKING&&obj->GetVar("state")!=TS_BREAKED)
				collisionList->push_back(obj);
	}

	//Xét va chạm để không bị rơi
	if(collisionList->size()>0)
	{
		Object* obj;
		list<Object*>::iterator i;
		for(i=collisionList->begin();i!=collisionList->end();i++)
		{
			obj=*i;
			if(oldRect.bottom<obj->rect.bottom)
				if(obj->y-height<y)
				{
					y=obj->y-height;
					vy=0;
				}
		}
		ResetRect();
	}
	xOld=x;
	yOld=y;
}
clsLadder49::clsLadder49(LPDIRECT3DDEVICE9 d3ddev, LPD3DXSPRITE _SpriteHandler, int _ID, float _x, float _y)
{
	m_ID = _ID;
	m_Sprite = NULL;
	m_x = _x;
	m_y = _y;
	ResetRect(0,20,0,50);
	LoadResources(d3ddev,_SpriteHandler);
}
示例#3
0
void Actor::Draw(SDL_Surface* s) {
	ResetRect();
	SDL_Rect source;
	source.x = 0;
	source.y = 0;
	source.w = rect.w;
	source.h = rect.h;
	SDL_BlitSurface(expressions[currExpression], &source, s, &rect);
}
clsGround10::clsGround10(LPDIRECT3DDEVICE9 d3ddev, LPD3DXSPRITE _SpriteHandler, int _ID, float _x, float _y)
{
	m_ID = _ID;
	m_Matdat = NULL;
	m_x = _x;
	m_y = _y;
	ResetRect(0,50,0,50);
	LoadResources(d3ddev,_SpriteHandler);
}
clsGate::clsGate(LPDIRECT3DDEVICE9 d3ddev, LPD3DXSPRITE _SpriteHandler, int _ID, float _x, float _y):clsObject(_x,_y,80,185)
{
	m_Ani = NULL;
	m_ID = _ID;
	m_x = _x;
	m_y = _y - 15;
	ResetRect();
	LoadResources(d3ddev,_SpriteHandler);
}
示例#6
0
Coin::Coin(float _x, float _y,float width,float height,int _ID,GSprite* _sprite):GObject(_x,_y,width,height)
{
	sprite	=_sprite;
	ID	=_ID;
	ani=new GAnimation(4,5,0.2,sprite);

	container=NULL;
	isCheckedContainer	=false;
	state	=IS_FREE;
	numCoin	=1;
	isNeedDelete	=false;
	ResetRect();
}
void Koopa::Update(list<Object*>* staObjs,list<Object*>* dynObjs,Input* input, float TPF)
{
	list<Object*>::iterator i;
	Object* obj;
	switch(state)
	{
	case ES_ACTIVING: 
		Move(TPF,staObjs);
		if(y>HEIGHT)
			ChangeState(ES_DIED);
		break;
	case ES_MOVE_SHELL_LEFT: case ES_MOVE_SHELL_RIGHT:
		Move(TPF,staObjs);
		for(i=dynObjs->begin();i!=dynObjs->end();i++)	
		{
			obj=*i;
			if(obj->ID==41||obj->ID==42&&obj!=this)							//Nếu đụng Goomba thì Goomba chết.
				if(Collision::RectVsRect(rect,obj->rect)&&obj->GetVar("state")!=ES_FALL)
				{
					if(vx>0)
						obj->Huong=1;
					else obj->Huong=2;
					obj->SetVar("state",ES_FALL);
				}
		}
		if(y>HEIGHT)
			ChangeState(ES_DIED);
		break;
	case ES_IDLE:
		waitIdle+=TPF;
		if(waitIdle>5)
		{
			waitIdle-=5;
			ChangeState(ES_ACTIVING);
		}
		break;
	case ES_FALL:
		x+=vx*TPF;
		vy+=ay*TPF;
		y+=vy*TPF+0.5*ay*TPF*TPF;
		ResetRect();
  		if(y>HEIGHT)
			ChangeState(ES_DIED);
		break;
	}
	
	UpdateAnimation(TPF);	
}
void LifeFungus::Update(list<Object*>* staObjs,list<Object*>* dynObjs,Input* input, float TPF)
{
	if(state==IS_ATE) return;
	switch(state)
	{
	case IS_IDLE:
		CheckObjects(staObjs);
		break;
	case IS_ACTIVING:
		if(y<container->y-TILE_SIZE-1)
			ChangeState(IS_MOVING);
		x+=vx*TPF;
		y+=vy*TPF+1/2*ay*TPF*TPF;
		break;
	case IS_MOVING:
		Move(TPF,staObjs,dynObjs);
		break;
	}
	ResetRect();
}
void clsMapple::Moving(list<clsObject*> *l_StaticObj, list<clsObject*> *l_DynamicObj)
{
	clsObject* temp;
	list<clsObject*>::iterator j;
	l_collision->clear();
	for(j=l_StaticObj->begin();j!=l_StaticObj->end();j++)
	{
		temp = *j;
		if(clsCollision::KiemTraVaCham(m_Rect,temp->m_Rect)&&(temp->m_ID<20||temp->m_ID>22))
		{
			m_x = m_oldX;
			m_bMove = false;
		}		
	}
	//if(!m_Climb&&m_Action!=CLIMB)
	//{
	//	m_vy += m_ay;
	//	m_y+=m_vy;	
	//}

	m_vy += m_ay;
	m_y+=m_vy;	

	if(!m_Dev)
	{
		ResetRect(0,65,8,42);
	}
	else 
	{
		ResetRect(0,65,0,50);
	}
	m_Climb = false;
	for(j=l_StaticObj->begin();j!=l_StaticObj->end();j++)
	{
		temp = *j;
		if(clsCollision::KiemTraVaCham(m_Rect,temp->m_Rect)&&(temp->m_ID<20||temp->m_ID>22))
		{
			l_collision->push_back(temp);
			if(m_Jumping==true && m_vy<0)
			{
				m_y = temp->m_y + m_height+1;
				m_vy*=-1;
			}
		}
		if(clsCollision::KiemTraVaCham(m_Rect,temp->m_Rect)&&(temp->m_ID>=20&&temp->m_ID<=22)&&(m_Rect.bottom<temp->m_Rect.bottom))
		{
			if(m_Rect.left>=(temp->m_Rect.left-10)&&m_Rect.right<=(temp->m_Rect.right+10))
				m_Climb = true;
		}
		
	}
	if(l_collision->size()>0)
	{
		clsObject *temp;
		list<clsObject*>::iterator i;
		for(i=l_collision->begin();i!=l_collision->end();i++)
		{
			temp = *i;
			if(m_Rect.bottom<temp->m_Rect.bottom&&m_vy>0)
				if(temp->m_y-m_height<m_y)
				{
					m_y = temp->m_y - m_height;
					
					m_vy = 0;
					if(m_Jumping == true)
					{
						m_Jumping = false;
						m_Action = STAND;
					}
					//m_Jumping = false;
					//	m_Action = STAND;
					if(m_Action==CLIMB)
					{
						//m_ay = 0.5;
						m_Climb = false;
						m_Action = STAND;
					}
				}	
		}
	}
	m_oldX = m_x;
	if(!m_Climb)
		m_ay = 0.5;
}
//Ham chua noi dung Update cac su kien
//Trong ham chua Ham kiem tra Ban phim
void clsMapple::Update(clsInput *input, clsCamera *camera, list<clsObject*> *l_StaticObj, list<clsObject*> *l_DynamicObj)
{
	if(m_x<camera->rectCamera.left)
		m_x = camera->rectCamera.left;
	if(m_x+m_width>camera->rectCamera.right)
		m_x = camera->rectCamera.right-m_width;
	ProcessInput(input);
	if(!m_Dev)
	{
		ResetRect(0,65,8,42);
		m_Arrow->ResetRect(3,9,8,60);
	}
	else 
	{
		ResetRect(0,65,0,50);
		m_Arrow->ResetRect(3,9,8,60);
	}
	//ResetRect();
	if(m_Light)
		if(m_Develop->Delay())
			m_Develop->Next();
	if(m_Develop->m_frameNow==m_Develop->m_frameTotal-1)
	{
		//m_Develop->SetIndex(0);
		m_Light = false;
	}
	if(m_exp>KN[m_level-1])
	{
		m_exp = 0;
		m_Light = true;
		m_dame+=20;
		m_level++;
		if(m_level==3)
		{
			m_Dev = true;
		}
		m_health = M[m_level-1];
 	}
	Moving(l_StaticObj,l_DynamicObj);
	
	//if(m_Jumping)
	//	Jump();
	if(m_Arrow->m_alive)
	{
		m_Arrow->Update(input, camera,l_StaticObj,l_DynamicObj);
		/*if(m_Arrow->m_x > 1000||m_Arrow->m_x < 0)
			m_Arrow->m_alive=false;*/
	}
	if(m_life<=0)
  		gamelose = true;
	clsObject *temp;
	list<clsObject*>::iterator i;
	
	for(i=l_DynamicObj->begin();i!=l_DynamicObj->end();i++)
	{
		temp = *i;
		if(clsCollision::KiemTraVaCham(m_Rect,temp->m_Rect)&& temp->m_ID!=4)
		{
			if(!isProtected&&temp->m_alive&&m_Action!=DIE)
			{
				if(m_health - temp->m_dame >0)
				{
					isProtected=true;
					waitProtected = 0;
					waitRender=0;
					m_health -= temp->m_dame;
				}
				else
				{
					m_health = 0;
					m_Action = DIE;
					m_life--;
				}
				break;
			}
		}
		if(clsCollision::KiemTraVaCham(m_Rect,temp->m_Rect)&&(temp->m_ID==4))
		{
			if(m_Rect.left>=(temp->m_Rect.left-10)&&m_Rect.right<=(temp->m_Rect.right+10))
				isNext = true;
		}
		else
			isNext = false;
	}

	if(isProtected)
	{
		if(m_timeProtcted->CallWaiting())
		{
			waitProtected++;
			waitRender++;
			if(waitRender>2)
			{
				waitRender--;
				isRender = !isRender;
			}
			if(waitProtected>50)
			{
				isRender = true;
				isProtected = false;
			}
		}	
	}

	switch(m_Action)
	{
		case STAND:
			if(m_Maple->Delay())
				m_Maple->Next(4,5);
			if(m_Maple->m_frameNow==4)
				m_Maple->m_delayTime->SetTimePerImage(500);
			break;
		case MOVE:
			if(m_Maple->Delay())
				m_Maple->Next(0,3);
			if(m_Mapple2->Delay())
				m_Mapple2->Next(0,3);
			break;
		case JUMP:
			m_Maple->SetIndex(8);
			m_Mapple2->SetIndex(4);
			//Jump();
			break;
		case SHOOT:
			if(!m_Dev)
			{
				if(m_Maple->Delay())
					m_Maple->Next(9,11);
				if(m_Maple->m_frameNow==11)
				{
					m_Action = m_oldAction;
					if(m_Jumping==false)
						m_Action = STAND;
				}
			}
			else
			{
				if(m_Mapple2->Delay())
					m_Mapple2->Next(7,9);
				if(m_Mapple2->m_frameNow==7)
				{
					m_Action = m_oldAction;
					if(m_Jumping==false)
						m_Action = STAND;
				}
			}			
			break;
		case CLIMB:
			/*if(m_Mapple2->Delay())
				m_Mapple2->Next(5,6);*/
			break;
		case DIE:
			if(m_Die->m_frameNow==m_Die->m_frameTotal-1)
			{
				if(m_life>0)
				{
					m_alive = true;
					m_Action = STAND;
					m_health = m_revivehealth;
					isProtected=true;
					waitProtected = 0;
					waitRender=0;
					m_Light = true;
				}
			}
			if(m_Die->Delay())
				m_Die->Next();
			break;
		default:			
			break;
	}
}