A problem with real-time thingy

Post your coding questions such as 'how to' here.
Post Reply
WinKIller0
Newcomer
Posts: 17
Joined: Mon Feb 09, 2009 8:07 am
Location: Ikaalinen, Finland

A problem with real-time thingy

Post by WinKIller0 »

Heya all, I've been working on a RPG with diablo & elder scrolls stylish attitude but now I've encountered a show stopper for me at least. The problem is that I'm not able to do for an example wolfs to the game with HP, collisions and such. I know it should be done with types somehow but I haven't yet realised how, could someone please help me?


tl/dr: How can I make multiple moobs with loot table/hp/exp with minium on code?


Thanks in advance :)
otto90x
Advanced Member
Posts: 349
Joined: Mon Aug 27, 2007 9:00 pm
Location: Lapinjärvi, Finland
Contact:

Re: A problem with real-time thingy

Post by otto90x »

WinKIller0 wrote:tl/dr: How can I make multiple moobs with loot table/hp/exp with minium on code?
Yeah, types should do it. You could make a type for all monsters. Something like this.

Code: Select all

Type Monster
    field obj
    field monstertype$
    field hp
End Type
Note that every monster instance of this type has variables assigned after word field. So if we make a monster it has same variables as written in fields.

Code: Select all

a.monster = new(monster) // note that colon . is used on creation and for - each loop, but backslash \  is used with variables (fields)
a\obj = loadobject("wolf.bmp") // a is the address of this instance
a\hp = 100
a\monstertype = "wolf" 
If you want more monsters at once, just put monster creation code (above) in for next loop like this:

Code: Select all

for i=1 to 5 
    a.monster = new(monster) 
    a\obj = loadobject("wolf.bmp")
    a\hp = 100
    a\monstertype = "wolf"
next i


If you add fields, you'll get more variables to each type instance (monster). Inventory table can be done with memoryblocks. Two dimensional integer array consisting id-number and quantity of item or more, whatever pleases you.

Going through all monsters is easy.

Code: Select all

for a.monster = each monster
    //we could check if hp=0 then delete monster
    if a\hp <= 0 then 
        //remember to remove object before type instance
        deleteobject a\obj
        delete a
    endif
    //after deletion or possible deletion you shouldn't use instance's variables.
    //eg. moveobject a\obj,1 will cause Memory access violation if some
    //monster runs out of hitpoints.

next a //a, address, changes to address to next monster
However this isn't very efficient if we want lots of different monsters and want to create them on the fly. I suggest that we make a database of monster data which can be read from other file. This allows us to balance hitpoints and such even after compilation. So I'd make folder with configuration files which have all basic values of each monstertype. More about configuration files (reading and writing) here.

Wolf.cgf could look like this:

Code: Select all

name=Wolf
hp=100
object=media/monsters/wolf.bmp
So I would do a function which loads all data into monsterdata type and then I'd make a function which makes new monster and assigns correct values from monsterdata type to new instance of monster type.

I'm sorry there isn't much official English help available.
Last edited by otto90x on Mon Feb 16, 2009 12:31 pm, edited 1 time in total.
Otto Martikainen a.k.a. MetalRain, otto90x, kAATOSade.
Runoblogi, vuodatusta ja sekoiluja.
WinKIller0
Newcomer
Posts: 17
Joined: Mon Feb 09, 2009 8:07 am
Location: Ikaalinen, Finland

Re: A problem with real-time thingy

Post by WinKIller0 »

Thanks for your reply I've made a good progress with this.I'll see if I get everything working as they should and then I could release it perhaps :)


thanks again and best wishes:
-WinKIller0

Edit: Lack of help files don't really bother me as long as there's some place I can ask for help
tuhoojabotti
Advanced Member
Posts: 485
Joined: Tue Aug 28, 2007 3:53 pm
Location: Suomi, Finland
Contact:

Re: A problem with real-time thingy

Post by tuhoojabotti »

Here is English manual! It's not as good as the finnish one, but it has some references about the language and the commands. *Click* replace folder "X:\program files\Coolbasic\help" with that (rename it to help).
Imagedev.tuhoojabotti.com — “Programmer (noun): An organism that turns caffeine into code.”
Post Reply