Exemplo n.º 1
0
void frame_play()
{
	manage_sprites(); 
	move_player();
	move_camera();
	animate_tilemap();

	all_sprite_move(); // sprite movement and collisions


	update_hud();
}
Exemplo n.º 2
0
bool Game::main_loop()
{
// Sanity check
  if (!w_map || !w_hud || !player || !worldmap || !map) {
    return false;
  }
  if (game_over) {
    return false;
  }
  player->gain_action_points();
  while (player->action_points > 0) {
    handle_player_activity();
    shift_if_needed();
    update_hud();
    map->draw(w_map, &entities, player->pos);
    w_map->refresh();

    if (!player->activity.is_active()) {
      long ch = input();
      if (ch == '!') {
        Monster* mon = new Monster;
        mon->set_type("zombie");
        mon->pos.x = player->pos.x - 3;
        mon->pos.y = player->pos.y - 3;
        entities.add_entity(mon);
      }
      Interface_action act = KEYBINDINGS.bound_to_key(ch);
      do_action(act);
    }
  }
  shift_if_needed();
  move_entities();
  if (game_over) {
    return false;
  }
  return true;
}
Exemplo n.º 3
0
int run_game_loop(GameState * state) {
	int done = 0;
	int i = 0;

	/* Initialise gui */
	init_gui(SCREEN_WIDTH,SCREEN_HEIGHT);

	/* Load resources */
	init_sprite_cache();
	render_world_to_sprite(&state->world);
	update_hud(
		&state->hud, 
		&state->score,
		&state->mana,
		&state->money, 
		&state->world.castle->castle.health,
		&state->wave.wave_number,
		&state->play);

	/* Initialise game loop */
	init_game_loop(FPS);
	while (!done) {
		
			/* Get events */
			Event ev;
			wait_for_event(&ev);

			/* Event handlers */
			switch (ev.type) {
			case EVENT_TIMER:
				state->redraw = 1;
				if (!state->game_over) {
					if (*state->hud.play) {
						check_spells(state);
						check_enemy_wave(state);
						update_movement(state);
						do_tower_attacks(state);
					}
				}
				break;
			case EVENT_MOUSE_MOVE:
				mouse_move(&ev.mouseMoveEvent, state);
				break;
			case EVENT_MOUSE_DOWN:
				mouse_down(&ev.mouseDownEvent, state);
				break;
			case EVENT_MOUSE_UP:
				mouse_up(&ev.mouseUpEvent, state);
				break;
			case EVENT_DISPLAY_CLOSE:
				done = 1;
				break;
			} 

			/* Render only on timer event AND if all movement and logic was processed */
			if (state->redraw && all_events_processed()) { 
				render_game(state);
			}
	}
	/* Cleanup */
	cleanup_game_loop();
	cleanup_sprite_cache();
	return 0;
}