Original Post

I’ve decided that since I have absolutely no experience whatsoever playing RPGs, that I am not a good candidate of programming one, so instead, I’m going to work on a fighting game (while I also have no experience playing a fighting game, I’d figure it’d be a lot easier programming one than an RPG.) So here’s my latest brainchild: Insect Combat. Right now, it’s just a warning screen and a title screen. The only two characters I’ve thought of so far are Gi-Ant and Behe-Moth. Any other punny names you guys can think of would also be appreciated.

Attachments:
399 Replies

For a video of the latest build, go to:
http://youtu.be/WtQnA4bTn0c

Looking good, im looking forward to the finished game.

Thanks. Here’s today’s change. Instead of remaking a new character select screen every time a new character is created, I decided to have the fighters scroll back and forth, so to select a fighter, you either press left or right to select who you want. The fighters will then scroll off the screen and a new one will pop up (except for now since there’s only one fighter created so far, but you can press left or right at the fighter select screen to get what I mean.) To download the latest ROM, click the link in my signature.

Attachments:

OK, finally got the background scrolling the way I wanted it to. The front background is moving at a faster rate than the deep background, but at a slower rate than the foreground (what’s in front of the characters.) Also, since this is a beehive, Rumblebee’s song is Nikolai Rimsky-Korsakov’s “Flight of the Bumblebee.” Wikipedia link: http://en.wikipedia.org/wiki/Flight_of_the_Bumblebee
Just thought it fitting.

Changed the speed of the ant walking and jumping dramatically, due to the fact that I wasn’t able to jump over the other ant. I also added some bass notes to the Flight of the Bumblebee song. The ant (as well as all the other characters when they get designed and programmed in) should now be able to walk in a better time, in my humble opinion. Let me know what you think about the changes.
Also, if anyone wants to work on this besides me (perhaps this being the community game people are talking about, which I would be really flattered if so), let me know, give me a PM or something.

I haven’t looked at this for a long time, but it’s amazing. It is of much higher quality than I expected. The background and foreground, even though they are simple layers thrown into a 3D space, look really cool. This is going to be interesting.

But there’s a bug. When you move yourself to the left, the sprite sometimes turns to the right and then to the left again. Haven’t we had a discussion about that a long time ago?

HorvatM wrote:
But there’s a bug. When you move yourself to the left, the sprite sometimes turns to the right and then to the left again. Haven’t we had a discussion about that a long time ago?

I’m playing and playing and I just can’t seem to activate this bug you’re talking about.

HorvatM wrote:

I haven’t looked at this for a long time, but it’s amazing. It is of much higher quality than I expected. The background and foreground, even though they are simple layers thrown into a 3D space, look really cool. This is going to be interesting.

Thank you for your compliments!:)

VirtualChris wrote:
I’m playing and playing and I just can’t seem to activate this bug you’re talking about.

It happens with Reality Boy and VBjin. If you tested this on real hardware (which I can’t) and it works correctly, it could be because the frame rate on hardware is lower than on emulators and the sprites switch so fast that it’s only visible on emulators.

I’m using Mednafen.

Today’s build is a little different. I made and used Insecticide’s own font and did a little updating with the text. Enjoy.

I’ve noticed that when the ant (character) is facing left during the match, the music slows down a little bit on real hardware (and not in Mednafen!) Is there any way to fix this? Right now to alter the BGMap so it shows the ant being flipped is by using a void thingy (void HFlip in the code, lines 137-154.) I call that, and was wondering if why the music is slowing down is because I call it and it isn’t actually part of the code during fights (it’s listed near the beginning.)

Apparently HFlip gets called three times, with the same parameters, in the game loop, if ‘left’ is true.

So when the fighter is facing left, the code flips an entire BGMap, three times (so it’s the same as if it only got flipped once), for every iteration of the game loop. And each time it is flipped, 1560 memory-to-memory swaps and 3120 in-memory XOR operations are done.

OK, I made it a lot better so it (hopefully) doesn’t have to work as hard as it once did; which made the music just about the same tempo (if not exactly) if you face left or right. Geez, I don’t quite understand how many operations per second it was doing, but it seemed like a lot.

OK, for a lark, I decided to see whether I could program the ant you don’t control to go to and fro (a necessity for the game’s program is to at least move the non-moving ant!) After about 4 hours, I succeeded, but the animation for the ant that you don’t control won’t work even though I tell it to (lines 1155 and 1159.) My question is why not?

OK, this works right, but the music is superslow on real hardware, I’m presuming since it’s working really hard, which I don’t know how to change. It needs to check to see if 2 character maps need to be flipped every frame because if I don’t, it doesn’t work right. Any thoughts on how I can make the VB not work as hard to flip the character maps?

