コード例 #1
0
ファイル: punity.c プロジェクト: gingerBill/LD35
void
text_draw(i32 x, i32 y, const char *text, u8 color)
{
    ASSERT(CORE->font);
    {
        Font *font = CORE->font;
        i32 columns = font->bitmap.width / font->char_width;

        i32 dx = x;
        i32 dy = y;

        Rect cr;
        char c;
        while (*text) {
            c = *text;
            switch (c) {
                case '\n':
                    dx = x;
                    dy += font->char_height;
                    break;
                default:
                    cr.left = (c % columns) * font->char_width;
                    cr.top = (c / columns) * font->char_height;
                    cr.right = cr.left + font->char_width;
                    cr.bottom = cr.top + font->char_height;
                    bitmap_draw(dx, dy, 0, 0, &font->bitmap, &cr, DrawFlags_Mask, color);
                    dx += font->char_width;
                    break;
            }
            text++;
        }
    }
}
コード例 #2
0
ファイル: bitmap.c プロジェクト: joaofidalgo23/feup-lcom
short* bitmap_copy(const char* filename)
{
	bitmap_t* bmp = (bitmap_t*) bitmap_read(filename);
	short* buffer = (short*) buffer_create();
	bitmap_draw(bmp, buffer, 0, 0);
	free(bmp);
	return ((short*) buffer);
}
コード例 #3
0
ファイル: aliens.c プロジェクト: bernardobelchior1/feup-lcom
int alien_draw(alien *a1) {
	if(a1->state == ALIEN_ALIVE){
		switch (a1->type) {
		case SMALL:
			bitmap_draw(invaders->small_alien->current->bmp, a1->x, a1->y,
					ALIGN_LEFT);
			break;
		case MEDIUM:
			bitmap_draw(invaders->medium_alien->current->bmp, a1->x, a1->y,
					ALIGN_LEFT);
			break;
		case LARGE:
			bitmap_draw(invaders->large_alien->current->bmp, a1->x, a1->y,
					ALIGN_LEFT);
			break;
		case UFO:
			bitmap_draw(ufo_img, a1->x, a1->y, ALIGN_LEFT);
			break;
		}
	} else {
		bitmap_draw(invaders->destroy->current->bmp, a1->x, a1->y, ALIGN_LEFT);
	}


#ifdef DEBUG
	if (invaders->last == a1)
		vg_draw_frame(a1->x + a1->width / 2, a1->y + a1->height / 2, 5, 5,
				rgb(0xCC0000));
	if (invaders->head == a1)
		vg_draw_frame(a1->x + a1->width / 2, a1->y + a1->height / 2, 5, 5,
				rgb(0x00FF00));
	if (invaders->leftmost == a1)
		vg_draw_frame(a1->x + a1->width / 2, a1->y + a1->height / 2, 5, 5,
				rgb(0xCC0066));
	if (invaders->rightmost == a1)
		vg_draw_frame(a1->x + a1->width / 2, a1->y + a1->height / 2, 5, 5,
				rgb(0xFFFF00));
#endif
}
コード例 #4
0
void start_menu_draw(){
	bitmap_draw(title, get_h_res()/2, 25, ALIGN_CENTER);
	menu_draw(start_menu);
	mouse_draw();
}
コード例 #5
0
ファイル: main.c プロジェクト: gingerBill/LD35
void
step(void)
{


	if (key_pressed(KEY_ESCAPE)) {
		CORE->running = 0;
		return;
	}

	     if (key_pressed(KEY_1)) set_palette_set(PS_WHITE);
	else if (key_pressed(KEY_2)) set_palette_set(PS_GREEN);
	else if (key_pressed(KEY_3)) set_palette_set(PS_BEIGE);
	else if (key_pressed(KEY_4)) set_palette_set(PS_BLUE);
	else if (key_pressed(KEY_5)) set_palette_set(PS_RED);
	else if (key_pressed(KEY_6)) set_palette_set(PS_PASTEL_MIX);
	else if (key_pressed(KEY_7)) set_palette_set(PS_RED_GREEN);




	switch (game.mode) {
	case GAME_MODE_TITLE: {
		if (game.intro_cooldown --> 0) {
			canvas_clear(PC_TRANSPARENT);
			bitmap_draw(0, 0, 0, 0, &title_screen, NULL, 0, 0);
		} else {
			game.mode = GAME_MODE_MAP;
		}
	} break;

	case GAME_MODE_MAP: {
		Map *map = &game.maps[game.curr_map_index];
		i32 i, j, x, y;
		gbVec2 old_player_pos = game.player.pos;
		b32 render_doctor_text = false;


		canvas_clear(PC_TRANSPARENT);

		game.player.vel = gb_vec2_zero();
		if (key_down(KEY_UP))    { game.player.vel.y -= 1.0f; }
		if (key_down(KEY_DOWN))  { game.player.vel.y += 1.0f; }
		if (key_down(KEY_LEFT))  { game.player.vel.x -= 1.0f; }
		if (key_down(KEY_RIGHT)) { game.player.vel.x += 1.0f; }
		gb_vec2_norm0(&game.player.vel, game.player.vel);
		gb_vec2_muleq(&game.player.vel, game.player.in_grass ? 2.5f : 3.5f);
		gb_vec2_addeq(&game.player.pos, game.player.vel);
		game.player.in_grass = false;

		game.player.is_moving = (gb_vec2_mag(game.player.vel) > 0);

		if (game.player.vel.x < 0) game.player.orientation = 2;
		if (game.player.vel.x > 0) game.player.orientation = 3;
		if (game.player.vel.y > 0) game.player.orientation = 0;
		if (game.player.vel.y < 0) game.player.orientation = 1;

		game.player.pos.x = gb_clamp(game.player.pos.x, 0, (map->width-1) *TILE_SIZE);
		game.player.pos.y = gb_clamp(game.player.pos.y, 0, (map->height-1)*TILE_SIZE);


		game.grass_event_cooldown--;
		if (game.grass_event_cooldown < 0)
			game.grass_event_cooldown = 0;

		draw_tooltip = false;
		gb_zero_array(tooltip_messages, gb_count_of(tooltip_messages));


		{ // Handle Interactions
			Rect player_rect = rect_make_size(game.player.pos.x+2, game.player.pos.y+12,
			                                  12, 4);
			for (j = 0; j < map->height; j++) {
				y = j*TILE_SIZE;
				for (i = 0; i < map->width; i++) {
					Rect tile_rect;
					char t = map->tiles[j][i];
					x = i*TILE_SIZE;
					tile_rect = rect_make_size(x, y, TILE_SIZE, TILE_SIZE);

					if (gb_char_is_digit(t)) {
						if (rect_collides(player_rect, tile_rect, NULL)) {
							change_map_to(t-'0');
							return;
						}
					}
					if ((t != ' ' && t != '.' && t != 'g')) {
						Rect inter;
						b32 do_collision = true;
						if (t == 'L') { // NOTE(bill): Lab Chemicals Top
							tile_rect = rect_make_size(x, y+7, TILE_SIZE, TILE_SIZE-7);
						}

						if (t == 'Q' && game.has_chosen_transmog) {
							do_collision = false;
						}
						if (do_collision && rect_collides(player_rect, tile_rect, &inter)) {
							game.player.pos = old_player_pos;
							game.player.is_moving = false;
						}

					}


					if (t == 'g' && game.player.is_moving && rect_collides(player_rect, tile_rect, NULL)) {
						i32 random = gb_random_range_int(0, 100);
						game.player.in_grass = true;
						if ((random < 7) && (game.grass_event_cooldown <= 0)) {
							game.grass_event_cooldown = 50;
#if 1
							change_to_battle_mode(BATTLE_TYPE_GRASS);
#endif
							return;
						}
					}

					if (t == 'D') {
						f32 dx = game.player.pos.x - (x + TILE_SIZE/2);
						f32 dy = game.player.pos.y - (y + TILE_SIZE/2);
						if (dx*dx+dy*dy < square(2*TILE_SIZE)) render_doctor_text = true;
					}

					if (t == 'Y') {
						set_tooltip(x, y, 1.5f,
						            "Hello! I'm your worst nightmare!",
						            "My name is Yugi the Boss.",
						            "Want to battle [z]?");

						if (key_pressed(KEY_Z)) {
							change_to_battle_mode(BATTLE_TYPE_BOSS);
							return;
						}
					}

					if (t == 'Q' && !game.has_chosen_transmog) {
						set_tooltip(x, y, 1.5f,
						            "It's dangerous to go alone",
						            "in there! You might get hurt.",
						            "Go see The Doctor in The Lab.");
					}

					if (t == 'L' || t == 'l') {
						set_tooltip(x, y, 1.0f,
						            "It appears to be weird chemicals.", NULL, NULL);
					}

					if (t == 'm' || t == 'c') {
						set_tooltip(x, y, 1.0f,
						            "State of the art computers",
						            "The new Pear Bartlett!",
						            NULL);
					}
					if (t == 'P') {
						set_tooltip(x, y, 0.6f,
						            "Such a lovely picture!", NULL, NULL);
					}

					if (t == 'B' || t == 'b') {
						set_tooltip(x, y, 1.2f,
						            "It is not time to sleep.", NULL, NULL);
					}

					if (t == 'W') {
						set_tooltip(x, y, 0.6f,
						            "It's a beautiful view outside.",
						            "Why not go outside and explore?", NULL);
					}
				}
			}
		}

		move_game_camera(map);


		// Render 1x1 Sprites
		for (j = 0; j < map->height; j++) {
			y = j*TILE_SIZE;
			for (i = 0; i < map->width; i++) {
				char t = map->tiles[j][i];
				x = i*TILE_SIZE;
				switch (t) {
				case ' ':
				case '.':
				case 'g':
				case 'Q':
				case 'D':
				case 'Y': {
					i32 sx = 0;
					i32 sy = map->outside;
					if (map->outside) {
						sx = (i+j)%2;
					}
					draw_sprite(x, y, sx, sy, 0);

					if (t == 'g') draw_sprite(x, y, 2, 1, 0); // grass
					if (t == 'Q' && !game.has_chosen_transmog)
						draw_sprite(x, y, 0, 3, 0); // Person in the way
					if (t == 'D') draw_sprite(x, y, 1, 3, 0); // Dr.
					if (t == 'Y') draw_sprite(x, y, 2, 3, 0); // Yugi
				} break;
				case 'x': draw_sprite(x, y,  1, 0, 0); break; // Wall
				case 'P': draw_sprite(x, y,  2, 0, 0); break; // Hanging Picture
				case 'W': draw_sprite(x, y,  3, 0, 0); break; // Window
				case 'T': draw_sprite(x, y,  3, 1, 0); break; // Thick Grass
				case 't': draw_sprite(x, y,  4, 1, 0); break; // Tree trunk
				case 'B': draw_sprite(x, y,  5, 0, 0); break; // Bed Top
				case 'b': draw_sprite(x, y,  5, 1, 0); break; // Bed bottom
				case 'M': draw_sprite(x, y,  6, 0, 0); break; // Computer monitor
				case 'm': draw_sprite(x, y,  6, 1, 0); break; // Computer keyboard
				case 'C': draw_sprite(x, y,  7, 0, 0); break; // Computer case
				case 'c': draw_sprite(x, y,  7, 1, 0); break; // Computer mouse
				case 'L': draw_sprite(x, y,  8, 0, 0); break; // Lap Chemicals top
				case 'l': draw_sprite(x, y,  8, 1, 0); break; // Lap Chemicals bottom

				default: {
					if (gb_char_is_digit(t)) draw_sprite(x, y, 4, 0, 0);
				} break;
				}
			}
		}

		// Render NxM Sprites
		// TODO(bill): Be more efficient
		for (j = 0; j < map->height; j++) {
			y = j*TILE_SIZE;
			for (i = 0; i < map->width; i++) {
				char t = map->tiles[j][i];
				x = i*TILE_SIZE;
				switch (t) {
				case 'h': draw_sprite_size(x, y, 12, 2, 4, 4, 0); break;
				case 'd': draw_sprite_size(x, y,  8, 2, 4, 4, 0); break;
				}
			}
		}

		{ // Render player and particles
			i32 sx = 0;
			u32 flags = 0;
			// 0 - down
			// 1 - up
			// 2 - left
			// 3 - right (-ve left)
			if (game.player.orientation == 0) sx = 0;
			if (game.player.orientation == 1) sx = 1;
			if (game.player.orientation == 2) sx = 2;
			if (game.player.orientation == 3) { sx = 2; flags |= DrawFlags_FlipH; }
			if (game.player.is_moving) {
				u32 flip = 10.0f*CORE->perf_frame.stamp;
				b32 use_flip = true;
				if (game.player.orientation == 0) {
					if (use_flip) {
						sx = 3;
						flags |= DrawFlags_FlipH * (flip%2);
					}
				} else if (game.player.orientation == 1) {
					if (use_flip) {
						sx = 4;
						flags |= DrawFlags_FlipH * (flip%2);
					}
				} else {
					sx += 3 * (flip%2);
				}
			}
			draw_sprite(game.player.pos.x, game.player.pos.y, sx, 2, flags);
		}

		{ // Render Text
			CORE->translate_x = 0;
			CORE->translate_y = 0;

			if (game.show_map_name_ticks-- > 0) {
				if (game.show_map_name_ticks < 0)
					game.show_map_name_ticks = 0;

				{
					char *name = game.maps[game.curr_map_index].name;
					i32 name_len = gb_strlen(name);
					i32 w = name_len*font.char_width+6;
					i32 h = font.char_height+6;

					rect_draw(rect_make_size(1, 1, w, h), PC_WHITE);
					rect_draw(rect_make_size(1,   0, w, 1), PC_DARK_GREY);
					rect_draw(rect_make_size(1, h+1, w, 1), PC_DARK_GREY);
					rect_draw(rect_make_size(0,   1, 1, h), PC_DARK_GREY);
					rect_draw(rect_make_size(w+1, 1, 1, h), PC_DARK_GREY);


					text_draw(4, 4, name, PC_BLACK);
				}
			}

			if (render_doctor_text) {
				if (game.doctor_line_index < gb_count_of(doctor_lines)) {
					draw_message_box(doctor_lines[game.doctor_line_index], "", "[Z] to continue");

					if (key_pressed(KEY_Z)) game.doctor_line_index++;
				} else if (!game.has_chosen_transmog) {
					draw_message_box("Line          [X]",
					                 "Triangle      [C]",
					                 "Square        [V]");
					if (key_pressed(KEY_X)) {
						game.player.my_transmog = make_transmog(TRANSMOG_TYPE_LINE);
						game.has_chosen_transmog = true;
					} else if (key_pressed(KEY_C)) {
						game.player.my_transmog = make_transmog(TRANSMOG_TYPE_TRIANGLE);
						game.has_chosen_transmog = true;
					} else if (key_pressed(KEY_V)) {
						game.player.my_transmog = make_transmog(TRANSMOG_TYPE_SQUARE);
						game.has_chosen_transmog = true;
					}

				} else {
					draw_message_box("Go now and find Transmogs!", "", "");
				}
			} else if (draw_tooltip) {
				draw_message_box(tooltip_messages[0], tooltip_messages[1], tooltip_messages[2]);
			}
		}
	} break;

	case GAME_MODE_BATTLE: {
		i32 i, w = CANVAS_WIDTH, h = CANVAS_HEIGHT;
		Transmog *enemy_mog = &game.battle_mode.enemy_mog;
		Transmog *player_mog = game.battle_mode.player_mog;
		char name_buf[32] = "";
		char *attack_names[3] = {
			"TRANSLATE",
			"ROTATE",
			"DIVIDE",
		};
		i32 level_diff = enemy_mog->shift_level - player_mog->shift_level;


		CORE->translate_x = 0;
		CORE->translate_y = 0;

		canvas_clear(PC_WHITE);

		// Enemy Transmog
		gb_snprintf(name_buf, gb_size_of(name_buf),
		            "%s LVL%d", transmog_name(enemy_mog->type), enemy_mog->shift_level);
		text_draw(8, 5, name_buf, PC_BLACK);
		draw_sprite_size(8, 12,
		                 2, 4,
		                 3, 1, 0);
		draw_sprite_size(24, 15,
		                 3, 5,
		                 2, 1, 0);
		{
			f32 hp_percent = cast(f32)enemy_mog->health/cast(f32)enemy_mog->max_health;
			rect_draw(rect_make_size(25, 16, hp_percent*30, 1), PC_LIGHT_GREY);
			draw_big_transmog(84, 4, enemy_mog->type);
		}


		// Player Transmog
		gb_snprintf(name_buf, gb_size_of(name_buf),
		            "%s LVL%d", transmog_name(player_mog->type), player_mog->shift_level);
		text_draw(100, 80, name_buf, PC_BLACK);
		draw_sprite_size(104, 92,
		                 5, 4,
		                 3, 1, 0);
		draw_sprite_size(117, 95,
		                 3, 5,
		                 2, 1, 0);
		{
			f32 hp_percent = cast(f32)player_mog->health/cast(f32)player_mog->max_health;
			char buf[16] = {0};
			gb_snprintf(buf, gb_size_of(buf),
			            "%03d/%03d", player_mog->health, player_mog->max_health);
			rect_draw(rect_make_size(118, 96, hp_percent*30, 1), PC_LIGHT_GREY);
			text_draw(118, 99, buf, PC_BLACK);

			draw_big_transmog(4, 54, player_mog->type);
		}

		if (!game.battle_mode.is_enemies_turn) {
			switch (game.battle_mode.state) {
			case BATTLE_TURN_STATE_INTRO: {
				char buf[32] = {0};
				gb_snprintf(buf, gb_size_of(buf),
				            "A wild %s appears!", transmog_name(enemy_mog->type));
				draw_message_box(buf, "", "[Z] to continue");

				if (key_pressed(KEY_Z)) {
					game.battle_mode.state = BATTLE_TURN_STATE_WHAT_TO_DO;
					return;
				}
			} break;
			case BATTLE_TURN_STATE_WHAT_TO_DO: {
				u32 hot_item = 0;
				if (game.battle_mode.type == BATTLE_TYPE_GRASS) {
					game.battle_mode.state_index %= 3;
					hot_item = game.battle_mode.state_index;
	 				draw_message_box("What to do?           Fight     ",
					                 "                      Substitute",
					                 "                      Escape    ");
					draw_sprite(70, 111, 0, 4, 0);
					draw_sprite(70, 127, 0, 5, 0);
					draw_sprite(90, 117 + hot_item*font.char_height, 5, 5, 0);

					if (key_pressed(KEY_DOWN)) {
						game.battle_mode.state_index++;
					}
					if (key_pressed(KEY_UP)) {
						if (game.battle_mode.state_index == 0)
							game.battle_mode.state_index = 2;
						else
							game.battle_mode.state_index--;
					}

					if (key_pressed(KEY_Z)) {
						switch (hot_item) {
						case 0:
							game.battle_mode.state = BATTLE_TURN_STATE_FIGHT;
							game.battle_mode.state_index = 0;
							game.battle_mode.fighting_state = FIGHTING_STATE_NONE;
							return;
						case 1:
							game.battle_mode.state = BATTLE_TURN_STATE_SUBSTITUTE;
							game.battle_mode.state_index = 0;
						case 2:
							game.battle_mode.state = BATTLE_TURN_STATE_ESPACE;
							game.battle_mode.state_index = 0;
							return;
						}
					}
				} else {
					game.battle_mode.state_index %= 2;
					hot_item = game.battle_mode.state_index;
	 				draw_message_box("What to do?           Fight     ",
					                 "                      Escape    ",
					                 "                                ");
					draw_sprite(70, 111, 0, 4, 0);
					draw_sprite(70, 127, 0, 5, 0);
					draw_sprite(90, 117 + hot_item*font.char_height, 5, 5, 0);

					if (key_pressed(KEY_DOWN)) {
						game.battle_mode.state_index++;
					}
					if (key_pressed(KEY_UP)) {
						if (game.battle_mode.state_index == 0)
							game.battle_mode.state_index = 1;
						else
							game.battle_mode.state_index--;
					}

					if (key_pressed(KEY_Z)) {
						switch (hot_item) {
						case 0:
							game.battle_mode.state = BATTLE_TURN_STATE_FIGHT;
							game.battle_mode.state_index = 0;
							game.battle_mode.fighting_state = FIGHTING_STATE_NONE;
							return;
						case 1:
							game.battle_mode.state = BATTLE_TURN_STATE_ESPACE;
							game.battle_mode.state_index = 0;
							return;
						}
					}
				}


			} break;
			case BATTLE_TURN_STATE_FIGHT: {
				char buf[32] = "";
				switch (game.battle_mode.fighting_state) {
				case FIGHTING_STATE_NONE: {
					u32 hot_item = game.battle_mode.state_index;
					draw_message_box("Which attack?         Translate ",
					                 "                      Rotate    ",
					                 "                      Divide    ");
					draw_sprite(70, 111, 0, 4, 0);
					draw_sprite(70, 127, 0, 5, 0);
					draw_sprite(90, 117 + hot_item*font.char_height, 5, 5, 0);

					if (key_pressed(KEY_DOWN)) {
						game.battle_mode.state_index++;
						game.battle_mode.state_index %= 3;
					}
					if (key_pressed(KEY_UP)) {
						if (game.battle_mode.state_index == 0)
							game.battle_mode.state_index = 2;
						else
							game.battle_mode.state_index--;
					}

					if (key_pressed(KEY_X)) {
						game.battle_mode.state_index = 0;
						game.battle_mode.state = BATTLE_TURN_STATE_WHAT_TO_DO;
						return;
					}

					if (key_pressed(KEY_Z)) {
						game.battle_mode.attack_index = hot_item;
						game.battle_mode.state_index = 0;
						game.battle_mode.fighting_state = FIGHTING_STATE_USE;
						return;
					}
				} break;
				case FIGHTING_STATE_USE: {
					gb_snprintf(buf, gb_size_of(buf),
					            "Your %s used %s",
					            transmog_name(enemy_mog->type),
					            attack_names[game.battle_mode.attack_index]);
					draw_message_box(buf, NULL, NULL);

					if (key_pressed(KEY_Z)) {
					if (-level_diff < 0) { // Higher level enemy
						game.battle_mode.fighting_state = FIGHTING_STATE_SUPER_EFFECTIVE;
					} else {
						if (gb_random_range_int(0, -level_diff+1) == 0) {
							game.battle_mode.fighting_state = FIGHTING_STATE_SUPER_EFFECTIVE;
						} else {
							if (gb_random_range_int(0, -level_diff/2 + 1) == 0)
								game.battle_mode.fighting_state = FIGHTING_STATE_EFFECTIVE;
							else
								game.battle_mode.fighting_state = FIGHTING_STATE_NO_EFFECT;
						}
					}
					return;
				}
				} break;
				case FIGHTING_STATE_EFFECTIVE: {
					gb_snprintf(buf, gb_size_of(buf),
					            "%s was effective",
					            attack_names[game.battle_mode.attack_index]);
					draw_message_box(buf, NULL, NULL);

					if (key_pressed(KEY_Z)) {
						i32 damage = gb_clamp(0, player_mog->attack_power/3 + level_diff/2, 1000);
						enemy_mog->health -= damage;

						game.battle_mode.fighting_state = FIGHTING_STATE_NEXT_TURN;
					}
				} break;
				case FIGHTING_STATE_SUPER_EFFECTIVE: {
					gb_snprintf(buf, gb_size_of(buf),
					            "%s was super effective",
					            attack_names[game.battle_mode.attack_index]);
					draw_message_box(buf, NULL, NULL);

					if (key_pressed(KEY_Z)) {
						i32 damage = gb_clamp(0, player_mog->attack_power/1 + level_diff/2, 1000);
						enemy_mog->health -= damage;
						game.battle_mode.fighting_state = FIGHTING_STATE_NEXT_TURN;
						game.battle_mode.state_index = 0;
					}
				} break;
				case FIGHTING_STATE_NO_EFFECT: {
					gb_snprintf(buf, gb_size_of(buf),
					            "%s had no effect",
					            attack_names[game.battle_mode.attack_index]);
					draw_message_box(buf, NULL, NULL);

					if (key_pressed(KEY_Z))
						game.battle_mode.fighting_state = FIGHTING_STATE_NEXT_TURN;
				} break;
				case FIGHTING_STATE_NEXT_TURN: {
					char *end_message = "";
					if (enemy_mog->health <= 0 &&
					    !(game.battle_mode.state_index & 1)) {
						enemy_mog->health = 0;
						player_mog->xp += clamp(1, 4 + level_diff, 1000);

						while (player_mog->xp >= 10) {
							player_mog->xp -= 10;
							player_mog->shift_level++;
							update_transmog_stats(player_mog);
							player_mog->health = player_mog->max_health;
							game.battle_mode.state_index |= 2;
						}

						game.battle_mode.state_index |= 1;
					}
					if (game.battle_mode.state_index & 1) {
						if (game.battle_mode.type == BATTLE_TYPE_GRASS) {
							if (game.battle_mode.state_index & 2)
								end_message = "Your Transmog has levelled up!";
							draw_message_box("You win this battle!", end_message, "Exit the battle.");
							if (key_pressed(KEY_Z)) {
								game.mode = GAME_MODE_MAP;
								game.battle_mode.state_index = 0;
								return;
							}
						} else {
							canvas_clear(PC_WHITE);
							draw_sprite(72, 40,
							            2, 3, 0);

							draw_message_box("You defeated me?! HOW?!",
							                 "Well it's my first battle...",
							                 "Well done and thank you!");

							if (key_pressed(KEY_Z)) {
								game.mode = GAME_MODE_END_SUCCESS;
								return;
							}
						}
					} else {
						draw_message_box("End turn.", NULL, NULL);
						if (key_pressed(KEY_Z)) {
							end_battle_mode_turn();
							return;
						}
					}
				} break;
				}
			} break;
			case BATTLE_TURN_STATE_SUBSTITUTE: {
				i32 level_diff = enemy_mog->shift_level - player_mog->shift_level;

				if (level_diff <= 0) {
					draw_message_box("Failed to substitute",
					                 "",
					                 "End turn.");

					if (key_pressed(KEY_Z)) {
						end_battle_mode_turn();
						return;
					}

				} else {
					if (game.battle_mode.state_index == 0) {
						if (gb_random_range_int(0, level_diff) != 0)
							game.battle_mode.state_index = 1; // Success
						else
							game.battle_mode.state_index = 2; // Failure
					}

					if (game.battle_mode.state_index == 1) {
						draw_message_box("Well done!",
						                 "You successfully substituted.",
						                 "Exit to world");

						if (key_pressed(KEY_Z)) {
							// Change it!
							game.player.my_transmog = *enemy_mog;
							game.mode = GAME_MODE_MAP;
							return;
						}
					} else {
						draw_message_box("Substitution failed!",
						                 "",
						                 "End turn.");

						if (key_pressed(KEY_Z)) {
							end_battle_mode_turn();
							return;
						}
					}
				}
			} break;
			case BATTLE_TURN_STATE_ESPACE: {
				if (game.battle_mode.state_index == 0) {
					if (gb_random_range_int(0, 100) < 90) {
						game.battle_mode.state_index = 1;
					} else {
						game.battle_mode.state_index = 2;
					}
				}

				if (game.battle_mode.state_index == 1) {
					draw_message_box("You escaped from this battle!",
					                 "",
					                 "[Z] to return to the world.");

					if (key_pressed(KEY_Z)) {
						game.mode = GAME_MODE_MAP;
						return;
					}
				} else {
					draw_message_box("You could not escape!",
					                 "You'll have to try again!",
					                 "[Z] to end turn.");
					end_battle_mode_turn();
					return;
				}
			} break;
			}
		} else {
		// NOTE(bill): Enemies Turn
			char buf[32] = {0};

			switch (game.battle_mode.fighting_state) {
			case FIGHTING_STATE_NONE: {
				game.battle_mode.attack_index = gb_random_range_int(0, 2);
				game.battle_mode.fighting_state = FIGHTING_STATE_USE;
				return;
			} break;
			case FIGHTING_STATE_USE: {
				gb_snprintf(buf, gb_size_of(buf),
				            "Enemy %s used %s",
				            transmog_name(enemy_mog->type),
				            attack_names[game.battle_mode.attack_index]);
				draw_message_box(buf, NULL, NULL);

				if (key_pressed(KEY_Z)) {
					if (level_diff < 0) { // Higher level enemy
						game.battle_mode.fighting_state = FIGHTING_STATE_SUPER_EFFECTIVE;
					} else {
						if (gb_random_range_int(0, -level_diff+3) == 0) {
							game.battle_mode.fighting_state = FIGHTING_STATE_SUPER_EFFECTIVE;
						} else {
							if (gb_random_range_int(0, -level_diff/2 + 3) == 0)
								game.battle_mode.fighting_state = FIGHTING_STATE_EFFECTIVE;
							else
								game.battle_mode.fighting_state = FIGHTING_STATE_NO_EFFECT;
						}
					}
					return;
				}
			} break;
			case FIGHTING_STATE_EFFECTIVE: {
				gb_snprintf(buf, gb_size_of(buf),
				            "%s was effective",
				            attack_names[game.battle_mode.attack_index]);
				draw_message_box(buf, NULL, NULL);

				if (key_pressed(KEY_Z)) {
					i32 damage = gb_clamp(0, enemy_mog->attack_power/6.0f - level_diff/3.0f, 1000);

					player_mog->health -= damage;

					game.battle_mode.fighting_state = FIGHTING_STATE_NEXT_TURN;
				}

			} break;
			case FIGHTING_STATE_SUPER_EFFECTIVE: {
				gb_snprintf(buf, gb_size_of(buf),
				            "%s was super effective",
				            attack_names[game.battle_mode.attack_index]);
				draw_message_box(buf, NULL, NULL);

				if (key_pressed(KEY_Z)) {
					i32 damage = gb_clamp(0, enemy_mog->attack_power/3.0f - level_diff/2.0f, 1000);

					player_mog->health -= damage;

					game.battle_mode.fighting_state = FIGHTING_STATE_NEXT_TURN;
				}
			} break;
			case FIGHTING_STATE_NO_EFFECT: {
				gb_snprintf(buf, gb_size_of(buf),
				            "%s had no effect",
				            attack_names[game.battle_mode.attack_index]);
				draw_message_box(buf, NULL, NULL);

				if (key_pressed(KEY_Z))
					game.battle_mode.fighting_state = FIGHTING_STATE_NEXT_TURN;
			} break;
			case FIGHTING_STATE_NEXT_TURN: {
				char *end_message = "";
				if (player_mog->health <= 0 &&
				    !(game.battle_mode.state_index & 1)) {
					player_mog->health = 0;

					game.battle_mode.state_index |= 1;
				}
				if (game.battle_mode.state_index & 1) {
					draw_message_box("You lost this battle!", "And the game :(", "Exit the battle.");
					if (key_pressed(KEY_Z)) {
						game.mode = GAME_MODE_END_FAIL;
						return;
					}
				} else {
					draw_message_box("The enemy's turn has ended.", NULL, NULL);
					if (key_pressed(KEY_Z)) {
						end_battle_mode_turn();
						return;
					}
				}
			} break;
			}

		}
	} break;

	case GAME_MODE_END_FAIL: {
		canvas_clear(PC_BLACK);
		draw_message_box("You have failed :(",
		                 "Would you like to try again?",
		                 "Try again [z] Exit [esc]");
		if (key_pressed(KEY_Z)) {
			init_game();
			return;
		}
	} break;

	case GAME_MODE_END_SUCCESS: {
		canvas_clear(PC_BLACK);

		text_draw(4, 4,
		          "Thank you for playing Transmog!\n"
		          "Ginger Bill (c) 2016\n"
		          "\n"
		          "Ludum Dare 35\n"
		          "Theme: Shapeshift\n"
		          "\n"
		          "Please remember for vote!\n",
		          PC_WHITE);

		draw_message_box("Exit [esc]", NULL, NULL);
	} break;
	}
}
コード例 #6
0
ファイル: main.c プロジェクト: gingerBill/LD35
gb_internal void
draw_sprite_size(i32 x, i32 y, i32 sx, i32 sy, i32 w, i32 h, u32 flags)
{
	Rect r = rect_make_size(sx*TILE_SIZE, sy*TILE_SIZE, w*TILE_SIZE, h*TILE_SIZE);
	bitmap_draw(x, y, 0, 0, &spritesheet, &r, flags, 0);
}
コード例 #7
0
int projectile_draw(projectile *proj) {
	//vg_draw_frame(proj->x, proj->y, proj->width, proj->height, rgb(0xFF0000));
	bitmap_draw(projectile_img, proj->x, proj->y, ALIGN_LEFT);

	return 1;
}