Original Post

Ever since I was a kid, I had an idea for a game in which a guy is trapped in a castle with tons of rooms, and the object of the game was to exit the door in each room. It’s kind of like a platform game, but with puzzle elements. This is a proof-of-concept to see if I could actually program such a game, and here it is. Left/right moves guy, A is for jumping. Right now, there’s no enemy or door to another room, so there’s not really that much to do so far.

Attachments:
64 Replies

hehe nice game, level 15 was hard thought but its an ok game

I would prefer things like rolling barrels, ladders… more things but wont vomplain to much its an ok game for being homebrew

If this game was complete, I would definately say it’s the best VB homebrew ever made.

Looking pretty good… the collision detection is a little off though (I get stuck in the side of walls pretty often, and it seems to miss landings that I think I shoulda landed)… and you only sorta fixed the bouncing thing. I think they should have to press A after landing… right now it seems to only check that the button has been released (so you can release A, then hold A again while falling and he’ll immediately jump again).

DogP

I don’t know, maybe you can look through my code (without telling me how awful it is!) and see some improvements to the collision in walls code I can make? The wall bricks are 8×8, so I don’t know why it’s causing it to do such crazy things.

Seems like it’s coming along quite nicely! 😀

The penultimate platform in room 4 (the one on the far right) is the hardest part of the game. Consider lowering it.

Anyway, have you considered having more doors and keys, like in Wario Land? It would make an interesting adventure game. The gameplay currently seems too GoSub-like.

Now with in-game music! (Same wonky, semi-working wall collision detection. Why won’t someone work on that for me?)

@Horvat, yes, I’m considering keys in. Maybe before you go through a door, you need to get the key first in some levels?

VirtualChris wrote:
Why won’t someone work on that for me?

Why won’t someone just do everything I want done for me? Nice attitude… :thumpdown:

DanB wrote:

VirtualChris wrote:
Why won’t someone work on that for me?

Why won’t someone just do everything I want done for me? Nice attitude… :thumpdown:

Actually, I would help, if only he cleaned up and commented his code. It’s a mess.

And being used to BASIC is not an excuse. I’m primarily a BASIC programmer too, you know.

OK, sorry I said that.

Just adding that I’m a vB (visual Basic) programmer (primarily) and still am trying to get the hang of C for Virtual Boy.

It’s quite simple, really.

Let’s have a little contest: I’ll give $25 US to the person who can fix the wall collision detection code for me.

I put all the files I’ve been using on the site in my signature so you can work with them.

I am optimizing your code. It may take a while because I have to figure out everything first.

So, how is optimizing my code going?

VirtualChris wrote:
So, how is optimizing my code going?

Wow… I just looked at the code… I think it’ll be a while 😉 . Okay… now the helpful criticism.

You can use nested ifs. Rather than:

if ((b>0) && (batdir==1)) batx=batx+1;
if ((b>0) && (batdir==0)) batx=batx-1;
and so on...

do:

if (b>0)
{
    if (batdir==1) batx=batx+1;
    if (batdir==0) batx=batx-1;
}

furthermore… obviously batdir can’t be 1 and 0, so use else if:

if (batdir==1) batx=batx+1;
else if (batdir==0) batx=batx-1;

it’s also generally better to not put everything on one line, and if you use braces, you can have an if statement do more than one thing.

if (batdir==1)
    batx=batx+1;
else if (batdir==0)
    batx=batx-1;

same as:

if (batdir==1)
{
    batx=batx+1;
}
else if (batdir==0)
{
    batx=batx-1;
}

batx=batx+1 is the same as batx++, and batx=batx-1; is batx–… not a requirement to use, but shorthand, and generally better.

if (batdir==1)
{
    batx++;
}
else if (batdir==0)
{
    batx--;
}

and while commas do WORK to seperate stuff, it’s not common practice. As I mentioned above, braces are better:

if ((g>0) && (g<3)) harryanim=44, harrytotal=8;
if ((g>2) && (g<6)) harryanim=53, harrytotal=12;

goes to:

if ((g>0) && (g<=2))
{
    harryanim=44;
    harrytotal=8;
}
if ((g>2) && (g<=5))
{
    harryanim=53;
    harrytotal=12;
}

also, notice I changed to > and <=... it's much less confusing what number is the boundary when one checks for the =. Even better... using the "else if" described above to fix that block of code:

if (g<=2)
{
    harryanim=44;
    harrytotal=8;
}
else if (g<=5)
{
    harryanim=53;
    harrytotal=12;
}
else if (g<=9)
{
    harryanim=80;
    harrytotal=7;
}
else if (g<=14)
{
    harryanim=68;
    harrytotal=11;
}
else if (g>14)
    g=1;

Also... a few comments explaining what your code is doing would go a LONG way. And maybe more descriptive variable names (what's c, d, g, h, z, etc).

DogP

VirtualChris wrote:
So, how is optimizing my code going?

So far, I’ve figured out what the ‘i’ and ‘j’ variables mean – they control what happens with the character at the end of each main loop iteration. Therefore, I’ve renamed them to ‘Fate’ and ‘Fate2’, and changed the ‘if ((i>1)&&(room==1))’ lines (well, they looked something like that – I’m not typing that from my home PC) to an ‘if’ block containing a ‘switch(room)’ with appropriate ‘cases’.

I’ve changed the comparisons of ‘if (example==0)’ to ‘if (!example)’, and ‘if (example==1)’ to ‘if (example)’ (of course making sure that ‘example’ can only be 0 or 1) but I somehow managed to screw up your jump/gravity code; ‘down’ apparently never gets set to 1, so once you jump, you can’t get down. You should use way less variables anyway; the way you make chain reactions (like with ‘i’/’Fate’ and ‘j’/’Fate2’) with them isn’t exactly elegant.

It would be helpful to know what the ‘d’ and ‘z’ variables are for. At a glance, they seem to control the left/right character movement, but I’m not sure.

In general, you really should use arrays to store room information. What if you some day decide to have 3 bats in a room, for example? Or if you decide to have enemies that shoot projectiles? Are you going to create a set of variables for each projectile? I can probably redesign the code to use arrays, but first I want to know whether you understand how to use them – apparently you don’t, considering how you stored the music data in 8 arrays, each containing 3 notes. (I’ve since put it all into one array and simplified the music playback code, by the way.)

And maybe you should use chars and objects instead of BGMaps and worlds for sprites. Copying a BGMap into a world each time you want to change an animation frame isn’t exactly the fastest option, in my opinion. But then again I have a bias towards objects because I used them extensively in Soviet Union 2010.

Here’s a rundown of what the unnamed variables mean:
a = control whether game is going or not (I guess you could get rid of it)
b = control whether bat 1 moves (I guess you could get rid of it)
c = control whether bat 2 moves (I guess you could get rid of it)
d = Moving left
g = Walking animation timer for going left
h = Walking animation timer for going right
i = collision detection for bat #1
j = collision detection for bat #2
z = moving right

Also, I don’t know what an array is, and I also thought that BGMap and worlds were the only way to get stuff on the screen.

All of those songs you declared (with 3 notes each) are arrays, so you have already used them! 🙂

Instead of going into a detailed description of them here, this is a good explanation of them, that I think you should read. If you still have questions about arrays after reading that, we’ll be happy to help.

I’ve simplified the code in hopes that this helps. I’ve also added useful variable names instead of just letters.

 

Write a reply

You must be logged in to reply to this topic.