You are working too hard! I notice pretty much everywhere, you are misusing “if” statements. What I mean is this…

 // Your code
    if (StartGame>2) vbTextOut(0, 20, 11,"IMPORTANT:");
    if (StartGame>2) vbTextOut(0, 14, 12,"SCREW THE INSTRUCTION");
    if (StartGame>2) vbTextOut(0, 13, 13,"AND PRECAUTION BOOKLETS");
    if (StartGame>2) vbTextOut(0, 15, 14,"JUST PLAY THE GAME.");

So yes, you are right that after an if statement, it will execute everything until the ;. Well, usually that is. But the preferred way is to use {} braces (usually called “curly braces”). Then it will do everything in between the {} braces (unless you did something bad like a goto). So anyway, you can rewrite the code like this then…

 // Right way
    if (StartGame>2) {
        vbTextOut(0, 20, 11,"IMPORTANT:");
        vbTextOut(0, 14, 12,"SCREW THE INSTRUCTION");
        vbTextOut(0, 13, 13,"AND PRECAUTION BOOKLETS");
        vbTextOut(0, 15, 14,"JUST PLAY THE GAME.");
    }

Notice I can get multiple things done with the same “if” statement, and I don’t have to use “,” between each thing. (the comma is almost never used in C).

For safety, you should always use the { and } braces every time you use an if statement (or for(;;) or while())

Then, lets look at this next bit of code…

if (fighter==1) vbTextOut(3, 1, 0,"GI-ANT               ");
if (fighter==2) vbTextOut(3, 1, 0,"BEHE-MOTH            ");
if (fighter==3) vbTextOut(3, 1, 0,"RUMBLEBEE            ");
// and so on until 8, but let's limit the scope to just 3 for now

The problem with this is that if “fighter == 1” then you know “fighter == 2” cannot be true, yet you still check it. This just wastes time. One way is to use the “else” statement along with “if”. Here is an example…

if (fighter==1) {
    vbTextOut(3, 1, 0,"GI-ANT               ");
} else if (fighter==2) {
    vbTextOut(3, 1, 0,"BEHE-MOTH            ");
} else if (fighter==3) {
    vbTextOut(3, 1, 0,"RUMBLEBEE            ");
} else {
    // If you want to do something when none of the above
    // is true, you can put it here.  let's just leave it
    // blank to match your original intent.
}

That is better, because if fighter == 1, you do not check the rest. But if fighter == 3, you still check first if fighter == 1, then if fighter == 2 before finally checking if fighter == 3. Bummer.

Another alternative in a case like this is the “switch” statement. This is very similar to the if/else example, except it is a little bit easier to read. It also can have performance gains, but it is more limited than the if/else statement. Either way, check out the example…

switch (fighter) {
case 1:
    vbTextOut(3, 1, 0,"GI-ANT               ");
    break; // Never forget this break!  It lets the switch know you are done.
case 2:
    vbTextOut(3, 1, 0,"BEHE-MOTH            ");
    break;
case 3:
    vbTextOut(3, 1, 0,"RUMBLEBEE            ");
    break;
default:
    // If none of the above cases are true, you do this
    // It is okay to leave it empty, or just not include it
    // but good programming says you should always include one
    // Don't forget to use break, even if you leave it empty!
    break;
}

So basically, the first part (switch(fighter)) says “I want to do things based on the value of “fighter”. Then “case 1:” essentially means “if fighter == 1, do all the code up until the break; command”. You can also see the “default” at the bottom of the switch is the same as the last “else” in the if statement.

The downfall with “switch” is that it only checks if things are equal. You cannot have a case for “if greater than”

Anyway, back on track, try going through your code making the following changes…

1) Always use {} with if() statements
2) Use if/else statements to prevent tests that you know will fail
3) Use switch statements when you want to do different things based on a single variable having different values.

There is still much more that can be done to speed up the code and make it more readable, but try to master the above first before moving on to the next steps.

OK, thanks for all the information. I can’t wait to learn more. I cleaned up the code a lot based on the things you said, although the fight scene doesn’t run faster, I bet I saved it a whole bunch of thinking power. I think most of what is going on with the fight is that I’m using HFlip twice during each gothrough of the code. I tried doing some stuff, but it would flip and then quickly flip back, so what I did didn’t work.

Now using the “Soviet 2010” sound engine. Still trying to get the hang of it, but it works better, especially for the fighting where I wanted the music to be faster.

I noticed you always call DoSounds and PlaySound in pairs. You only have to call PlaySound when you want the sound to start playing. After that, you only have to make sure the game loop calls DoSounds after each frame and that will take care of playing the sounds. Calling PlaySound in a loop will make all free sound channels play the same sound, which probably isn’t what you want.

And you don’t need the FramesUntilNextSound variable. I only used that in the example because the sounds are triggered by pressing buttons and holding down a button would create the problem described above.

It’s nice to see my sound engine being used. Just make sure to credit me if you decide to stick with it. 🙂

 

Write a reply

You must be logged in to reply to this topic.