void Statue::update()
{
	// timeout
	Game::update();

	if (!finished)
	{
		if (keysDown() & KEY_TOUCH)
		{
			touchPosition touch;
			touchRead(&touch);

			SpriteEntry* statue = oamMain.oamMemory + STATUE_SPRITE;

			if (	touch.px > statue->x && touch.px < statue->x + 64 &&
				touch.py > statue->y && touch.py < statue->y + 64)
			{
				++counter;

				// play hit sfx with random pitch
				sfxhandle_statue_hit = mmEffect( SFX_STATUE_HIT );
				mmEffectRate( sfxhandle_statue_hit, 1024 + (rand() % 256 - 128) );

				if (counter >= 3)
				{
					mmEffect( SFX_STATUE_BREAK );
					game_end(true);
				}
			}
		}
	}
}
void Aim::update()
{
	// timeout
	Game::update();

	if (!finished)
	{
		if (keysDown() & KEY_TOUCH)
		{
			touchPosition touch;
			touchRead(&touch);

			SpriteEntry* capitalist = oamMain.oamMemory + SOVIET_SPRITE + capitalist_sprite;

			if (	touch.px > capitalist->x && touch.px < capitalist->x + 64 &&
				touch.py > capitalist->y && touch.py < capitalist->y + 64)
			{
				mmEffect( SFX_YEEHAW );
				game_end(true);
				capitalist->gfxIndex = SOVIET_TILE + anim[capitalist_sprite]*SOVIET_TILE_COUNT;
				capitalist->palette = 1;
				capitalist_sprite = -1;
			}
		}
	}

	for (int i = 0; i <= NUM_SOVIET; ++i)
	{
		++frame[i];
		if (frame[i] == 8)
		{
			frame[i] = 0;
			anim[i] = (anim[i] + 1) % 2;

			if (i == capitalist_sprite)
			{
				(oamMain.oamMemory + SOVIET_SPRITE + i)->gfxIndex = CAPITALIST_TILE + anim[i]*CAPITALIST_TILE_COUNT;
			}
			else
			{
				(oamMain.oamMemory + SOVIET_SPRITE + i)->gfxIndex = SOVIET_TILE + anim[i]*SOVIET_TILE_COUNT;
			}
		}
	}
}
Exemple #3
0
DSGM_SoundInstance *DSGM_PlaySoundFull(DSGM_Sound *sound) {
	DSGM_SoundInstance *soundInstance = DSGM_AddSoundInstance(sound);
	
	if(sound->type == DSGM_SOUND_STREAM) {
		if(!sound->loaded) {
			mmLoad(sound->ID);
			sound->loaded = true;
		}
		mmStart(sound->ID, MM_PLAY_LOOP);
	}
	else {
		if(!sound->loaded) {
			mmLoadEffect(sound->ID - DSGM_soundStreamCount);
			sound->loaded = true;
		}
		soundInstance->effectNumber = mmEffect(sound->ID - DSGM_soundStreamCount);
		mmEffectRelease(soundInstance->effectNumber);
	}
	
	soundInstance->volume = 255;
	soundInstance->panning = 128;
	
	return soundInstance;
}
Exemple #4
0
void handleInput(Ship * ship, MathVector2D<int> * moonPos,
                 SpriteInfo * moonInfo, touchPosition * touch) {

    /* Handle up and down parts of D-Pad. */
    if (keysDown() & KEY_UP) {
        // Play our sound only when the button is initially pressed
        mmEffect(SFX_THRUST);
    }
    if (keysHeld() & KEY_UP) {
        //accelerate ship
        ship->accelerate();
    } else if (keysHeld() & KEY_DOWN) {
        //reverse ship direction
        ship->reverseTurn();
    }

    /* Handle left and right parts of D-Pad. */
    if (keysHeld() & KEY_LEFT) {
        //rotate counter clockwise
        ship->turnCounterClockwise();
    } else if (keysHeld() & KEY_RIGHT) {
        //rotate clockwise
        ship->turnClockwise();
    }

    /*
     *  Handle the touch screen.
     *
     *  This is basically some fancy pants junk to enable grabbing and moving
     *  of the moon. It isn't essential to know how this code works to
     *  understand how to reach values from the touch screen, but it was cool
     *  enough that I wanted to put it in the case study.
     */
    static MathVector2D<int> moonGrip;
    if (keysDown() & KEY_TOUCH) {
        /* Record the grip */
        moonGrip.x = touch->px;
        moonGrip.y = touch->py;
    } else if (keysHeld() & KEY_TOUCH) {
        int newX = moonPos->x + touch->px - moonGrip.x;
        int newY = moonPos->y + touch->py - moonGrip.y;

        /* Prevent dragging off the screen. */
        if (newX < 0) {
            moonPos->x = 0;
        } else if (newX > (SCREEN_WIDTH - moonInfo->width)) {
            moonPos->x = SCREEN_WIDTH - moonInfo->width;
        } else {
            moonPos->x = newX;
        }
        if (newY < 0) {
            moonPos->y = 0;
        } else if (newY > (SCREEN_HEIGHT - moonInfo->height)) {
            moonPos->y = SCREEN_HEIGHT - moonInfo->height;
        } else {
            moonPos->y = newY;
        }

        /* Record the grip again. */
        moonGrip.x = touch->px;
        moonGrip.y = touch->py;
    }
}