Exemple #1
0
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;
}
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
}
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;
}
Exemple #4
0
// _DragStateFor
//! where is expected in canvas view coordinates
DragState*
TransformBox::_DragStateFor(BPoint where, float canvasZoom)
{
	DragState* state = NULL;
	// convert to canvas zoom level
	//
	// the conversion is necessary, because the "hot regions"
	// around a point should be the same size no matter what
	// zoom level the canvas is displayed at

	float inset = INSET / canvasZoom;

	// priorities:
	// transformation center point has highest priority ?!?
	if (point_point_distance(where, fPivot) < inset)
		state = fOffsetCenterState;

	if (!state) {
		// next, the inner area of the box

		// for the following calculations
		// we can apply the inverse transformation to all points
		// this way we have to consider BRects only, not transformed polygons
		BPoint lt = fLeftTop;
		BPoint rb = fRightBottom;
		BPoint w = where;

		InverseTransform(&w);
		InverseTransform(&lt);
		InverseTransform(&rb);

		// next priority has the inside of the box
		BRect iR(lt, rb);
		float hInset = min_c(inset, max_c(0, (iR.Width() - inset) / 2.0));
		float vInset = min_c(inset, max_c(0, (iR.Height() - inset) / 2.0));

		iR.InsetBy(hInset, vInset);
		if (iR.Contains(w))
			state = fTranslateState;
	}

	if (!state) {
		// next priority have the corners
		float dLT = point_point_distance(fLeftTop, where);
		float dRT = point_point_distance(fRightTop, where);
		float dLB = point_point_distance(fLeftBottom, where);
		float dRB = point_point_distance(fRightBottom, where);
		float d = min4(dLT, dRT, dLB, dRB);
		if (d < inset) {
			if (d == dLT)
				state = fDragLTState;
			else if (d == dRT)
				state = fDragRTState;
			else if (d == dLB)
				state = fDragLBState;
			else if (d == dRB)
				state = fDragRBState;
		}
	}

	if (!state) {
		// next priority have the sides
		float dL = point_line_dist(fLeftTop, fLeftBottom, where, inset);
		float dR = point_line_dist(fRightTop, fRightBottom, where, inset);
		float dT = point_line_dist(fLeftTop, fRightTop, where, inset);
		float dB = point_line_dist(fLeftBottom, fRightBottom, where, inset);
		float d = min4(dL, dR, dT, dB);
		if (d < inset) {
			if (d == dL)
				state = fDragLState;
			else if (d == dR)
				state = fDragRState;
			else if (d == dT)
				state = fDragTState;
			else if (d == dB)
				state = fDragBState;
		}
	}

	if (!state) {
		BPoint lt = fLeftTop;
		BPoint rb = fRightBottom;
		BPoint w = where;

		InverseTransform(&w);
		InverseTransform(&lt);
		InverseTransform(&rb);

		// check inside of the box again
		BRect iR(lt, rb);
		if (iR.Contains(w)) {
			state = fTranslateState;
		} else {
			// last priority has the rotate state
			state = fRotateState;
		}
	}

	return state;
}