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 / Artist wanting to code. (DBC)

Author
Message
tha_rami
18
Years of Service
User Offline
Joined: 25th Mar 2006
Location: Netherlands
Posted: 20th Oct 2006 21:02 Edited at: 20th Oct 2006 21:04
Okay, I know I'm more of an artist by trade, or a writer, but I've got one simple wish. I want to be able to actually use what I create in a game. This game would be a SP RPG. The story is worked out, I've reserved about 4 months to complete the project. I've already started working on 3D-models and have several ready, altho' the game will be using a more top-down/iso perspective, and I hope to be able to program it in such a way that it resembles Zelda a bit in gaming style (no battle screen).

Before I get flamed: I want to start simple. Really, I do not aspire creating Oblivion 2 or something. I want to start as simple as possible without having no challenge (I KNOW I can do a Pong, but do I want to do a Pong? No, because I know I can do it). I can arrange the music, I've written a storyboard. I've got concept art for staffs and character. I've got experience in several aspects of BASIC and programming. I know how to code organized. I want to make everything from scratch though. I don't want to use a premade engine. But I don't know how. This is practice and learning, for me.

The story is simple. As a little child, you're found to have a special spiritual force that allows you to manipulate the elements to your advantage (usually referred to as Magic). You're sent to one of the two magical schools in the game, in the hope that your life will be better there. The world is plagued by demons and monsters that had suddenly appeared, and the other magic school is held responsible for that. Alas, his luck is not to be. His homevillage is raided and his parents murdered. From there on, the player will fight towards the evil school through several environments (plan to start small, 3 environments or something: Desert, Swamp, Forest). During the game, the player is to unravel the truth about the demons.

That's the story. The setting is a semi-middle-age one. Humanity still travels by animal, but its not a knightdom. No, it's a world plagued by demons and monsters, but the normal farmer will not have the power to fight them. It's up to the mages to defeat the monsters and protect society. They've created magical barriers around cities, so that people may live safely.

The game will resolve around several magical staffs. There will be no melee combat (from the players side). Normal RPG equipment (Armor, Level ect.) are things I'd like to code, and a reputation. Staffs should each have an affinity. With leveling, you'll be able to learn new magic, which is influenced by affinity (Fire spells being strong on a Fire wand, but weak on a Water wand). I'm thinking the four elements as affinities.

Now, I've got experience in 3D. I'm wondering whether I'll do 2D or 3D, 3D seeming easier for special effects. I've got little experience in coding, and I need to know several things.

- How to create a world efficiently? The matrix command seems to be highly inefficient in regards of framerate.
- How to start. Should I create some sort of grid with special locations or how do I make the game understand the player is interacting with, for example, a shelf or a person?

Don't worry about story or NPC interaction. I've got a load of imagination and I write a lot. Those gaps will be filled. I've got concept art for most things, starting working on making 3D models, now all I need is a little push into coding. I understand variables and I've worked on a lot of 2D/text-based/mathemathical programs in other BASIC languages. It seems that the step to free 3D gameplay is just one step too large for me.

This is not a team-request. This is not asking for a complete code or models or things. This is wanting a push in the right direction in 3D programming.

I hope you can help,
Thanks in advance,
Rami Ismail

tha_rami - the best way to predict the future is to invent it
Cliff Mellangard 3DEGS
Developer
18
Years of Service
User Offline
Joined: 20th Feb 2006
Location: Sweden
Posted: 20th Oct 2006 21:24
How to create a world efficiently? The matrix command seems to be highly inefficient in regards of framerate.
--------------------
_there must i say you are wrong as you are going to make an top down view game.
an matrix are not that good if you want to make type an fps or third person game.
but in an top down view will you never have that much view of the whole matrix at the same time so it will not do much differrence there.
i recomend that you start up with an matrix world and then later when you get better yust shift to something else if you nead to .
an matrix can be very good to start up with.

------------------------
- How to start. Should I create some sort of grid with special locations or how do I make the game understand the player is interacting with, for example, a shelf or a person?
-------------------------
that is extremely simple as you yust can use an distance calculation to se how long the player are from that object or person.
and add in the intersect command to after if you want the player to only be able to talk or pick up if facing the person or object
hope this helps cheers
Latch
18
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 20th Oct 2006 22:20
@tha_rami

I actually am trying to help but I think this will sound a little like a lecture. Hopefully not.

Quote: "I want to start as simple as possible without having no challenge (I KNOW I can do a Pong, but do I want to do a Pong? No, because I know I can do it)"


If you've done it, you can do it. If you've thought about it, but actually haven't done it, you might not be able to do it. One thing in programming I've discovered over and over again, experience and practice go very far.

Let's look at Pong quickly, you asked how can you tell the difference between a character and a shelf... with a little imagination, Pong can teach us. Pong uses a simple collision test when it hits a paddle or a floor and ceiling. It "knows" what these things are and it also knows when it goes past the player. The concept is simple - the ceiling and the walls and paddles are defined within the pong world and the empty space behind the paddle is defined as well, although indirectly.

