コード例 #1
0
ファイル: tick.c プロジェクト: galexcode/elf_forest
void tick(int steps) {
  tick_general_controls();
  if (steps == 0 || PAUSED) {
    return;
  }
  adjust_physics_resolution();
  int i;
  for (i = 0; i < steps; ++i) {
    TICK_COUNT = (TICK_COUNT + 1) % TICKS_PER_SECOND_I;
    tick_motion_controls();
    tick_entities(&MAIN_FRAME);
    warp_space(&MAIN_FRAME, PLAYER);
    tick_blocks(&MAIN_FRAME);
  }
  tick_data();
  clear_edge_triggers();
}
コード例 #2
0
ファイル: Game.cpp プロジェクト: quantumrain/LD29
void GameUpdate() {
	game* g = &g_game;

	if (is_key_pressed(KEY_RESET)) {
		memset(g->_map, 0, sizeof(g->_map));

		g->_entities.free();
		g->_player = 0;

		g->_cam_pos = vec2(MAP_WIDTH * 0.5f, 8.5f);
		g->_target_cam_y = 8.5f;

		g->_diff = 1;
		g->_diff_dmg = 1;
		g->_spawn_time = 800;
		g->_spawn_count = 6;
		g->_wave_incoming = true;
		g->_plr_dmg = 1;

		GameInit();

		g_title = true;
	}

	if (g_title) {
		set_camera(vec2(), 10.0f);

		float ratio = g_WinSize.y / (float)g_WinSize.x;
		vec2 orig(-10.0f, -10.0f * ratio);

		draw_string(vec2(0.0f, -4.75), 0.15f, TEXT_CENTRE, colour(0.5f, 0.5f, 1.0f, 1.0f), "Tunnel Defense");

		float y = -3.25f;

		draw_string(vec2(0.0f, y), 0.05f, TEXT_CENTRE, colour(0.3f, 0.3f, 0.6f, 1.0f), "Originally made for LD29 - post competition version"); y += 0.5f;

		y += 0.5f;

		draw_string(vec2(0.0f, y), 0.05f, TEXT_CENTRE, colour(0.6f, 0.3f, 0.3f, 1.0f), "Dig for your life, the creeps are coming and the"); y += 0.5f;
		draw_string(vec2(0.0f, y), 0.05f, TEXT_CENTRE, colour(0.6f, 0.3f, 0.3f, 1.0f), "only safe place is underground! Collect resources"); y += 0.5f;
		draw_string(vec2(0.0f, y), 0.05f, TEXT_CENTRE, colour(0.6f, 0.3f, 0.3f, 1.0f), "and build turrets to protect yourself."); y += 0.5f;

		y += 0.25f;

		float r = 5.0f;

		draw_string(vec2(-r, y), 0.05f, TEXT_LEFT, colour(0.6f, 0.6f, 0.6f, 1.0f), "\001\002\003\004");
		draw_string(vec2(r, y), 0.05f, TEXT_RIGHT, colour(0.3f, 0.6f, 0.3f, 1.0f), "Move + Aim"); y += 0.5f;
		draw_string(vec2(-r, y), 0.05f, TEXT_LEFT, colour(0.6f, 0.6f, 0.6f, 1.0f), "%c", g_LocKeyZ);
		draw_string(vec2(r, y), 0.05f, TEXT_RIGHT, colour(0.3f, 0.6f, 0.3f, 1.0f), "Jump"); y += 0.5f;
		draw_string(vec2(-r, y), 0.05f, TEXT_LEFT, colour(0.6f, 0.6f, 0.6f, 1.0f), "%c", g_LocKeyX);
		draw_string(vec2(r, y), 0.05f, TEXT_RIGHT, colour(0.3f, 0.6f, 0.3f, 1.0f), "Dig block / shoot"); y += 0.5f;
		draw_string(vec2(-r, y), 0.05f, TEXT_LEFT, colour(0.6f, 0.6f, 0.6f, 1.0f), "%c", g_LocKeyC);
		draw_string(vec2(r, y), 0.05f, TEXT_RIGHT, colour(0.3f, 0.6f, 0.3f, 1.0f), "Build / upgrade turret"); y += 0.5f;

		y += 0.25f;

		draw_string(vec2(0.0f, y), 0.05f, TEXT_CENTRE, colour(0.15f, 0.3f, 0.15f, 1.0f), "Alternate controls - %c%c%c%c, %c, %c, %c", g_LocKeyW, g_LocKeyA, g_LocKeyS, g_LocKeyD, g_LocKeyI, g_LocKeyO, g_LocKeyP); y += 0.5f;

		y += 0.25f;

		draw_string(vec2(0.0f, y), 0.05f, TEXT_CENTRE, colour(0.3f, 0.15f, 0.3f, 1.0f), "Building / upgrading a turret costs 3 metal."); y += 0.5f;
		draw_string(vec2(0.0f, y), 0.05f, TEXT_CENTRE, colour(0.3f, 0.15f, 0.3f, 1.0f), "Building a turret increases your shot power."); y += 0.5f;

		y += 0.25f;

		draw_string(vec2(0.0f, y), 0.05f, TEXT_CENTRE, colour(0.5f, 0.5f, 0.5f, 1.0f), "press SPACE to START"); y+= 0.5f;

		y += 0.5f;

		draw_string(vec2(0.0f, y), 0.035f, TEXT_CENTRE, colour(0.15f, 0.15f, 0.15f, 1.0f), "by Stephen Cakebread @quantumrain");

		if (is_key_pressed(KEY_FIRE) || is_key_pressed(KEY_ALT_FIRE)) g_title = false;

		return;
	}

	if (player* p = g->_player) {
		vec2 target_cam_pos = vec2(MAP_WIDTH * 0.5f, p->centre().y);

		float dy = target_cam_pos.y - g->_target_cam_y;

		float hyst = 1.25f;

		if (fabsf(dy) > hyst) {
			if (dy > 0.0f)
				g->_target_cam_y += dy - hyst;
			else
				g->_target_cam_y += dy + hyst;
		}

		target_cam_pos.y = g->_target_cam_y;

		update_search(g, to_ivec2(p->centre()));

		g->_cam_pos = lerp(g->_cam_pos, target_cam_pos, 0.2f);

		g->_plr_dmg = 1;

		for(uint32_t i = 0; i < g->_entities.size(); i++) {
			entity* e = g->_entities[i];
			if (!(e->_flags & entity::FLAG_DESTROYED)) {
				if (e->_type == ET_TURRET)
					g->_plr_dmg++;
			}
		}
	}

	set_camera(g->_cam_pos, 15.0f);

	if (g->_player) {
		if (--g->_spawn_time <= 0) {
			if (g->_wave_incoming) {
				g->_spawn_count = 4 + 4 * (int)g->_diff;
				g->_diff_dmg = (int)(2.5f * (1 + g->_diff)) - 1;
			}

			g->_wave_incoming = false;

			vec2 pos(g_game_rand.frand(1.0f, MAP_WIDTH - 1.0f), 2.0f);

			if (bug* e = spawn_entity(&g_game, new bug(), pos)) {
				e->_max_damage = g->_diff_dmg;

				if (g_game_rand.rand(0, 5) == 0) e->_max_damage += g_game_rand.rand(0, g->_diff_dmg);
				if (g_game_rand.rand(0, 15) == 0) e->_max_damage += g_game_rand.rand(0, g->_diff_dmg);
				if (g_game_rand.rand(0, 30) == 0) e->_max_damage += g_game_rand.rand(0, g->_diff_dmg);
			}

			g->_spawn_time = clamp(60 - ((g->_diff * 5) / 4), 10, 60);

			if (--g->_spawn_count <= 0){
				g->_diff += 1 + (g->_diff / 5);
				g->_spawn_time = 600;
				g->_wave_incoming = true;
			}
		}
	}

	tick_entities(g);
	purge_entities(g);
	update_particles(g);

	colour sky0(0.4f, 0.7f, 1.0f, 1.0f);
	colour sky1(0.45f, 0.75f, 1.0f, 1.0f);
	colour sky2(0.3f, 0.6f, 0.9f, 1.0f);
	colour sky3(0.35f, 0.65f, 0.9f, 1.0f);
	
	sky0 *= colour(0.65f, 0.0f);
	sky1 *= colour(0.65f, 0.0f);
	sky2 *= colour(0.35f, 1.0f);
	sky3 *= colour(0.35f, 1.0f);

	float sky_space = 4.5f;
	float sky_top = 4.75f;
	float sky_y = 10.0f;
	float sky_yf = 10.5f;
	float sky_yb = 11.0f;

	for(int j = 0; j < MAP_HEIGHT; j++) {
		colour bk_colour(get_master_colour(j) * colour(0.2f, 1.0f));

		for(int i = 0; i < MAP_WIDTH; i++) {
			int t = g->get_tile(i, j);

			if (t == TT_EMPTY || t == TT_TURRET) {
				int hash = ((i * 7) ^ (j * 3)) + (i + j);
				hash ^= ((hash >> 3) * 9);

				int tile_num = 132 + (hash % 4);

				draw_tile(vec2((float)i, (float)j), vec2(i + 1.0f, j + 1.0f), bk_colour, tile_num, 0);
			}
		}
	}