Hello everyone! Today I will be showcasing what I have done in 3DS Development. Right now, I am working with 3 other people to make a homebrew Geometry Dash clone called Shape Sprint 3D! We don't have much because we recently decided to rewrite it in C, but here is what we have right now:
Basically, we made a cube move and jump For a more complicated answer:
The first 3 lines are including vital libraries that make my program work. sf2d is a standard 2d library, stdio is short for "standard input output" which controls just that, and 3ds is the standard 3ds homebrew library. The next block of code is a "structure" assigning all the properties of my image that I imported in a different .c file. From there, I start the main function off. I initialize sf2d and declare curx and cury which is the current x and y values for the main character. I will explain more about this later. I also make a pointer to my image so I can use it later. After that, I start the main loop. First I scan input, and I assign KeyHeld/Up/Down variables for easy access. After that, I draw the picture on the screen at the top screen at the position of curx and cury. I start to assign things to buttons after that. The first thing is basically, if the Start button is pressed, break out of the function and exit the program. Then I say, if the A button is held, go up by 10 pixels, then, else if the cube is below or equal to 190 (almost the bottom of the screen), make cury equal to 190, so it doesn't go below the screen. The Else just means decrease cury by 4 if A isn't held. I also added a little test thing that says if the Left button on the DPad or Circle Pad is held, move left by 5 pixels, and if the right button is held, move right 5 pixels. From there I wrap up the program by swapping the buffers, freeing the image from memory, and finishing all processes.
That's basically all I have so far. I'm also working on a little simple platformer, that I may release. If you want to download this, there is a link with everything built at the top of the blog.
Here is a video:
Keep in mind that this is a very early alpha. Thank you for reading! Suggestions and corrections are appreciated.
Code:
#include <3ds.h>
#include <sf2d.h>
#include <stdio.h>
extern const struct {
unsigned int width;
unsigned int height;
unsigned int bytes_per_pixel;
unsigned char pixel_data[];
} mainchar;
int main(int argc, char **argv){
int cury = 190;
int curx = 50;
sf2d_init();
sf2d_texture *mainchar1 = sf2d_create_texture_mem_RGBA8(mainchar.pixel_data, mainchar.width, mainchar.height, TEXFMT_RGBA8, SF2D_PLACE_RAM);
while (aptMainLoop()){
hidScanInput();
u32 kDown = hidKeysDown();
u32 kUp = hidKeysUp();
u32 kHeld = hidKeysHeld();
sf2d_start_frame(GFX_TOP, GFX_LEFT);
sf2d_draw_texture(mainchar1, curx, cury);
sf2d_end_frame();
if (kDown & KEY_START) break;
if (kHeld & KEY_A){
cury -= 10;
}else if (cury >= 190){
cury = 190;
}else{
cury += 4;
}
if (kHeld & KEY_LEFT) {
curx -= 5;
}else if (kHeld & KEY_RIGHT){
curx += 5;
}
sf2d_swapbuffers();
}
sf2d_free_texture(mainchar1);
sf2d_fini();
return 0;
}
The first 3 lines are including vital libraries that make my program work. sf2d is a standard 2d library, stdio is short for "standard input output" which controls just that, and 3ds is the standard 3ds homebrew library. The next block of code is a "structure" assigning all the properties of my image that I imported in a different .c file. From there, I start the main function off. I initialize sf2d and declare curx and cury which is the current x and y values for the main character. I will explain more about this later. I also make a pointer to my image so I can use it later. After that, I start the main loop. First I scan input, and I assign KeyHeld/Up/Down variables for easy access. After that, I draw the picture on the screen at the top screen at the position of curx and cury. I start to assign things to buttons after that. The first thing is basically, if the Start button is pressed, break out of the function and exit the program. Then I say, if the A button is held, go up by 10 pixels, then, else if the cube is below or equal to 190 (almost the bottom of the screen), make cury equal to 190, so it doesn't go below the screen. The Else just means decrease cury by 4 if A isn't held. I also added a little test thing that says if the Left button on the DPad or Circle Pad is held, move left by 5 pixels, and if the right button is held, move right 5 pixels. From there I wrap up the program by swapping the buffers, freeing the image from memory, and finishing all processes.
That's basically all I have so far. I'm also working on a little simple platformer, that I may release. If you want to download this, there is a link with everything built at the top of the blog.
Here is a video:
Keep in mind that this is a very early alpha. Thank you for reading! Suggestions and corrections are appreciated.