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.

DarkBASIC Professional Discussion / @DBPro Experts: Migrating from Object-Oriented Language, please help

Author
Message
Nytus Sermus
13
Years of Service
User Offline
Joined: 17th Jan 2013
Location:
Posted: 22nd Feb 2013 21:39 Edited at: 14th Mar 2013 04:30
...

You could be done already.....stop trying to re-invent the wheel.
Chris Tate
DBPro Master
17
Years of Service
User Offline
Joined: 29th Aug 2008
Location: London, England
Posted: 22nd Feb 2013 22:39 Edited at: 22nd Feb 2013 22:53
Using character to character collision isn't fast. If they are close to each other then they have collided, so a simple distance check can suffice.

Matrix1 utilities features object grouping, so you'd use Call Function For Object Group, and add all characters close to the given character to an array. I often do this and then sort the array using Matrix1 Sort Array commands; doing so in order of distance to handle AI decisions or racing order.

You can store User-defined-types within arrays to create object orientated classes. UDT Arrays can be put into other UDT arrays by converting them into memblocks. You can also use link lists to interface classes together and have different UDTs share functionality; or you could also use LUA scripting to handle such things.

Note that the collision commands in the help files are mostly redundant. (Unless you wanted to get into the static universe)

Try to use Sparkys Collision, or even better Dynamix; a bit like using Photoshop instead of MS Paint; you make your work easier and you can create more.

Ortu
DBPro Master
18
Years of Service
User Offline
Joined: 21st Nov 2007
Location: Austin, TX
Posted: 23rd Feb 2013 02:39
Quote: "If so, can you have statements like obj.property or is this possible with TYPES, something like classes? obj.parent.grandson.scale_x for example"


absolutely. in dbpro, the two main limitations to user types that you should be aware of are you cannot define a method or declare a function within the type, and a type cannot contain an array. although as chris said, an array can be of a type.

so, allowed:

obj.loc_x
obj.loc.x
obj(0).loc_x

not allowed:

obj.getLoc_x()
obj.players(0).loc_x
parents(0).children(0).loc_x

Libervurto
20
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 23rd Feb 2013 12:56
Quote: "my.health -= you.damage;"

In DBP this would be: dec my.health, you.damage


Quel
17
Years of Service
User Offline
Joined: 13th Mar 2009
Location:
Posted: 23rd Feb 2013 17:11
I've been asking people for quite a few years to tell me what the hell object oriented is... so you are saying (thread starter Nytus Sermus) it is like using UDTs (user defined types, a sort of multidimensional array but better) and calling funtions (your self written commands basically) with parameters attached?

That would be funny, because an experienced DBPro user, who actually wants to do something useful, does that all the freakin time.

-Mental Hybrid: A unique heavy story based shoot'em ~40% (primary project)
-CoreFleet: An underground commander unit based RTS (canned) ~15%
Phaelax
DBPro Master
23
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 23rd Feb 2013 18:18
Quote: " so you are saying (thread starter Nytus Sermus) it is like using UDTs (user defined types, a sort of multidimensional array but better) and calling funtions (your self written commands basically) with parameters attached?"

In the simplest way, yes objects are a UDT that have functions(or 'methods' if you're a java guy) instead of just variables. But you also have encapsulation to protect data among other capabilities.


Quote: "That would be funny, because an experienced DBPro user, who actually wants to do something useful, does that all the freakin time."

Not sure what you mean.


Say you wanted to move a player or enemy, in Java you might simply put player.move(); And you could call the move method on anything that perhaps implemented the specific interface.

To do so in DB, the function exists outside of the objects and you'd pass the object to the function as a parameter instead.




But there's still a downside. DB doesn't pass by reference, so while you could read the values from myguy, updating its variables inside the function would have no effect on it outside the function. If you need them to (as you probably would in this case) this is when you'd want to make a subroutine instead. Unless you made everything global, but no need to do that.

"You're all wrong. You're all idiots." ~Fluffy Rabbit
Nytus Sermus
13
Years of Service
User Offline
Joined: 17th Jan 2013
Location:
Posted: 23rd Feb 2013 22:13 Edited at: 14th Mar 2013 04:31
......

You could be done already.....stop trying to re-invent the wheel.
Phaelax
DBPro Master
23
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 23rd Feb 2013 23:36 Edited at: 23rd Feb 2013 23:36
Just so you know, arrays are global by default. So in my example above, if you had an array of similar objects, then rather than passing it into the function, pass it's array index instead.

Rather than using GOTO statements, use exit to escape out of a loop.

Change this:

To this:


I would also suggest using constants in place of the 202 and 301 values.

Arrays are also expandable, like the Collections framework in Java.

Here's a different method for managing your monster creation:



First, we grab the next available object number. Then we insert a new element at the end of the array. (if we did it at the beginning, all existing elements would need to be shifted down) You'll notice I didn't specify an index, and in this case we don't need to. After inserting a new element, an internal pointer points at that new index automatically.

"You're all wrong. You're all idiots." ~Fluffy Rabbit
Nytus Sermus
13
Years of Service
User Offline
Joined: 17th Jan 2013
Location:
Posted: 24th Feb 2013 00:09 Edited at: 14th Mar 2013 04:31
.............

You could be done already.....stop trying to re-invent the wheel.
Ortu
DBPro Master
18
Years of Service
User Offline
Joined: 21st Nov 2007
Location: Austin, TX
Posted: 24th Feb 2013 00:55
for your collision, sparkys plugin is really excellent, well documented, widely used, and free. it uses raycasting rather than object on object, and if you dont specify objects to check gainst, it will return whatever object is hit. can also work with object groups

Phaelax
DBPro Master
23
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 24th Feb 2013 03:10
Quote: " i know i cant possibly check all objects against eachother"

Why not?

You can either do multiple loops, or if you had an array to keep track of all your objects you could check their distance from each other. If they're within a certain distance, run a collision routine on it.

Also, there's always Box2D.

"You're all wrong. You're all idiots." ~Fluffy Rabbit
Nytus Sermus
13
Years of Service
User Offline
Joined: 17th Jan 2013
Location:
Posted: 24th Feb 2013 11:35 Edited at: 14th Mar 2013 04:32
.............................

You could be done already.....stop trying to re-invent the wheel.
Ortu
DBPro Master
18
Years of Service
User Offline
Joined: 21st Nov 2007
Location: Austin, TX
Posted: 24th Feb 2013 19:45
yes, it is 3d

Nytus Sermus
13
Years of Service
User Offline
Joined: 17th Jan 2013
Location:
Posted: 26th Feb 2013 20:39 Edited at: 14th Mar 2013 04:32
..................

You could be done already.....stop trying to re-invent the wheel.

Login to post a reply

Server time is: 2026-07-07 18:22:00
Your offset time is: 2026-07-07 18:22:00