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.

64 Replies

Cool… sounds kinda like Castle Quest.


Still using linear gravity I see… still, a good idea and not a bad beginning.

Glad to see you’re still dev’ing and hanging around PVB!

Oh, yeah… I forgot:

The “vbWaitFrame” function that comes with the Wiki Sample Code (and the PVB Coding Competition logo code), which uses the XPSTTS register, is fundamentally flawed and should not be used in new code.

I have not yet found a suitable replacement. I thought about making something that uses the VB’s timer, but while looking at the Bound High source, I noticed that it only uses the timer for playing music. I’ve yet to find how it synchronizes animation and user input.

What do you mean by linear gravity? Also, thanks for telling me about the vbWaitFrame function, now I know not to use it.

VirtualChris wrote:
What do you mean by linear gravity?

I explained it in detail in this post (which is a reply to this post) and then attached my implementation to this post.

RunnerPack wrote:
The “vbWaitFrame” function that comes with the Wiki Sample Code (and the PVB Coding Competition logo code), which uses the XPSTTS register, is fundamentally flawed and should not be used in new code.

I’d recommend a calibrated delay function, like I used in my audio apps. Using a hardware timer is a waste of resources IMO (and not compatible with code already using the timer for something else). It’s not necessary since you’d just be using the CPU to poll the timer, rather than just using the CPU to count however long it wants to delay (if you know how many CPU cycles it takes to execute a chunk of code, you know how long that delay is).

The hardware timer is nice because it can run in the “background”, and either interrupt, or just have the CPU check it on occasion while doing other stuff.

I also don’t like the name “waitframe”, as it makes it sound as if it’s waiting a certain number of display or game frames (which makes a non-deterministic delay unless you know where in the first frame you are when executing the function), but its common use is as a general delay function. I’d rather have delay_ms(), which delays a specified number of milliseconds, and have a waitframe() function wait for the next game frame (so you can just call that function at the end of your main loop to sync everything to 50Hz).

One thing I really wish the V810 had is a free running counter though. They make delays, profiling execution time, etc. so much easier.


OK, I need help. As things stand right now, I have the guy in CharSeg 2, the walls (room info) in CharSeg1, and the door in CharSeg 0. No matter how I change things around, the guy is always behind the door and behind the walls (even when he was at CharSeg 0, the walls being CharSeg1, and the door being CharSeg 2.) How do I make the guy be in front of everything?


Read! http://www.planetvb.com/modules/dokuwiki/doku.php?id=graphics_overview

It’s not the CharSeg that determines layering (or “what’s in front of what”). 🙂

OK, the code has been nice and polished. (although the jumping is still the way it was before.) I think I understand what while(1) does, but, what if I want to go back to before I typed in while(1)? What is an easy way to do that without using a goto statement? For example, what I want to do is once the character enters the door, go back (codewise) and add +1 to the room value so it displays a new room.


The correct way would be (I believe) to another while() loop around the existing one like this:

while(1) {
  // your code here
  // once the character enters a door:

I had to make some more changes to the code because I added an enemy, and apparently it doesn’t like it when I add another world, the previous code goes berzerk and so I have to modify it. I think I’m done with worlds for now, and the game has three rooms now, with an enemy on level 3, and if you’ll look at my code, there is not one single goto.


OK, since I added another enemy in room 4, the code I had for enemy collision wasn’t working, so now I need to come up with a new one. What is a good way to have collision detection?


I think everything is fixed. If not, please tell me.


Looks great. But the collision detection against walls moves you far too away from the wall.

BTW, is the gravity code based on my code? Just askin’.

No, I programmed that part myself. It’s basically what I use in batari Basic (an Atari 2600 programming language) for jumps when I have a character like Mario that needs to.

Added another room (room 5). You start at room 4.


OK, I’m having trouble again. What I’m doing in room 8 is having an elevator go up and down. I’m doing this by taking the world and creating a new one, moving it ahead by 328 pixels, creating a ledge that moves up and down at the right side of the screen. The only trouble is, the guy doesn’t recognize the ledge and keeps falling even though he’s reached the bottom of the moving ledge. How do I make the code recognize the guy is on the ledge so he can stop falling?


I ditched the elevator in room 8 because I couldn’t get it working. So here’s the latest ROM.


I think you definitely need to work on the movement and jumping.

I mean, the character jumps ONLY, and very slowly, when you hold the jump button. It should much rather just start jumping a certain fixed height, then slowly fall back down. You know, jumping physics. Even if you don’t do the whole gravity thing, you could still make sure there’s some sort of variable that remembers how long you’ve been jumping, to set a minimum jumping height.

Then, the jumping stops when you touch a wall. He falls back down. This should probably be fixed, too.

Also, the movement speed of your character is constant, so why bounce him back as heavily as you do in the game? You should be able to know exactly how many pixels your character is going to move to the left or right. So take preemptive measures and do a “will he be stuck inside the wall next frame?” check to decide whether he should move into that direction at all.

Movement is VERY important in platformers as a bad movement system will have the player fighting against the controls instead of the game designer’s intended challenges. And that will make them stop playing much sooner than you want them to.

Note that I’m not an expert in VB coding, but I DO have a lot of experience trying to make a proper platform system that works as I want it to (and without bugs/stuttering movement). I wish you much luck getting the platforming system to work right. 🙂

OK, I worked on the collision detection of the walls. How is this? Better? Next up: Working on the jumping.



Write a reply

You must be logged in to reply to this topic.