start on rabbit positioning
This commit is contained in:
parent
ba0a52db3a
commit
129b1f7566
87
arena.c
Normal file
87
arena.c
Normal file
@ -0,0 +1,87 @@
|
||||
#include "bmpload.h"
|
||||
#include "const.h"
|
||||
#include "arena.h"
|
||||
|
||||
char arenaLayout[10][10] = {
|
||||
{ 1, 1, 1, 1, 0, 0, 1, 1, 1, 1 },
|
||||
{ 1, 2, 2, 2, 0, 0, 2, 2, 2, 1 },
|
||||
{ 1, 0, 0, 0, 0, 0, 0, 0, 0, 1 },
|
||||
{ 1, 0, 0, 0, 0, 0, 0, 0, 0, 1 },
|
||||
{ 2, 0, 0, 0, 0, 0, 0, 0, 0, 2 },
|
||||
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
|
||||
{ 1, 0, 0, 0, 0, 0, 0, 0, 0, 1 },
|
||||
{ 1, 0, 0, 0, 0, 0, 0, 0, 0, 1 },
|
||||
{ 1, 0, 0, 0, 0, 0, 0, 0, 0, 1 },
|
||||
{ 1, 1, 1, 1, 0, 0, 1, 1, 1, 1 }
|
||||
};
|
||||
|
||||
struct SpriteRender arenaWallTop, arenaWallSide, arenaFloor;
|
||||
|
||||
void setupWallSprites(struct BMPImage *spritesheetImage) {
|
||||
buildSpriteFromSpritesheet(
|
||||
spritesheetImage,
|
||||
&arenaWallTop,
|
||||
0, 0, 20, 20
|
||||
);
|
||||
|
||||
buildSpriteFromSpritesheet(
|
||||
spritesheetImage,
|
||||
&arenaWallSide,
|
||||
20, 0, 20, 20
|
||||
);
|
||||
|
||||
buildSpriteFromSpritesheet(
|
||||
spritesheetImage,
|
||||
&arenaFloor,
|
||||
40, 0, 20, 20
|
||||
);
|
||||
}
|
||||
|
||||
void renderArenaTile(int x, int y) {
|
||||
char tile;
|
||||
struct SpriteRender *target;
|
||||
|
||||
tile = arenaLayout[y][x];
|
||||
|
||||
switch (tile) {
|
||||
case 0:
|
||||
target = &arenaFloor;
|
||||
break;
|
||||
case 1:
|
||||
target = &arenaWallTop;
|
||||
break;
|
||||
case 2:
|
||||
target = &arenaWallSide;
|
||||
break;
|
||||
}
|
||||
|
||||
target->x = x * 20;
|
||||
target->y = y * 20;
|
||||
|
||||
drawSprite(target);
|
||||
}
|
||||
|
||||
void drawOnlyArena(struct SpriteBounds *bounds) {
|
||||
int leftTileX, rightTileX,
|
||||
topTileY, bottomTileY;
|
||||
|
||||
leftTileX = bounds->left / TILE_SIZE;
|
||||
rightTileX = bounds->right / TILE_SIZE;
|
||||
topTileY = bounds->top / TILE_SIZE;
|
||||
bottomTileY = bounds->bottom / TILE_SIZE;
|
||||
|
||||
renderArenaTile(leftTileX, topTileY);
|
||||
renderArenaTile(rightTileX, topTileY);
|
||||
renderArenaTile(rightTileX, bottomTileY);
|
||||
renderArenaTile(leftTileX, bottomTileY);
|
||||
}
|
||||
|
||||
void buildArena() {
|
||||
int x, y;
|
||||
|
||||
for (y = 0; y < 10; ++y) {
|
||||
for (x = 0; x < 10; ++x) {
|
||||
renderArenaTile(x, y);
|
||||
}
|
||||
}
|
||||
}
|
6
arena.h
Normal file
6
arena.h
Normal file
@ -0,0 +1,6 @@
|
||||
#include "bmpload.h"
|
||||
#include "system/vga.h"
|
||||
|
||||
void drawOnlyArena(struct SpriteBounds *bounds);
|
||||
void buildArena();
|
||||
void setupWallSprites(struct BMPImage *);
|
5
const.h
5
const.h
@ -0,0 +1,5 @@
|
||||
#define TILE_SIZE (20)
|
||||
#define RAD2DEG (180/3.14159)
|
||||
#define DEG2RAD (3.14159/180)
|
||||
#define MOUSE_DISTANCE (32)
|
||||
|
126
game.c
126
game.c
@ -7,33 +7,14 @@
|
||||
#include "system/mouse_io.h"
|
||||
#include "system/pc_stuff.h"
|
||||
#include "bmpload.h"
|
||||
#include "const.h"
|
||||
#include "arena.h"
|
||||
|
||||
struct BMPImage spritesheetImage;
|
||||
struct VGAColor vgaColors[256];
|
||||
|
||||
struct SpriteRender arenaWallTop, arenaWallSide, arenaFloor;
|
||||
struct SpriteRender rabbit, mouse;
|
||||
|
||||
void setupWallSprites() {
|
||||
buildSpriteFromSpritesheet(
|
||||
&spritesheetImage,
|
||||
&arenaWallTop,
|
||||
0, 0, 20, 20
|
||||
);
|
||||
|
||||
buildSpriteFromSpritesheet(
|
||||
&spritesheetImage,
|
||||
&arenaWallSide,
|
||||
20, 0, 20, 20
|
||||
);
|
||||
|
||||
buildSpriteFromSpritesheet(
|
||||
&spritesheetImage,
|
||||
&arenaFloor,
|
||||
40, 0, 20, 20
|
||||
);
|
||||
}
|
||||
|
||||
void setupRabbitSprites() {
|
||||
buildSpriteFromSpritesheet(
|
||||
&spritesheetImage,
|
||||
@ -54,52 +35,6 @@ void setupRabbitSprites() {
|
||||
mouse.offsetY = 4;
|
||||
}
|
||||
|
||||
char arenaLayout[10][10] = {
|
||||
{ 1, 1, 1, 1, 0, 0, 1, 1, 1, 1 },
|
||||
{ 1, 2, 2, 2, 0, 0, 2, 2, 2, 1 },
|
||||
{ 1, 0, 0, 0, 0, 0, 0, 0, 0, 1 },
|
||||
{ 1, 0, 0, 0, 0, 0, 0, 0, 0, 1 },
|
||||
{ 2, 0, 0, 0, 0, 0, 0, 0, 0, 2 },
|
||||
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
|
||||
{ 1, 0, 0, 0, 0, 0, 0, 0, 0, 1 },
|
||||
{ 1, 0, 0, 0, 0, 0, 0, 0, 0, 1 },
|
||||
{ 1, 0, 0, 0, 0, 0, 0, 0, 0, 1 },
|
||||
{ 1, 1, 1, 1, 0, 0, 1, 1, 1, 1 }
|
||||
};
|
||||
|
||||
void renderArenaTile(int x, int y) {
|
||||
char tile;
|
||||
struct SpriteRender *target;
|
||||
|
||||
tile = arenaLayout[y][x];
|
||||
|
||||
switch (tile) {
|
||||
case 0:
|
||||
target = &arenaFloor;
|
||||
break;
|
||||
case 1:
|
||||
target = &arenaWallTop;
|
||||
break;
|
||||
case 2:
|
||||
target = &arenaWallSide;
|
||||
break;
|
||||
}
|
||||
|
||||
target->x = x * 20;
|
||||
target->y = y * 20;
|
||||
|
||||
drawSprite(target);
|
||||
}
|
||||
|
||||
void buildArena() {
|
||||
int x, y;
|
||||
|
||||
for (y = 0; y < 10; ++y) {
|
||||
for (x = 0; x < 10; ++x) {
|
||||
renderArenaTile(x, y);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#define RABBIT_MOTION_DRAG (2)
|
||||
#define RABBIT_MOTION_ACCELERATION (5)
|
||||
@ -186,75 +121,26 @@ void handleRabbitMovement() {
|
||||
}
|
||||
}
|
||||
|
||||
#define TILE_SIZE (20)
|
||||
|
||||
struct SpriteBounds bounds;
|
||||
|
||||
char tileRenderQueue[400];
|
||||
|
||||
void drawOnlyArena() {
|
||||
int leftTileX, rightTileX,
|
||||
topTileY, bottomTileY;
|
||||
|
||||
leftTileX = bounds.left / TILE_SIZE;
|
||||
rightTileX = bounds.right / TILE_SIZE;
|
||||
topTileY = bounds.top / TILE_SIZE;
|
||||
bottomTileY = bounds.bottom / TILE_SIZE;
|
||||
|
||||
renderArenaTile(leftTileX, topTileY);
|
||||
renderArenaTile(rightTileX, topTileY);
|
||||
renderArenaTile(rightTileX, bottomTileY);
|
||||
renderArenaTile(leftTileX, bottomTileY);
|
||||
}
|
||||
|
||||
void drawOnlyMouseArena() {
|
||||
mouse.x = oldMousePosition[0];
|
||||
mouse.y = oldMousePosition[1];
|
||||
getSpriteBounds(&mouse, &bounds);
|
||||
drawOnlyArena();
|
||||
drawOnlyArena(&bounds);
|
||||
|
||||
bounds.top = oldMouseDotPosition[1];
|
||||
bounds.bottom = oldMouseDotPosition[1];
|
||||
bounds.left = oldMouseDotPosition[0];
|
||||
bounds.right = oldMouseDotPosition[0];
|
||||
drawOnlyArena();
|
||||
drawOnlyArena(&bounds);
|
||||
}
|
||||
|
||||
void drawOnlyRabbitArena() {
|
||||
rabbit.x = oldRabbitPosition[0];
|
||||
rabbit.y = oldRabbitPosition[1];
|
||||
getSpriteBounds(&rabbit, &bounds);
|
||||
drawOnlyArena();
|
||||
}
|
||||
|
||||
#define RAD2DEG (180/3.14159)
|
||||
#define DEG2RAD (3.14159/180)
|
||||
#define MOUSE_DISTANCE (32)
|
||||
|
||||
void calculateTargetAngle() {
|
||||
float distanceX, distanceY;
|
||||
float angle;
|
||||
|
||||
oldMouseDotPosition[0] = mouseDotPosition[0];
|
||||
oldMouseDotPosition[1] = mouseDotPosition[1];
|
||||
|
||||
mouseDotPosition[0] = mouseStatus.xPosition;
|
||||
mouseDotPosition[1] = mouseStatus.yPosition;
|
||||
|
||||
distanceX = mouseStatus.xPosition - rabbitPosition[0];
|
||||
distanceY = mouseStatus.yPosition - rabbitPosition[1];
|
||||
|
||||
angle = atan2(distanceY, distanceX) * 180 / 3.14159 + 90;
|
||||
if (angle < 0) angle += 360;
|
||||
|
||||
distanceX = sin(angle * DEG2RAD) * MOUSE_DISTANCE;
|
||||
distanceY = -cos(angle * DEG2RAD) * MOUSE_DISTANCE;
|
||||
|
||||
oldMousePosition[0] = mousePosition[0];
|
||||
oldMousePosition[1] = mousePosition[1];
|
||||
|
||||
mousePosition[0] = rabbitPosition[0] + distanceX;
|
||||
mousePosition[1] = rabbitPosition[1] + distanceY;
|
||||
drawOnlyArena(&bounds);
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
@ -270,7 +156,7 @@ int main(void) {
|
||||
|
||||
spritesheetImage.transparentColor = 0;
|
||||
|
||||
setupWallSprites();
|
||||
setupWallSprites(&spritesheetImage);
|
||||
setupRabbitSprites();
|
||||
|
||||
setVideoMode(VIDEO_MODE_VGA_256);
|
||||
|
2
makefile
2
makefile
@ -1,4 +1,4 @@
|
||||
obj = game.o bmpload.o
|
||||
obj = game.o bmpload.o arena.o
|
||||
|
||||
all: system/system.lib game.exe .SYMBOLIC
|
||||
|
||||
|
28
movement.c
Normal file
28
movement.c
Normal file
@ -0,0 +1,28 @@
|
||||
#include "const.h"
|
||||
#include <math.h>
|
||||
|
||||
void calculateTargetAngle() {
|
||||
float distanceX, distanceY;
|
||||
float angle;
|
||||
|
||||
oldMouseDotPosition[0] = mouseDotPosition[0];
|
||||
oldMouseDotPosition[1] = mouseDotPosition[1];
|
||||
|
||||
mouseDotPosition[0] = mouseStatus.xPosition;
|
||||
mouseDotPosition[1] = mouseStatus.yPosition;
|
||||
|
||||
distanceX = mouseStatus.xPosition - rabbitPosition[0];
|
||||
distanceY = mouseStatus.yPosition - rabbitPosition[1];
|
||||
|
||||
angle = atan2(distanceY, distanceX) * 180 / 3.14159 + 90;
|
||||
if (angle < 0) angle += 360;
|
||||
|
||||
distanceX = sin(angle * DEG2RAD) * MOUSE_DISTANCE;
|
||||
distanceY = -cos(angle * DEG2RAD) * MOUSE_DISTANCE;
|
||||
|
||||
oldMousePosition[0] = mousePosition[0];
|
||||
oldMousePosition[1] = mousePosition[1];
|
||||
|
||||
mousePosition[0] = rabbitPosition[0] + distanceX;
|
||||
mousePosition[1] = rabbitPosition[1] + distanceY;
|
||||
}
|
3
movement.h
Normal file
3
movement.h
Normal file
@ -0,0 +1,3 @@
|
||||
struct RabbitPositioning {
|
||||
|
||||
};
|
Loading…
Reference in New Issue
Block a user