Start to add drifting, cleanup of header files, separate control logic into another file (not yet used) etc.

This commit is contained in:
Heath Mitchell 2022-07-01 16:05:17 +01:00
parent fe4fb25476
commit 5a77df5042
81 changed files with 262 additions and 77 deletions

View File

@ -9,6 +9,7 @@
"3d.h": "c",
"display.h": "c",
"math.h": "c",
"generated_lut.h": "c"
"generated_lut.h": "c",
"stdbool.h": "c"
}
}

View File

@ -113,7 +113,7 @@ generated_lut.cpp: /home/heath/ti-mario-kart-py/compress.py lookup_gen_config.ya
# Still not really sure what I'm doing here
html/index.html: src/*.c data-headers/*.h
emcc -D FXCG_MOCK -D EMSCRIPTEN -Ifxcg-mock/include --g src/*.c ./fxcg-mock/include/fxcg/*.c -o html/index.html
emcc -D FXCG_MOCK -D EMSCRIPTEN -Ifxcg-mock/include -g -sSTACK_OVERFLOW_CHECK=1 src/*.c ./fxcg-mock/include/fxcg/*.c -o html/index.html
browser: html/index.html
emrun --browser=chromium --browser_args=--auto-open-devtools-for-tabs html/index.html

BIN
assets/img/bush.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 KiB

BIN
assets/img/castle.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 18 KiB

After

Width:  |  Height:  |  Size: 18 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 18 KiB

After

Width:  |  Height:  |  Size: 18 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 22 KiB

After

Width:  |  Height:  |  Size: 22 KiB

BIN
assets/img/kart/11.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

BIN
assets/img/kart/12.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

BIN
assets/img/kart/13.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

BIN
assets/img/kart/14.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 19 KiB

BIN
assets/img/kart/15.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 19 KiB

BIN
assets/img/kart/16.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 20 KiB

BIN
assets/img/kart/17.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 20 KiB

BIN
assets/img/kart/18.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 20 KiB

BIN
assets/img/kart/19.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 21 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 18 KiB

After

Width:  |  Height:  |  Size: 18 KiB

BIN
assets/img/kart/20.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 21 KiB

BIN
assets/img/kart/21.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 22 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 18 KiB

After

Width:  |  Height:  |  Size: 19 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 19 KiB

After

Width:  |  Height:  |  Size: 19 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 20 KiB

After

Width:  |  Height:  |  Size: 19 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 20 KiB

After

Width:  |  Height:  |  Size: 20 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 21 KiB

After

Width:  |  Height:  |  Size: 20 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 21 KiB

After

Width:  |  Height:  |  Size: 21 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 21 KiB

After

Width:  |  Height:  |  Size: 21 KiB

BIN
assets/img/kart/old/0.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

BIN
assets/img/kart/old/1.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

BIN
assets/img/kart/old/10.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 22 KiB

BIN
assets/img/kart/old/2.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

BIN
assets/img/kart/old/3.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

BIN
assets/img/kart/old/4.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 19 KiB

BIN
assets/img/kart/old/5.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 20 KiB

BIN
assets/img/kart/old/6.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 20 KiB

BIN
assets/img/kart/old/7.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 21 KiB

BIN
assets/img/kart/old/8.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 21 KiB

BIN
assets/img/kart/old/9.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 21 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 22 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 19 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 19 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 20 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 20 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 20 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 21 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 21 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 22 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 19 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 19 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 19 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 20 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 20 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 21 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 21 KiB

BIN
assets/img/loop.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

BIN
assets/img/shadow.ora Normal file

Binary file not shown.

BIN
assets/img/shadow1.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 224 B

BIN
assets/img/shadow2.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 223 B

View File

@ -1,4 +1,5 @@
main.o: /home/heath/PrizmSDK-win-0.5.2/projects/mario-kart/src/main.c \
/home/heath/PrizmSDK-win-0.5.2/projects/mario-kart/src/./main.h \
/home/heath/PrizmSDK-win-0.5.2/include/fxcg/display.h \
/home/heath/PrizmSDK-win-0.5.2/include/fxcg/keyboard.h \
/home/heath/PrizmSDK-win-0.5.2/include/fxcg/misc.h \
@ -9,6 +10,7 @@ main.o: /home/heath/PrizmSDK-win-0.5.2/projects/mario-kart/src/main.c \
/home/heath/PrizmSDK-win-0.5.2/projects/mario-kart/src/./sprites.h \
/home/heath/PrizmSDK-win-0.5.2/projects/mario-kart/src/./physics.h \
/home/heath/PrizmSDK-win-0.5.2/projects/mario-kart/src/../data-headers/images.h
/home/heath/PrizmSDK-win-0.5.2/projects/mario-kart/src/./main.h:
/home/heath/PrizmSDK-win-0.5.2/include/fxcg/display.h:
/home/heath/PrizmSDK-win-0.5.2/include/fxcg/keyboard.h:
/home/heath/PrizmSDK-win-0.5.2/include/fxcg/misc.h:

Binary file not shown.

File diff suppressed because one or more lines are too long

View File

@ -18,6 +18,9 @@ int setKeyState(unsigned char key, unsigned char state) {
case 88: // x
keysPressed[78] = state;
break;
case 90: // z
keysPressed[77] = state;
break;
case 68: // d
keysPressed[31] = state;
break;

View File

@ -1,3 +1,5 @@
#include "./3d.h"
#include "./main.h"
#include "./tilemap.h"
#include "./maths.h"

View File

@ -1,2 +1,7 @@
#ifndef _3D_H_
#define _3D_H_
unsigned char getTileType(short xPos, short yPos);
unsigned short getScreenPixel(unsigned short x, unsigned short y);
#endif // _3D_H_

30
src/buttons.c Normal file
View File

@ -0,0 +1,30 @@
#include "./buttons.h"
#include <fxcg/keyboard.h>
buttonState buttons = {0};
buttonState lastButtons = {0};
// https://www.cemetech.net/forum/viewtopic.php?p=173836&sid=9eabb0dbeddeeb6507c19c8a65dbe249
#ifndef FXCG_MOCK
int keydown(int basic_keycode) {
const unsigned short* keyboard_register = (unsigned short*)0xA44B0000;
int row, col, word, bit;
row = basic_keycode % 10;
col = basic_keycode / 10 - 1;
word = row >> 1;
bit = col + 8 * (row & 1);
return (0 != (keyboard_register[word] & 1 << bit));
}
#endif
void scanButtons() {
lastButtons = buttons;
buttons.up = keydown(KEY_PRGM_UP);
buttons.down = keydown(KEY_PRGM_DOWN);
buttons.left = keydown(KEY_PRGM_LEFT);
buttons.right = keydown(KEY_PRGM_RIGHT);
buttons.accel = keydown(KEY_PRGM_SHIFT);
buttons.hop = keydown(KEY_PRGM_ALPHA);
buttons.debug = keydown(KEY_PRGM_RETURN);
}

22
src/buttons.h Normal file
View File

@ -0,0 +1,22 @@
#ifndef _BUTTONS_H
#define _BUTTONS_H
#include <stdbool.h>
typedef struct {
// D-pad
bool left;
bool right;
bool up;
bool down;
// Buttons
bool accel;
bool hop;
bool debug;
} buttonState;
extern buttonState buttons;
extern buttonState lastButtons;
#endif // _BUTTONS_H

View File

@ -1,13 +1,19 @@
#include "./main.h"
#include <fxcg/display.h>
#include <fxcg/keyboard.h>
#ifndef FXCG_MOCK
#include <fxcg/misc.h>
#include <fxcg/rtc.h>
#include <fxcg/system.h>
#define debug_printf(...)
#else
#include <fxcg/mock.h>
#ifdef EMSCRIPTEN
#include <emscripten.h>
#include <stdio.h>
#define debug_printf(...) printf(__VA_ARGS__)
#endif
#endif
@ -17,10 +23,6 @@
#include "../data-headers/images.h"
#define bool unsigned char
#define true 1
#define false 0
#define MIN(X, Y) (((X) < (Y)) ? (X) : (Y))
#define MAX(X, Y) (((X) < (Y)) ? (Y) : (X))
@ -60,13 +62,23 @@ float sin(int angle) {
if (mod(angle, 360) > 180) {
sign *= -1;
}
return sign * table[(int)(newAngle / 0.18) - 1];
return sign * table[(int)(newAngle / 0.18) /*- 1*/];
}
float cos(int angle) {
return sin(angle + 90);
}
double abs_double(double x) {
if (x < 0) return -x;
return x;
}
int abs_int(int x) {
if (x < 0) return -x;
return x;
}
short index2;
unsigned short element;
@ -85,19 +97,6 @@ int PRGM_GetKey(void) {
#define PI 3.14159265358979323846
// https://www.cemetech.net/forum/viewtopic.php?p=173836&sid=9eabb0dbeddeeb6507c19c8a65dbe249
#ifndef FXCG_MOCK
int keydown(int basic_keycode) {
const unsigned short* keyboard_register = (unsigned short*)0xA44B0000;
int row, col, word, bit;
row = basic_keycode % 10;
col = basic_keycode / 10 - 1;
word = row >> 1;
bit = col + 8 * (row & 1);
return (0 != (keyboard_register[word] & 1 << bit));
}
#endif
void cameraBehind(short x, short y, short objectAngle, short distance) {
// objectAngle = 90 - objectAngle;
yOffset = y - sin(-objectAngle) * distance;
@ -111,6 +110,7 @@ void fillSky(unsigned short yMin, unsigned short yMax) {
}
} */
draw(img_bg, 0, 0);
// draw_loop_x(img_loop, 0, 0, 0, LCD_WIDTH_PX);
Bdisp_PutDisp_DD();
}
@ -165,18 +165,27 @@ bool exeWasPressed = false;
// For framerate counter
int lastTime;
int frameCount = 0;
int fpsCount = 0;
int totalFrameCount = 0;
int bounce = 0;
int jitter = 0;
int hopStage = 0;
const int hopAnim[15] = {
1, 1, 2, 3, 4,
4, 5, 5, 5, 4,
4, 3, 2, 1, 1,
};
bool drifting = false;
bool alphaWasPressed = false;
Car kart;
void main_loop() {
// Main game loop
#ifndef FXCG_MOCK
int currentTime = RTC_GetTicks();
totalFrameCount += 1;
// If 1 second has passed, print framerate
if (currentTime - lastTime >= 128) {
lastTime = currentTime;
@ -186,7 +195,7 @@ void main_loop() {
int y = 0;
char buffer[17] = "FPS: ";
itoa(frameCount, (unsigned char*)buffer + 5);
itoa(fpsCount, (unsigned char*)buffer + 5);
PrintMiniMini(&x, &y, buffer, 0, COLOR_BLACK, 0);
Bdisp_PutDisp_DD_stripe(24, 34);
@ -200,7 +209,7 @@ void main_loop() {
PrintMiniMini(&x, &y, buffer, 0, COLOR_BLACK, 0);
Bdisp_PutDisp_DD_stripe(24, 34);
}
frameCount = 0;
fpsCount = 0;
}
#endif
@ -241,6 +250,7 @@ void main_loop() {
bool leftPressed = keydown(KEY_PRGM_LEFT);
bool rightPressed = keydown(KEY_PRGM_RIGHT);
bool shiftPressed = keydown(KEY_PRGM_SHIFT);
bool alphaPressed = keydown(KEY_PRGM_ALPHA);
ControlState controls = {
up: shiftPressed,
@ -249,6 +259,8 @@ void main_loop() {
right: leftPressed,
};
turnSpeed = drifting ? 0.003: 0.002;
updateWithControls(&kart, controls);
kartX = kart.x * 12;
@ -263,7 +275,12 @@ void main_loop() {
kartVel += kartSpeed;
} */
#define maxSteerAnim 20
if (!alphaPressed) {
drifting = false;
}
// #define maxSteerAnim 10
int maxSteerAnim = drifting ? 20 : 10;
if (leftPressed && !rightPressed/* && kartVel > 3 */) {
kartAngle -= kartVel / 10;
@ -345,33 +362,66 @@ void main_loop() {
}
}
// Pattern: 0 1 2 1 0 1 2 1 0 etc.
int newBounce;
bounce++;
bounce = bounce % 4;
if (bounce == 3) {
newBounce = 0;
jitter++;
if (abs_double(kart.xVelocity) + abs_double(kart.yVelocity) < 0.02) {
jitter = 0;
} else if (abs_double(kart.xVelocity) + abs_double(kart.yVelocity) < 0.30) {
jitter = (totalFrameCount / 4) % 2;
} else if (abs_double(kart.xVelocity) + abs_double(kart.yVelocity) < 0.50) {
jitter = (totalFrameCount / 3) % 2;
} else if (abs_double(kart.xVelocity) + abs_double(kart.yVelocity) < 1) {
jitter = (totalFrameCount / 2) % 2;
} else {
newBounce = bounce;
jitter = totalFrameCount % 2;
}
// debug_printf("totalFrameCount: %d\n", totalFrameCount);
if (alphaPressed && hopStage == 0 && !alphaWasPressed) {
hopStage = 1;
if (leftPressed || rightPressed) {
drifting = true;
}
}
if (hopStage != 0) {
hopStage++;
if (hopStage >= 15) {
hopStage = 0;
}
}
int animNo = abs_int(kartSteerAnim) / 2 + (jitter * 11);
// draw_alpha(img_shadow, (LCD_WIDTH_PX / 2) - (96 / 2), 116, 2);
// if (totalFrameCount % 2 == 0) {
// draw(img_shadow1, (LCD_WIDTH_PX / 2) - (96 / 2), 112);
// } else {
// draw(img_shadow2, (LCD_WIDTH_PX / 2) - (96 / 2), 112);
// }
if (hopStage != 0) {
draw(img_shadow1, (LCD_WIDTH_PX / 2) - (96 / 2), 112);
}
if (kartSteerAnim >= 0) {
// CopySpriteMasked(/*mksprites[kartSteerAnim / 2]*/sprite, (LCD_WIDTH_PX / 2) - 39, 128, 78, 81, 0x07e0);
// CopySpriteMasked(mksprites[kartSteerAnim / 4], (LCD_WIDTH_PX / 2) - 36, 128, 72, 80, 0x4fe0);
draw(imgs_kart[kartSteerAnim / 2], (LCD_WIDTH_PX / 2) - (96 / 2), 120 /* + bounce*/);
draw(imgs_kart[animNo], (LCD_WIDTH_PX / 2) - (96 / 2), 112 + jitter - (hopAnim[hopStage] * 3));
} else {
// CopySpriteMaskedFlipped(/*mksprites[-kartSteerAnim / 2]*/sprite, (LCD_WIDTH_PX / 2) - 39, 128, 78, 81, 0x07e0);
// CopySpriteMaskedFlipped(mksprites[-kartSteerAnim / 4], (LCD_WIDTH_PX / 2) - 36, 128, 72, 80, 0x4fe0);
draw_flipped(imgs_kart[-kartSteerAnim / 2], (LCD_WIDTH_PX / 2) - (96 / 2), 120);
draw_flipped(imgs_kart[animNo], (LCD_WIDTH_PX / 2) - (96 / 2), 112 + jitter - (hopAnim[hopStage] * 3));
}
Bdisp_PutDisp_DD_stripe(horizon + 2, LCD_HEIGHT_PX);
// draw_loop_x(img_loop, 0, 0, angle, LCD_WIDTH_PX);
// draw_loop_x(img_castle, 0, 0, angle * 1.5, LCD_WIDTH_PX);
// draw_loop_x(img_bush, 0, 0, angle * 2, LCD_WIDTH_PX);
// Bdisp_PutDisp_DD();
frameCount++;
alphaWasPressed = alphaPressed;
totalFrameCount += 1;
fpsCount++;
}
int main() {

View File

@ -1,3 +1,8 @@
#ifndef _MAIN_H
#define _MAIN_H
#include <stdbool.h>
extern short angle;
extern short xOffset;
extern short yOffset;
@ -12,3 +17,5 @@ extern unsigned short* VRAM;
int mod(int a, int b);
float sin(int angle);
float cos(int angle);
#endif // _MAIN_H

View File

@ -1,3 +1,5 @@
#include "./maths.h"
#define angleWidth 192
// const short lut[91] = {

View File

@ -1,2 +1,9 @@
#ifndef _MATHS_H
#define _MATHS_H
#include <stdbool.h>
short fpsin(short x);
short fpcos(short x);
#endif // _MATHS_H

View File

@ -1,11 +1,9 @@
#include "./physics.h"
#include "./maths.h"
#define angleWidth 192
#define false 0
#define true 1
typedef unsigned char bool;
// #define maxPower 0.075
#define maxPower 0.125
#define maxReverse 0.0375
@ -15,7 +13,8 @@ typedef unsigned char bool;
// #define drag 0.9
double drag = 0.9;
#define angularDrag 0.9
#define turnSpeed 0.002
// #define turnSpeed 0.002
double turnSpeed = 0.002;
#define WIDTH 500
#define HEIGHT 500
@ -36,38 +35,6 @@ double fmax(double a, double b) {
return a > b ? a : b;
}
typedef struct {
bool up;
bool left;
bool right;
bool down;
} ControlState;
typedef struct {
double x;
double y;
double xVelocity;
double yVelocity;
double power;
double reverse;
double angle;
double angularVelocity;
bool isThrottling;
bool isReversing;
bool isShooting;
bool isTurningLeft;
bool isTurningRight;
} Car;
ControlState getControls() {
ControlState controls;
controls.up = true;
controls.left = false;
controls.right = true;
controls.down = false;
return controls;
}
void updateCar (Car *car) {
if (car->isThrottling) {
car->power += powerFactor * car->isThrottling;

View File

@ -1,4 +1,7 @@
typedef unsigned char bool;
#ifndef _PHYSICS_H
#define _PHYSICS_H
#include <stdbool.h>
typedef struct {
bool up;
@ -24,5 +27,8 @@ typedef struct {
} Car;
extern double drag;
extern double turnSpeed;
void updateWithControls(Car *car, ControlState controls);
#endif // _PHYSICS_H

View File

@ -1,3 +1,5 @@
#include "./sprites.h"
#include <fxcg/display.h>
#include "./main.h"
@ -20,6 +22,23 @@ void CopySpriteMasked(const void* datar, int x, int y, int width, int height, in
}
}
void CopySpriteMaskedAlpha(const void*datar, int x, int y, int width, int height, color_t maskcolor, int alpha) {
color_t*data = (color_t*) datar;
color_t* VRAM = (color_t*)GetVRAMAddress();
VRAM += LCD_WIDTH_PX*y + x;
alpha %= 32;
for(int j=y; j<y+height; j++) {
for(int i=x; i<x+width; i++) {
if (*(data) != maskcolor) {
*(VRAM) = (color_t)((((int)(*data & 0xf81f) * alpha + (int)(*VRAM & 0xf81f) * (32-alpha) + 0x8010) >> 5) & 0xf81f) |
(color_t)((((int)(*data & 0x07e0) * alpha + (int)(*VRAM & 0x07e0) * (32-alpha) + 0x0400) >> 6) & 0x07e0);
VRAM++; data++;
} else { VRAM++; data++; }
}
VRAM += LCD_WIDTH_PX-width;
}
}
// Version of the function above that draws the sprite flipped horizontally
void CopySpriteMaskedFlipped(const void* datar, int x, int y, int width, int height, int maskcolor) {
color_t* data = (color_t*)datar;
@ -41,6 +60,25 @@ void CopySpriteMaskedFlipped(const void* datar, int x, int y, int width, int hei
}
}
// Copy a sprite that loops around with an X offset
void CopySpriteLoopX(const void* datar, int x, int y, int width, int height, int xOffset, int drawWidth, int maskcolor) {
color_t* data = (color_t*)datar;
// color_t* VRAM2 = (color_t*)VRAM;
// Loop over all the y positions
for (int j = 0; j < height; j++) {
// Loop over all the x positions
for (int i = 0; i < drawWidth; i++) {
// Get the pixel at the current position
color_t pixel = data[(j * width) + ((i + xOffset) % width)];
// Draw the pixel
if (pixel != maskcolor) {
VRAM[(j + y) * LCD_WIDTH_PX + (i + x)] = pixel;
}
}
}
}
void draw(const unsigned short* data, int x, int y) {
// The height and width of the sprite are the first two elements in the data array
int width = data[0];
@ -51,6 +89,16 @@ void draw(const unsigned short* data, int x, int y) {
CopySpriteMasked(data2, x, y, width, height, 0x4fe0);
}
void draw_alpha(const unsigned short* data, int x, int y, int alpha) {
// The height and width of the sprite are the first two elements in the data array
int width = data[0];
int height = data[1];
// The data array starts at index 2
const unsigned short* data2 = data + 2;
// Now draw the sprite
CopySpriteMaskedAlpha(data2, x, y, width, height, 0x4fe0, alpha);
}
void draw_flipped(const unsigned short* data, int x, int y) {
// The height and width of the sprite are the first two elements in the data array
int width = data[0];
@ -60,3 +108,13 @@ void draw_flipped(const unsigned short* data, int x, int y) {
// Now draw the sprite
CopySpriteMaskedFlipped(data2, x, y, width, height, 0x4fe0);
}
void draw_loop_x(const unsigned short* data, int x, int y, int xOffset, int drawWidth) {
// The height and width of the sprite are the first two elements in the data array
int width = data[0];
int height = data[1];
// The data array starts at index 2
const unsigned short* data2 = data + 2;
// Now draw the sprite
CopySpriteLoopX(data2, x, y, width, height, xOffset, drawWidth, 0x4fe0);
}

View File

@ -1,4 +1,13 @@
#ifndef _SPRITES_H
#define _SPRITES_H
#include <stdbool.h>
void CopySpriteMasked(const void* datar, int x, int y, int width, int height, int maskcolor);
void CopySpriteMaskedFlipped(const void* datar, int x, int y, int width, int height, int maskcolor);
void draw(const unsigned short* data, int x, int y);
void draw_alpha(const unsigned short* data, int x, int y, int alpha);
void draw_flipped(const unsigned short* data, int x, int y);
void draw_loop_x(const unsigned short* data, int x, int y, int xOffset, int drawWidth);
#endif // _SPRITES_H

View File

@ -1,3 +1,5 @@
#include "./tilemap.h"
#include "./main.h"
#include "../data-headers/track.h"

View File

@ -1,2 +1,9 @@
#ifndef _TILEMAP_H
#define _TILEMAP_H
#include <stdbool.h>
unsigned char getTileType(short xPos, short yPos);
unsigned short samplePixel(short xPos, short yPos);
#endif // _TILEMAP_H