My point is, don't dismiss ideas without actually understanding why they are good or bad ideas.

Cliff had some insights on why using a matrix would be a good idea. I agree. It's simple to use, and depending on the environment, you may or may not experience a performance hit, and if you did and the drop in frames per second was 100 to 60, what's the difference? At 40 frames, the eye isn't going to catch any flicker unless the SYNCing is done poorly and at 60, it's gonna look very smooth.

With all that being said, If I were to suggest a focus on how to proceed, the first thing I'd do is start messing around with creating a world with matrices. Try raising and lowering points, randomizing, texturing, anything you can think of to manipulate the matrix. Once you are comfortable with that, trying creating a few objects and putting them in different places on the matrix. Use the camera to move around and look at your world.

If you can successfully and confidently do these things, you'll have a great start. The modeling and music and bells and whistles are the least of your concerns. Once you figure out how to place an object, you can simply replace that with any model. Once you understand a matrix and how objects relate to your "3d world", you'll have a good working concept of some of the base premises of DarkBASIC.

A few thought on collision:
I've read a lot of posts regarding collision, and I think a lot of people look at collision in 3d as if it were in the real world. From what I've gleaned, often there is the belief that 3d objects push and pull each other and that collision is what will make this happen. All collision detection is, is a measurement of distance, using different methods. Once this distance has been reached, or the distance is changed, you are responsible for telling your 3d objects what to do. 3d points and objects don't really exist, but a visual representation of a series of vertices that describe the object does. If you can look at all that is happening in the 3d world as math (this is this far from that, this minus that equals this, etc) I believe it will help with your coding. This of course is just my opinion, but it helps me not to get bogged down with concepts that are actually beyond the scope of what is really happening. In terms of collision, I say use the built in collision that comes with DarkBASIC until you understand it. There is a lot of talk about it being poor and that it slows things down too much. Again, until you try it and understand it, you can't dismiss it.

Before you look for alternative solutions such as external DLLs, or methods that aren't part of the DarkBASIC package, learn and use what you have. It's posible to end up on a quest for the perfect physics engine or collision DLL, which you would have to learn how to implement anyway, when there may have been a simple solution to what you were trying to accomplish. If you understand and can implement a concept, you can adapt it to another programming language or situation.

One last thing (finally - huh?), always look for the simplest way to do something. Don't start a project by optimizing it. You can optimize later. Start your project by getting it to work in a way that you understand.

Enjoy your day.
tha_rami
18
Years of Service
User Offline
Joined: 25th Mar 2006
Location: Netherlands
Posted: 20th Oct 2006 23:25
Okay. Well, I've taken your tips and I actually have a very basic engine with a house and an enemy. The world isn't really a world yet. The camera positions itself depending on the distance to the enemy. It follows on a distance on walking, but it hangs still in the air if you get nearby (or the other way around). Performance is still good, lol, so I guess that's good. Does fogging improve performance?

