starting on shotgun

This commit is contained in:
John Bintz 2024-02-26 20:40:05 -05:00
parent 71a6c65f3b
commit 20bf569dac
10 changed files with 238 additions and 13 deletions

View File

@ -31,10 +31,12 @@ void attemptToFireRabbitBullet(
struct RabbitWeaponry *rabbitWeaponry, struct RabbitWeaponry *rabbitWeaponry,
struct BulletPosition rabbitBulletPosition[] struct BulletPosition rabbitBulletPosition[]
) { ) {
int okToFire = 0, availableBullet, i; int okToFire = 0, i, mouseAngle;
signed int doubleVelocityX, doubleVelocityY; signed int doubleVelocityX, doubleVelocityY;
int availableBullets[3];
if (rabbitWeaponry->cooldown > 0) return; if (rabbitWeaponry->cooldown > 0) return;
mouseAngle = rabbitPosition->mouseAngle;
rabbitWeaponry->cooldown = RABBIT_BULLET_COOLDOWN; rabbitWeaponry->cooldown = RABBIT_BULLET_COOLDOWN;
@ -42,18 +44,18 @@ void attemptToFireRabbitBullet(
for (i = 0; i < RABBIT_BULLET_LIMIT; ++i) { for (i = 0; i < RABBIT_BULLET_LIMIT; ++i) {
if (rabbitBulletPosition[i].isActive == 0) { if (rabbitBulletPosition[i].isActive == 0) {
okToFire = 1; okToFire = 1;
availableBullet = i; availableBullets[0] = i;
break; break;
} }
} }
if (!okToFire) return; if (!okToFire) return;
doubleVelocityX = sin(rabbitPosition->mouseAngle * DEG2RAD) * (RABBIT_BULLET_VELOCITY * 2); doubleVelocityX = sin(mouseAngle * DEG2RAD) * (RABBIT_BULLET_VELOCITY * 2);
doubleVelocityY = -cos(rabbitPosition->mouseAngle * DEG2RAD) * (RABBIT_BULLET_VELOCITY * 2); doubleVelocityY = -cos(mouseAngle * DEG2RAD) * (RABBIT_BULLET_VELOCITY * 2);
setupBullet( setupBullet(
&rabbitBulletPosition[availableBullet], &rabbitBulletPosition[availableBullets[0]],
rabbitPosition->rabbitPosition[0], rabbitPosition->rabbitPosition[0],
rabbitPosition->rabbitPosition[1], rabbitPosition->rabbitPosition[1],
doubleVelocityX, doubleVelocityX,
@ -62,13 +64,22 @@ void attemptToFireRabbitBullet(
); );
} else if (rabbitWeaponry->currentWeapon == SPREAD_SHOT_GUN) { } else if (rabbitWeaponry->currentWeapon == SPREAD_SHOT_GUN) {
// make sure three bullets are available // make sure three bullets are available
for (i = 0; i < RABBIT_BULLET_LIMIT; ++i) {
if (rabbitBulletPosition[i].isActive == 0) {
availableBullets[okToFire++] = i;
if (okToFire == 3) break;
}
}
if (okToFire < 3) return;
// if so, fire away // if so, fire away
for (i = -1; i <= 1; ++i) { for (i = 0; i < 3; ++i) {
doubleVelocityX = sin(rabbitPosition->mouseAngle * DEG2RAD) * (RABBIT_BULLET_VELOCITY * 2); doubleVelocityX = sin((mouseAngle + (i - 1) * RABBIT_BULLET_SHOTGUN_SPREAD) * DEG2RAD) * (RABBIT_BULLET_VELOCITY * 2);
doubleVelocityY = -cos(rabbitPosition->mouseAngle * DEG2RAD) * (RABBIT_BULLET_VELOCITY * 2); doubleVelocityY = -cos((mouseAngle + (i - 1) * RABBIT_BULLET_SHOTGUN_SPREAD) * DEG2RAD) * (RABBIT_BULLET_VELOCITY * 2);
setupBullet( setupBullet(
&rabbitBulletPosition[availableBullet], &rabbitBulletPosition[availableBullets[i]],
rabbitPosition->rabbitPosition[0], rabbitPosition->rabbitPosition[0],
rabbitPosition->rabbitPosition[1], rabbitPosition->rabbitPosition[1],
doubleVelocityX, doubleVelocityX,

View File

@ -10,11 +10,13 @@
#define RABBIT_MOTION_MAX_SPEED (12) #define RABBIT_MOTION_MAX_SPEED (12)
#define RABBIT_MOTION_VELOCITY_DECAY (5) #define RABBIT_MOTION_VELOCITY_DECAY (5)
#define RABBIT_BULLET_LIMIT (12) #define RABBIT_BULLET_LIMIT (9)
#define RABBIT_BULLET_VELOCITY ((RABBIT_MOTION_ACCELERATION / 2) + 1) #define RABBIT_BULLET_VELOCITY ((RABBIT_MOTION_ACCELERATION / 2) + 1)
#define RABBIT_BULLET_COOLDOWN (10) #define RABBIT_BULLET_COOLDOWN (10)
#define RABBIT_BULLET_HEIGHT_START (8) #define RABBIT_BULLET_HEIGHT_START (8)
#define RABBIT_BULLET_SHOTGUN_SPREAD (15)
#define RABBIT_HEALTH_MAX (100) #define RABBIT_HEALTH_MAX (100)
#define MOUSE_LIMIT_TOP (TILE_SIZE) #define MOUSE_LIMIT_TOP (TILE_SIZE)

34
game.c
View File

@ -19,7 +19,12 @@
#include "game.h" #include "game.h"
// TODO: centralize these outside of game.c // TODO: centralize these outside of game.c
struct CompiledSpriteRender rabbit, mouse, bullet, enemy, enemyBullet; struct CompiledSpriteRender rabbit,
mouse,
bullet,
enemy,
enemyBullet,
shotgun;
struct SpriteBounds bounds; struct SpriteBounds bounds;
struct BMPImage spritesheetImage; struct BMPImage spritesheetImage;
@ -41,6 +46,7 @@ struct EnemyPosition enemyPosition[ENEMY_MAX_COUNT];
struct BulletPosition rabbitBulletPosition[RABBIT_BULLET_LIMIT]; struct BulletPosition rabbitBulletPosition[RABBIT_BULLET_LIMIT];
struct BulletPosition enemyBulletPosition[ENEMY_BULLET_LIMIT]; struct BulletPosition enemyBulletPosition[ENEMY_BULLET_LIMIT];
struct RabbitWeaponry rabbitWeaponry; struct RabbitWeaponry rabbitWeaponry;
struct PlayerPowerup playerPowerup;
struct SpawnPointRange spawnPointRanges[4] = { struct SpawnPointRange spawnPointRanges[4] = {
// top // top
@ -65,6 +71,12 @@ void setupRabbitBullets() {
rabbitWeaponry.currentWeapon = SPREAD_SHOT_GUN; rabbitWeaponry.currentWeapon = SPREAD_SHOT_GUN;
} }
void setupPowerup() {
playerPowerup.x = 100;
playerPowerup.y = 100;
playerPowerup.isActive = 0;
}
void setupEnemyBullets() { void setupEnemyBullets() {
int i; int i;
@ -212,6 +224,17 @@ void setupRabbitSprites() {
); );
} }
void setupPowerupSprites() {
buildCompiledSprite(
&sprite_shotgun,
&shotgun,
SPRITE_SHOTGUN_WIDTH,
SPRITE_SHOTGUN_HEIGHT,
SPRITE_SHOTGUN_OFFSET_X,
SPRITE_SHOTGUN_OFFSET_Y
);
}
void renderMouse() { void renderMouse() {
mouse.x = rabbitPosition.mousePosition[0]; mouse.x = rabbitPosition.mousePosition[0];
mouse.y = rabbitPosition.mousePosition[1]; mouse.y = rabbitPosition.mousePosition[1];
@ -266,6 +289,13 @@ void renderEnemyBullets() {
} }
} }
void renderPowerup() {
shotgun.x = playerPowerup.x;
shotgun.y = playerPowerup.y;
drawCompiledSprite(&shotgun);
}
void drawOnlyMouseArena() { void drawOnlyMouseArena() {
mouse.x = rabbitPosition.oldMousePosition[0]; mouse.x = rabbitPosition.oldMousePosition[0];
mouse.y = rabbitPosition.oldMousePosition[1]; mouse.y = rabbitPosition.oldMousePosition[1];
@ -351,6 +381,7 @@ int setupGame() {
setupRabbitSprites(); setupRabbitSprites();
setupRabbitBullets(); setupRabbitBullets();
setupEnemySprites(); setupEnemySprites();
setupPowerupSprites();
setVideoMode(VIDEO_MODE_VGA_256); setVideoMode(VIDEO_MODE_VGA_256);
bmp256ColorPaletteToVGAColorPalette(&spritesheetImage, vgaColors); bmp256ColorPaletteToVGAColorPalette(&spritesheetImage, vgaColors);
@ -452,6 +483,7 @@ void handleRedraw() {
redrawArena(); redrawArena();
renderPowerup();
renderRabbit(); renderRabbit();
renderEnemies(); renderEnemies();
renderMouse(); renderMouse();

View File

@ -1,4 +1,4 @@
obj = game.o bmpload.o arena.o movement.o sprites.o combat.o obj = sprites.o game.o bmpload.o arena.o movement.o combat.o
all: system/system.lib game.exe .SYMBOLIC all: system/system.lib game.exe .SYMBOLIC
@ -17,7 +17,7 @@ sprites.asm: sprtsht.bmp spritesheet.yml
bin/build_spritesheet_asm.rb bin/build_spritesheet_asm.rb
game.exe: $(obj) system/system.lib game.exe: $(obj) system/system.lib
wcl386 -q -bt=dos -l=dos4g $(obj) system/system.lib wcl386 -q -fe=game -bt=dos -l=dos4g $(obj) system/system.lib
clean: .SYMBOLIC clean: .SYMBOLIC
rm *.o rm *.o

View File

@ -24,6 +24,16 @@ struct RabbitPosition {
struct RabbitWeaponry { struct RabbitWeaponry {
char cooldown; char cooldown;
char currentWeapon; char currentWeapon;
int currentWeaponRemainingRounds;
};
#define POWERUP_SHOTGUN (0);
struct PlayerPowerup {
int x, y;
int cooldown;
char isActive;
char type;
}; };
struct BulletPosition { struct BulletPosition {

View File

@ -6,6 +6,7 @@ PUBLIC sprite_rabbit_
PUBLIC sprite_mouse_ PUBLIC sprite_mouse_
PUBLIC sprite_bullet_ PUBLIC sprite_bullet_
PUBLIC sprite_enemy_ PUBLIC sprite_enemy_
PUBLIC sprite_shotgun_
.386 .386
.model flat,c .model flat,c
@ -1403,4 +1404,158 @@ sprite_enemy_:
ret ret
sprite_shotgun_:
push ebp
mov ebp, esp
mov BYTE PTR [eax + -1926], 6
mov BYTE PTR [eax + -1925], 6
mov BYTE PTR [eax + -1924], 6
mov BYTE PTR [eax + -1923], 6
mov BYTE PTR [eax + -1922], 6
mov BYTE PTR [eax + -1921], 6
mov BYTE PTR [eax + -1920], 6
mov BYTE PTR [eax + -1919], 6
mov BYTE PTR [eax + -1918], 6
mov BYTE PTR [eax + -1917], 6
mov BYTE PTR [eax + -1916], 6
mov BYTE PTR [eax + -1915], 6
mov BYTE PTR [eax + -1606], 6
mov BYTE PTR [eax + -1605], 6
mov BYTE PTR [eax + -1604], 6
mov BYTE PTR [eax + -1603], 6
mov BYTE PTR [eax + -1602], 6
mov BYTE PTR [eax + -1601], 6
mov BYTE PTR [eax + -1600], 6
mov BYTE PTR [eax + -1599], 6
mov BYTE PTR [eax + -1598], 6
mov BYTE PTR [eax + -1597], 6
mov BYTE PTR [eax + -1596], 6
mov BYTE PTR [eax + -1595], 6
mov BYTE PTR [eax + -1286], 6
mov BYTE PTR [eax + -1285], 6
mov BYTE PTR [eax + -1284], 6
mov BYTE PTR [eax + -1283], 6
mov BYTE PTR [eax + -1282], 6
mov BYTE PTR [eax + -1281], 6
mov BYTE PTR [eax + -1280], 6
mov BYTE PTR [eax + -1279], 6
mov BYTE PTR [eax + -1278], 6
mov BYTE PTR [eax + -1277], 6
mov BYTE PTR [eax + -1276], 6
mov BYTE PTR [eax + -1275], 6
mov BYTE PTR [eax + -966], 6
mov BYTE PTR [eax + -965], 6
mov BYTE PTR [eax + -964], 6
mov BYTE PTR [eax + -963], 6
mov BYTE PTR [eax + -962], 6
mov BYTE PTR [eax + -961], 6
mov BYTE PTR [eax + -960], 6
mov BYTE PTR [eax + -959], 6
mov BYTE PTR [eax + -958], 6
mov BYTE PTR [eax + -957], 6
mov BYTE PTR [eax + -956], 6
mov BYTE PTR [eax + -955], 6
mov BYTE PTR [eax + -646], 6
mov BYTE PTR [eax + -645], 6
mov BYTE PTR [eax + -644], 6
mov BYTE PTR [eax + -643], 6
mov BYTE PTR [eax + -642], 6
mov BYTE PTR [eax + -641], 6
mov BYTE PTR [eax + -640], 6
mov BYTE PTR [eax + -639], 6
mov BYTE PTR [eax + -638], 6
mov BYTE PTR [eax + -637], 6
mov BYTE PTR [eax + -636], 6
mov BYTE PTR [eax + -635], 6
mov BYTE PTR [eax + -326], 6
mov BYTE PTR [eax + -325], 6
mov BYTE PTR [eax + -324], 6
mov BYTE PTR [eax + -323], 6
mov BYTE PTR [eax + -322], 6
mov BYTE PTR [eax + -321], 6
mov BYTE PTR [eax + -320], 6
mov BYTE PTR [eax + -319], 6
mov BYTE PTR [eax + -318], 6
mov BYTE PTR [eax + -317], 6
mov BYTE PTR [eax + -316], 6
mov BYTE PTR [eax + -315], 6
mov BYTE PTR [eax + -6], 6
mov BYTE PTR [eax + -5], 6
mov BYTE PTR [eax + -4], 6
mov BYTE PTR [eax + -3], 6
mov BYTE PTR [eax + -2], 6
mov BYTE PTR [eax + -1], 6
mov BYTE PTR [eax + 0], 6
mov BYTE PTR [eax + 1], 6
mov BYTE PTR [eax + 2], 6
mov BYTE PTR [eax + 3], 6
mov BYTE PTR [eax + 4], 6
mov BYTE PTR [eax + 5], 6
mov BYTE PTR [eax + 314], 6
mov BYTE PTR [eax + 315], 6
mov BYTE PTR [eax + 316], 6
mov BYTE PTR [eax + 317], 6
mov BYTE PTR [eax + 318], 6
mov BYTE PTR [eax + 319], 6
mov BYTE PTR [eax + 320], 6
mov BYTE PTR [eax + 321], 6
mov BYTE PTR [eax + 322], 6
mov BYTE PTR [eax + 323], 6
mov BYTE PTR [eax + 324], 6
mov BYTE PTR [eax + 325], 6
mov BYTE PTR [eax + 634], 6
mov BYTE PTR [eax + 635], 6
mov BYTE PTR [eax + 636], 6
mov BYTE PTR [eax + 637], 6
mov BYTE PTR [eax + 638], 6
mov BYTE PTR [eax + 639], 6
mov BYTE PTR [eax + 640], 6
mov BYTE PTR [eax + 641], 6
mov BYTE PTR [eax + 642], 6
mov BYTE PTR [eax + 643], 6
mov BYTE PTR [eax + 644], 6
mov BYTE PTR [eax + 645], 6
mov BYTE PTR [eax + 954], 6
mov BYTE PTR [eax + 955], 6
mov BYTE PTR [eax + 956], 6
mov BYTE PTR [eax + 957], 6
mov BYTE PTR [eax + 958], 6
mov BYTE PTR [eax + 959], 6
mov BYTE PTR [eax + 960], 6
mov BYTE PTR [eax + 961], 6
mov BYTE PTR [eax + 962], 6
mov BYTE PTR [eax + 963], 6
mov BYTE PTR [eax + 964], 6
mov BYTE PTR [eax + 965], 6
mov BYTE PTR [eax + 1274], 6
mov BYTE PTR [eax + 1275], 6
mov BYTE PTR [eax + 1276], 6
mov BYTE PTR [eax + 1277], 6
mov BYTE PTR [eax + 1278], 6
mov BYTE PTR [eax + 1279], 6
mov BYTE PTR [eax + 1280], 6
mov BYTE PTR [eax + 1281], 6
mov BYTE PTR [eax + 1282], 6
mov BYTE PTR [eax + 1283], 6
mov BYTE PTR [eax + 1284], 6
mov BYTE PTR [eax + 1285], 6
mov BYTE PTR [eax + 1594], 6
mov BYTE PTR [eax + 1595], 6
mov BYTE PTR [eax + 1596], 6
mov BYTE PTR [eax + 1597], 6
mov BYTE PTR [eax + 1598], 6
mov BYTE PTR [eax + 1599], 6
mov BYTE PTR [eax + 1600], 6
mov BYTE PTR [eax + 1601], 6
mov BYTE PTR [eax + 1602], 6
mov BYTE PTR [eax + 1603], 6
mov BYTE PTR [eax + 1604], 6
mov BYTE PTR [eax + 1605], 6
pop ebp
ret
end end

View File

@ -81,5 +81,16 @@ extern void sprite_enemy(byte *);
#define SPRITE_ENEMY_OFFSET_Y (8) #define SPRITE_ENEMY_OFFSET_Y (8)
extern void sprite_shotgun(byte *);
#define SPRITE_SHOTGUN_WIDTH (12)
#define SPRITE_SHOTGUN_HEIGHT (12)
#define SPRITE_SHOTGUN_OFFSET_X (6)
#define SPRITE_SHOTGUN_OFFSET_Y (6)
#endif #endif

Binary file not shown.

View File

@ -33,3 +33,7 @@ files:
position: [0, 20] position: [0, 20]
dimensions: [16, 16] dimensions: [16, 16]
offset: [8, 8] offset: [8, 8]
shotgun:
position: [32, 20]
dimensions: [12, 12]
offset: [6, 6]

Binary file not shown.

Before

Width:  |  Height:  |  Size: 39 KiB

After

Width:  |  Height:  |  Size: 39 KiB