void CFT_Area::ConstructL() { // TRACE ("WARNING !! Test\n"); CAE_Object::ConstructL(); iBeaconC = CAE_TState<TInt>::NewL(KAreaBeaconCName, this, TTransInfo()); iBeaconX = CAE_TState<TInt>::NewL(KAreaBeaconXName, this, TTransInfo()); iLbDown = CAE_TState<TInt>::NewL("LbDown", this, TTransInfo(), CAE_StateBase::EType_Input); iMcPos = CAE_TState<CF_TdPoint>::NewL("McPos", this, TTransInfo(), CAE_StateBase::EType_Input); iRect = CAE_TState<CF_Rect>::NewL(KAreaRectName, this, TTransInfo(), CAE_StateBase::EType_Input); *iRect = iInitRect; // Create borders CF_Rect rt = iInitRect; float midx, midy; midx = (rt.iRightLower.iX - rt.iLeftUpper.iX)/2.0; midy = (rt.iRightLower.iY - rt.iLeftUpper.iY)/2.0; printf("area_constr: lx= %d, ly= %d, rx= %d, ry= %d\n", rt.iLeftUpper.iX, rt.iLeftUpper.iY, rt.iRightLower.iX, rt.iRightLower.iY); CreateBorder(rt.iLeftUpper.iX-KBorderRadius, midy, KObjBorderLeftName, CAE_TRANS(UpdateBordHookLeft)); CreateBorder(rt.iRightLower.iX + KBorderRadius, midy, KObjBorderRightName, CAE_TRANS(UpdateBordHookRight)); CreateBorder(midx, rt.iLeftUpper.iY - KBorderRadius, KObjBorderTopName, CAE_TRANS(UpdateBordHookTop)); CreateBorder(midx, rt.iRightLower.iY + KBorderRadius, KObjBorderBottomName, CAE_TRANS(UpdateBordHookBottom)); // Create balls CreateBall(40, 40, 2000, 20, "Ball1"); CreateBall(300, 300, 2000, 30, "Ball2"); CreateBall(200, 400, 3000, 40, "Ball3"); #if 0 CreateBall(300, 300, 200, 40, "Ball2"); CreateBall(400, 300, 300, 60, "Ball3"); #endif }
void Board::Restart() { needCheckLines_ = false; needSpawnBalls_ = false; gameOver_ = false; for (int i = 0; i < height_; i++) { for (int j = 0; j < width_; j++) { if (board_[i][j]) { board_[i][j]->GetNode()->Remove(); board_[i][j] = nullptr; } } } selectedBall_ = nullptr; LoadRecord(); for (int i = 0; i < numAddBalls_; i++) SpawnBall(); if (difficulty_ <= D_NORMAL) { for (int i = 0; i < numAddBalls_; i++) CreateBall(true); } score_ = 0; }
CFT_Ball* CFT_Area::CreateBorder(float aCoordX, float aCoordY, const char* aInstName, TTransFun aHookUpdate) { CFT_Ball *bord = CreateBall(aCoordX, aCoordY, KBorderMass, KBorderRadius, aInstName, ETrue); // Bind hook of the border with area rectangle LinkL(bord->iMcPos, iRect, aHookUpdate); // Make the border hooked initially *(bord->iHookedPerm) = TRUE; *(bord->iTransp) = TRUE; }
CETest() { Add(tst.BottomPos(40, 20).HSizePos()); Add(h.TopPos(0, 20).HSizePos(20, 20)); Add(option.SetLabel("Option").TopPos(20, 20).LeftPos(100, 100)); Add(editor.TopPos(40, 20).LeftPos(0, 100)); Add(button.SetLabel("U++").TopPos(200, 20).LeftPos(0, 100)); for(int i = 0; i < 200; i++) h.Add(i); ball = CreateBall(80, Cyan); editor <<= Breaker(); button <<= Breaker(); }
//---------------------------------------------------------------------------- void BouncingBall::CreateScene () { mScene = new0 Node(); mWireState = new0 WireState(); mRenderer->SetOverrideWireState(mWireState); CreateBall(); CreateFloor(); CreateWall(); mScene->AttachChild(mFloor); mScene->AttachChild(mWall); // The floor reflects an image of the ball. mPREffect = new0 PlanarReflectionEffect(1); mPREffect->SetPlane(0, mFloor); mPREffect->SetReflectance(0, 0.2f); }
bool Board::SpawnBall() { for (int y = 0; y < height_; y++) { for (int x = 0; x < width_; x++) { if (board_[y][x] && board_[y][x]->GetBallState() == BS_GHOST) { board_[y][x]->SetBallState(BS_NORMAL); needCheckLines_ = true; return true; } } } return CreateBall(false); }
// Create a number of balls across the world. void LiquidFunScene::CreateBalls(const int numberOfBalls, const float relativeBallSize) { const float oneOverNumberOfBalls = 1.0f / static_cast<float>(numberOfBalls); const b2Vec2 worldInWallsSize = m_worldExtentsInWalls - m_worldOffsetInWalls; const float ballDiameter = b2Vec2Min(b2Vec2( worldInWallsSize.x * relativeBallSize, worldInWallsSize.y * relativeBallSize)); for (int i = 0; i < numberOfBalls; i++) { const float relativeOffset = static_cast<float>(i) * oneOverNumberOfBalls; const b2Vec2 worldPosition( m_worldOffsetInWalls.x + worldInWallsSize.x * relativeOffset, m_worldOffsetInWalls.y + worldInWallsSize.y * relativeOffset); CreateBall(worldPosition, b2Vec2(ballDiameter, ballDiameter)); } }
/* Main Function */ int main(void) { glutInitWindowPosition( 150, 150 ); glutInitWindowSize( windW, windH ); glutInitDisplayMode( GLUT_RGB | GLUT_DOUBLE ); glutCreateWindow("Soft Body 2D v1.0 by Maciej Matyka"); CreateBall(); glutKeyboardFunc(key); glutReshapeFunc(Reshape); glutDisplayFunc(Draw); glutIdleFunc(Idle); glutMouseFunc(Mouse); glutMotionFunc(Motion); glutMainLoop(); return 0; }
void Board::HandleClickCell(const Cell* cell) { if (Path::GetTotalCount() != 0) return; IntVector2 pos = cell->GetBoardPosition(); if (board_[pos.y_][pos.x_] && board_[pos.y_][pos.x_]->GetBallState() == BS_NORMAL) { HandleClickBall(board_[pos.y_][pos.x_]); } else if (selectedBall_) { IntVector2 oldPos = selectedBall_->GetBoardPosition(); IntVector2 newPos = pos; Vector<IntVector2> boardPath; if (FindPath(oldPos, newPos, boardPath)) { bool needCreateGhost = false; BallColor color; if (board_[newPos.y_][newPos.x_]) // в точке назначения может быть призрак { color = board_[newPos.y_][newPos.x_]->GetColor(); board_[newPos.y_][newPos.x_]->Kill(); // убиваем needCreateGhost = true; } board_[newPos.y_][newPos.x_] = selectedBall_; selectedBall_->SetBoardPosition(newPos); board_[oldPos.y_][oldPos.x_] = nullptr; Path* path = selectedBall_->GetNode()->CreateComponent<Path>(); path->AddControlPoint(IV2ToV3(oldPos)); for (int i = 0; i < boardPath.Size(); i++) path->AddControlPoint(IV2ToV3(boardPath[i])); path->SetSpeed(80.0f); selectedBall_ = nullptr; selectionNode_->SetEnabled(false); needCheckLines_ = true; needSpawnBalls_ = true; if (needCreateGhost) CreateBall(true, color); // создаем призрака в новом месте того же цвета } } }
void Board::Init(Difficulty difficulty) { SetDifficulty(difficulty); node_->SetPosition(Vector3(0.0f, 0.0f, Max(width_, height_) * 2.8f)); needCheckLines_ = false; needSpawnBalls_ = false; gameOver_ = false; score_ = 0; record_ = 0; board_.Resize(height_); cells_.Resize(height_); for (int i = 0; i < height_; i++) { board_[i].Resize(width_); cells_[i].Resize(width_); for (int j = 0; j < width_; j++) { Node* cellNode = node_->CreateChild(); Cell* cell = cellNode->CreateComponent<Cell>(); Vector3 targetPos = IV2ToV3(IntVector2(j, i)); Vector3 startPos = Vector3(Random(-50.0f, 50.0f), Random(-50.0f, 50.0f), Random(-50.0f, 50.0f)); cell->Init(startPos, targetPos, IntVector2(j, i)); cells_[i][j] = cell; } } for (int i = 0; i < numAddBalls_; i++) SpawnBall(); if (difficulty_ <= D_NORMAL) { for (int i = 0; i < numAddBalls_; i++) CreateBall(true); } InitSelection(); LoadRecord(); }
void Scene2Controller::Update() { model_.dialogue.Update(); UpdateRackets(); model_.world.Step(delta_time * 0.5, box2d_velocity_iterations, box2d_position_iterations); if (model_.score >= max_balls_goal) { scene_manager.NextScene(); return; } model_.score = 0.0; model_.inverse_score = 0.0; for (auto ball : model_.ball_body) { if (ball->GetPosition().x > 0 && ball->GetLinearVelocity().Length() < 5.0) { model_.score += 1.0; } if (ball->GetPosition().x < 0 && ball->GetLinearVelocity().Length() < 5.0) { model_.inverse_score += 1.0; } } if (ofGetElapsedTimef() > scene_begin_time + 8.0 && ofGetFrameNum() % 1 == 0 && model_.ball_body.size() < max_balls) { const ofVec2f position = ball_initial_position.GetValue() + ofVec2f(-ofNoise(-1.7 * ofGetElapsedTimef()), ofSignedNoise(1.3 * ofGetElapsedTimef())); const ofVec2f velocity = ball_initial_velocity.GetValue() .rotated(-15.0 + ofSignedNoise(ofGetElapsedTimef()) * 30.0) * (1.0 + 0.1 * ofSignedNoise(1.3 * ofGetElapsedTimef())); CreateBall(position, velocity, 0.0, angular_velocity * ofRandomf()); if (model_.ball_body.size() > max_balls) { b2Body *const body = model_.ball_body.front(); DestroyBall(body); model_.ball_body.pop_front(); } } if (keys[OF_KEY_BACKSPACE] && !previous_keys[OF_KEY_BACKSPACE]) { if (model_.ball_body.size() > 0) { b2Body *const body = model_.ball_body.front(); DestroyBall(body); model_.ball_body.pop_front(); } } Controller::Update(); }
void Scene3Controller::Update() { model_.dialogue.Update(); if (model_.score >= 10) { model_.outro += 1.0 / 60.0 / 2.6; } if (model_.outro >= 1.0) { scene_manager.NextScene(); return; } if (model_.bounces >= ((model_.opponent_index == 5) ? 8 : 2)) { DestroyBall(model_.ball_body); model_.ball_body = nullptr; model_.bounces = 0; } if (model_.opponent_index != 2 && model_.extra_balls.size()) { for (auto ball : model_.extra_balls) { model_.world.DestroyBody(ball); } model_.extra_balls.clear(); } UpdateRackets(); model_.world.Step(model_.time_slowed ? 0.1 * delta_time : delta_time, box2d_velocity_iterations, box2d_position_iterations); for (std::vector<Scene3Model::Particle>::iterator particle = model_.particles.begin(); particle != model_.particles.end(); ++particle) { particle->angle += particle->angular_velocity * delta_time; particle->position += particle->velocity * delta_time; particle->velocity += -ofVec2f(0.0, 0.5) * delta_time; particle->life -= 1.0 / 60.0 / 8.0; } model_.particles.erase(std::remove_if(model_.particles.begin(), model_.particles.end(), [] (Scene3Model::Particle &particle) -> bool { return particle.life <= 0.0; }), model_.particles.end()); if (model_.ball_trail.size() > ball_trail_length_scholar || (model_.opponent_index != 7 && model_.ball_trail.size() > 0)) { model_.ball_trail.pop_front(); } if (model_.ball_body && model_.opponent_index == 7) { Scene3Model::Trail trail; trail.position = OpenFrameworksVector(model_.ball_body->GetPosition()); trail.text = nullptr; model_.ball_trail.push_back(trail); } if (model_.ball_in_play && !model_.ball_body) { CreateBall(ofVec2f(0.377 * half_court_length, court_height), ofVec2f(0, 0), 0.0, -ofRandomuf() * angular_velocity); if (model_.opponent_index == 8) { model_.ball_body->GetFixtureList()->SetRestitution(0.0); } if (!(model_.opponent_index == 9 && model_.mirror_score > 0)) { model_.opponent = model_.opponent_target = ofVec2f(half_court_length, racket_radius + court_thickness); } } if (keys[OF_KEY_BACKSPACE] && !previous_keys[OF_KEY_BACKSPACE]) { if (model_.ball_body) { DestroyBall(model_.ball_body); model_.ball_body = nullptr; } } if (model_.angle <= 180.0 - 180.0 / 60.0 / 2.0) { model_.angle += 180.0 / 60.0 / 2.0; } if (model_.glass_hits == 2 && model_.glass <= 1.0 - 1.0 / 60.0) { model_.glass += 1.0 / 60.0; } if (model_.glass_hits > 2 && model_.glass <= 1.0 - 1.0 / 60.0) { model_.glass += 1.0 / 60.0; } if (model_.opponent_index == 7 && model_.nerd_energy >= 1.0 / 60.0 / 30.0) { model_.nerd_energy -= 1.0 / 60.0 / 30.0; } Controller::Update(); }
void Board::Update(float timeStep) { if (gameOver_) { if (score_ > record_) { record_ = score_; SaveRecord(); } Restart(); return; } selectionNode_->Rotate(Quaternion(0.0f, timeStep * 50, 0.0f)); if (Path::GetTotalCount() > 0) return; if (needCheckLines_) { if (CheckLines()) { needSpawnBalls_ = false; } needCheckLines_ = false; // может быть что поле полностью занято, новых шаров спанить не надо и ходить некуда // не работает чот gameOver_ = true; for (int i = 0; i < height_; i++) { for (int j = 0; j < width_; j++) { if (!board_[i][j] || board_[i][j]->GetBallState() == BS_GHOST) { gameOver_ = false; break; } } } if (gameOver_) return; } if (needSpawnBalls_) { for (int i = 0; i < numAddBalls_; i++) { if (!SpawnBall()) { gameOver_ = true; return; } } if (difficulty_ <= D_NORMAL) { for (int i = 0; i < numAddBalls_; i++) CreateBall(true); } needSpawnBalls_ = false; } UIElement* uiRoot = GetSubsystem<UI>()->GetRoot(); Text* t = static_cast<Text*>(uiRoot->GetChild("Score", true)); t->SetText("Score: " + String(score_)); t = static_cast<Text*>(uiRoot->GetChild("Colors", true)); t->SetText("Colors: " + String(numColors_)); t = static_cast<Text*>(uiRoot->GetChild("LineLength", true)); t->SetText("Line length: " + String(lineLength_)); t = static_cast<Text*>(uiRoot->GetChild("Record", true)); t->SetText("Record: " + String(record_)); // нужно выбрасывать шары если после уделаения линий поле пустое }
void InitNx() { // Create a memory allocator gAllocator = new UserAllocator; // Create the physics SDK gPhysicsSDK = NxCreatePhysicsSDK(NX_PHYSICS_SDK_VERSION, gAllocator); if (!gPhysicsSDK) return; // Set the physics parameters gPhysicsSDK->setParameter(NX_SKIN_WIDTH, 0.01); // Set the debug visualization parameters gPhysicsSDK->setParameter(NX_VISUALIZATION_SCALE, 1); gPhysicsSDK->setParameter(NX_VISUALIZE_COLLISION_SHAPES, 1); gPhysicsSDK->setParameter(NX_VISUALIZE_ACTOR_AXES, 1); gPhysicsSDK->setParameter(NX_VISUALIZE_JOINT_LIMITS, 1); // Create the scene NxSceneDesc sceneDesc; sceneDesc.gravity = gDefaultGravity; sceneDesc.simType = NX_SIMULATION_HW; gScene = gPhysicsSDK->createScene(sceneDesc); if(!gScene) { sceneDesc.simType = NX_SIMULATION_SW; gScene = gPhysicsSDK->createScene(sceneDesc); if(!gScene) return; } // gScene->setTiming(0.01); // timeStep, maxIter, TIMESTEP_FIXED // Create the default material NxMaterial* defaultMaterial = gScene->getMaterialFromIndex(0); defaultMaterial->setRestitution(0.5); defaultMaterial->setStaticFriction(0.5); defaultMaterial->setDynamicFriction(0.5); // Create the objects in the scene CreateGroundPlane(); NxU32 r; NxI32 x, z; NxReal fRX, fRZ; // create grass block for (x = -patchsize; x < patchsize; x++) { for (z = -patchsize; z < patchsize; z++) { fRX = NxMath::rand(-45,45)*0.01; fRZ = NxMath::rand(-45,45)*0.01; r = NxMath::rand(0,4); if (r == 0) { grassBlade[x+patchsize][z+patchsize] = new Blade(NxVec3(scale*(x+fRX),0,scale*(z+fRZ)),3,4); } else if (r == 1) { grassBlade[x+patchsize][z+patchsize] = new Blade(NxVec3(scale*(x+fRX),0,scale*(z+fRZ)),1.8,2); } else if (r == 1) { grassBlade[x+patchsize][z+patchsize] = new Blade(NxVec3(scale*(x+fRX),0,scale*(z+fRZ)),2,3); } else if (r == 1) { grassBlade[x+patchsize][z+patchsize] = new Blade(NxVec3(scale*(x+fRX),0,scale*(z+fRZ)),1.5,2); } else { grassBlade[x+patchsize][z+patchsize] = new Blade(NxVec3(scale*(x+fRX),0,scale*(z+fRZ)),2.1,3); } } } gScene->setGroupCollisionFlag(1,1,false); ball = CreateBall(NxVec3(0,10,0),1.5,350); SetActorCollisionGroup(ball, 3); gSelectedActor = ball; gCameraSpeed = 20; gForceStrength = 850000; // Initialize HUD InitializeHUD(); // Get the current time getElapsedTime(); // Start the first frame of the simulation if (gScene) StartPhysics(); }
int main() { SceUID video_thid; //int xx, yy, nubspeed; SetupCallbacks(); pspDebugScreenInit(); initGraphics(); SceCtrlData pad, oldpad; oldpad.Buttons = 0xFFFFFFFF; sceCtrlSetSamplingCycle(0); sceCtrlSetSamplingMode(PSP_CTRL_MODE_ANALOG); // Start the video thread to draw objects to screen and manage video input. video_thid = sceKernelCreateThread("video_thread", video_thread, 0x12, 512 * 1024, 0, NULL); if (video_thid > 0) sceKernelStartThread(video_thid, 0, NULL); while (!connected) { sceCtrlReadBufferPositive(&pad, 1); if (pad.Buttons) connected = 1; } // Wait for camera to be aligned to playing area and for game to start. while (running && (!aligned || menu)) { // Uncomment the following lines to include analog stick and button input during alignment. /*sceCtrlPeekBufferPositive(&pad, 1); xx = pad.Lx - 128; yy = pad.Ly - 128; nubspeed = sqrt((xx * xx) + (yy * yy)) / (2 * sqrt(sqrt((xx * xx) + (yy * yy)))); if (xx > 30) cursorx += nubspeed; else if (xx < -30) cursorx -= nubspeed; if (yy > 30) cursory += nubspeed; else if (yy < -30) cursory -= nubspeed; if (cursorx > 480) cursorx = 480; else if (cursorx < 0) cursorx = 0; if (cursory > 272) cursory = 272; else if (cursory < 0) cursory = 0; // Detect changes in button input. if (pad.Buttons != oldpad.Buttons) { } oldpad.Buttons = pad.Buttons;*/ sceKernelDelayThread(50000); } int x; // Initialize global data. _highScore = 0; _score = 0; _ballCount = 0; _resBalls = START_RES_BALLS; _gameState = GAME_RUNNING; _pauseSem = sceKernelCreateSema("PauseSem", 0, 1, 1, 0); // Initialize array used to keep track of balls in play. for (x = 0; x < MAX_BALLS; x++) { _activeBalls[x] = 0; } // Initialize the paddle (&_paddle)->h = 60; (&_paddle)->w = 8; (&_paddle)->xPos = 3; (&_paddle)->yPos = 136; (&_paddle)->xPosOld = 250; (&_paddle)->yPosOld = 250; (&_paddle)->speed = 10; (&_paddle)->dir = 1; (&_paddle)->color = COLOR_LIGHT_BLUE; while (running) { // Uncomment the following lines to include analog stick and button input. // Defeats the purpose as holding the PSP or touching it shakes the camera // and makes the laser pointer input very inaccurate. Could be useful with // the PSP remote control to allow games to be played using the remote // for D-Pad movement and the laser pointer for looking/aiming. /*sceCtrlPeekBufferPositive(&pad, 1); xx = pad.Lx - 128; yy = pad.Ly - 128; nubspeed = sqrt((xx * xx) + (yy * yy)) / (2 * sqrt(sqrt((xx * xx) + (yy * yy)))); if (xx > 30) cursorx += nubspeed; else if (xx < -30) cursorx -= nubspeed; if (yy > 30) cursory += nubspeed; else if (yy < -30) cursory -= nubspeed; if (cursorx > 480) cursorx = 480; else if (cursorx < 0) cursorx = 0; if (cursory > 272) cursory = 272; else if (cursory < 0) cursory = 0; // Detect changes in button input. if (pad.Buttons != oldpad.Buttons) { } oldpad.Buttons = pad.Buttons;*/ // Change sprite speeds, positions and behaviors here. CreateBall(); // Create a ball and put it in play. while (_gameState == GAME_RUNNING) { CheckUserInput(); } while (_gameState == GAME_CONTINUE) { sceKernelDelayThread(2000); } while (_gameState == GAME_OVER) { sceKernelDelayThread(2000); } sceKernelDelayThread(200); //CreateBall(); // Create a ball and put it in play. } StopApp(); sceKernelExitGame(); return 0; }
void CFT_Area::AddBallL(float aCoordX, float aCoordY, TInt aMass, TInt aRad, const char* aName) { CreateBall(aCoordX, aCoordY, aMass, aRad, aName); }
inline void LevelManager::InitLevel() { CreatePlayer(); CreateBall(); CreateBricks(); }