gravity working!

This commit is contained in:
pradyun 2023-03-07 17:12:49 +13:00
parent aee130dca0
commit 53a951ae76
2 changed files with 20 additions and 48 deletions

Binary file not shown.

View File

@ -18,46 +18,16 @@
// Simple sprite struct // Simple sprite struct
typedef struct { typedef struct {
C2D_Sprite spr; C2D_Sprite spr;
float x, y; // pos float x, y, w; // pos, rot
} Sprite; } Sprite;
// init spritesheet // init spritesheet
static C2D_SpriteSheet spriteSheet; static C2D_SpriteSheet spriteSheet;
static Sprite sprites[MAX_SPRITES]; static Sprite sprites[MAX_SPRITES];
//---------------------------------------------------------------------------------
static void initSprites() { static void initSprites() {
//---------------------------------------------------------------------------------
size_t numImages = C2D_SpriteSheetCount(spriteSheet); size_t numImages = C2D_SpriteSheetCount(spriteSheet);
// srand(time(NULL));
// for (size_t i = 0; i < MAX_SPRITES; i++)
// {
// Sprite* thisSprite = &sprites[i];
// // Random image, position, rotation and speed
// // C2D_SpriteFromSheet(*Sprite, C2D_SpriteSheet, int);
// C2D_SpriteFromSheet(&thisSprite->spr, spriteSheet, i);
// C2D_SpriteSetCenter(&thisSprite->spr, 0.5f, 0.5f);
// C2D_SpriteSetPos(&thisSprite->spr, rand() % SCREEN_WIDTH, rand() % SCREEN_HEIGHT);
// // C2D_SpriteSetRotation(&sprite->spr, C3D_Angle(rand()/(float)RAND_MAX));
// thisSprite->dx = rand()*4.0f/RAND_MAX - 2.0f;
// thisSprite->dy = rand()*4.0f/RAND_MAX - 2.0f;
// }
// for (size_t i = 0; i < MAX_SPRITES; i++) {
// Sprite* thisSprite = &sprites[i];
// float x = rand() % SCREEN_WIDTH;
// float y = rand() % SCREEN_HEIGHT;
// C2D_SpriteFromSheet(&thisSprite->spr, spriteSheet, i);
// C2D_SpriteSetCenter(&thisSprite->spr, 0.5f, 0.5f);
// C2D_SpriteSetPos(&thisSprite->spr, x, y);
// thisSprite->x = x;
// thisSprite->y = y;
// }
// 17 sprites (i hope)
for (size_t i = 0; i < numImages; i++) { for (size_t i = 0; i < numImages; i++) {
Sprite* thisSprite = &sprites[i]; Sprite* thisSprite = &sprites[i];
float x = rand() % SCREEN_WIDTH; float x = rand() % SCREEN_WIDTH;
@ -68,6 +38,7 @@ static void initSprites() {
C2D_SpriteSetPos(&thisSprite->spr, x, y); C2D_SpriteSetPos(&thisSprite->spr, x, y);
thisSprite->x = x; thisSprite->x = x;
thisSprite->y = y; thisSprite->y = y;
thisSprite->w = 0;
} }
} }
@ -84,6 +55,10 @@ void moveSprite(Sprite *spr, s16 dx, s16 dy) {
C2D_SpriteSetPos(&spr->spr, spr->x, spr->y); C2D_SpriteSetPos(&spr->spr, spr->x, spr->y);
} }
void rotateSprite(Sprite *spr, float dw) {
}
int main(int argc, char* argv[]) { int main(int argc, char* argv[]) {
// Init libs // Init libs
@ -107,6 +82,10 @@ int main(int argc, char* argv[]) {
// Initialize sprites // Initialize sprites
initSprites(); initSprites();
// init gravity calc vars
float a = 0.4f; // acceleration
float v = 0; // velocity
// set bg properties // set bg properties
C2D_SpriteSetPos(&sprites[SPR_BG].spr, 200, 120); // center bg C2D_SpriteSetPos(&sprites[SPR_BG].spr, 200, 120); // center bg
C2D_SpriteSetScale(&sprites[SPR_BG].spr, 2.7778, 2.7907); C2D_SpriteSetScale(&sprites[SPR_BG].spr, 2.7778, 2.7907);
@ -117,8 +96,7 @@ int main(int argc, char* argv[]) {
Sprite scoreSprite; Sprite scoreSprite;
// Main loop // Main loop
while (aptMainLoop()) while (aptMainLoop()) {
{
hidScanInput(); hidScanInput();
// Respond to user input // Respond to user input
@ -127,23 +105,17 @@ int main(int argc, char* argv[]) {
if (kDown & KEY_START) if (kDown & KEY_START)
break; // break in order to return to hbmenu break; // break in order to return to hbmenu
if (kHeld & KEY_LEFT) {
Sprite *this = &sprites[SPR_BIRD]; // gravity calcs
moveSprite(this, -1, 0); v += a;
} moveSprite(&sprites[SPR_BIRD], 0, v);
if (kHeld & KEY_RIGHT) {
Sprite *this = &sprites[SPR_BIRD]; if (kDown & KEY_A) {
moveSprite(this, 1, 0); v = -5.5;
} moveSprite(&sprites[SPR_BIRD], 0, v);
if (kHeld & KEY_DOWN) {
Sprite *this = &sprites[SPR_BIRD];
moveSprite(this, 0, 1);
}
if (kHeld & KEY_UP) {
Sprite *this = &sprites[SPR_BIRD];
moveSprite(this, 0, -1);
} }
// Render the scene // Render the scene
C3D_FrameBegin(C3D_FRAME_SYNCDRAW); C3D_FrameBegin(C3D_FRAME_SYNCDRAW);
C2D_SceneBegin(top); C2D_SceneBegin(top);