Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers DBPro Corner / 2d text, 3d windows, loops in subs, modularity, keyboard buffer

Author
Message
Yar
22
Years of Service
User Offline
Joined: 23rd Jul 2003
Location: United States
Posted: 24th Jul 2003 00:43
First of all, I'm ecstatic that I can code again. I was an amateur C programmer but I gave it up 15 years ago with the advent of C++ and Windows. My project is to do a remake of Starflight II with 3d effects. There's a SF III project underway but it's been going on for 10 years(!) so I'm a little impatient and want to try on my own, something I see possible given the amount of work I've been able to do in DBPro.

Now that I have the registered version of DBPro, I've run into a couple of problems. First, I "borrowed" the code from the memory block tutorial to create a 3d starfield in the upper left quadrant. However, I couldn't figure out how to draw to just that area. Any decrease in the x, y, variables only decreased the y axis. So I'm under the impression that when using 3d, the whole screen is involved. Therefore, I masked the rest with 2d boxes, using black set at (1, 1, 1) to confine the 3d graphics to the upper left quadrant. I get image the static screen then display it as a sprite.
Question 1 is, can I confine the 3d to one area of the screen?

However, I found out that I could only switch the menues on the left by creating the submenu, writing text, capture image then turn it into a sprite, then blank it out with a black box and write the next submenu. In other words, the menu changes are accomplished by hiding/showing these sprites.

Okay, so far, but I need to send text to update spaceship coordinates and other info to areas on the static interface sprite. My second question then, is is this possible? I've tried every combination of print and text statements I can think of and can't get the text to the screen.

3rd Question: It seems that DB is a cross between C and BASIC. I know C (but rusty) but don't know BASIC. So my question is, when I try to do a do/loop in a subroutine, it doesn't cycle rather it runs through once and returns.

4th question, it seems DB only allows functions in #includes. If this is true, then how do you keep the code straight? I'm already at 730 lines, and I've just started. I'd rather not plow through several thousand lines.

Last question, I keep having to put in sleep statements after keypresses to avoid repeating keys. Is there any way to flush the buffer? I've tried clear entry buffer but it doesn't seem to work.

Well, this is my first post so I apologize if it's too long. I'm going to try and include the source code and a picture, but I don't know exactly how it works.

If you run the code, you'll have to hit the [Enter] button on Captain, then [Enter] button on Launch to remove the viewport mask. [Downarrow] to Bridge, hit [Enter] to go to main menu. [Downarrow] to Navigator, hit [Enter] then hit [Enter] again on Maneuver. The 3d starfield should appear. Other cautions: I have no idea about how fast this will be on other machines. Also, you might need to change the font if the one I use isn't on your system.

Thanks!

TDK
Retired Moderator
23
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 24th Jul 2003 02:31
Lots of questions!

1. 3D output in the top left corner - Set Camera View X1,Y1,X2,Y2.

2. You aren't trying to use the Text command over the 3D area are you? You need to turn the cam off first if you are. If DB Pro is the same as DBC, then you can't place text over sprites.

Not sure I fully understand this question actually as I cannot see any way I would have to use sprites to do what I think you are describing. I'd be using Copy/Paste Image.

3. There wasn't a question!

Don't know about DBPro, but in DBC, a Do...Loop will loop continuously until an EXIT statement is executed.

4. DBC and Pro both can have functions in the code - they don't have to be external in an include file.

5. I use the following simple procedure:

NoKey:
Repeat
Until ScanCode()=0
Return

And just do a Gosub NoKey after each keypress I get.

TDK
IanM
Retired Moderator
23
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 24th Jul 2003 02:41
You don't need memblocks to do a starfield, although they will be faster in full screen. Here's code that just does an 8-way starfield to a limited area. I've use LOCK PIXEL/UNLOCK PIXEL to speed up the dot operations.

You can stop the automatic redraw of the background by the 3d system by using the BACKDROP OFF command, so you don't need to do everything in sprites.

You have suprised me with your code layout. I would expect a layout more like mine from a C coder, using functions rather than subroutines. I find that it's easier in the long run to do it this way, purely because of being able to have local variables that cannot be interfered with by outside code.

Also, setting out your code this way makes it easy to use includes - just create a new file, cut'n'paste the functions to it, and then include the file using the Project manager panel.

Anyway, you've got a good start there. Good luck with the rest of it
Yar
22
Years of Service
User Offline
Joined: 23rd Jul 2003
Location: United States
Posted: 24th Jul 2003 06:58
Thanks a lot TDK and IanM! I have 30 days of vacation I can spend programming so needed a hand to jump start the project. The manual and usage/showcase wasn't much help. I understand for them to sell/support this at that price they probably don't have much time to do a lot of snippets for each individual function/keyword/statement.

TDK: That helped a lot about the camera which I hadn't figure out. Also, I tried a number of subroutines using loops and none of loops worked. Once through and that was that no matter what loop I put in there. Also, I can't remember why I went from paste image to sprite, but I think it had something to do with masking the 3d.

IanM: The snippet answered a lot of questions. I thought the answer might lie with functions, but I was unsure of the scope of variables and where to declare. Is this how it works?

Main File:

Global W: would make W visible in all files main as well as includes
W = 1: assign value to global variable
X = 1: visible to Main file only

Include File:

Y = 1: visible to ALL functions in this include file

function 1
local z: visible only to the function
z = 1
code
endfunction

Anyway, thanks again to both of you for your time and insight.
IanM
Retired Moderator
23
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 24th Jul 2003 10:13
Yep, you seem to have got it, but with currently (patch 4.1), there is a problem with variable scope - don't give local and globals the same name. This is fixed in the Update 5 beta (coming soon).
TDK
Retired Moderator
23
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 26th Jul 2003 01:04
Now you know how to restrict the camera output area, you can switch back to Paste Image which will remove the 'inability to print text over sprites' problem.

With the loops question, a procedure which is like this:



will result in never returning when you do a Gosub MyProc. Take out the REM and it gives a condition for the loop to be exited.

But, I guess you knew this already!

TDK
Defoman
23
Years of Service
User Offline
Joined: 1st Nov 2002
Location:
Posted: 7th Aug 2003 08:46
Post a link to some screenshots or development status for this project as it progresses.. I was a HUGE fan of Starflight II back in the old days.. Only good game I had on my EGA monitor..

Login to post a reply

Server time is: 2026-07-06 07:50:30
Your offset time is: 2026-07-06 07:50:30