Creating a non-linear strategic adventure

I renamed the topic because the stuff I am now working on is not limited to the labeltext problem anymore. it is evolving so I made a special topic on my game. :slight_smile:
I hope to put update demos in a frequency of about 2 weeks.

First problem I have is with displaying labeltext. When it is displayed sometimes the first part is missing or replaced by solid white or black text.
The text above the sprites are made with CastleText and works fine, but the labeltexts to the right of the closeup scene are corrupted for a while when I push buttons. (I added a second label top middle of the screen just to compare and it shows the same corruption).

I uploaded a video to demonstrate this problem. What could be wrong here?

I found some double references and in recalling the same procedure. This sorted out the corrupted double text problem with the text next to the closeup scene, but not the labeltext top middle of screen. Although I put it there just to compare, it is still strange. This textlabel was created in the editor as design. The labeltext that now works allright was made in code.
I will put another video demo in a few days with my progression on this. Hope you like it and have some ideas on further improving. :slight_smile:

Hi all.
Here is my updated demo.
I reworked some of the code but sometimes there is still the corrupted text. It looks like it is partly overwritten by text or transform. Still finding out why but in this demo it only appears during “talk” with the first character.

There are 3 closeup scenes per character:

  • on initialisation (silent)
  • speaking short text
  • speaking longer text

Depending on the length of the NPC answering message it selects the short or longer talk animation.

Next updates will be:

  • hero walking closer to a character before starting talk
  • custom buttons
  • text displayed on a partially transparant rectangle or label background.

If you have any ideas or comments, they are very welcome.

Hi all.
Here another update.

Things I have added:

  • boundary checking (for instance player character refuses to walk into the sea)
  • character comments on “look at” now appear above its head instead of above NPC
  • player character automatically walks towards NPC after selecting “talk to”.
  • NPC turns toward player character to talk
  • Closeup scene is activated after player character reaches NPC
  • Collision checking between player character and NPC (at this moment it only activates player talk text)
  • Pointing arrow to indicate location exit.

As you might notice there are some flaws with the direction movements and approaching NPC.
I will have to work on that but I think for now it is an improvement compared to the previous demo.

Maybe I will change the close up coordinates to that of the “talking” NPC (instead of left bottom screen).
And I would like to add a partially transparant rectangle or label background to it also.
Any tips how I can achieve this?

And if you have any ideas, suggestions or improvements, let me know!

I got this error after adding a Transform on this location that appears to be invisible but present, because when I move the mouse(scene) over its position it collides. But it remains invisible. How can I track what is wrong here, because when my main character walks off location and returns then the invisible transform is visible allright.
All location NPC are loaded from a list and work fine, just this one remains invisible and causes the error.

This means something is using TBox3D.Max method on an empty bounding box. Which is not allowed – an empty bounding box has, conceptually, no position and no size, it is just empty.

The appropriate code should probably check TBox3D.IsEmpty earlier, and do whatever it should in this case. Like

if MyCharacter.BoundingBox.IsEmpty then
  // do something (or nothing and just ignore the situation)
end else
  // do something with MyCharacter.BoundingBox.Max

To tell more, you should track where this occurs. Use the Lazarus “Call Stack” window to tell you what causes the exception – IDE Window: Call Stack - Free Pascal wiki . This should show you what called the TBox3D.Max in an invalid situation.

Thanks. Just before trying this approach I had changed some code and then got this error:
Then I found out that the NPC database was trying to load a spritescreen from a wrong subdir.
(my fault, I had pointed to a still empty folder).
Now it works again, also without TBox3D problem. :slight_smile:

After that I set up the Lazarus “Call Stack” from the manual and recreated the error to compare, but then I still got this error message without further information.
Do I have to select different options instead of F9 on running this stack option?

Once the error occurs, and debugger pauses the execution of your program, you should see an information in the “Call Stack” window. Read and see the screen on IDE Window: Call Stack - Free Pascal wiki – you should see something similar. Make a screenshot of whole Lazarus (maybe just whole desktop) with “Call Stack” window open, this should clear things up.

Setting up background zones for detection

