Example #1
0
void init_sounds(void)
{
#ifdef USE_SOUND
    //FMOD_RESULT result;
    if (fmod_init()) {
        printf("ERROR - fmod_init()\n\n");
        return;
    }
    if (fmod_createsound("./sounds/Intro Quack.mp3", 0)) {
        printf("ERROR - fmod_createsound()\n\n");
        return;
    }
    if (fmod_createsound("./sounds/KillingJokeIntro.mp3", 1)) {
        printf("ERROR - fmod_createsound()\n\n");
        return;
    }
    if (fmod_createsound("./sounds/PunchSoundEffect.mp3", 2)) {
        printf("ERROR - fmod_createsound()\n\n");
        return;
    }
    fmod_setmode(0,FMOD_LOOP_NORMAL);
    fmod_playsound(0);
    //fmod_systemupdate();
#endif //USE_SOUND
}
Example #2
0
void kangarooDeath(void)
{
    fmod_playsound(4);
    white ^= 1;
    lives--;
    rhinoReset();
    animalReset();
    kangarooReset();

}
Example #3
0
void attack_list::copyAttackPlatform(Object *caster, int tId, int x, int y){
  if(currents_length >= MAX_CURRENTS) return;

  currents[currents_length] = new Attack(attacks[tId]);
  currents[currents_length]->setID(currents_length);

  currents[currents_length]->targetAt(caster);
  currents[currents_length]->setCenter(caster->getCenterX()+x,
      caster->getCenterY()+y);
#ifdef USE_SOUND
  //cout << currents[currents_length]->getAttackSound()<<endl;
  fmod_playsound(currents[currents_length]->getAttackSound());
#endif
  currents_length++;
}
Example #4
0
int main(void)
{
    int done=0;
    srand(time(NULL));
    initXWindows();
    init_opengl();
    init_sounds();

    clock_gettime(CLOCK_REALTIME, &timePause);
    clock_gettime(CLOCK_REALTIME, &timeStart);
    //declare game object
    Game game;

    fmod_playsound(1);
    //start animation
    while(!done) {
	while(XPending(dpy)) {
	    XEvent e;
	    XNextEvent(dpy, &e);
	    check_resize(&e);
	    check_mouse(&e, &game);
	    done = check_keys(&e, &game);
	}
	clock_gettime(CLOCK_REALTIME, &timeCurrent);
	timeSpan = timeDiff(&timeStart, &timeCurrent);
	timeCopy(&timeStart, &timeCurrent);
	movementCountdown += timeSpan;
	while(movementCountdown >= movementRate)
	{
	    movement(&game);
	    movementCountdown -= movementRate;
	}
	render(&game);
	glXSwapBuffers(dpy, win);
    }
    cleanupXWindows();
    cleanup_fonts();
#ifdef USE_SOUND
    fmod_cleanup();
#endif //USE_SOUND
    return 0;
}
void render(void)
{
    Rect r;
    //Clear the screen
    glClearColor(1.0, 1.0, 1.0, 1.0);
    glClear(GL_COLOR_BUFFER_BIT);

    //
    //
    //draw a quad with texture
    glColor3f(1.0, 1.0, 1.0);

    //Loop the background
    double *yOFFsetLevel = &setLevel;
    double *yOFFsetMountain = &setMountain;

    if(*yOFFsetLevel <= -(levelImage->width))
        *yOFFsetLevel = 0.0;
    if(*yOFFsetMountain <= -(mountainsImage->width))
        *yOFFsetMountain = 0.0;
    /////////////////////////////////////////////

    if (background) {
        draw_background();
    }
    if (start) {
        StartMenu();
    }

    perspective();

    if(show_ufo)
    {
        draw_ufo();
        draw_yellow();
    }
    if(white)
    {
        draw_white();
    }
    if (lives <= 0) {
        GameOver();
        gameover = 1;
        if(soundcount == 0)
            fmod_playsound(1);
        soundcount++;
    }

    glDisable(GL_TEXTURE_2D);
    glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
    glEnable(GL_BLEND);
    glDisable(GL_BLEND);
    glEnable(GL_TEXTURE_2D);

    glBindTexture(GL_TEXTURE_2D, 0);

    r.bot = yres - 20;
    r.left = 10;
    r.center = 0;
    unsigned int cref = 0x00ffffff;

    if(start)
    {
        r.bot = yres - 175;
        r.left = (xres/2) - 80;
        r.center = 0;
        unsigned int cref = 0x00000000;

        //Help menu only show in start
        ggprint10(&r, 16, cref, "Move Up: UP Arrow Key");
        ggprint10(&r, 16, cref, "Move Down: Down Arrow Key");
        ggprint10(&r, 16, cref, "Move Left: Left Arrow Key");
        ggprint10(&r, 16, cref, "Move Right: Right Arrow Key");
        ggprint10(&r, 16, cref, "Punch: Space Key");
    }
    if(show_animal && show_rhino)
    {
        //In game menu, only show in game
        ggprint16(&r, 16, cref, "Lives: %i", lives);
        ggprint16(&r, 16, cref, "High Score: %i", high_score);
        if(ufocount) {
            ggprint16(&r, 16, cref, "UFO Help (Press Enter): %i", ufocount);
        }
    }
}
Example #6
0
void play_music() {
    fmod_playsound(0);
}
Example #7
0
void check_keys(XEvent *e)
{
    //keyboard input?
    int key = XLookupKeysym(&e->xkey, 0);
    if (e->type == KeyRelease) {
        if (key == XK_Shift_L || key == XK_Shift_R)
            return;
    }
    if (e->type == KeyPress) {
        if (key == XK_Shift_L || key == XK_Shift_R) {
            return;
        }
    } else {
        return;
    }

    Flt punch_dist, hit_dist, apple_hit_dist;//##################APPLE_HIT_DIST########################################
    switch(key) {
        /*Dont need this because start button;
          case XK_Return:
          start = 0;
          break;
          */
        case XK_a:
            show_ufo ^= 1;
            break;
        case XK_j:
            kangarooDeath();
            break;
        case XK_k:
            lives += 1;
            break;
        case XK_l:
            lives -= lives;
            break;
        case XK_Left:
            if (!(kangaroo.pos[0] - kangaroo.width2 < (xres-xres))) {
                VecCopy(kangaroo.pos, kangaroo.lastpos);
                hop ^= 1;
                kangaroo.pos[0] -= 67.0;
            }
            break;
        case XK_Right:
            if (!(kangaroo.pos[0] + kangaroo.width2 >= xres)) {
                VecCopy(kangaroo.pos, kangaroo.lastpos);
                hop ^= 1;
                kangaroo.pos[0] += 67.0;
            }
            break;
        case XK_Up:
            if (!(kangaroo.pos[1] >= (float)yres/2)) {
                VecCopy(kangaroo.pos, kangaroo.lastpos);
                hop ^= 1;
                kangaroo.pos[1] += 67.0;
            }
            break;
        case XK_Down:
            if (!(kangaroo.pos[1] < 100.0)) {
                VecCopy(kangaroo.pos, kangaroo.lastpos);
                hop ^= 1;
                kangaroo.pos[1] -= 67.0;
            }
            break;
        case XK_space:
            /*punch_image+=1;*/
            punch ^= 1;
            fmod_playsound(2);

            punch_dist = kangaroo.pos[0] + kangaroo.height2;
            hit_dist = rhino.pos[0] - rhino.height2;
            apple_hit_dist = apple.pos[0] - apple.height2;//apple line!!##################
            if (rhino.pos[1] >= (kangaroo.pos[1] - kangaroo.height2)
                    && rhino.pos[1] <= (kangaroo.pos[1] + kangaroo.height2)) {
                if ((hit_dist - punch_dist) >= 25 && (hit_dist - punch_dist <= 90.0))
                {
                    if (show_rhino) {
                        rhinoReset();
                    }
                    high_score += 100;
                }
            }
            hit_dist = animal.pos[0] - animal.height2;
            if (animal.pos[1] >= (kangaroo.pos[1] - kangaroo.height2)
                    && animal.pos[1] <= (kangaroo.pos[1] + kangaroo.height2)) {
                if ((hit_dist - punch_dist) >= 25 && (hit_dist - punch_dist <= 90.0))
                {
                    if (show_animal) {
                        animalReset();
                    }
                    high_score += 500;
                }
            }
           /* if (apple.pos[1] >= (kangaroo.pos[1] - kangaroo.height2)
                    && apple.pos[1] <= (kangaroo.pos[1] + kangaroo.height2)) {
                if ((apple_hit_dist - punch_dist) >= 25 && (apple_hit_dist - punch_dist <= 90.0))
                {
                    if (show_apple) {
                        appleReset();
                        lives++;
                    }*/ //##############################################ANGEL

                }
            }
Example #8
0
void check_mouse(XEvent *e, Game *game)
{
    int y = WINDOW_HEIGHT - e->xbutton.y;

    Duck *d = game->duck;
    Duck *saved = new Duck;
    struct timespec dt;
    clock_gettime(CLOCK_REALTIME, &dt);
    double ts;

    if (e->type == ButtonRelease) {
	return;
    }
    if (e->type == ButtonPress) {
	if (e->xbutton.button==1) {
	    //#ifdef USE_SOUND //////////////////////////////////////////////////
	    //Left button was pressed
	    while(d)
	    {
		fmod_playsound(0);
		if(e->xbutton.x >= d->s.center.x - d->s.width &&
			e->xbutton.x <= d->s.center.x + d->s.width &&
			y <= d->s.center.y + d->s.height &&
			y >= d->s.center.y - d->s.height)
		{
		    makeDeadDuck(game, d);
		    ts = timeDiff(&d->time, &dt);
		    if(ts < 1.5)
		    {
			game->deadD->points = true;
			game->score += 200;
		    }
		    else
		    {
			game->deadD->points = false;
			game->score += 100;
		    }
		    saved = d->next;
		    deleteDuck(game, d);
		    d = saved;
		    game->bullets--;
		    game->duckShot++;
		    game->duckCaptured++;
		    if(game->bullets < 1)
		    {
			if(game->n == 1)
			{
			    makeFreeDuck(game, d);
			    saved = d->next;
			    deleteDuck(game, d);
			    d = saved;
			}
			return;
		    }
		    return;
		}
		if(game->n == 2)
		{
		    d = d->next;
		    if(e->xbutton.x >= d->s.center.x - d->s.width &&
			    e->xbutton.x <= d->s.center.x + d->s.width &&
			    y <= d->s.center.y + d->s.height &&
			    y >= d->s.center.y - d->s.height)
		    {
			makeDeadDuck(game, d);
			ts = timeDiff(&d->time, &dt);
			if(ts < 1.5)
			{
			    game->deadD->points = true;
			    game->score += 200;
			}
			else
			{
			    game->deadD->points = false;
			    game->score += 100;
			}
			saved = d->prev;
			deleteDuck(game, d);
			d = saved;
			game->bullets--;
			game->duckShot++;
			game->duckCaptured++;
			if(game->bullets < 1)
			{
			    if(game->n == 1)
			    {
				makeFreeDuck(game, d);
				saved = d->next;
				deleteDuck(game, d);
				d = saved;
			    }
			    return;
			}
			return;
		    }
		}
		if(game->bullets <= 1)
		{
		    game->bullets--;
		    if(game->n == 2)
		    {
			d = d->prev;
		    }
		    makeFreeDuck(game, d);
		    saved = d->next;
		    deleteDuck(game, d);
		    d = saved;
		    if(game->n == 1)
		    {
			makeFreeDuck(game, d);
			saved = d->next;
			deleteDuck(game, d);
			d = saved;
		    }
		    return;
		}
		game->bullets--;
		d = d->next;
	    }
	}
	//#endif
    }
    if (e->xbutton.button==3) {
	//Right button was pressed
	return;
    }
}
Example #9
0
void play() {
    fmod_playsound(0);
}
Example #10
0
void check_raindrops()
{
	if (random(100) < 50) {
		create_raindrop(ndrops);
	}
	//
	//move rain droplets
	//if (ihead) {
	Raindrop *node = ihead;
	while(node) {
		//force is toward the ground
		node->vel[1] += gravity;
		VecCopy(node->pos, node->lastpos);
		node->pos[0] += node->vel[0] * timeslice;
		node->pos[1] += node->vel[1] * timeslice;
		if (fabs(node->vel[1]) > node->maxvel[1])
			node->vel[1] *= 0.96;
		node->vel[0] *= 0.999;
		//
		//if (node->next == NULL) break;
		node = node->next;
	}
	//}
	//
	//check rain droplets
	//if (ihead) {
	int n=0;
	//Raindrop *savenode;
	node = ihead;
	while(node) {
		n++;
		#ifdef USE_SOUND
		if (node->pos[1] < 0.0f) {
			//raindrop hit ground
			if (!node->sound && play_sounds) {
				//small chance that a sound will play
				int r = random(50);
				if (r==1)
					fmod_playsound(0);
				//if (r==2)
				//	fmod_playsound(1);
				//sound plays once per raindrop
				node->sound=1;
			}
		}
		#endif //USE_SOUND
		#ifdef USE_UMBRELLA
		//collision detection for raindrop on umbrella
		if (show_umbrella) {
			if (umbrella.shape == UMBRELLA_FLAT) {
				if (node->pos[0] >= (umbrella.pos[0] - umbrella.width2) &&
					node->pos[0] <= (umbrella.pos[0] + umbrella.width2)) {
					if (node->lastpos[1] > umbrella.lastpos[1] ||
						node->lastpos[1] > umbrella.pos[1]) {
						if (node->pos[1] <= umbrella.pos[1] ||
							node->pos[1] <= umbrella.lastpos[1]) {
							if (node->linewidth > 1) {
								Raindrop *savenode = node->next;
								delete_rain(node);
								node = savenode;
								continue;
							}
						}
					}
				}
			}
			if (umbrella.shape == UMBRELLA_ROUND) {
				float d0 = node->pos[0] - umbrella.pos[0];
				float d1 = node->pos[1] - umbrella.pos[1];
				float distance = sqrt((d0*d0)+(d1*d1));
				//Log("distance: %f  umbrella.radius: %f\n",
				//							distance,umbrella.radius);
				if (distance <= umbrella.radius &&
										node->pos[1] > umbrella.pos[1]) {
					if (node->linewidth > 1) {
						if (deflection) {
							//deflect raindrop
							double dot;
							Vec v, up = {0,1,0};
							VecSub(node->pos, umbrella.pos, v);
							VecNormalize(v);
							node->pos[0] =
								umbrella.pos[0] + v[0] * umbrella.radius;
							node->pos[1] =
								umbrella.pos[1] + v[1] * umbrella.radius;
							dot = VecDot(v,up);
							dot += 1.0;
							node->vel[0] += v[0] * dot * 1.0;
							node->vel[1] += v[1] * dot * 1.0;
						} else {
							Raindrop *savenode = node->next;
							delete_rain(node);
							node = savenode;
							continue;
						}
					}
				}
			}
			//VecCopy(umbrella.pos, umbrella.lastpos);
		}
		#endif //USE_UMBRELLA
		if (node->pos[1] < -20.0f) {
			//rain drop is below the visible area
			Raindrop *savenode = node->next;
			delete_rain(node);
			node = savenode;
			continue;
		}
		//if (node->next == NULL) break;
		node = node->next;
	}
	if (maxrain < n)
		maxrain = n;
	//}
}