Diablo 1/2 Inventory system

Started by
11 comments, last by Alex131 15 years, 3 months ago

Hi again. I don't know the language syntaxe/semantics, but let's think a little in pseudo code:


 - Create a inventoryfunction InventoryCreate (width, height)   Invbox.width=width   Invbox.height=height   Invbox.objects=NULL   Invbox.nrobjects=0    return Invboxend - Create a Objfunction ObjectCreate(some_vars_about_the_object, inv_width, inv_height, inv_image)   Obj.vars= some_vars_about_the_object   ...   ...   Obj.inv_width=inv_width   Obj.inv_height=inv_height   Obj.inv_image=inv_image   return Objend -- Add a object to a inventory on position X,Yprocedure InventoryAddObject(inv, obj, x, y)   -- check to see if it fits   if inv.width < x+ obj.inv_width return "does not fit"   if inv.height <y+ obj.inv_height return "does not fit"   for every object already in inventory       if inv_obj.x <  x+ obj.inv_width and          inv_obj.x+ inv_obj.width >= x return "does not fit"        .....        same for Y   end   inv.objects[inv.nrobjects].x=x   inv.objects[inv.nrobjects].y=y   inv.objects[inv.nrobjects].obj=obj   inv.nrobjects++end-- Now using itinv=InventoryCreate(10,5)obj=ObjectCreate("Sword", "blablabla", 1,3, "cool_sword.jpg")-- get mouse position, find that user wants to "drop a sword in the inventory", transform the X,Y screen coordinates to a inventory X,YInventoryAddObject(inv, obj, x,y)


this is was just typed without too much thinking. But it would help you sort some ideas, I hope :)

About the other question: you can post the executable, or the source code, it isn't forbiden in here. Its just a personal oppinion about posting full functional source code: users just grab it, use it, without knowing what it does or how it does it.


Advertisement
Thanks for the fast answer, but i do managed to use almost the same things as you mentioned in you code but i still haven't seen my problem solved as it is that i get undeclared identifier when i try to use my custom made TImageSprite because the procedures are before the custom classes in delphi 6. Also i need to know how can i include integers in component names as i need to name the component InventoryBox1x1 where 1x1 means that this component is on the 1st row and 1st column of the inventory. Though i think that this is impossible, maybe someone could point a more effective way for me knowing that some component belongs to some row and column by setting something in its component parameters or maybe someone could tell me how i can include 2 custom parameters to my component - InventoryBox.Column and InventoryBox.Row because this way i think i could easily manage the code by using these parameters. Though i still do not know how could i make a function to name and declare the components like InventoryBox1,InventoryBox2,InventoryBox3 and etc so that i wouldn't need to declare and create them all.
I got the idea how to make my custom component and now i can do all the calculations i need very smoothly :). The only problem i have now is to make a function/procedure which can declare and name my components, something like i said in my previous post InventoryBox1,InventoryBox2,InventoryBox3 and etc. I hope someone will come with an idea how to make this in delphi 6 :).


Edit 1: I'm so stupid, i forgot that i can make an array not only of numbers but of custom components as well :). I think i will be able to show some executable soon :).

[Edited by - Alex131 on January 17, 2009 12:33:55 AM]

This topic is closed to new replies.

Advertisement