Exemplo n.º 1
0
void my_display()
{
 glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);

  glMatrixMode(GL_PROJECTION);
  glPushMatrix();
  glLoadIdentity();
  glMatrixMode(GL_MODELVIEW);
  glPushMatrix();
  glLoadIdentity();

  draw_nozzles();


  if (light_screen) {
   glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
   light_screen++;

   if (light_screen >= 4) {
    light_screen = 0;
    glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
   }
  }

  draw_explosion();

  // restore projection
  glMatrixMode(GL_PROJECTION);
  glPopMatrix();
  glMatrixMode(GL_MODELVIEW);
  glPopMatrix();

  glutSwapBuffers();
}
Exemplo n.º 2
0
void my_display()
{
 glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);

 if (shift_camera) {
    glLoadIdentity();
    //setup the camera (1st person? 3rd person?)

    gluLookAt(3, 0, 6,
        0, 0, 0,
        0, 1, 0);
  }
  else {
    glMatrixMode(GL_PROJECTION);
    glPushMatrix();
    glLoadIdentity();
    glMatrixMode(GL_MODELVIEW);
    glPushMatrix();
    glLoadIdentity();
  }

  draw_nozzles();
  draw_explosion();

  if (!shift_camera) {
    // restore projection
    glMatrixMode(GL_PROJECTION);
    glPopMatrix();
    glMatrixMode(GL_MODELVIEW);
    glPopMatrix();
  }
  glutSwapBuffers();
}
Exemplo n.º 3
0
void
draw_explosions(void)
{
	int i;

	glPushAttrib(GL_ALL_ATTRIB_BITS);

	glDisable(GL_LIGHTING);
	glDisable(GL_CULL_FACE);
	glShadeModel(GL_FLAT);
	glDisable(GL_CULL_FACE);

	glEnable(GL_TEXTURE_2D);

	glEnable(GL_BLEND);

	for (i = 0; i < NUM_EXPLOSION_TYPES; i++) {
		const struct explosion *p;

		glBindTexture(GL_TEXTURE_2D, gl_texture_id(explosion_data[i].texture_id));

		switch (explosion_data[i].blend_type) {
			case 0:
				glBlendFunc(GL_SRC_ALPHA,
				  GL_ONE_MINUS_SRC_ALPHA);
				break;

			case 1:
				glBlendFunc(GL_ONE, GL_ONE);
				break;

			default:
				assert(0);
		}

		for (p = explosions; p != &explosions[MAX_EXPLOSIONS]; p++) {
			if (p->used && p->type == i)
				draw_explosion(p);
		}
	}

	glPopAttrib();
}
Exemplo n.º 4
0
/* from f to t */
void ball(int fx, int fy, int tx, int ty, int dmg, int dtype)
{
    int xx,yy,ex,ey,i;
    Monster *target;
    Symbol expchar=('@' | CLR(LIGHT_PURPLE));

    xx = fx;
    yy = fy;

    switch(dtype) {
    case FLAME:
        expchar=('*' | CLR(LIGHT_RED));
        break;
    case COLD:
        expchar=('o' | CLR(WHITE));
        break;
    case ELECTRICITY:
        expchar=('^' | CLR(LIGHT_BLUE));
        break;
    }

    do_los(expchar,&xx,&yy,tx,ty);
    draw_explosion(expchar,xx,yy);
    for(i=0; i<9; i++) {
        ex = xx + Dirs[0][i];
        ey = yy + Dirs[1][i];

        if ((ex == Player.x) && (ey == Player.y)) {
            switch(dtype) {
            case FLAME:
                mprint("You were blasted by a fireball!");
                p_damage(random_range(dmg),FLAME,"a fireball");
                break;
            case COLD:
                mprint("You were blasted by a snowball!");
                p_damage(random_range(dmg),COLD,"a snowball");
                break;
            case ELECTRICITY:
                mprint("You were blasted by ball lightning!");
                p_damage(random_range(dmg),ELECTRICITY,"ball lightning");
                break;
            case UNSTOPPABLE:
                mprint("Oh No! Manastorm!");
                p_damage(random_range(dmg),UNSTOPPABLE,"a manastorm!");
                break;
            }
        }
        if (NULL != (target = Level->site[ex][ey].creature)) {
            if (los_p(Player.x,Player.y,target->x,target->y)) {
                if (target->uniqueness == COMMON) {
                    strcpy(Str1,"The ");
                    strcat(Str1,target->name);
                }
                else strcpy(Str1,target->name);
                switch(dtype) {
                case FLAME:
                    strcat(Str1," was zorched by a fireball!");
                    break;
                case COLD:
                    strcat(Str1," was blasted by a snowball!");
                    break;
                case ELECTRICITY:
                    strcat(Str1," was zapped by ball lightning!");
                    break;
                case UNSTOPPABLE:
                    strcat(Str1," was nuked by a manastorm!");
                    break;
                }
                mprint(Str1);
            }
            m_status_set(target,HOSTILE);
            target->m_damage(random_range(dmg),dtype);
        }
        if (Level->site[ex][ey].locchar == HEDGE)
            if (Level->site[ex][ey].p_locf != L_TRIFID) {
                if ((dtype == FLAME)||(dtype == ELECTRICITY)) {
                    mprint("The hedge is blasted away!");
                    Level->site[ex][ey].p_locf = L_NO_OP;
                    Level->site[ex][ey].locchar = FLOOR;
                    plotspot(ex,ey,true);
                    lset(ex, ey, CHANGED);
                }
                else mprint("The hedge is unaffected.");
            }
            else mprint("The trifid absorbs the energy and laughs!");
        else if (Level->site[ex][ey].locchar == WATER)
            if (dtype == FLAME) {
                mprint("The water is vaporised!");
                Level->site[ex][ey].p_locf = L_NO_OP;
                Level->site[ex][ey].locchar = FLOOR;
                plotspot(ex,ey,true);
                lset(ex, ey, CHANGED);
            }
    }
}
Exemplo n.º 5
0
int main(int argc, char const *argv[])
{
	const int FPS = 60;
	const int MAX_BULLETS = 10;
	const int MAX_ASTEROIDS = 10;
	const int MAX_EXPLOSIONS = 10;
	srand(time(NULL));
	int done = 0;
	int redraw = 1;

	if(!al_init())
	{
		al_show_native_message_box(NULL, "Error", "Error", 
			"Could not initialize Allegro 5.", 0, ALLEGRO_MESSAGEBOX_ERROR);
		return -1;
	}

	ALLEGRO_DISPLAY *display = al_create_display(screen_width, screen_height);
	if(!display)
	{
		al_show_native_message_box(NULL, "Error", "Error", 
			"Could not create display.", 0, ALLEGRO_MESSAGEBOX_ERROR);
		return -1;
	}

	ALLEGRO_EVENT_QUEUE *event_queue = al_create_event_queue();
	if(!event_queue)
	{
		al_show_native_message_box(display, "Error", "Error", 
			"Could not create event queue.", 0, ALLEGRO_MESSAGEBOX_ERROR);
		return -1;
	}

	ALLEGRO_TIMER *timer = al_create_timer(1.0/FPS);
	if(!timer)
	{
		al_show_native_message_box(display, "Error", "Error", 
			"Could not create timer.", 0, ALLEGRO_MESSAGEBOX_ERROR);
		return -1;
	}

	if(!al_install_keyboard())
	{
		al_show_native_message_box(display, "Error", "Error", 
			"Could not install keyboard.", 0, ALLEGRO_MESSAGEBOX_ERROR);
		return -1;
	}

	if(!al_install_mouse())
	{
		al_show_native_message_box(display, "Error", "Error", 
			"Could not install mouse.", 0, ALLEGRO_MESSAGEBOX_ERROR);
		return -1;
	}

	if(!al_init_image_addon())
	{
		al_show_native_message_box(display, "Error", "Error", 
			"Could not initialize image addon.", 0, ALLEGRO_MESSAGEBOX_ERROR);
		return -1;
	}

	if(!al_init_primitives_addon())
	{
		al_show_native_message_box(display, "Error", "Error", 
			"Could not initialize primitives addon.", 0, ALLEGRO_MESSAGEBOX_ERROR);
	}

	al_init_font_addon(); // for whatever reason this function is void returning

	if(!al_init_ttf_addon())
	{
		al_show_native_message_box(display, "Error", "Error", 
			"Could not initialize ttf addon.", 0, ALLEGRO_MESSAGEBOX_ERROR);
	}
	
	al_hide_mouse_cursor(display);

	al_register_event_source(event_queue, al_get_mouse_event_source());
	al_register_event_source(event_queue, al_get_keyboard_event_source());
	al_register_event_source(event_queue, al_get_display_event_source(display));
	al_register_event_source(event_queue, al_get_timer_event_source(timer));

	ALLEGRO_FONT *font18 = al_load_font("Arial.ttf", 18, 0);

	int prev_x = screen_width, prev_y = screen_height;
	int fps_counter = 0;
	int fps_counter2 = 0;
	int i, j, k;

	struct spaceship ship;
	init_ship(&ship);

	struct bullet bullets[MAX_BULLETS];
	for(i = 0; i < MAX_BULLETS; i++)
	{
		init_bullet(&bullets[i]);
	}

	struct asteroid asteroids[MAX_ASTEROIDS];
	for(i = 0; i < MAX_ASTEROIDS; i++)
	{
		init_asteroid(&asteroids[i]);
	}

	struct explosion explosions[MAX_EXPLOSIONS];
	for(i = 0; i < MAX_EXPLOSIONS; i++)
	{
		init_explosion(&explosions[i]);
	}

	al_start_timer(timer);

	while(!done)
	{
		ALLEGRO_EVENT event;
		al_wait_for_event(event_queue, &event);

		if(event.type == ALLEGRO_EVENT_DISPLAY_CLOSE)
		{
			done = 1;
		}
		if(event.type == ALLEGRO_EVENT_KEY_DOWN)
		{
			switch(event.keyboard.keycode)
			{
				case ALLEGRO_KEY_Q: 
					done = 1;
					break;
				case ALLEGRO_KEY_ESCAPE:
					done = 1;
					break;
			}
		}
		if(event.type == ALLEGRO_EVENT_MOUSE_BUTTON_DOWN)
		{
			if(event.mouse.button & 1)
			{
				for(i = 0; i < MAX_BULLETS; i++)
				{
					if(!bullets[i].live)
					{
						fire_bullet(&bullets[i], ship);
						break;
					}
				}
			}
		}
		if(event.type == ALLEGRO_EVENT_MOUSE_AXES ||
              event.type == ALLEGRO_EVENT_MOUSE_ENTER_DISPLAY)
		{
			set_ship_coordinates(&ship, event.mouse.x, event.mouse.y);
		}
		if(event.type == ALLEGRO_EVENT_TIMER)
		{	
			if(ship.x > prev_x)
			{	
				ship.sprite.dir_horizontal = RIGHT;
			}
			else if(ship.x == prev_x)
			{
				ship.sprite.dir_horizontal = CENTER;
			}
			else if(ship.x < prev_x) 
			{
				ship.sprite.dir_horizontal = LEFT;
			}

			if(ship.y > prev_y)
			{
				ship.sprite.dir_vertical = BACK;
			}
			else if(ship.y == prev_y)
			{
				ship.sprite.dir_vertical = NEUTRAL;
			}
			else if(ship.y < prev_y)
			{
				ship.sprite.dir_vertical = FORWARD;
			}

			if(++fps_counter >= FPS / 5)
			{
				fps_counter = 0;
				prev_x = ship.x;
				prev_y = ship.y;	
			}

			if(++fps_counter2 >= 2 * FPS)
			{
				for(i = 0; i < MAX_ASTEROIDS; i++)
				{
					if(!asteroids[i].live)
					{
						start_asteroid(&asteroids[i]);
						break;
					}
				}
				fps_counter2 = 0;
			}

			for(i = 0; i < MAX_BULLETS; i++)
			{
				if(bullets[i].live)
				{
					update_bullet(&bullets[i]);
				}
			}

			for(i = 0; i < MAX_ASTEROIDS; i++)
			{
				if(asteroids[i].live)
				{
					update_asteroid(&asteroids[i], &ship);
				}
			}

			for(i = 0; i < MAX_EXPLOSIONS; i++)
			{
				if(explosions[i].live)
				{
					update_explosion(&explosions[i]);
				}
			}

			update_ship_boundaries(&ship);

			for(i = 0; i < MAX_BULLETS; i++)
			{
				if(bullets[i].live)
				{
					for(j = 0; j < MAX_ASTEROIDS; j++)
					{
						if(asteroids[j].live)
						{
							if(bullet_and_asteroid_collision(bullets[i], asteroids[j]))
							{
								bullets[i].live = 0;
								asteroids[j].live = 0;
								ship.score += 20;
								for(k = 0; k < MAX_EXPLOSIONS; k++)
								{
									if(!explosions[k].live)
									{
										start_explosion(&explosions[k], bullets[i].x, bullets[i].y);
										break;
									}
								}
							}
						}
					}
				}
			}

			for(i = 0; i < MAX_ASTEROIDS; i++)
			{
				if(asteroids[i].live)
				{
					if(ship_and_asteroid_collision(ship, asteroids[i]))
					{
						asteroids[i].live = 0;
						for(k = 0; k < MAX_EXPLOSIONS; k++)
						{
							if(!explosions[k].live)
							{
								start_explosion(&explosions[k], ship.x, ship.y);
								break;
							}
						}
						
						ship.lives--;
					}
				}
			}

			if(!ship.lives)
			{
				done = true;
			}

			redraw = 1;
		}

		if(redraw)
		{
			redraw = 0;
			draw_ship_sprite(ship.sprite, ship.x, ship.y);
			for(i = 0; i < MAX_BULLETS; i++)
			{
				if(bullets[i].live)
				{
					draw_bullet(bullets[i]);
				}
			}
			for(i = 0; i < MAX_ASTEROIDS; i++)
			{
				if(asteroids[i].live)
				{
					draw_asteroid(asteroids[i]);
				}
			}
			for(i = 0; i < MAX_EXPLOSIONS; i++)
			{
				if(explosions[i].live)
				{
					draw_explosion(explosions[i]);
				}
			}
			al_draw_textf(font18, al_map_rgb(255, 255, 255), 50, 5, 0, 
				"Score: %d ", ship.score); // I have no idea why it doesn't print the S...
			al_draw_textf(font18, al_map_rgb(255, 255, 255), 50, 25, 0, 
				"Lives: %d", ship.lives);
			al_flip_display();
			al_clear_to_color(al_map_rgb(0, 0, 0));
		}
	}

	for(i = 0; i < MAX_ASTEROIDS; i++)
	{
		destroy_asteroid(&asteroids[i]);
	}
	for(i = 0; i < MAX_EXPLOSIONS; i++)
	{
		destroy_explosion(&explosions[i]);
	}
	destroy_sprite(&ship.sprite);
	al_destroy_display(display);
	al_destroy_event_queue(event_queue);
	al_destroy_timer(timer);
	al_destroy_font(font18);

	return 0;
}