Advice on code optimization and bug issue
Posted: Thu Feb 21, 2013 5:39 pm
Background
I've taken a couple of computer science classes back in high school (several years ago), and when Udacity first appeared I took their introductory Python course.
I'm by no means an expert programmer, or even an intermediate-level programmer for that matter, but I've taken it upon myself to learn Lua/Love2d for the past couple of days. I've put together a small game (if you can call it that), combining many of the things I've come across since starting, with a few of my own addtions.
It's essentially a sprite character that can move by pressing left and right, sprint by pressing space, and is on top of a background with a moving cloud.
Issue
I'm having one issue in particular that I haven't been able to solve. Most of my solutions tend to breed more problems than solutions, so I wanted to get some advice on how to tackle the issue.
Basically, the issue is, when you are moving the character in one direction (holding down the right arrow, for instance), and then simultaneously press another direction (left arrow, for instance), the character will do a sort of moon-walk. I understand, logically, why it's doing this and I can see in the code where it is having the issue, but I'm just not sure on how to fix it without it creating other problems.
Advice/Misc
Additionally, if anyone could offer any advice on cleaning, optimizing, or simplifying my code I'd greatly appreciate it. I'd like to begin my learning experience with a solid foundation of good habits to follow.
On another unrelated note, how are modular sprites implemented (akin to something like Terraria), assuming that is a real thing? I'm currently using Quads to integrate my sprites, and I could image you could just use quad sections or something of that nature, but I'm sure there is a more elegant solution.
Anyways, thank you in advance for your suggestions. I appreciate anything anyone can offer. I also apologize in advance for my custom music, though some might just find it humorous.
TL;DR: Having an issue with character "moon-walking". Looking for suggestions and general coding advice.
I've taken a couple of computer science classes back in high school (several years ago), and when Udacity first appeared I took their introductory Python course.
I'm by no means an expert programmer, or even an intermediate-level programmer for that matter, but I've taken it upon myself to learn Lua/Love2d for the past couple of days. I've put together a small game (if you can call it that), combining many of the things I've come across since starting, with a few of my own addtions.
It's essentially a sprite character that can move by pressing left and right, sprint by pressing space, and is on top of a background with a moving cloud.
Issue
I'm having one issue in particular that I haven't been able to solve. Most of my solutions tend to breed more problems than solutions, so I wanted to get some advice on how to tackle the issue.
Basically, the issue is, when you are moving the character in one direction (holding down the right arrow, for instance), and then simultaneously press another direction (left arrow, for instance), the character will do a sort of moon-walk. I understand, logically, why it's doing this and I can see in the code where it is having the issue, but I'm just not sure on how to fix it without it creating other problems.
Advice/Misc
Additionally, if anyone could offer any advice on cleaning, optimizing, or simplifying my code I'd greatly appreciate it. I'd like to begin my learning experience with a solid foundation of good habits to follow.
On another unrelated note, how are modular sprites implemented (akin to something like Terraria), assuming that is a real thing? I'm currently using Quads to integrate my sprites, and I could image you could just use quad sections or something of that nature, but I'm sure there is a more elegant solution.
Anyways, thank you in advance for your suggestions. I appreciate anything anyone can offer. I also apologize in advance for my custom music, though some might just find it humorous.
TL;DR: Having an issue with character "moon-walking". Looking for suggestions and general coding advice.