static void chopper_load(bool newgame) { int i; int g; if (newgame) { iScreenX = LCD_WIDTH * SIZE; iScreenY = LCD_HEIGHT * SIZE; blockh = iScreenY / 5; blockw = iScreenX / 20; iPlayerAlive = 1; iCurrLevelMode = iLevelMode; score = 0; } iRotorOffset = 0; iPlayerPosX = 60; iPlayerPosY = (iScreenY * 4) / 10; iLastBlockPlacedPosX = 0; iGravityTimerCountdown = 2; chopCounter = 0; iPlayerSpeedX = 3; iPlayerSpeedY = 0; iCameraPosX = 30; for (i=0; i < NUMBER_OF_PARTICLES; i++) mParticles[i].bIsActive = 0; for (i=0; i < NUMBER_OF_BLOCKS; i++) mBlocks[i].bIsActive = 0; g = iScreenY - 10; chopClearTerrain(&mGround); for (i=0; i < MAX_TERRAIN_NODES; i++) chopAddTerrainNode(&mGround,i * 30,g - iR(0,20)); if (chopUpdateTerrainRecycling(&mGround) == 1) /* mirror the sky if we've changed the ground */ chopCopyTerrain(&mGround, &mRoof, 0, - ( (iScreenY * 3) / 4)); if (iCurrLevelMode == LEVEL_MODE_NORMAL) /* make it a bit more exciting, cause it's easy terrain... */ iPlayerSpeedX *= 2; }
static int chopGameLoop(void) { int move_button, ret; bool exit=false; bool showsplash=true; int end, i=0, bdelay=0, last_button=BUTTON_NONE; if (chopUpdateTerrainRecycling(&mGround) == 1) /* mirror the sky if we've changed the ground */ chopCopyTerrain(&mGround, &mRoof, 0, - ( (iScreenY * 3) / 4)); ret = chopMenu(0); if (ret != -1) return PLUGIN_OK; while (!exit) { end = *rb->current_tick + CYCLETIME; if(chopUpdateTerrainRecycling(&mGround) == 1) /* mirror the sky if we've changed the ground */ chopCopyTerrain(&mGround, &mRoof, 0, - ( (iScreenY * 3) / 4)); iRotorOffset = iR(-1,1); /* We need to have this here so particles move when we're dead */ for (i=0; i < NUMBER_OF_PARTICLES; i++) if(mParticles[i].bIsActive == 1) { mParticles[i].iWorldX += mParticles[i].iSpeedX; mParticles[i].iWorldY += mParticles[i].iSpeedY; } /* Redraw the main window: */ chopDrawScene(); iGravityTimerCountdown--; if(iGravityTimerCountdown <= 0) { iGravityTimerCountdown = 3; chopAddParticle(iPlayerPosX, iPlayerPosY+5, 0, 0); } if(iCurrLevelMode == LEVEL_MODE_NORMAL) chopGenerateBlockIfNeeded(); if (showsplash) { chopDrawScene(); rb->splash(HZ, "Get Ready!"); showsplash = false; } move_button=rb->button_status(); if (rb->button_get(false) == QUIT) { ret = chopMenu(1); if (ret != -1) return PLUGIN_OK; showsplash = true; bdelay = 0; last_button = BUTTON_NONE; move_button = BUTTON_NONE; } switch (move_button) { case ACTION: #ifdef ACTION2 case ACTION2: #endif if (last_button != ACTION #ifdef ACTION2 && last_button != ACTION2 #endif ) bdelay = -2; if (bdelay == 0) iPlayerSpeedY = -3; break; default: if (last_button == ACTION #ifdef ACTION2 || last_button == ACTION2 #endif ) bdelay = 3; if (bdelay == 0) iPlayerSpeedY = 4; if (rb->default_event_handler(move_button) == SYS_USB_CONNECTED) return PLUGIN_USB_CONNECTED; break; } last_button = move_button; if (bdelay < 0) { iPlayerSpeedY = bdelay; bdelay++; } else if (bdelay > 0) { iPlayerSpeedY = bdelay; bdelay--; } iCameraPosX = iPlayerPosX - 25; iPlayerPosX += iPlayerSpeedX; iPlayerPosY += iPlayerSpeedY; chopCounter++; /* increase speed as we go along */ if (chopCounter == 100){ iPlayerSpeedX++; chopCounter=0; } if (iPlayerPosY > iScreenY-10 || iPlayerPosY < -5 || chopPointInTerrain(&mGround, iPlayerPosX, iPlayerPosY + 10, 0) || chopPointInTerrain(&mRoof, iPlayerPosX ,iPlayerPosY, 1)) { chopKillPlayer(); chopDrawScene(); ret = chopMenu(0); if (ret != -1) return ret; showsplash = true; } for (i=0; i < NUMBER_OF_BLOCKS; i++) if(mBlocks[i].bIsActive == 1) if(chopBlockCollideWithPlayer(&mBlocks[i])) { chopKillPlayer(); chopDrawScene(); ret = chopMenu(0); if (ret != -1) return ret; showsplash = true; } if (TIME_BEFORE(*rb->current_tick, end)) rb->sleep(end - *rb->current_tick); /* wait until time is over */ else rb->yield(); } return PLUGIN_OK; }
void new_chopper_window(void) { int i,g; i=0; chopGC = pz_get_gc(1); /* Get the graphics context */ GrGetScreenInfo(&screen_info); /* Get screen info */ /* Open the window: */ chopWindow = pz_new_window (0, 21, screen_info.cols, screen_info.rows - 21, /* Height of screen - header */ chopDrawScene, chopHandleEvent); chopBuffer = GrNewPixmap(screen_info.cols, (screen_info.rows - (HEADER_TOPLINE + 1)), NULL); iScreenX = screen_info.cols; iScreenY = screen_info.rows - 21; /* Select the types of events you need for your window: */ GrSelectEvents (chopWindow, GR_EVENT_MASK_KEY_DOWN | GR_EVENT_MASK_TIMER | GR_EVENT_MASK_KEY_UP); /* Display the window: */ GrMapWindow (chopWindow); /* Create the timer used for animating your application: */ chopTimer = GrCreateTimer (chopWindow, 75); /* Timer interval, millisecs */ /*chopDrawScene();*/ iRotorOffset = 0; //chopAddBlock(100,100,20,20); iPlayerPosX = 60; iPlayerPosY = iScreenY * 0.2; iLastBlockPlacedPosX = 0; iGravityTimerCountdown = 2; iPlayerAlive = 1; chopCounter = 0; while(i < NUMBER_OF_BLOCKS) { mBlocks[i].bIsActive = 0; i++; } g = iScreenY - 10; chopClearTerrain(&mGround); i=0; while(i < MAX_TERRAIN_NODES) //we could add less, probably. { chopAddTerrainNode(&mGround,i * 30,g - iR(0,20)); i++; } if(chopUpdateTerrainRecycling(&mGround)==1) chopCopyTerrain(&mGround,&mRoof,0,-( iScreenY * 0.75)); //mirror the sky if we've changed the ground iLevelMode = iR(1,2); iPlayerSpeedX = 4; iPlayerSpeedY = 0; if(iLevelMode == LEVEL_MODE_NORMAL) iPlayerSpeedX*=2; //make it a bit more exciting, cause it's easy terrain... //printf("level mode: %d",iLevelMode); bWaitingToStart = 1; }
static void chopGameLoop() { int i=0; iRotorOffset = iR(-1,1); /* Redraw the main window: */ chopDrawScene(); if(bWaitingToStart == 1)return; //We need to have this here so particles move when we're dead while(i < NUMBER_OF_PARTICLES) { if(mParticles[i].bIsActive == 1) { mParticles[i].iWorldX += mParticles[i].iSpeedX; mParticles[i].iWorldY += mParticles[i].iSpeedY; } i++; } i=0; if(iPlayerAlive == 0)return; //increase score chopCounter++; iCameraPosX = iPlayerPosX - 25; iPlayerPosX+=iPlayerSpeedX; iPlayerPosY+=iPlayerSpeedY; iGravityTimerCountdown--; if(iGravityTimerCountdown <= 0) { //iPlayerSpeedY++; iGravityTimerCountdown = 3; chopAddParticle(iPlayerPosX,iPlayerPosY+5,0,0); //pretty hax putting this here :S } //cap player vel if(iPlayerSpeedY < -2) iPlayerSpeedY = -2; if(iLevelMode == LEVEL_MODE_NORMAL) chopGenerateBlockIfNeeded(); if(bPlayerPressingUp == 1) { if(iPlayerSpeedY > 0) iPlayerSpeedY = 0; else iPlayerSpeedY-=2; } else iPlayerSpeedY++; //increase speed as we go along if(chopCounter % 300 == 0) iPlayerSpeedX++; if(iPlayerPosY > iScreenY-10 || iPlayerPosY < -5 || chopPointInTerrain(&mGround,iPlayerPosX,iPlayerPosY + 10,0) || chopPointInTerrain(&mRoof,iPlayerPosX,iPlayerPosY,1) ) { chopKillPlayer(); } while(i < NUMBER_OF_BLOCKS) { if(mBlocks[i].bIsActive == 1) { if(chopBlockCollideWithPlayer(&mBlocks[i])) { //pwned chopKillPlayer(); } } i++; } if(chopUpdateTerrainRecycling(&mGround)==1) chopCopyTerrain(&mGround,&mRoof,0,-( iScreenY * 0.75)); //mirror the sky if we've changed the ground }