Now I would like to set some zones (rectangles?) on the location background that limits the movement path of the player transform when it collides.
I did not see a TRectangle in the CGE editor (maybe Shape?) so I created a TRectangle in code but it is not visible (I put it in the TState update procedure). It would be convenient if I could draw the zones in the CGE editor over the background picture so they are visible on design and then hide them and add collision checking in code. How can I draw them in the editor?

( Note that this question rather deserves a separate thread :slight_smile: It’s an unrelated question that could be read and answered independently from other things in this topic. )

Short answer: Use TCastlePlane

  • with Axis set to 2 (so it is a plane in Z axis)
  • and large Size or Scale.XY .
  • You most likely want to put it at large Z (and do “Sort Items for Correct 2D Blending”) to have this plane above everything else.
  • And set Material to pmUnlit, and adjust Color as you like.

You can drag it (move, scale) in CGE editor visually, or just input numbers for Translation, Size, Scale (you can modify Size as well as Scale – in practice it doesn’t matter for your case; just keep Scale.Z = 1 to not be confused by it later).

Then you can set it’s Exists to false when running the game (to make it invisible to players). You can query in code MyPlane.WorldBoundingBox.RectangleXY to have the corresponding TFloatRectangle that you can use to check for collisions with your character.


TRectangle is by design not something visible. Similar to TFloatRectangle and TBox3D. These things only express a shape that can collide, but they have no ability to actually show it.

Note that there’s also TCastleBox (for 3D box), but for 2D game the TCastlePlane is probably simpler.

Note that there’s also TCastleRectangleControl that allows to draw rectangle in UI (and has EffectiveRect to query the rect). But this is not for your use-case, as you’d have to convert UI coordinates into viewport. Using TCastlePlane will be more straighftorward.

Here’s a trivial project. It’s just our standard “2D game” template, I only modified the gamestateplay.castle-user-interface to add the sample TCastlePlane instance. I used color with partial transparency to make it look nice. (10.7 MB)

I downloaded and run the attachment but it does not show the MyPlane.
I think you uploaded the standard 2D template without it? :slight_smile:

Ups, sorry. I actually didn’t save the version with TCastlePlane, I think I automatically clicked “No” when editor asked me to save the modified design :slight_smile:

I’ve redone it, here it is (just the gamestateplay.castle-user-interface, just drop it into the “2D game” template). (1.4 KB)

@michalis I encountered an error in CGE with the fourth plane I created, while I was rotating it.
The nasty thing is I could not get control again of CGE again because the error message won’t get away (when I clicked the “ok” button of the error message, it immediately returned). so I had to Ctrl+Alt+Delete CGE and so lost all my changes :frowning:

Hm it means somehow you made an invalid rotation. Please describe reproduction steps, we definitely want to fix it:)

@michalis I tried recreating the problem but up until now no problems. I remember suddenly the plane went off screen with an unsuspected movement. The main problem was I could not get rid of the error requester anymore so CGE was stuck.

Your screenshot shows that you managed to put an incorrect value NaN (“not a number”) into the transformation matrix, so all attempts at rendering and any scene manipulation just have to fail. If you’d save the design at this state, it would also be invalid.

So the only solution here is to fix the underlying problem, i.e. we need to reproduce how did you do it, and prevent it from happening again :slight_smile:

@michalis Well, I will try, but some things in life only happen once. Maybe this error is one of those things. :wink:

I found a similar problem with CGE. When I just slowly move up the plane with the mouse it loses control and the plane shoots out of the screen, with translation values off the limits. This is like the same problem as I described earlier while rotating the plane.
It happened when I rotated the plane 90 degrees (to third rotation value 1).
And so when the red arrow is pointing vertical instead of horizontal.

When I just slowly move up the plane with the mouse it loses control and the plane shoots out of the screen, with translation values off the limits.

Thanks – I mean this is a bug and I very much want to fix this.

I tried to reproduce the problem now with an old version of “Rescue Island” code I got from you, and dragging to translate seems to work OK. Also from your video I don’t know what you are dragging, so I was just testing by dragging characters and backgrounds.

Please submit a testcase to reproduce the problem. In this case it doesn’t even have to compile, I only need a project that I can open in CGE editor, open some design inside and drag something to reproduce the problem.

(Sorry for being quiet on the forum lately. Too many things consume my time. I’m back now, and may answer in some old threads. Please ping me if there’s some unresolved question that I missed answering.)