Here is my code:
https://drive.google.com/file/d/1b8J7cQOpRSOukdOxplM1sqr39zie4x5A/view?usp=sharing

I'm having trouble getting it to lag less. I know it wont be lagless, but lagging less would be nice. Is there any way I could maybe draw the background once and have it not interfere with the player sprite? It's made up of tiles. If there is, could you give an example that doesn't have "insert blank here" lines, maybe the source to a game that uses that method would work. The FPS dips when you walk into the middle of the flowers quite a bit. Also, is there a good way I can minimize storage usage without stripping down major parts of the code or removing sprites? Lastly, is there a good way I can avoid using all of those "ifs" before it's total spaghetti code? Thanks in advance Smile (Also, I apologize in advance for my horrendous coding skills. Advice would be nice.)
What language is this programmed in?

Nobody can even see any of the code. You need to make the file public.
Michael2_3B wrote:
What language is this programmed in?

Nobody can even see any of the code. You need to make the file public.


Oh wow, okay, that was stupid of me. Here's the new link if you need it: https://drive.google.com/file/d/1b8J7cQOpRSOukdOxplM1sqr39zie4x5A/view?usp=sharing

Btw, it's in C
You probably want to use tilemaps instead of manually drawing each sprite. There's an example for this here.

There are techniques for only drawing the background once, but they're significantly more complicated. There's not really enough room for more that two buffers, so you would have to undraw the player (and anything on top of the screen), copy the entire screen in whatever direction the player moved in, then redraw the player (and anything else that needs to say static relative to the screen, like a UI).

For the if statements, you could use a 2D array of player sprites. As a simplified example, for a player that can only face left and right and only has two animation frames:

Code:
#define NUM_DIRECTIONS 2
#define NUM_ANIM_FRAMES 2

enum direction {
    DIR_LEFT,
    DIR_RIGHT,
};

gfx_sprite_t *player_sprites[NUM_DIRECTIONS][NUM_ANIM_FRAMES] = {
    [DIR_LEFT] = {mySprite_left0, mySprite_left1},
    [DIR_RIGHT] = {mySprite_right0, mySprite_right1},
};

void draw_player(enum direction dir, int frame) {
    gfx_TransparentSpriteNoClip(player_sprites[direction][frame], PLAYER_X, PLAYER_Y);
}
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 1 of 1
» All times are UTC - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement