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 / item inventory

Author
Message
Tattered brush
15
Years of Service
User Offline
Joined: 1st Dec 2008
Location:
Posted: 2nd Apr 2009 22:52
Hi guys

Please take a look at the image provided to give you an insight into what I am trying to achieve.

I want to create an inventory which only allows 4 items to be carried at once.

When the player collides with an item it is added to position 1 in the inventory, all other items are shifted to the next position.

If the inventory was full, item in position 4 is dropped to the ground.

Can anyone advise me on how I can code this or if there are any tutorials that can help me to achieve this?

Attachments

Login to view attachments
Virtual Nomad
Moderator
18
Years of Service
User Offline
Joined: 14th Dec 2005
Location: SF Bay Area, USA
Posted: 3rd Apr 2009 00:31 Edited at: 9th Dec 2010 04:13
this should help:


specifically, the quick array sort:

and the showinventory subroutine/how i'd display the items:


sorry for the sprite generation, and extra code, etc, but a working app helps me make sure my suggestions function as intended

added lang=dbp formatting

Virtual Nomad @ California, USA . DBPro V7.5
AMD Phenomâ„¢ X4 9750 Quad-Core @ 2.4 GHz . 8 GB PC2-6400 RAM
ATI Radeon HD 3650 @ 512 MB . Vista Home Premium 64 Bit
Tattered brush
15
Years of Service
User Offline
Joined: 1st Dec 2008
Location:
Posted: 3rd Apr 2009 10:40
Thanks for your help, it's good to see a working example although it's a bit confusing for me, but that's down to my inexperience in coding rather than your code.

It's exactly what I was looking for, just need to play about with it to understand it, thanks again.
Tattered brush
15
Years of Service
User Offline
Joined: 1st Dec 2008
Location:
Posted: 3rd Apr 2009 17:30
If I wanted the object to be picked up when the control key was pressed for example, rather than an automatic pick up, how would I code this.

Also, say for example, there is one object in the inventory, and the player is not standing next to an object. When the player presses the control key I want the item to move to the next space in the inventory with nothing in the one previous. How would I code this please?
Virtual Nomad
Moderator
18
Years of Service
User Offline
Joined: 14th Dec 2005
Location: SF Bay Area, USA
Posted: 3rd Apr 2009 21:10 Edited at: 9th Dec 2010 04:19
the first part is easy. in the main loop, only call the collision subroutine if the control key is pressed:


then, we'll add a second function to the routine that cycles the inventory if there's nothing to pick up using else. here's the new "collision" subroutine:

note the addition of the lastcycle time-stamp in both places and the else functionality.

here's the complete code:


pasting all this now. gonna add some more comments in a minute...

ok, back/more:

the way it is now, if you cycle the inventory (without picking up a new item), item 4 (if it exists) will be dropped when a new one is picked up. if you want to see, instead, if there's a free slot to move it to before dropping it (or any other functionality), i'll let you try to work that out on your own. give it a shot and come back with questions if you have any.

added lang=dbp

Virtual Nomad @ California, USA . DBPro V7.5
AMD Phenomâ„¢ X4 9750 Quad-Core @ 2.4 GHz . 8 GB PC2-6400 RAM
ATI Radeon HD 3650 @ 512 MB . Vista Home Premium 64 Bit
Tattered brush
15
Years of Service
User Offline
Joined: 1st Dec 2008
Location:
Posted: 4th Apr 2009 16:02
Thanks alot for your help, you've given me alot to go on and it's slowly beginning to sink in. Thanks again!

Login to post a reply

Server time is: 2024-11-24 09:37:23
Your offset time is: 2024-11-24 09:37:23