void RunnerSprite::fixCollision(CollisionFace face,Rect box){ CCLOG("fix face %d,x %f y %f w %f h %f",face,box.origin.x,box.origin.y,box.size.width,box.size.height); //Director::getInstance()->pause(); Rect interRect = mRunner->getBoundingBox(); float maxX = MIN(interRect.getMaxX(), box.getMaxX()); float minX = MAX(interRect.getMinX(), box.getMinX()); float maxY = MIN(interRect.getMaxY(), box.getMaxY()); float minY = MAX(interRect.getMinY(), box.getMinY()); float width = maxX - minX; float height = maxY - minY; if(face == kBOTTON){ setRolePos(Vec2(getRolePos().x,getRolePos().y + height)); return; } if(face == kTOP){ setRolePos(Vec2(getRolePos().x,getRolePos().y - height)); return; } if(face == kLEFT){ setRolePos(Vec2(getRolePos().x + width,getRolePos().y )); return; } if(face == kRIGHT){ if(getRunState() == kROLEJUMP){ setRolePos(Vec2(getRolePos().x - width ,getRolePos().y )); } else{ setRolePos(Vec2(getRolePos().x - width,getRolePos().y )); } return; } if(face == kRTOP){ if(getRunState() == kROLEJUMP || getRunState() == kROLEJUMP2){ setRolePos(Vec2(getRolePos().x - width ,getRolePos().y - height)); } else{ setRolePos(Vec2(getRolePos().x - width ,getRolePos().y )); } } if(face == kRBOTTON){ if(getRunState() == kROLEJUMPDOWN){ setRolePos(Vec2(getRolePos().x - width ,getRolePos().y )); } else{ setRolePos(Vec2(getRolePos().x - width ,getRolePos().y +height)); } } };
void RunnerSprite::jumpDownLogic(){ if(isCollisionWithBarriers(kBOTTON)){ ySpeed = constYSpeed; CCLOG("isCollisionWithBarriers"); setDoubledJumped(false); setRunState(kROLERUN); return; } if(isCollisionWithBarriers(kRBOTTON)){ CCLOG("isCollisionWithBarriers jumpDownLogic"); } Vec2 curPos = getRolePos(); ySpeed += gravity; if(ySpeed >= 15){ ySpeed = 15; } Vec2 rlt = curPos + Vec2(xSpeed,-ySpeed); setRolePos(rlt); };
void SceneController::tick(float dt) { if (sceneManager) sceneManager->tick(dt); Player* player = PlayerController::getInstance().getRole(); if (player) setRolePos(player->getPosition()); }
void RunnerSprite::jumpUpLogic(){ Vec2 curPos = getRolePos(); CCLOG("ySpeed %f",ySpeed); if(isCollisionWithBarriers(kTOP)){ setRunState(kROLEJUMPDOWN); return; } if(isCollisionWithBarriers(kRIGHT)){ xSpeed = 0; } else if(isCollisionWithBarriers(kRBOTTON)){ xSpeed = constXSpeed; } else if(isCollisionWithBarriers(kRTOP)){ setRunState(kROLEJUMPDOWN); return; } ySpeed -= gravity; if(ySpeed <=0){ ySpeed = 0; } if(ySpeed == 0){ setRunState(kROLEJUMPDOWN); return; } float xPos = xSpeed + curPos.x; float yPos = ySpeed + curPos.y; setRolePos(Vec2(xPos,yPos)); };
void RunnerSprite::runLogic(){ CCLOG("runner runLogic"); if(isCollisionWithBarriers(kRIGHT)){ setRunState(kROLESTANDBY); return; } if (isCollisionWithBarriers(kRTOP)) { setRunState(kROLESTANDBY); return; } if(!isCollisionWithBarriers(kBOTTON) ){ setRunState(kROLEJUMPDOWN); } CCLOG("cont"); Vec2 preXPos = getRolePos(); Vec2 targetXPos = Vec2(preXPos.x+xSpeed,preXPos.y); setRolePos(targetXPos); };