2024-02-25 17:52:42 +00:00
|
|
|
#include <stddef.h>
|
2024-02-15 13:34:50 +00:00
|
|
|
#include <stdio.h>
|
2024-02-20 11:48:12 +00:00
|
|
|
#include <math.h>
|
|
|
|
#include <conio.h>
|
2024-02-21 21:25:00 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <time.h>
|
2024-02-15 13:34:50 +00:00
|
|
|
|
2024-02-24 12:36:18 +00:00
|
|
|
#include "sprites.h"
|
2024-02-20 13:00:13 +00:00
|
|
|
#include "system/vga.h"
|
|
|
|
#include "system/keyboard.h"
|
|
|
|
#include "system/mouse_io.h"
|
|
|
|
#include "system/pc_stuff.h"
|
2024-02-21 13:25:55 +00:00
|
|
|
|
2024-02-15 13:34:50 +00:00
|
|
|
#include "bmpload.h"
|
2024-02-20 17:51:59 +00:00
|
|
|
#include "const.h"
|
|
|
|
#include "arena.h"
|
2024-02-21 13:25:55 +00:00
|
|
|
#include "movement.h"
|
2024-02-25 13:43:30 +00:00
|
|
|
#include "combat.h"
|
2024-02-26 23:12:39 +00:00
|
|
|
#include "game.h"
|
2024-02-26 12:52:59 +00:00
|
|
|
|
2024-02-25 13:43:30 +00:00
|
|
|
// TODO: centralize these outside of game.c
|
2024-02-27 01:40:05 +00:00
|
|
|
struct CompiledSpriteRender rabbit,
|
|
|
|
mouse,
|
|
|
|
bullet,
|
|
|
|
enemy,
|
|
|
|
enemyBullet,
|
2024-02-27 13:16:16 +00:00
|
|
|
shotgun,
|
|
|
|
shieldKiller;
|
2024-02-25 13:43:30 +00:00
|
|
|
struct SpriteBounds bounds;
|
2024-02-15 01:15:55 +00:00
|
|
|
|
2024-02-15 13:34:50 +00:00
|
|
|
struct BMPImage spritesheetImage;
|
|
|
|
struct VGAColor vgaColors[256];
|
|
|
|
|
2024-02-25 13:43:30 +00:00
|
|
|
struct MouseStatus mouseStatus;
|
|
|
|
|
2024-02-21 13:25:55 +00:00
|
|
|
struct RabbitPosition rabbitPosition = {
|
|
|
|
.rabbitPosition = { 60, 60 },
|
2024-02-26 23:12:39 +00:00
|
|
|
.rabbitLimits = {
|
|
|
|
{ 20, 20 },
|
|
|
|
{ (ARENA_WIDTH_TILES - 1) * TILE_SIZE - 2, (ARENA_HEIGHT_TILES - 1) * TILE_SIZE - 2 }
|
|
|
|
},
|
2024-02-21 13:25:55 +00:00
|
|
|
.mousePosition = { 0, 0 },
|
|
|
|
.rabbitVelocity = { 0, 0 },
|
|
|
|
.mouseDotPosition = { 0, 0 }
|
|
|
|
};
|
2024-02-21 21:25:00 +00:00
|
|
|
struct EnemyPosition enemyPosition[ENEMY_MAX_COUNT];
|
2024-02-21 13:25:55 +00:00
|
|
|
struct BulletPosition rabbitBulletPosition[RABBIT_BULLET_LIMIT];
|
2024-02-25 21:59:04 +00:00
|
|
|
struct BulletPosition enemyBulletPosition[ENEMY_BULLET_LIMIT];
|
2024-02-21 13:25:55 +00:00
|
|
|
struct RabbitWeaponry rabbitWeaponry;
|
2024-02-27 01:40:05 +00:00
|
|
|
struct PlayerPowerup playerPowerup;
|
2024-02-21 13:25:55 +00:00
|
|
|
|
2024-02-25 21:59:04 +00:00
|
|
|
struct SpawnPointRange spawnPointRanges[4] = {
|
2024-02-26 23:12:39 +00:00
|
|
|
// top
|
|
|
|
{ .left = TILE_SIZE * 4, .width = TILE_SIZE * 2, .top = TILE_SIZE - 8, .height = TILE_SIZE },
|
|
|
|
// right
|
|
|
|
{ .left = (ARENA_WIDTH_TILES - 1) * TILE_SIZE - 8, .width = TILE_SIZE, .top = TILE_SIZE * 4, .height = TILE_SIZE * 2 },
|
|
|
|
// bottom
|
|
|
|
{ .left = TILE_SIZE * 4, .width = TILE_SIZE * 2, .top = (ARENA_HEIGHT_TILES - 1) * TILE_SIZE - 8, .height = TILE_SIZE },
|
|
|
|
// left
|
|
|
|
{ .left = TILE_SIZE - 8, .width = TILE_SIZE, .top = TILE_SIZE * 4, .height = TILE_SIZE * 2 },
|
2024-02-25 13:43:30 +00:00
|
|
|
};
|
|
|
|
|
2024-02-21 13:25:55 +00:00
|
|
|
void setupRabbitBullets() {
|
2024-02-21 21:25:00 +00:00
|
|
|
int i;
|
2024-02-21 13:25:55 +00:00
|
|
|
|
|
|
|
for (i = 0; i < RABBIT_BULLET_LIMIT; ++i) {
|
|
|
|
rabbitBulletPosition[i].isActive = 0;
|
|
|
|
rabbitBulletPosition[i].willBeInactive = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
rabbitWeaponry.cooldown = 0;
|
2024-02-27 13:16:16 +00:00
|
|
|
rabbitWeaponry.currentWeapon = WEAPON_TYPE_SINGLE_SHOT_GUN;
|
|
|
|
rabbitWeaponry.currentWeaponRemainingRounds = 0;
|
2024-02-21 13:25:55 +00:00
|
|
|
}
|
|
|
|
|
2024-02-27 01:40:05 +00:00
|
|
|
void setupPowerup() {
|
|
|
|
playerPowerup.x = 100;
|
|
|
|
playerPowerup.y = 100;
|
2024-02-27 13:16:16 +00:00
|
|
|
playerPowerup.cooldown = 20 + rand() % 10;
|
|
|
|
playerPowerup.type = POWERUP_TYPE_SHOTGUN;
|
2024-02-27 01:40:05 +00:00
|
|
|
playerPowerup.isActive = 0;
|
|
|
|
}
|
|
|
|
|
2024-02-25 21:59:04 +00:00
|
|
|
void setupEnemyBullets() {
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < ENEMY_BULLET_LIMIT; ++i) {
|
|
|
|
enemyBulletPosition[i].isActive = 0;
|
|
|
|
enemyBulletPosition[i].willBeInactive = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-02-21 21:25:00 +00:00
|
|
|
void setupEnemies() {
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < ENEMY_MAX_COUNT; ++i) {
|
|
|
|
enemyPosition[i].isActive = 0;
|
|
|
|
enemyPosition[i].willBeInactive = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-02-25 21:59:04 +00:00
|
|
|
int spawnCooldown = 0;
|
|
|
|
int difficulty = 0;
|
|
|
|
int kills = 0;
|
2024-02-26 12:52:59 +00:00
|
|
|
int health = RABBIT_HEALTH_MAX;
|
2024-02-25 21:59:04 +00:00
|
|
|
|
|
|
|
int difficultyBands[10] = { 10, 20, 30, 50, 80, 130, 210, 340, 550, 890 };
|
|
|
|
|
|
|
|
void handleEnemyKills() {
|
2024-02-27 13:16:16 +00:00
|
|
|
int i, hadKill, currentKillCount;
|
|
|
|
|
|
|
|
currentKillCount = 0;
|
2024-02-25 21:59:04 +00:00
|
|
|
|
|
|
|
for (i = 0; i < ENEMY_MAX_COUNT; ++i) {
|
|
|
|
if (enemyPosition[i].wasKilled) {
|
|
|
|
enemyPosition[i].wasKilled = 0;
|
|
|
|
kills++;
|
2024-02-27 13:16:16 +00:00
|
|
|
currentKillCount++;
|
2024-02-26 12:52:59 +00:00
|
|
|
health += ENEMY_KILL_HEALTH_GAIN;
|
|
|
|
if (health > RABBIT_HEALTH_MAX) health = RABBIT_HEALTH_MAX;
|
2024-02-25 21:59:04 +00:00
|
|
|
|
|
|
|
hadKill = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-02-27 13:16:16 +00:00
|
|
|
kills += currentKillCount;
|
|
|
|
|
|
|
|
playerPowerup.cooldown -= currentKillCount;
|
|
|
|
if (playerPowerup.cooldown <= 0) {
|
|
|
|
playerPowerup.x = TILE_SIZE + rand() % ((ARENA_WIDTH_TILES - 2) * TILE_SIZE);
|
|
|
|
playerPowerup.y = TILE_SIZE + rand() % ((ARENA_HEIGHT_TILES - 2) * TILE_SIZE);
|
|
|
|
playerPowerup.isActive = 1;
|
|
|
|
|
|
|
|
playerPowerup.cooldown = POWERUP_RESPAWN_COOLDOWN_PER_LEVEL * difficulty +
|
|
|
|
rand() % (POWERUP_RESPAWN_COOLDOWN_PER_LEVEL * difficulty);
|
|
|
|
}
|
|
|
|
|
2024-02-25 21:59:04 +00:00
|
|
|
if (hadKill) {
|
|
|
|
for (i = 0; i < 10; ++i) {
|
|
|
|
if (kills > difficultyBands[i]) {
|
|
|
|
difficulty = i + 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-02-21 21:25:00 +00:00
|
|
|
void maybeSpawnEnemy() {
|
|
|
|
char canSpawn;
|
2024-02-26 23:12:39 +00:00
|
|
|
int i, gate, availableEnemy, gatePlayerIsFacing;
|
|
|
|
int spawnX, spawnY, spawnTry;
|
|
|
|
|
|
|
|
char buffer[20];
|
2024-02-21 21:25:00 +00:00
|
|
|
|
2024-02-25 21:59:04 +00:00
|
|
|
if (spawnCooldown-- > 0) return;
|
|
|
|
|
2024-02-21 21:25:00 +00:00
|
|
|
for (i = 0; i < ENEMY_MAX_COUNT; ++i) {
|
|
|
|
if (!enemyPosition[i].isActive) {
|
|
|
|
availableEnemy = i;
|
|
|
|
canSpawn = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!canSpawn) return;
|
|
|
|
|
2024-02-26 23:12:39 +00:00
|
|
|
// determine which gate the player is at and reduce the likelihood of
|
|
|
|
// spawning from that gate
|
|
|
|
// * 8 chances to spawn [0, 1] for each gate
|
|
|
|
// * if the gate the player is looking at gets [0], reroll
|
|
|
|
// * try three times max to limit cost of calculating
|
|
|
|
for (spawnTry = 0; spawnTry < 3; ++spawnTry) {
|
|
|
|
i = rand() % 12;
|
|
|
|
gate = i / 3;
|
|
|
|
|
|
|
|
if (gatePlayerIsFacing == gate && i % 3 != 0) continue;
|
|
|
|
}
|
2024-02-25 21:59:04 +00:00
|
|
|
|
2024-02-26 23:12:39 +00:00
|
|
|
spawnX = spawnPointRanges[gate].left + rand() % spawnPointRanges[gate].width;
|
|
|
|
spawnY = spawnPointRanges[gate].top + rand() % spawnPointRanges[gate].height;
|
2024-02-21 21:25:00 +00:00
|
|
|
|
|
|
|
enemyPosition[availableEnemy].isActive = 1;
|
2024-02-25 21:59:04 +00:00
|
|
|
enemyPosition[availableEnemy].willBeInactive = 0;
|
|
|
|
enemyPosition[availableEnemy].wasKilled = 0;
|
2024-02-26 23:12:39 +00:00
|
|
|
enemyPosition[availableEnemy].hitPoints = 1 + difficulty / ENEMY_HIT_POINT_DIFFICULTY_INCREASE_EVERY;
|
|
|
|
enemyPosition[availableEnemy].hasLeftGate = 0;
|
|
|
|
enemyPosition[availableEnemy].gateExitedFrom = gate;
|
2024-02-25 21:59:04 +00:00
|
|
|
enemyPosition[availableEnemy].enemyMoveDelayStep = 0;
|
|
|
|
enemyPosition[availableEnemy].enemyFireDelayStep = ENEMY_FIRE_MIN_DELAY + rand() % ENEMY_FIRE_VARIABLE_DELAY;
|
2024-02-21 21:25:00 +00:00
|
|
|
enemyPosition[availableEnemy].enemyPosition[0] = spawnX;
|
|
|
|
enemyPosition[availableEnemy].enemyPosition[1] = spawnY;
|
2024-02-25 13:43:30 +00:00
|
|
|
enemyPosition[availableEnemy].oldEnemyPosition[0] = spawnX;
|
|
|
|
enemyPosition[availableEnemy].oldEnemyPosition[1] = spawnY;
|
2024-02-25 21:59:04 +00:00
|
|
|
|
2024-02-26 12:52:59 +00:00
|
|
|
spawnCooldown = (BASE_ENEMY_SPAWN_COOLDOWN - (difficulty * DIFFICULTY_SPAWN_COOLDOWN_REDUCTION)) + MINIMUM_ENEMY_SPAWN_COOLDOWN + rand() % VARIABLE_ENEMY_SPAWN_COOLDOWN;
|
2024-02-21 21:25:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void setupEnemySprites() {
|
2024-02-24 15:38:46 +00:00
|
|
|
buildCompiledSprite(
|
|
|
|
&sprite_enemy,
|
2024-02-21 21:25:00 +00:00
|
|
|
&enemy,
|
2024-02-24 15:38:46 +00:00
|
|
|
SPRITE_ENEMY_WIDTH,
|
|
|
|
SPRITE_ENEMY_HEIGHT,
|
|
|
|
SPRITE_ENEMY_OFFSET_X,
|
|
|
|
SPRITE_ENEMY_OFFSET_Y
|
2024-02-21 21:25:00 +00:00
|
|
|
);
|
2024-02-25 21:59:04 +00:00
|
|
|
|
|
|
|
buildCompiledSprite(
|
|
|
|
&sprite_bullet,
|
|
|
|
&enemyBullet,
|
|
|
|
SPRITE_BULLET_WIDTH,
|
|
|
|
SPRITE_BULLET_HEIGHT,
|
|
|
|
SPRITE_BULLET_OFFSET_X,
|
|
|
|
SPRITE_BULLET_OFFSET_Y
|
|
|
|
);
|
2024-02-21 21:25:00 +00:00
|
|
|
}
|
|
|
|
|
2024-02-16 02:18:15 +00:00
|
|
|
void setupRabbitSprites() {
|
2024-02-24 15:38:46 +00:00
|
|
|
buildCompiledSprite(
|
|
|
|
&sprite_rabbit,
|
2024-02-16 02:18:15 +00:00
|
|
|
&rabbit,
|
2024-02-24 15:38:46 +00:00
|
|
|
SPRITE_RABBIT_WIDTH,
|
|
|
|
SPRITE_RABBIT_HEIGHT,
|
|
|
|
SPRITE_RABBIT_OFFSET_X,
|
|
|
|
SPRITE_RABBIT_OFFSET_Y
|
2024-02-16 02:18:15 +00:00
|
|
|
);
|
2024-02-20 11:48:12 +00:00
|
|
|
|
2024-02-24 15:38:46 +00:00
|
|
|
buildCompiledSprite(
|
|
|
|
&sprite_mouse,
|
2024-02-20 11:48:12 +00:00
|
|
|
&mouse,
|
2024-02-24 15:38:46 +00:00
|
|
|
SPRITE_MOUSE_WIDTH,
|
|
|
|
SPRITE_MOUSE_HEIGHT,
|
|
|
|
SPRITE_MOUSE_OFFSET_X,
|
|
|
|
SPRITE_MOUSE_OFFSET_Y
|
2024-02-20 11:48:12 +00:00
|
|
|
);
|
|
|
|
|
2024-02-24 15:38:46 +00:00
|
|
|
buildCompiledSprite(
|
|
|
|
&sprite_bullet,
|
2024-02-21 13:25:55 +00:00
|
|
|
&bullet,
|
2024-02-24 15:38:46 +00:00
|
|
|
SPRITE_BULLET_WIDTH,
|
|
|
|
SPRITE_BULLET_HEIGHT,
|
|
|
|
SPRITE_BULLET_OFFSET_X,
|
|
|
|
SPRITE_BULLET_OFFSET_Y
|
2024-02-21 13:25:55 +00:00
|
|
|
);
|
|
|
|
}
|
2024-02-16 02:18:15 +00:00
|
|
|
|
2024-02-27 01:40:05 +00:00
|
|
|
void setupPowerupSprites() {
|
|
|
|
buildCompiledSprite(
|
|
|
|
&sprite_shotgun,
|
|
|
|
&shotgun,
|
|
|
|
SPRITE_SHOTGUN_WIDTH,
|
|
|
|
SPRITE_SHOTGUN_HEIGHT,
|
|
|
|
SPRITE_SHOTGUN_OFFSET_X,
|
|
|
|
SPRITE_SHOTGUN_OFFSET_Y
|
|
|
|
);
|
2024-02-27 13:16:16 +00:00
|
|
|
|
|
|
|
buildCompiledSprite(
|
|
|
|
&sprite_shieldKiller,
|
|
|
|
&shieldKiller,
|
|
|
|
SPRITE_SHIELDKILLER_WIDTH,
|
|
|
|
SPRITE_SHIELDKILLER_HEIGHT,
|
|
|
|
SPRITE_SHIELDKILLER_OFFSET_X,
|
|
|
|
SPRITE_SHIELDKILLER_OFFSET_Y
|
|
|
|
);
|
2024-02-27 01:40:05 +00:00
|
|
|
}
|
|
|
|
|
2024-02-20 17:39:28 +00:00
|
|
|
void renderMouse() {
|
2024-02-21 13:25:55 +00:00
|
|
|
mouse.x = rabbitPosition.mousePosition[0];
|
|
|
|
mouse.y = rabbitPosition.mousePosition[1];
|
2024-02-24 15:38:46 +00:00
|
|
|
drawCompiledSprite(&mouse);
|
2024-02-21 13:25:55 +00:00
|
|
|
drawPixel(rabbitPosition.mouseDotPosition[0], rabbitPosition.mouseDotPosition[1], 2);
|
2024-02-20 11:48:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void renderRabbit() {
|
2024-02-21 13:25:55 +00:00
|
|
|
rabbit.x = rabbitPosition.rabbitPosition[0];
|
|
|
|
rabbit.y = rabbitPosition.rabbitPosition[1];
|
2024-02-24 15:38:46 +00:00
|
|
|
drawCompiledSprite(&rabbit);
|
2024-02-16 02:18:15 +00:00
|
|
|
}
|
|
|
|
|
2024-02-21 21:25:00 +00:00
|
|
|
void renderEnemies() {
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < ENEMY_MAX_COUNT; ++i) {
|
|
|
|
if (!enemyPosition[i].isActive) continue;
|
|
|
|
|
|
|
|
enemy.x = enemyPosition[i].enemyPosition[0];
|
|
|
|
enemy.y = enemyPosition[i].enemyPosition[1];
|
2024-02-24 15:38:46 +00:00
|
|
|
drawCompiledSprite(&enemy);
|
2024-02-21 21:25:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-02-21 13:25:55 +00:00
|
|
|
void renderRabbitBullets() {
|
|
|
|
char i;
|
2024-02-16 02:18:15 +00:00
|
|
|
|
2024-02-21 13:25:55 +00:00
|
|
|
for (i = 0; i < RABBIT_BULLET_LIMIT; ++i) {
|
|
|
|
if (!rabbitBulletPosition[i].isActive) continue;
|
2024-02-16 02:18:15 +00:00
|
|
|
|
2024-02-21 13:25:55 +00:00
|
|
|
bullet.x = rabbitBulletPosition[i].x;
|
|
|
|
bullet.y = rabbitBulletPosition[i].y;
|
2024-02-24 15:38:46 +00:00
|
|
|
drawCompiledSprite(&bullet);
|
2024-02-16 02:18:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-02-25 21:59:04 +00:00
|
|
|
void renderEnemyBullets() {
|
|
|
|
char i;
|
|
|
|
|
|
|
|
for (i = 0; i < ENEMY_BULLET_LIMIT; ++i) {
|
|
|
|
if (!enemyBulletPosition[i].isActive) continue;
|
|
|
|
|
|
|
|
enemyBullet.x = enemyBulletPosition[i].x;
|
|
|
|
enemyBullet.y = enemyBulletPosition[i].y;
|
|
|
|
drawCompiledSprite(&enemyBullet);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-02-27 01:40:05 +00:00
|
|
|
void renderPowerup() {
|
2024-02-27 13:16:16 +00:00
|
|
|
if (!playerPowerup.isActive) return;
|
2024-02-27 01:40:05 +00:00
|
|
|
|
2024-02-27 13:16:16 +00:00
|
|
|
switch (playerPowerup.type) {
|
|
|
|
case POWERUP_TYPE_SHOTGUN:
|
|
|
|
shotgun.x = playerPowerup.x;
|
|
|
|
shotgun.y = playerPowerup.y;
|
|
|
|
drawCompiledSprite(&shotgun);
|
|
|
|
break;
|
|
|
|
case POWERUP_TYPE_SHIELD_KILLER:
|
|
|
|
shieldKiller.x = playerPowerup.x;
|
|
|
|
shieldKiller.y = playerPowerup.y;
|
|
|
|
drawCompiledSprite(&shieldKiller);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void drawOnlyArenaForSprite(struct CompiledSpriteRender *sprite) {
|
|
|
|
getSpriteBounds(sprite, &bounds);
|
|
|
|
drawOnlyArena(&bounds);
|
2024-02-27 01:40:05 +00:00
|
|
|
}
|
|
|
|
|
2024-02-20 11:48:12 +00:00
|
|
|
void drawOnlyMouseArena() {
|
2024-02-21 13:25:55 +00:00
|
|
|
mouse.x = rabbitPosition.oldMousePosition[0];
|
|
|
|
mouse.y = rabbitPosition.oldMousePosition[1];
|
2024-02-27 13:16:16 +00:00
|
|
|
drawOnlyArenaForSprite(&mouse);
|
2024-02-20 17:39:28 +00:00
|
|
|
|
2024-02-21 13:25:55 +00:00
|
|
|
bounds.top = rabbitPosition.oldMouseDotPosition[1];
|
|
|
|
bounds.bottom = rabbitPosition.oldMouseDotPosition[1];
|
|
|
|
bounds.left = rabbitPosition.oldMouseDotPosition[0];
|
|
|
|
bounds.right = rabbitPosition.oldMouseDotPosition[0];
|
2024-02-20 17:51:59 +00:00
|
|
|
drawOnlyArena(&bounds);
|
2024-02-20 11:48:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void drawOnlyRabbitArena() {
|
2024-02-21 13:25:55 +00:00
|
|
|
rabbit.x = rabbitPosition.oldRabbitPosition[0];
|
|
|
|
rabbit.y = rabbitPosition.oldRabbitPosition[1];
|
2024-02-27 13:16:16 +00:00
|
|
|
drawOnlyArenaForSprite(&rabbit);
|
|
|
|
}
|
|
|
|
|
|
|
|
void drawOnlyPowerupArena() {
|
|
|
|
if (!playerPowerup.isActive) return;
|
|
|
|
|
|
|
|
switch (playerPowerup.type) {
|
|
|
|
case POWERUP_TYPE_SHOTGUN:
|
|
|
|
shotgun.x = playerPowerup.x;
|
|
|
|
shotgun.y = playerPowerup.y;
|
|
|
|
drawOnlyArenaForSprite(&shotgun);
|
|
|
|
break;
|
|
|
|
case POWERUP_TYPE_SHIELD_KILLER:
|
|
|
|
shieldKiller.x = playerPowerup.x;
|
|
|
|
shieldKiller.y = playerPowerup.y;
|
|
|
|
drawOnlyArenaForSprite(&shieldKiller);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (playerPowerup.willBeInactive) {
|
|
|
|
playerPowerup.isActive = 0;
|
|
|
|
}
|
2024-02-20 11:48:12 +00:00
|
|
|
}
|
|
|
|
|
2024-02-21 21:25:00 +00:00
|
|
|
void drawOnlyEnemiesArena() {
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < ENEMY_MAX_COUNT; ++i) {
|
|
|
|
if (!enemyPosition[i].isActive) continue;
|
|
|
|
|
|
|
|
enemy.x = enemyPosition[i].oldEnemyPosition[0];
|
|
|
|
enemy.y = enemyPosition[i].oldEnemyPosition[1];
|
2024-02-27 13:16:16 +00:00
|
|
|
drawOnlyArenaForSprite(&enemy);
|
2024-02-21 21:25:00 +00:00
|
|
|
|
|
|
|
if (enemyPosition[i].willBeInactive) {
|
2024-02-25 13:43:30 +00:00
|
|
|
enemyPosition[i].isActive = 0;
|
2024-02-21 21:25:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-02-21 13:25:55 +00:00
|
|
|
void drawOnlyRabbitBulletArena() {
|
|
|
|
int i;
|
|
|
|
for (i = 0; i < RABBIT_BULLET_LIMIT; ++i) {
|
|
|
|
if (!rabbitBulletPosition[i].isActive) continue;
|
|
|
|
|
|
|
|
bullet.x = rabbitBulletPosition[i].oldX;
|
|
|
|
bullet.y = rabbitBulletPosition[i].oldY;
|
2024-02-27 13:16:16 +00:00
|
|
|
drawOnlyArenaForSprite(&bullet);
|
2024-02-21 13:25:55 +00:00
|
|
|
|
|
|
|
if (rabbitBulletPosition[i].willBeInactive) {
|
|
|
|
rabbitBulletPosition[i].isActive = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-02-25 21:59:04 +00:00
|
|
|
void drawOnlyEnemyBulletArena() {
|
|
|
|
int i;
|
|
|
|
for (i = 0; i < ENEMY_BULLET_LIMIT; ++i) {
|
|
|
|
if (!enemyBulletPosition[i].isActive) continue;
|
|
|
|
|
|
|
|
enemyBullet.x = enemyBulletPosition[i].oldX;
|
|
|
|
enemyBullet.y = enemyBulletPosition[i].oldY;
|
2024-02-27 13:16:16 +00:00
|
|
|
drawOnlyArenaForSprite(&enemyBullet);
|
2024-02-25 21:59:04 +00:00
|
|
|
|
|
|
|
if (enemyBulletPosition[i].willBeInactive) {
|
|
|
|
enemyBulletPosition[i].isActive = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-02-21 21:25:00 +00:00
|
|
|
int setupGame() {
|
2024-02-15 13:34:50 +00:00
|
|
|
FILE *fh;
|
2024-02-15 01:15:55 +00:00
|
|
|
|
|
|
|
installKeyboardHandler();
|
2024-02-15 13:34:50 +00:00
|
|
|
initializeDrawBuffer();
|
|
|
|
|
|
|
|
fh = fopen("sprtsht.bmp", "rb");
|
|
|
|
if (readBMPIntoNewMemory(fh, &spritesheetImage)) return 1;
|
|
|
|
fclose(fh);
|
|
|
|
|
|
|
|
spritesheetImage.transparentColor = 0;
|
|
|
|
|
2024-02-25 17:52:42 +00:00
|
|
|
setupWallSprites();
|
2024-02-16 02:18:15 +00:00
|
|
|
setupRabbitSprites();
|
2024-02-21 13:25:55 +00:00
|
|
|
setupRabbitBullets();
|
2024-02-27 13:16:16 +00:00
|
|
|
setupEnemies();
|
|
|
|
setupEnemyBullets();
|
2024-02-21 21:25:00 +00:00
|
|
|
setupEnemySprites();
|
2024-02-27 13:16:16 +00:00
|
|
|
setupPowerup();
|
2024-02-27 01:40:05 +00:00
|
|
|
setupPowerupSprites();
|
2024-02-15 13:34:50 +00:00
|
|
|
|
|
|
|
setVideoMode(VIDEO_MODE_VGA_256);
|
|
|
|
bmp256ColorPaletteToVGAColorPalette(&spritesheetImage, vgaColors);
|
|
|
|
setVGAColors(vgaColors, 256);
|
2024-02-15 01:15:55 +00:00
|
|
|
|
2024-02-20 11:48:12 +00:00
|
|
|
activateMouse(&mouseStatus);
|
|
|
|
|
2024-02-16 02:18:15 +00:00
|
|
|
buildArena();
|
2024-02-21 13:25:55 +00:00
|
|
|
clearArenaRedrawRequests();
|
2024-02-15 13:34:50 +00:00
|
|
|
|
2024-02-21 21:25:00 +00:00
|
|
|
srand(time(NULL));
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2024-02-25 13:43:30 +00:00
|
|
|
void handleMovement() {
|
|
|
|
handleRabbitMovement(
|
|
|
|
&rabbitPosition,
|
|
|
|
&keyboardKeydownState
|
|
|
|
);
|
2024-02-25 21:59:04 +00:00
|
|
|
handleEnemyMovement(
|
|
|
|
enemyPosition,
|
|
|
|
&rabbitPosition
|
|
|
|
);
|
2024-02-25 13:43:30 +00:00
|
|
|
captureAndLimitMousePosition(
|
|
|
|
&rabbitPosition,
|
|
|
|
&mouseStatus
|
|
|
|
);
|
|
|
|
calculateTargetAngle(
|
|
|
|
&rabbitPosition,
|
|
|
|
&mouseStatus
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
void handleCombat() {
|
2024-02-26 12:52:59 +00:00
|
|
|
int didHitRabbit;
|
|
|
|
|
2024-02-25 13:43:30 +00:00
|
|
|
if (mouseStatus.leftButtonDown) {
|
2024-02-27 13:16:16 +00:00
|
|
|
if (attemptToFireRabbitBullet(
|
2024-02-25 13:43:30 +00:00
|
|
|
&rabbitPosition,
|
|
|
|
&rabbitWeaponry,
|
|
|
|
rabbitBulletPosition
|
2024-02-27 13:16:16 +00:00
|
|
|
)) {
|
|
|
|
if (rabbitWeaponry.currentWeaponRemainingRounds > 0) {
|
|
|
|
rabbitWeaponry.currentWeaponRemainingRounds--;
|
|
|
|
if (rabbitWeaponry.currentWeaponRemainingRounds == 0) {
|
|
|
|
rabbitWeaponry.currentWeapon = WEAPON_TYPE_SINGLE_SHOT_GUN;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2024-02-25 13:43:30 +00:00
|
|
|
}
|
|
|
|
|
2024-02-25 21:59:04 +00:00
|
|
|
attemptToFireEnemyBullets(
|
|
|
|
enemyPosition,
|
|
|
|
enemyBulletPosition,
|
2024-02-26 12:52:59 +00:00
|
|
|
&rabbitPosition,
|
|
|
|
difficulty
|
2024-02-25 21:59:04 +00:00
|
|
|
);
|
|
|
|
|
2024-02-25 13:43:30 +00:00
|
|
|
advanceRabbitBullets(
|
|
|
|
rabbitBulletPosition,
|
|
|
|
&rabbitWeaponry
|
|
|
|
);
|
|
|
|
|
2024-02-25 21:59:04 +00:00
|
|
|
advanceEnemyBullets(
|
|
|
|
enemyBulletPosition
|
|
|
|
);
|
|
|
|
|
2024-02-25 20:48:19 +00:00
|
|
|
buildCollisionGrids(
|
|
|
|
rabbitBulletPosition,
|
2024-02-26 12:52:59 +00:00
|
|
|
enemyBulletPosition,
|
2024-02-25 20:48:19 +00:00
|
|
|
&rabbitPosition,
|
2024-02-27 13:16:16 +00:00
|
|
|
enemyPosition,
|
|
|
|
&playerPowerup
|
2024-02-25 20:48:19 +00:00
|
|
|
);
|
|
|
|
|
2024-02-26 12:52:59 +00:00
|
|
|
didHitRabbit = handleRabbitToEnemyCollisions(
|
2024-02-25 17:52:42 +00:00
|
|
|
&rabbitPosition,
|
|
|
|
enemyPosition
|
|
|
|
);
|
|
|
|
|
2024-02-26 12:52:59 +00:00
|
|
|
if (didHitRabbit) {
|
|
|
|
health -= ENEMY_COLLISION_DAMAGE * didHitRabbit;
|
|
|
|
}
|
|
|
|
|
|
|
|
didHitRabbit = handleEnemyBulletToRabbitCollisions(
|
|
|
|
enemyBulletPosition,
|
|
|
|
&rabbitPosition
|
|
|
|
);
|
|
|
|
|
|
|
|
if (didHitRabbit) {
|
|
|
|
health -= ENEMY_BULLET_DAMAGE * didHitRabbit;
|
|
|
|
}
|
|
|
|
|
2024-02-25 13:43:30 +00:00
|
|
|
handleRabbitBulletToEnemyCollisions(
|
|
|
|
rabbitBulletPosition,
|
|
|
|
enemyPosition
|
|
|
|
);
|
2024-02-27 13:16:16 +00:00
|
|
|
|
|
|
|
if (handleRabbitToPowerupCollision(&rabbitPosition, &playerPowerup)) {
|
|
|
|
playerPowerup.willBeInactive = 1;
|
|
|
|
rabbitWeaponry.currentWeapon = WEAPON_TYPE_SPREAD_SHOT_GUN;
|
|
|
|
rabbitWeaponry.currentWeaponRemainingRounds = (difficulty + 1) * SHOTGUN_ROUNDS_PER_LEVEL;
|
|
|
|
}
|
2024-02-25 13:43:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void handleRedraw() {
|
|
|
|
drawOnlyRabbitArena();
|
|
|
|
drawOnlyEnemiesArena();
|
|
|
|
drawOnlyMouseArena();
|
|
|
|
drawOnlyRabbitBulletArena();
|
2024-02-25 21:59:04 +00:00
|
|
|
drawOnlyEnemyBulletArena();
|
2024-02-27 13:16:16 +00:00
|
|
|
drawOnlyPowerupArena();
|
2024-02-25 13:43:30 +00:00
|
|
|
|
|
|
|
redrawArena();
|
|
|
|
|
2024-02-27 01:40:05 +00:00
|
|
|
renderPowerup();
|
2024-02-25 13:43:30 +00:00
|
|
|
renderRabbit();
|
|
|
|
renderEnemies();
|
|
|
|
renderMouse();
|
|
|
|
renderRabbitBullets();
|
2024-02-25 21:59:04 +00:00
|
|
|
renderEnemyBullets();
|
2024-02-25 13:43:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2024-02-21 21:25:00 +00:00
|
|
|
double speedCalcs[200];
|
|
|
|
int currentSpeedCalc = 0;
|
|
|
|
double averageSpeedCalc;
|
|
|
|
clock_t startTime;
|
2024-02-25 13:43:30 +00:00
|
|
|
*/
|
2024-02-21 21:25:00 +00:00
|
|
|
|
|
|
|
int main(void) {
|
2024-02-24 12:36:18 +00:00
|
|
|
byte *drawBuffer;
|
2024-02-21 21:25:00 +00:00
|
|
|
int keepRunning = 1;
|
2024-02-25 17:52:42 +00:00
|
|
|
int i;
|
2024-02-21 21:25:00 +00:00
|
|
|
|
2024-02-26 12:52:59 +00:00
|
|
|
char buffer[20];
|
|
|
|
|
2024-02-21 21:25:00 +00:00
|
|
|
if (setupGame()) return 1;
|
|
|
|
|
2024-02-24 12:36:18 +00:00
|
|
|
drawBuffer = getDrawBuffer();
|
|
|
|
|
2024-02-16 02:18:15 +00:00
|
|
|
while (keepRunning) {
|
|
|
|
readMouse(&mouseStatus);
|
|
|
|
populateKeyboardKeydownState();
|
2024-02-21 13:25:55 +00:00
|
|
|
|
2024-02-25 21:59:04 +00:00
|
|
|
maybeSpawnEnemy();
|
|
|
|
|
2024-02-25 13:43:30 +00:00
|
|
|
handleMovement();
|
|
|
|
handleRedraw();
|
2024-02-25 20:48:19 +00:00
|
|
|
handleCombat();
|
2024-02-26 12:52:59 +00:00
|
|
|
handleEnemyKills();
|
|
|
|
|
|
|
|
sprintf(buffer, "Hit: %d", kills);
|
|
|
|
renderStringToDrawBuffer(buffer, 1, 0, 210, 20);
|
|
|
|
sprintf(buffer, "Health: %d ", health);
|
|
|
|
renderStringToDrawBuffer(buffer, 1, 0, 210, 30);
|
2024-02-27 13:16:16 +00:00
|
|
|
sprintf(buffer, "Rnds: %d ", rabbitWeaponry.currentWeaponRemainingRounds);
|
|
|
|
renderStringToDrawBuffer(buffer, 1, 0, 210, 40);
|
2024-02-20 13:20:35 +00:00
|
|
|
|
|
|
|
waitStartVbl();
|
2024-02-15 13:34:50 +00:00
|
|
|
copyDrawBufferToDisplay();
|
2024-02-25 21:59:04 +00:00
|
|
|
|
2024-02-15 13:34:50 +00:00
|
|
|
waitEndVbl();
|
2024-02-16 02:18:15 +00:00
|
|
|
|
2024-02-20 17:39:28 +00:00
|
|
|
if (keyboardKeydownState.KEY_ESC) { keepRunning = 0; }
|
2024-02-15 01:15:55 +00:00
|
|
|
}
|
2024-02-16 02:18:15 +00:00
|
|
|
|
|
|
|
freeBMP(&spritesheetImage);
|
|
|
|
|
|
|
|
setVideoMode(VIDEO_MODE_80x25_TEXT);
|
|
|
|
uninstallKeyboardHandler();
|
|
|
|
|
2024-02-25 13:43:30 +00:00
|
|
|
/*
|
2024-02-21 21:25:00 +00:00
|
|
|
averageSpeedCalc = 0;
|
|
|
|
for (currentSpeedCalc = 0; currentSpeedCalc < 200; ++currentSpeedCalc) {
|
|
|
|
averageSpeedCalc += speedCalcs[currentSpeedCalc];
|
|
|
|
}
|
|
|
|
|
|
|
|
averageSpeedCalc /= 200;
|
|
|
|
|
|
|
|
fprintf(stderr, "average: %f\n", averageSpeedCalc);
|
2024-02-25 13:43:30 +00:00
|
|
|
*/
|
2024-02-21 13:25:55 +00:00
|
|
|
|
2024-02-15 13:34:50 +00:00
|
|
|
return 0;
|
2024-02-15 01:15:55 +00:00
|
|
|
}
|