messing with assembler
This commit is contained in:
parent
cf3cdad788
commit
3e18d9cdb2
4
arena.c
4
arena.c
@ -55,8 +55,8 @@ void renderArenaTile(int x, int y) {
|
||||
break;
|
||||
}
|
||||
|
||||
target->x = x * 20;
|
||||
target->y = y * 20;
|
||||
target->x = x * TILE_SIZE;
|
||||
target->y = y * TILE_SIZE;
|
||||
|
||||
drawSprite(target);
|
||||
}
|
||||
|
1
const.h
1
const.h
@ -22,3 +22,4 @@
|
||||
#define RAD2DEG (180/3.14159)
|
||||
#define DEG2RAD (3.14159/180)
|
||||
|
||||
#define ENEMY_MAX_COUNT (20)
|
||||
|
149
game.c
149
game.c
@ -1,6 +1,8 @@
|
||||
#include <stdio.h>
|
||||
#include <math.h>
|
||||
#include <conio.h>
|
||||
#include <stdlib.h>
|
||||
#include <time.h>
|
||||
|
||||
#include "system/vga.h"
|
||||
#include "system/keyboard.h"
|
||||
@ -15,7 +17,7 @@
|
||||
struct BMPImage spritesheetImage;
|
||||
struct VGAColor vgaColors[256];
|
||||
|
||||
struct SpriteRender rabbit, mouse, bullet;
|
||||
struct SpriteRender rabbit, mouse, bullet, enemy;
|
||||
struct RabbitPosition rabbitPosition = {
|
||||
.rabbitPosition = { 60, 60 },
|
||||
.rabbitLimits = { { 20, 20 }, { 180, 180 } },
|
||||
@ -24,11 +26,13 @@ struct RabbitPosition rabbitPosition = {
|
||||
.mouseDotPosition = { 0, 0 }
|
||||
};
|
||||
|
||||
struct EnemyPosition enemyPosition[ENEMY_MAX_COUNT];
|
||||
|
||||
struct BulletPosition rabbitBulletPosition[RABBIT_BULLET_LIMIT];
|
||||
struct RabbitWeaponry rabbitWeaponry;
|
||||
|
||||
void setupRabbitBullets() {
|
||||
char i;
|
||||
int i;
|
||||
|
||||
for (i = 0; i < RABBIT_BULLET_LIMIT; ++i) {
|
||||
rabbitBulletPosition[i].isActive = 0;
|
||||
@ -38,6 +42,15 @@ void setupRabbitBullets() {
|
||||
rabbitWeaponry.cooldown = 0;
|
||||
}
|
||||
|
||||
void setupEnemies() {
|
||||
int i;
|
||||
|
||||
for (i = 0; i < ENEMY_MAX_COUNT; ++i) {
|
||||
enemyPosition[i].isActive = 0;
|
||||
enemyPosition[i].willBeInactive = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void attemptToFireRabbitBullet() {
|
||||
char okToFire = 0, availableBullet, i;
|
||||
signed char doubleVelocityX, doubleVelocityY;
|
||||
@ -99,6 +112,62 @@ void advanceRabbitBullets() {
|
||||
if (rabbitWeaponry.cooldown > 0) rabbitWeaponry.cooldown--;
|
||||
}
|
||||
|
||||
void detectPlayerBulletToEnemyCollisions() {
|
||||
int bulletIdx, enemyIdx;
|
||||
|
||||
for (bulletIdx = 0; bulletIdx < RABBIT_BULLET_LIMIT; ++bulletIdx) {
|
||||
if (!rabbitBulletPosition[bulletIdx].isActive) continue;
|
||||
|
||||
for (enemyIdx = 0; enemyIdx < ENEMY_MAX_COUNT; ++enemyIdx) {
|
||||
if (!enemyPosition[enemyIdx].isActive) continue;
|
||||
|
||||
// bullets hit enemies if:
|
||||
// * bulletY - bullet_height_start is within 3px of enemy base
|
||||
// *
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct SpawnPointRange {
|
||||
int left, width;
|
||||
int top, height;
|
||||
};
|
||||
|
||||
struct SpawnPointRange spawnPointRanges[1] = {
|
||||
{ .left = 50, .width = 30, .top = 50, .height = 30 }
|
||||
};
|
||||
|
||||
void maybeSpawnEnemy() {
|
||||
char canSpawn;
|
||||
int i, availableEnemy;
|
||||
int spawnX, spawnY;
|
||||
|
||||
for (i = 0; i < ENEMY_MAX_COUNT; ++i) {
|
||||
if (!enemyPosition[i].isActive) {
|
||||
availableEnemy = i;
|
||||
canSpawn = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!canSpawn) return;
|
||||
|
||||
spawnX = spawnPointRanges[0].left + rand() % spawnPointRanges[0].width;
|
||||
spawnY = spawnPointRanges[0].top + rand() % spawnPointRanges[0].height;
|
||||
|
||||
enemyPosition[availableEnemy].isActive = 1;
|
||||
enemyPosition[availableEnemy].enemyPosition[0] = spawnX;
|
||||
enemyPosition[availableEnemy].enemyPosition[1] = spawnY;
|
||||
}
|
||||
|
||||
void setupEnemySprites() {
|
||||
buildSpriteFromSpritesheet(
|
||||
&spritesheetImage,
|
||||
&enemy,
|
||||
0, 20, 16, 16
|
||||
);
|
||||
}
|
||||
|
||||
void setupRabbitSprites() {
|
||||
buildSpriteFromSpritesheet(
|
||||
&spritesheetImage,
|
||||
@ -145,20 +214,28 @@ void renderRabbit() {
|
||||
drawSprite(&rabbit);
|
||||
}
|
||||
|
||||
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];
|
||||
|
||||
drawSprite(&enemy);
|
||||
}
|
||||
}
|
||||
|
||||
void renderRabbitBullets() {
|
||||
char i;
|
||||
|
||||
char buffer[20];
|
||||
|
||||
for (i = 0; i < RABBIT_BULLET_LIMIT; ++i) {
|
||||
if (!rabbitBulletPosition[i].isActive) continue;
|
||||
|
||||
bullet.x = rabbitBulletPosition[i].x;
|
||||
bullet.y = rabbitBulletPosition[i].y;
|
||||
|
||||
sprintf(buffer, "%d %d", bullet.x, bullet.y);
|
||||
writeString(buffer, 0, 10);
|
||||
|
||||
drawSprite(&bullet);
|
||||
}
|
||||
}
|
||||
@ -185,6 +262,23 @@ void drawOnlyRabbitArena() {
|
||||
drawOnlyArena(&bounds);
|
||||
}
|
||||
|
||||
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];
|
||||
getSpriteBounds(&enemy, &bounds);
|
||||
drawOnlyArena(&bounds);
|
||||
|
||||
if (enemyPosition[i].willBeInactive) {
|
||||
enemyPosition[i].willBeInactive = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void drawOnlyRabbitBulletArena() {
|
||||
int i;
|
||||
for (i = 0; i < RABBIT_BULLET_LIMIT; ++i) {
|
||||
@ -201,9 +295,8 @@ void drawOnlyRabbitBulletArena() {
|
||||
}
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
int setupGame() {
|
||||
FILE *fh;
|
||||
int keepRunning = 1;
|
||||
|
||||
installKeyboardHandler();
|
||||
initializeDrawBuffer();
|
||||
@ -217,6 +310,7 @@ int main(void) {
|
||||
setupWallSprites(&spritesheetImage);
|
||||
setupRabbitSprites();
|
||||
setupRabbitBullets();
|
||||
setupEnemySprites();
|
||||
|
||||
setVideoMode(VIDEO_MODE_VGA_256);
|
||||
bmp256ColorPaletteToVGAColorPalette(&spritesheetImage, vgaColors);
|
||||
@ -227,6 +321,30 @@ int main(void) {
|
||||
buildArena();
|
||||
clearArenaRedrawRequests();
|
||||
|
||||
srand(time(NULL));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
double speedCalcs[200];
|
||||
int currentSpeedCalc = 0;
|
||||
double averageSpeedCalc;
|
||||
clock_t startTime;
|
||||
|
||||
extern int doAThing(int);
|
||||
#pragma aux (__cdecl) doAThing "doAThing_"
|
||||
|
||||
int main(void) {
|
||||
int keepRunning = 1;
|
||||
|
||||
fprintf(stderr, "%d\n", doAThing(1000));
|
||||
|
||||
return 0;
|
||||
|
||||
if (setupGame()) return 1;
|
||||
|
||||
maybeSpawnEnemy();
|
||||
|
||||
while (keepRunning) {
|
||||
readMouse(&mouseStatus);
|
||||
populateKeyboardKeydownState();
|
||||
@ -248,10 +366,14 @@ int main(void) {
|
||||
advanceRabbitBullets();
|
||||
|
||||
drawOnlyRabbitArena();
|
||||
drawOnlyEnemiesArena();
|
||||
drawOnlyMouseArena();
|
||||
drawOnlyRabbitBulletArena();
|
||||
|
||||
redrawArena();
|
||||
|
||||
renderRabbit();
|
||||
renderEnemies();
|
||||
renderMouse();
|
||||
renderRabbitBullets();
|
||||
|
||||
@ -269,7 +391,14 @@ int main(void) {
|
||||
setVideoMode(VIDEO_MODE_80x25_TEXT);
|
||||
uninstallKeyboardHandler();
|
||||
|
||||
fprintf(stderr, "meow\n");
|
||||
averageSpeedCalc = 0;
|
||||
for (currentSpeedCalc = 0; currentSpeedCalc < 200; ++currentSpeedCalc) {
|
||||
averageSpeedCalc += speedCalcs[currentSpeedCalc];
|
||||
}
|
||||
|
||||
averageSpeedCalc /= 200;
|
||||
|
||||
fprintf(stderr, "average: %f\n", averageSpeedCalc);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
2
makefile
2
makefile
@ -1,4 +1,4 @@
|
||||
obj = game.o bmpload.o arena.o movement.o
|
||||
obj = game.o bmpload.o arena.o movement.o test.o
|
||||
|
||||
all: system/system.lib game.exe .SYMBOLIC
|
||||
|
||||
|
10
movement.h
10
movement.h
@ -1,4 +1,5 @@
|
||||
#include "system/keyboard.h"
|
||||
|
||||
struct RabbitPosition {
|
||||
int rabbitPosition[2];
|
||||
int oldRabbitPosition[2];
|
||||
@ -30,6 +31,15 @@ struct BulletPosition {
|
||||
char velocityStep;
|
||||
};
|
||||
|
||||
struct EnemyPosition {
|
||||
char isActive;
|
||||
|
||||
char willBeInactive;
|
||||
|
||||
int enemyPosition[2];
|
||||
int oldEnemyPosition[2];
|
||||
};
|
||||
|
||||
void calculateTargetAngle(struct RabbitPosition*, struct MouseStatus*);
|
||||
void captureAndLimitMousePosition(struct RabbitPosition*, struct MouseStatus*);
|
||||
void handleRabbitMovement(struct RabbitPosition*, struct KeyboardKeydownState*);
|
||||
|
@ -57,6 +57,7 @@ void drawPixel(int x, int y, int color) {
|
||||
void drawSprite(struct SpriteRender* sprite) {
|
||||
int x, y;
|
||||
byte pixel;
|
||||
int modulo = VGA_DISPLAY_WIDTH - sprite->width;
|
||||
|
||||
byte* spriteData = sprite->data;
|
||||
byte* drawBufferPos =
|
||||
@ -77,7 +78,7 @@ void drawSprite(struct SpriteRender* sprite) {
|
||||
drawBufferPos++;
|
||||
}
|
||||
|
||||
drawBufferPos += (VGA_DISPLAY_WIDTH - sprite->width);
|
||||
drawBufferPos += modulo;
|
||||
spriteData += sprite->modulo;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user