I've got several new questions.
* I've got a matrix texture. I prepared a 4x3 tileset. I want the matrix to have those 12 textures applied randomly per tile a bit. I'll look whether I can blend them a bit later. I've tried using for-to loops (which works fluidly in the programs I've created, but for some reason, the program locks up when I do that here)... So, how to apply a random tile to every matrix location (after that, I'll actually make terrains, but for now I'd like to test some things.
* I want tree's, placed randomly in the matrix. I do not want them to collide with any other object. I want to create them from two plains for now. I remember there was a DarkBASIC example with a tank that did this, but I don't have it anymore. How to accomplish this?

Really, you two've got me started. I hope to keep receiving tips as long that I need them. Thanks.

tha_rami - the best way to predict the future is to invent it
indi
22
Years of Service
User Offline
Joined: 26th Aug 2002
Location: Earth, Brisbane, Australia
Posted: 21st Oct 2006 07:27 Edited at: 21st Oct 2006 07:28
think about this for your trees.
if your map is 10 x 10 with ten units between each unit



you could place things within that map by a division of ten.
this means things look a little square but you also apply an offset to the tree within that zone on its x and y shorter then offsetting into the next zone.

this way will prevent things loading on top of themselves.

if you want to place many different items within your map that wont overlap, you will have to store the used locations in an array and then check if that location is full before placing.

tha_rami
18
Years of Service
User Offline
Joined: 25th Mar 2006
Location: Netherlands
Posted: 21st Oct 2006 12:19 Edited at: 21st Oct 2006 12:23
Great, thanks indi. I've modified the code to my needs. I'm working on placing houses and NPC's now. Everything seems to go well. I'll be needing to learn how to use skyspheres, it seems. The backdrop option doesn't really do what I want. So, I've got several prepared photographs of a sky (sunset, bright day, sunrise, night). I've got a clock running in the game. I want to know the following:

* How do you make the light come from a certain direction? (I figured out how to have an actual shadow for the trees that rotates along).
* How do you create a light-emitting sphere that rises and sets?
* How do I blend the transmission between images when applying them to the skysphere?

I created some 3D trees from using three plains and texturing them with a tree. Looks quite good. Since the game is mostly top-down, there's a horizontal one too. Actually, it looks quite convincing.

Now, I've got some houses being made. I actually have Green and Red NPC's, the reddies being able to damage you. It's not combat yet, more like a collision check which hurdles you backwards and colors you red temporarily. You can't block nor attack. Also, talking has not yet been implemented. This will come later. First I'm adding a house. One that you can walk in and out of. Shouldn't be too hard. But I read about Murphy's law - and I know it to be true.

This is mostly an engine test. After this, I'll start working on a real level, but for now, I'm just looking at the options. Jumping turned out to be problematic, so I dropped jumping. Also, get ground height() seems to be quite inaccurate. Any tips on fixing that?

tha_rami - the best way to predict the future is to invent it
Mistrel
Retired Moderator
19
Years of Service
User Offline
Joined: 9th Nov 2005
Location:
Posted: 21st Oct 2006 20:57 Edited at: 21st Oct 2006 21:04
I'm an artist too. I don't consider myself a programmer but I found DarkBasic to be rather straightforward and easy to read once I knew what I was doing (once I stared at the code long enough). After you can read the code and you've familiarized yourself with the documentation it's not all that hard to make something work.

And don't forget: The forum search button and everyone here is your friend. We can help too.

http://3dfolio.com
Xenocythe
19
Years of Service
User Offline
Joined: 26th May 2005
Location: You Essay.
Posted: 21st Oct 2006 21:04
Rami, you can e-mail me about anything you want to know. I'm always available. Oh crap- I'm supposed to post an example for someone


tha_rami
18
Years of Service
User Offline
Joined: 25th Mar 2006
Location: Netherlands
Posted: 22nd Oct 2006 18:27
Okay, I've declared a function that positions an object at the right height on the matrix. Now, I've got a problem.

This is the function.


I want to use this function like this:
autoyposition(3,100,100,5)

But, I get an error. What's wrong in the code?

tha_rami - the best way to predict the future is to invent it
Xenocythe
19
Years of Service
User Offline
Joined: 26th May 2005
Location: You Essay.
Posted: 22nd Oct 2006 18:40
if the object already exists, making it again will cause an error


tha_rami
18
Years of Service
User Offline
Joined: 25th Mar 2006
Location: Netherlands
Posted: 22nd Oct 2006 19:06
It doesn't, I get a message:

Program ran into a function at line 2.

tha_rami - the best way to predict the future is to invent it
Latch
18
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 22nd Oct 2006 22:05
Hello,

For DBC it's a good practice to declare all of your functions at the very end of the program. Precede the functions section with the END command. That keeps the program from running into them. There are other ways to achieve the same result, but this is the easiest.

Example:



Enjoy your day.
tha_rami
18
Years of Service
User Offline
Joined: 25th Mar 2006
Location: Netherlands
Posted: 22nd Oct 2006 22:19 Edited at: 22nd Oct 2006 22:44
Yup, putting it at the end helped. Thanks for that Latch. I actually found it out just before checking the forums. Quite funny, in for example Java I've always learned to do that the other way around.

Okay, next step. I want to spawn some enemies. I've got a model ready, animated and such, but now I want to load those objects in such a way that the game understands they are enemies. Then, I want to load a friendly NPC model, and also group all NPC's for the game as allied.
I want, for now, to place them randomly. Is this a possibility? I mean, I could say object 1000 to 10000 is friendly and object 10001-20001 is hostile (which should be more than enough), but I'm running into problems with creating and checking for objects in the vicinity of the player.

My question, if I create an object, is there a possibility to add some sort of 'flag' to it? I've been looking at the possiblity of using an array. Would this be smart? And if so, what's the most efficient way?

I'm sorry for all these questions - but I really want to get a bit of understanding of the language. Is an array in fact a (three-dimensional) matrix? How fast does it process, could I use other techniques that are faster? If I need to check 40 objects for hostility or alliance, does that give a framedrop?

- EDIT

Okay, I got an array, but now I've got a new problem. I want an array that contains data about the objects numbered 1000-1250. I can't use objects(object#-1000,2) since that'll check the rep of objects I do not want to be checked (2 being the array in which I save the NPC's reputation). Any way to make an array that counts from 1000 till 1250 instead of from 0 to 250?

tha_rami - the best way to predict the future is to invent it
Latch
18
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 23rd Oct 2006 00:32 Edited at: 23rd Oct 2006 16:49
Ok,

If I were to try something similar I would do it this way:

1. How many enemies do I need all together?
2. How many NPCs do I need all together?
3. Are there common characteristics that I will need to control or to test for?
4. How many of these characteristics total?
5. Since I'm using DBC, there is no TYPE or STRUCT definition, but I can get around this with MEMBLOCKS... do I need to account for multiple data types for a single object?

For my example, I've decided I need 5 enemies and 5 NPCs. I've also decided that I'm going to reserve object numbers 1-5 for enemies, and 6-10 for NPCs. With that decided, I can easily test if the object is enemy or npc with a conditional:

If you are numbering your character objects in the thousands, I would use the method you demonstrated to get at lower numbered array:

Quote: "(object#-1000,2)"


Assuming obj is the object number:


Now, are there characteristics that I need to check for? Yes. I actually want to have the object and it's position closely related to each other. In this case I will need an array. An array is an allocation of memory to store data in. The dimensions of the array determine how that memory is configured. With this in mind, you can make some reasonable determinations about efficiency, depending on the size and how you manage the array. The more dimensions it has, the more memory it consumes (whether you populate the memory or not) - the larger the index, the more memory it consumes. A general formula in terms of resources is:

Type Bytes x index dimension 1+1 x index dimesion 2+1 x etc..

so a 2 dimensional array with 10 as the index numbers defined as a float: myfloat#(10,10) would roughly take up this much memory

4x11x11 = 484 bytes of memory.

Since I know I've reserved numbers 1-10 for character objects, that's going to be my first dimension. The other things I want to store are the x,y, and z position and the reputation. That means I need another dimension with an index number of 4. Since x,y, and z for an object are floats, and I as long as I don't use a decimal I can reference the object number with a float, I will dimension my array as a float:

dim character#(10,4)

NOTE: An array index actually starts at 0 so 10 actually means 11 elements and 4 actually means 5 elements... but there is such a small use of memory I'm not gonna worry about that level of efficiency and just use 10 and 4 for what they are.

The first dimension represents the character number. I don't have to keep track in the array as a separate data element if they are good or bad because that is tested for simply by the object number.

The second dimension holds x y z and reputation
1=x
2=y
3=z
4=reputation

If reputation doesn't apply to an enemy, it doesn't matter - you just won't test for it when there is interaction with an enemy. You will already have a subroutine specifically designed for the character type based on the object number.

So for example, obj = 5, and object 5 is located at (345,20,-45). Reputation = 2

character#(obj,1)=345
character#(obj,2)=20
character#(obj,3)=-45
character#(obj,4)=2

You could use a loop to assign all the values for all of the different characters.

In order to keep the number of characters from being cycled through in all of your loops, you have to find a way to skip some and include others. One way would be whether or not the appear on the screen. Another would be if they were in jail or in some situation where they couldn't be interacted with (unconsious). Another could be the distance from the main player.

to calculate the distance use the distance formula for the difference between the character (obj) and the main player (mp):



To place objects randomly, you will need a check in your loop to determine if they are on the same spot as another object. If they are, then reposition them randomly and check again.

You would be randomizing x and z. Y would be the ground height of the matrix plus the distance to the objects center (in general). This test is a little inefficient, but you can use the general idea and improve upon it. You could streamline the test with collision detection, but I'm assuming this would be a one time placement of objects, so it can be run once before the action in the game starts and therefore won't detract from game play.



Enjoy your day.
tha_rami
18
Years of Service
User Offline
Joined: 25th Mar 2006
Location: Netherlands
Posted: 23rd Oct 2006 17:23
Great, I've used your formula for distance and with it I was able to create what I wanted. Definetly cool.

Now, I could go for NPC interaction, but I want one critical part of the HUD to go first: the compass. I've heard I should try to avoid 2D as much as I can so I figured I'd simply create a plan, texture it, point it at the camera and be done with it. But how hard I try, I can't keep the compass in the lower right corner. I want it to be 'locked to the screen', but the command which should be doing that doesn't do what I want it to do. Anyone can help me?

tha_rami - the best way to predict the future is to invent it
Latch
18
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 23rd Oct 2006 20:28
Hello,

If you follow along with this thread, I answered a lot of similar questions that you are asking. The examples provided are variations of a tutorial on these forums called Monster Hunt. I helped someone with collision detection, radar usage, randomly placing objects, disappearing objects, and some other stuff.

Heres the link. I hope you find it useful.

http://forum.thegamecreators.com/?m=forum_view&t=87363&b=10

Enjoy your day.
tha_rami
18
Years of Service
User Offline
Joined: 25th Mar 2006
Location: Netherlands
Posted: 23rd Oct 2006 22:27
Thank you Latch, really, I'm starting to get the hang of this. Now just one more Q (for now).

I got a plain textured with a compass, now I want it in the lower-right corner, I want it to rotate according to camera direction. That's all.

tha_rami - the best way to predict the future is to invent it
Latch
18
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 23rd Oct 2006 22:59 Edited at: 24th Oct 2006 15:04
Assuming you have used LOCK OBJECT ON to lock the plain to the 3d window, you can use ZROTATE OBJECT plain object number,camera y angle variable.

There's an example of this in the link I posted previously. If you follow the completed version, you can see how these snippets relate to the whole package.





Enjoy your day.
tha_rami
18
Years of Service
User Offline
Joined: 25th Mar 2006
Location: Netherlands
Posted: 24th Oct 2006 10:24
Latch, really. I must thank you for your persistent help. It seems I've got it running, finally - a small engine for walking, talking and camera movement. I got a compass, I have an objective indicator ON the compass, I've got a working reputation system. I got a low-quality skybox (I'm working on a good one), I got a castle, I got tree's. For a first try, I'm impressed with what DB can do.

tha_rami - the best way to predict the future is to invent it
tha_rami
18
Years of Service
User Offline
Joined: 25th Mar 2006
Location: Netherlands
Posted: 25th Oct 2006 14:22
Okay, a question:

Does anyone know why


crashes my program while



does work? Is there anyway to avoid that?

tha_rami - the best way to predict the future is to invent it
Latch
18
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 25th Oct 2006 15:33
Depends,

As far as the crashing in general when a=0, an object can't have a number of zero. You can't have division by zero.

Your snippet doesn't provide enough info. What is the code within the loop? What are the error messages? Are you using a float as A in the for a = 0 to 25 (i.e. a#)? A has to be an integer in this case.

Enjoy your day.
tha_rami
18
Years of Service
User Offline
Joined: 25th Mar 2006
Location: Netherlands
Posted: 26th Oct 2006 00:50
Hehe, you fixed it double up - I was using a check for object collision and I was using a float. Hey, I'm actually making enough progress to feel good about this now. I got a talking system, an easy object creation function and stuff. I'm trying now to make it so that I can load 'levels' from external files. If that works, I really got the ball rolling, I guess.

tha_rami - the best way to predict the future is to invent it
tha_rami
18
Years of Service
User Offline
Joined: 25th Mar 2006
Location: Netherlands
Posted: 29th Oct 2006 09:48 Edited at: 29th Oct 2006 09:49
Okay, I've made some good progress by now. It's not really like it's really up and running and I'm running into several things I can't explain.

First one:
I'm doing a basic NPC AI which is based upon random number generation and distance to starting location. (Not as impressive as it sounds to me). It will generate a targetx and targetz and move towards it. At location it will generate another targetx and targetz. I've created a function to contain the AI, so that I can easily find that function again. Now the problem is when I add another AI entity - they all do the same. Exactly the same. Every NPC in the world clones movement from the others. Is this a result of using the function?

EDIT: PROBLEM 1 FIXED

Secondary:
I want DB to read a external file. The file would be built like this:

create("monster.3ds",25,50,50,1,-5,50,"Enemy"," ",-50,150)
build("castle.3ds",26,3000,1)

I want the program to read it like this:
- create( should take the program to the create function with the other strings loaded (object, objectx#, objectz#, size ect...)
- build( should to the program to the build function with the other strings loaded.

I really need to get this this way - I can't use for example:

1
monster.3ds
25
ect. ect.

Is there any way to achieve this? The "monster.3ds" string could be of variable length. In fact, every number there could be any length, so checking for character 10-15 won't work.

Thirdly:
I need a hand with collision. I get the idea of collision being only a check, but I can't get that check to make my objects running against a wall. Every object can move right through any other. I think this might have been asked before, but what I found all relates to a .dll and I think those are DBP (correct me if I'm wrong).

tha_rami - the best way to predict the future is to invent it
Latch
18
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 29th Oct 2006 16:49 Edited at: 31st Oct 2006 19:49
Thirdly:

There some great collision examples in the DBC documentation. You should take a look at those. Here's an example I whipped up some time ago of some very basic collision, but it shows the premise...



Walls floors and ceilings are a little different. An easy way for walls is if you know the coordinates and dimension of the wall, then when an object moves or attempts to move within that space, you position the object in it's last position. So escentially, it stays where it is.

If you want sliding collision where the object moves along the wall it is hitting, there is an excellent example in the DBC docs. It uses static object collision boxes and puts them around the walls (a box for each wall, ceiling and floor).

There is a DLL for DBC.
http://forum.thegamecreators.com/?m=forum_view&t=31051&b=5

Secondly:
To start off, you won't be able to call a function out of a file (i'm not talking about an include library file that is a DB script of functions). So if your file has the function name and all of it's parameters stored as if you were executing it as a command, you can't just read that in and run it.

If you want to store it that way for whatever reason (maybe to build a db script file that can be run by itself?), make the whole line a string:


But it can only be 255 characters long. This one is only about 50 or 60.

If your line ends up being longer than 255 characters, write 1 byte at a time representing each character until the whole line is written.

Otherwise, I would write each function parameter to a file as it's data type. Then I would read back each variable, 1 at a time as it's specific data type and assign it to the function.



Then again, maybe your function creates the file after you supply the parameters?

I don't understand your goal the way your question is worded.

Enjoy your day.
tha_rami
18
Years of Service
User Offline
Joined: 25th Mar 2006
Location: Netherlands
Posted: 29th Oct 2006 19:53 Edited at: 30th Oct 2006 21:47
What I want is this:

This is in the external file
create("monster.3ds",25,50,50,1,-5,50,"Enemy"," ",-50,150)
build("castle.3ds",26,3000,1)

This is what I want DBC to do:
- Check what function should be run, in the first case it is the function 'create'.
- store are variables into the appropriate type. So, object$="monster.3ds", objectx#=25, objectz#=50, ect. ect.
- Finally, I want it to run the appropriate function.

So - basicly, I want to split up every line in that external file into this and store every part:

create(
"monster.3ds"
25
50
50
1
-5
50
"Enemy"
" "
-50
150

Is there any way to read in a string partly? Like from comma to comma?

tha_rami - the best way to predict the future is to invent it
tha_rami
18
Years of Service
User Offline
Joined: 25th Mar 2006
Location: Netherlands
Posted: 31st Oct 2006 16:30
Previous question didn't receive much replies so I guess it is impossible to do so. I'll use include# in that case.

A new question though.


This is my first type of magic. I've set global collision on. Skybox collision is off. object refers to the object which represents the magic.

The function is called with this code.


It never returns that any objects are colliding nor hitting. What am I doing wrong?

tha_rami - the best way to predict the future is to invent it
Latch
18
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 1st Nov 2006 00:48 Edited at: 23rd Nov 2006 23:13
Hello,

Regarding your question about reading a function from the file. Because an entire line is written to the file including quotation marks, commas, etc., it has to be read back in the same way. This can be accomplished with strings, but on the read back side of things, the information has to be delineated. In the example function you provide, there are four linear separators:

( " , )

Since there are no commands to do this simply in DBC, I decided to create a custom reader. I mentioned this could by done with strings, I also mentioned that it could be done by reading individual bytes from the file and converting that information. The string method is a little easier, it saves a couple of steps and tests, but I prefer the BYTE method because it allows me virtually any length line when string lines are limited to 255 characters.

The example I've included first creates a test file in the format you seem to want (it's the format that makes it tricky to read back the way you want), then it reads it back and assigns all the values to elements in two arrays - 1 for string data, and 1 for numeric data.

I've written it only to read a single line from the file. The challenge for you would be to extend it so it reads the whole file if it contained multiple functions. You actually only need a couple more lines to do this.


I believe you have to have individual collision set for your individual objects. I think SET GLOBAL COLLISION ON and OFF actually turns on or off whether collision is detected period.

So try using SET OBJECT COLLISION TO BOXES object to test it out with the least CPU hungry collision type.

Enjoy your day.
tha_rami
18
Years of Service
User Offline
Joined: 25th Mar 2006
Location: Netherlands
Posted: 1st Nov 2006 14:53 Edited at: 1st Nov 2006 15:24
Latch, wow. Your code works perfectly, and I'm trying to edit it so that it works the way I want it to. But this works perfectly .

I'm continuing my work again. I'm looking into that collision thing as well. Thanks for your help.

tha_rami - the best way to predict the future is to invent it
tha_rami
18
Years of Service
User Offline
Joined: 25th Mar 2006
Location: Netherlands
Posted: 1st Nov 2006 17:14
Great, done. Finally I've learned simple collision, not sliding, but it works. It works great, to be exact.

So, now I've started on simple magic. It works good, but I want to do the following:

Left Mouse: Target and use an offensive spell.
Right Mouse: Defensive spell.
Both/Middle: Statistic spell.

I've completed Defensive and Statistic (CircularShield and SpeedUp). Now I'm working on Fireblast. This would create a cone and point it at the location the mouse is clicking. Now I've got a problem in DBC.

I need to convert mousex() and mousey() into a x and z coordinate in my world. In DBP, this is quite easy it seems. In DBC, I haven't found a single example. If such an example exists and this is possible, then could someone point me to it? Or can anyone tell me how to do this?

tha_rami - the best way to predict the future is to invent it
Latch
18
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 2nd Nov 2006 22:28 Edited at: 2nd Nov 2006 22:51
Quote: "I need to convert mousex() and mousey() into a x and z coordinate in my world."


It may be better to approach this from a different angle in my opinion based on the assumption that your intention is to direct your spells at 3d objects and characters.

I think there should be two conditions:

1. You cast the spell without aiming in which case the spell goes in the direction the character is facing. If that is the case then you calculate the point the spell is directed at using newxvalue() newyvalue() and newzvalue() starting from the caster's position.

distance = how far the spell travels
spellx#=newxvalue(casterx,caster angle y,distance)
spelly#=newyvalue(castery,caster angle y,distance)
spellz#=newzvalue(casterz,caster angle y,distance)

point object spell,spellx#,spelly#,spellz#

2. You want the spell directed at a specific target. Use the Object Screen x(obj) and the Object Screen y(obj) functions to get the screen coordinates of your target 3d object. Compare this to the current mousex() and mousey(). If they overlap, whichever object they are overlapping, get the object's 3d coordinates with object position x() object positino y() and object position z().

Then point object spell, obj's x, obj's y, obj's z.


Another way would be to use the first method using the direction the character is facing, but then control the character's y rotation when the mouse button is clicked and you move the mouse left or right. This could effectively spin the character and fan a flame around in an arc.

Enjoy your day.
tha_rami
18
Years of Service
User Offline
Joined: 25th Mar 2006
Location: Netherlands
Posted: 5th Nov 2006 19:39
Again, a very effective way to do this. I used the second method, and it seems to work. I'm working on having the character strafe at the moment, seems to be quite nasty to do so. But I'm working out things.

Thanks again, Latch.

tha_rami - the best way to predict the future is to invent it
Latch
18
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 5th Nov 2006 21:51 Edited at: 5th Nov 2006 22:12
One other thing, when using Object Screen x() and y, you may want to expand the bounds a little bit so that the mouse click isn't focused on the center point of the object. You can use a calculation based on the camera's distance and the size of the object you want to detect, or you can choose a number that's a best guess. I've done it both ways. I prefer however just to take a guess - usually 5 or ten units above and below x and y.

So it looks something like
if mousex() > object screen x()-5 and mousex() < object screen x()+5

Do something similar for y, it gives you a greater area on the object to detect. The only problem is, if the objects are far away and your bounds are too wide, you could detect the object even if you aren't on target.

-----------------------------------------------------------
Strafing

Seems harder than it is because you always want to strafe relative to the direction the object is facing. If you know anything about polar coordinates, you know that cartesian x and y are calculated relative to the origin using an angle, some radius and cos for x and sin for y. Since strafing is left and right of the direction your object is facing, there will always be an angluar offset of 90 degrees in either direction to strafe. So if you are facing 0 degrees, in mathematical polar coordinates, left would +90 (pi/2)and right would be -90 (or +270 3pi/2). The thing then would be to move in those directions at some distance per iteration represented by the radius.

This should be enough information to solve the problem. Once you figure it out, this opens the door to a whole series of uses of this basic premise.

However, the creators of DarkBASIC thought about this and made an easier way to do it where you can avoid using trig math. If you get stumped trying it using trig, look at the code below. I use DBC functions instead (they have the trig built in). Just note that the DBC functions I use open the angles in the opposite direction than standard polar coordinates.

Here's some strafing code I whipped up when answering someone elses question:



Enjoy your day.
tha_rami
18
Years of Service
User Offline
Joined: 25th Mar 2006
Location: Netherlands
Posted: 8th Nov 2006 22:37 Edited at: 11th Nov 2006 11:02
Great, most of it works. But okay, time for another problem!

The game speeds up and slows down a lot (not too far in both directions, though). I want the game to have a stable speed. How do I make sure it has a stable speed? I've been reading up on timer based movement and stuff but I don't really get the idea behind it.

tha_rami - the best way to predict the future is to invent it
tha_rami
18
Years of Service
User Offline
Joined: 25th Mar 2006
Location: Netherlands
Posted: 11th Nov 2006 11:05
And another question, which hopefully will get the above into attention.

For my mouse cursor I'm using a sprite, however, several 'guru's' around here told me not to and use plains instead. I'm having some difficulty figuring out how to do this. Isn't there a way that is as simple as a sprite that I can use for a mouse cursor? Otherwise I'll use a plain, but it seems I've got a hell of framedrop already. I'm finishing it, however, and afterwards I'll look at optimizing things or rewriting it more efficiently.

tha_rami - the best way to predict the future is to invent it
indi
22
Years of Service
User Offline
Joined: 26th Aug 2002
Location: Earth, Brisbane, Australia
Posted: 11th Nov 2006 11:19
players mouse co-ordinates can be managed using mouse x() and mouse y() commands

you could position an image using these commands.

pseudo code

hide the mouse prior to your main loop - HIDE MOUSE

create two variables, lets call them playermouseX and playermousY
load an image
PLRX = mouse x()
PLRY = mouse y()

LOAD IMAGE

in the main loop place this image via the current mouse position by always updating your vairables

PLRX = mouse x()
PLRY = mouse y()

PASTE IMAGE PLRX,PLRY

you could use a sprite if you wanted, I guess it drops the frame rate, not sure tho.
a small 32 x 32 icon based image should be ok

indi
22
Years of Service
User Offline
Joined: 26th Aug 2002
Location: Earth, Brisbane, Australia
Posted: 11th Nov 2006 11:20
at this point in time id also like to point out, your a coder and an artist now.
well done mate.

tha_rami
18
Years of Service
User Offline
Joined: 25th Mar 2006
Location: Netherlands
Posted: 11th Nov 2006 11:27
Hehe, an Australian. You always can see someone is Australian when he uses 'mate'. But okay, thanks mate.

Pasting the image manually every time gives less than a frame drop than a sprite. Does anyone know whether this is better than a 3d plain with texture?

tha_rami - the best way to predict the future is to invent it
indi
22
Years of Service
User Offline
Joined: 26th Aug 2002
Location: Earth, Brisbane, Australia
Posted: 11th Nov 2006 11:43 Edited at: 11th Nov 2006 11:51
Give it a try with all 3, remark the code for each component and leave remarks in your code why you chose the best method.

hehe some english people here use the mate term as well.
Its used so often down under i forget its foreign to some

Id like to visit amsterdam one day, apparently artists are tax free so i hear, sounds right up my alley.

a 3d object has benefits, you could rotate it and scale it and etc without having to make any more media.

tha_rami
18
Years of Service
User Offline
Joined: 25th Mar 2006
Location: Netherlands
Posted: 11th Nov 2006 14:00
Lol, since the basic engine is coming along great, I know I'm mad but I'm planning on creating an easy way to create environments for myself. Simply said, I'm going for a level editor. It's possible that I'll have a lot of matrix related questions for that reason, but I hope you'll bear with me as long as needed. The project in total is going better than I hoped. After I get some nice environment I'll start working on additional magic (I only got three spells now), levelling, a ingame menu to select which spell for which slot (Attack,Defense,Enhance) and a combat AI. Oh, and WSAD controls .

You'll see me around for a lot more, I'm afraid . But it's coming along . It really is

tha_rami - the best way to predict the future is to invent it
tha_rami
18
Years of Service
User Offline
Joined: 25th Mar 2006
Location: Netherlands
Posted: 12th Nov 2006 11:41
I've got a problem with my level editor, so here's a small part of the code:



The problem is one of these: I'd like to write everything between BUILDING START and BUILDING END in a single line. ( build(object$,object#,objx#,objz#,s,y) would be the syntax). The second problem is I get all sorts of weird symbols in the file, instead of the variables. I've tried all write options (long, file, word, float ect. ect.) but it never exports correctly. What should I do?

tha_rami - the best way to predict the future is to invent it
Latch
18
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 23rd Nov 2006 23:33
Hello,

You may want to try changing all your data elements to strings, link all the strings together as one final string, then write that final string to the file so it appears as one line. I made an example of this earlier in this thread.



Based on your recent code, it might look something like:

st$="build("
st1$="object$,"
st2$="object#,"
st3$="objx#,"
etc...

Then you would do something like

fileline$=st1$+st2$+st3$+etc

then write the string fileline$ to your file.

The only drawback of this method is that a string line can be up to 255 characters. This will most likely fit your needs most of the time, but if it has to be longer, you may want to write each character code of the final string as a byte to the file. The file won't look as pretty, but the information would be stored sequentially.

This is just an example of method, the idea being you create the line as you want it written to the file as a string so it outputs as text. When you read it back, you can use the byte conversion algorithm I showed you before so you can separate the different variable types and commas and parenthesis.

Enjoy your day.
tha_rami
18
Years of Service
User Offline
Joined: 25th Mar 2006
Location: Netherlands
Posted: 26th Nov 2006 17:45
Well, that again, helped. It's starting to work better and better. My level editor works and I can load levels into the game. I've got most textures ready. Story has been implemented. The engine is scalable, modular and moddable. While most objects are still cubes or pre-made objects, the basic engine is running and running smoothly in most cases. I'm quite happy with what I've got till now.

Next steps:
- Implementing magic/skills/equipment.
- Finishing battle-system (realtime).
- Implementing menu's.

I'll make this into a W.I.P. after I finish these steps. I thank you all for your support (Xenocythe and Latch, you're heroes) - I might need it again, but without your help I wouldn't be as far as I am now.

tha_rami - the best way to predict the future is to invent it
tha_rami
18
Years of Service
User Offline
Joined: 25th Mar 2006
Location: Netherlands
Posted: 26th Nov 2006 21:45
I do not know whether you consider this a double-post, but I got one more question about my level editor. When saving, it goes past every point on the matrix one by one and gets the matrix height. It writes a string to a file. The game then reads the file and sets the matrix height on every point.

My question: I also want the level editor to save the tile I use on the matrix. Is there any way to retrieve the tile on saving (so not during editing due to not wanting to save coordinates).

I hope my question is clear...

tha_rami - the best way to predict the future is to invent it
Latch
18
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 27th Nov 2006 01:35 Edited at: 27th Nov 2006 01:54
Glad to hear you're making such good progress! It would be nice to see the fruits of your efforts some day.

Now I'm not sure if this addresses your tile question but here goes:

A matrix has a number of points and a number of tiles, we know that. That's not anything new. The trick to consider is that the number of tiles across is 1 less than the number of points across and the number of tiles up and down is 1 less than the number of points up and down.

If you don't want to save all of the individual x and z coordinates, just get the highest value of each. That way, you can reference them both later with a for next loop.

The number of tiles is just highetTileX * highestTileZ. But to keep the reference relative to the x and z coordinates and to reference individual tiles, it would be 2 for next loops just like your coordinate for next loops (except 1 value less in each direction).

Ultimately you wouldn't be saving the actual tile, but a reference to it and any properties you might want to set. You could use an array for this, and save the array to the file that has all of the information for each tile referenced.

Here is a short program that shows how I'm referencing the tiles just to apply a texture. I have it drawing the textures on the matrix so you can see what is happening for demonstration purposes. I'm determining the tile with the method I'm describing above. I Know you said you didn't want to save the coordinates, but I'm just including them as examples of tile properties you could save. These could very well be references to objects that are at this tile location, or coordinates of a trigger:



Enjoy your day.

Login to post a reply

Server time is: 2024-11-26 05:29:04
Your offset time is: 2024-11-26 05:29:04