Author Topic: Inventory System  (Read 5363 times)

0 Members and 1 Guest are viewing this topic.

Offline collechess

  • LV3 Member (Next: 100)
  • ***
  • Posts: 93
  • Rating: +22/-2
    • View Profile
Inventory System
« on: November 18, 2011, 05:56:49 pm »
How would one design an inventory system in axe?  I want to be able to easily add and change items and I want each item to have a name, description, type, and 8x8 sprite.  I don't want to just use a lot of if loops.

Offline ben_g

  • Hey cool I can set a custom title now :)
  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1002
  • Rating: +125/-4
  • Asm noob
    • View Profile
    • Our programmer's team: GameCommandoSquad
Re: Inventory System
« Reply #1 on: November 18, 2011, 06:49:21 pm »
Inventories aren't that hard to make. You just start with a location to store the data to. Here, I'll use L1, but you can store it to any location you like.

Now, We decide how many spaces we want. Here, I'll use an inventory 4 items wide (32 pixels) and 6 items tall (48 pixels). This will give us an inventory which can carry 24 items, So we'll need 24 bytes to store them (or 12, if a maximum of 16 items is enough for you).

An inventory doesn't contains any information about the items themselves, only the 'ID' of the item, So now we store the items themselves:
This is the way I'd use to store the items: (there might and probably is a more optimised way to do this)

Code: [Select]
.the sprite
[FF00FF00FF00FF00] -> GDB0 .only do the -> GDB0 in the first item
[00] .type of item
[Str000] .pointer to the string containing the name of the item
[Str001] .pointer to string containing the description

.repeat for other items
Now we have the data of the items, and a place to store which items are carried. Now we just need some code to make it useful:

Code: [Select]
.Here we'll make the inventory ready to use
for(T,0,23)
0->{T+L1}
End
.this made the inventory empty, so we won't end up with random items when the game starts

Code: [Select]
.Now we add an item,of which the ID is stored in A, to the inventory
0->T
while(T<24)
if({T+L1}=0
A -> {T+L1}
0->A
24->T
End
T++
End
.I made it so that when the item could be placed in the inventory, A is set to 0. If it couldn't store it becouse the inventory was full, A would still have the original value.

Code: [Select]
.What can also be useful is checking if the inventory contains an item. The ID of the item should be stored to A
0->T
While(T<24)
if({T+L1}=A)
...
.remove those 3 dots and those below the code if you want to delete the item when it's found
0->{T+L1}
...
0->A
24->T
End
T++
End
.A will be 0 when the item was found and will still contian it's original value when it couldn't find the item.

Code: [Select]
.Unless your game is entirely text-based, a way to draw the inventory is also useful
For(T,0,5)
For(U,0,3)
If(4*T+U) .If there is an item here
Pt_On(U*8+X,T*8+Y,4*T+U*13+L1) .you can use any sprite drawing routine you want
End
End
End
.Guess what X and Y are
.Correct: They are the X and Y coordinates on which the inventory should be drawn.

I hope this helped. Sorry, but none of the code is tested.
« Last Edit: November 18, 2011, 06:51:50 pm by ben_g »
My projects
 - The Lost Survivors (Unreal Engine) ACTIVE [GameCommandoSquad main project]
 - Oxo, with single-calc multiplayer and AI (axe) RELEASED (screenshot) (topic)
 - An android version of oxo (java)  ACTIVE
 - A 3D collision detection library (axe) RELEASED! (topic)(screenshot)(more recent screenshot)(screenshot of it being used in a tilemapper)
Spoiler For inactive:
- A first person shooter with a polygon-based 3d engine. (z80, will probably be recoded in axe using GLib) ON HOLD (screenshot)
 - A java MORPG. (pc) DEEP COMA(read more)(screenshot)
 - a minecraft game in axe DEAD (source code available)
 - a 3D racing game (axe) ON HOLD (outdated screenshot of asm version)

This signature was last updated on 20/04/2015 and may be outdated

Offline collechess

  • LV3 Member (Next: 100)
  • ***
  • Posts: 93
  • Rating: +22/-2
    • View Profile
Re: Inventory System
« Reply #2 on: November 21, 2011, 10:14:40 am »
Thanks. I don't really understand the drawing part though.  What is the Ux13 for?

Offline ben_g

  • Hey cool I can set a custom title now :)
  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1002
  • Rating: +125/-4
  • Asm noob
    • View Profile
    • Our programmer's team: GameCommandoSquad
Re: Inventory System
« Reply #3 on: November 21, 2011, 02:51:43 pm »
Thanks. I don't really understand the drawing part though.  What is the Ux13 for?
the U*13 part (which is actually (4*T+U)*13) is because every item is 13 bytes long.

BTW: the pointer to the name is ID*13+9 and to the description is ID*13+11

If there is still anything that I didn't explain well, just ask
My projects
 - The Lost Survivors (Unreal Engine) ACTIVE [GameCommandoSquad main project]
 - Oxo, with single-calc multiplayer and AI (axe) RELEASED (screenshot) (topic)
 - An android version of oxo (java)  ACTIVE
 - A 3D collision detection library (axe) RELEASED! (topic)(screenshot)(more recent screenshot)(screenshot of it being used in a tilemapper)
Spoiler For inactive:
- A first person shooter with a polygon-based 3d engine. (z80, will probably be recoded in axe using GLib) ON HOLD (screenshot)
 - A java MORPG. (pc) DEEP COMA(read more)(screenshot)
 - a minecraft game in axe DEAD (source code available)
 - a 3D racing game (axe) ON HOLD (outdated screenshot of asm version)

This signature was last updated on 20/04/2015 and may be outdated

Offline collechess

  • LV3 Member (Next: 100)
  • ***
  • Posts: 93
  • Rating: +22/-2
    • View Profile
Re: Inventory System
« Reply #4 on: November 21, 2011, 03:38:39 pm »
I seem to be something wrong, as it won't compile.  An invalid token error.  Here is the source.
Code: [Select]
.INVNTRY
"SWORD"->Str00
"10 DAMAGE"->Str10
"POTION"->Str01
"+20 HP"->Str11
"PEAR"->Str02
"+20 MP"->Str12

[03050A94E870F0D8]->GDB0
[01]
[Str00]
[Str10]
[181824244242423C]
[00]
[Str01]
[Str11]
[0C1028284482827C]
[00]
[Str02]
[Str12]

For(T,0,23)
1ü{T+L‚}
End
Repeat getKey(15)
sub(DRAW
DispGra
End
Lbl ADD
0->r6
While (r6<24)
!If {r6+L2}
r1->{r6+L2}
24->T
End
T++
End
Return
Lbl DRAW
For(T,0,5)
For(U,0,3)
If ({4*T+U+L2})
Pt-On(U*8,T*8,(4*T+U+{L2})*13-13+GDB0
End
End
End
Return

Edit:Nevermind, I have it working now.
« Last Edit: November 21, 2011, 10:27:12 pm by collechess »

Offline collechess

  • LV3 Member (Next: 100)
  • ***
  • Posts: 93
  • Rating: +22/-2
    • View Profile
Re: Inventory System
« Reply #5 on: November 22, 2011, 09:58:48 am »
I understand how to do the picture inventory now, but it doesn't really suit my game.   How would you create an inventory that just showed the names of items and scrolled, and when an item is selected, it shows more info?  Also, how can you create a maximum unique item count?

Offline ben_g

  • Hey cool I can set a custom title now :)
  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1002
  • Rating: +125/-4
  • Asm noob
    • View Profile
    • Our programmer's team: GameCommandoSquad
Re: Inventory System
« Reply #6 on: November 24, 2011, 03:43:50 pm »
I understand how to do the picture inventory now, but it doesn't really suit my game.   How would you create an inventory that just showed the names of items and scrolled, and when an item is selected, it shows more info?  Also, how can you create a maximum unique item count?
that's even easyer: you just create a list again which is the same sixe as the (maximum) number of items. Then you make everything 0 again at the start of the game. To get the name of an item, just do ID*13+9 and to get the description is ID*13+11 (those are the pointers). You can easily check before drawing the string if you reached the end.
My projects
 - The Lost Survivors (Unreal Engine) ACTIVE [GameCommandoSquad main project]
 - Oxo, with single-calc multiplayer and AI (axe) RELEASED (screenshot) (topic)
 - An android version of oxo (java)  ACTIVE
 - A 3D collision detection library (axe) RELEASED! (topic)(screenshot)(more recent screenshot)(screenshot of it being used in a tilemapper)
Spoiler For inactive:
- A first person shooter with a polygon-based 3d engine. (z80, will probably be recoded in axe using GLib) ON HOLD (screenshot)
 - A java MORPG. (pc) DEEP COMA(read more)(screenshot)
 - a minecraft game in axe DEAD (source code available)
 - a 3D racing game (axe) ON HOLD (outdated screenshot of asm version)

This signature was last updated on 20/04/2015 and may be outdated

Offline Jonius7

  • python! Lua!
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1918
  • Rating: +82/-18
  • Still bringing new dimensions to the TI-nspire...
    • View Profile
    • TI Stadium
Re: Inventory System
« Reply #7 on: November 24, 2011, 06:37:58 pm »
I could probably do this in TI-basic and Casio Basic. And I'd better get used to Axe cuz Im still kinda a beginner.
Programmed some CASIO Basic in the past
DJ Omnimaga Music Discographist ;)
DJ Omnimaga Discography
My Own Music!
My Released Projects (Updated 2015/05/08)
TI-nspire BASIC
TI-nspire Hold 'em
Health Bar
Scissors Paper Rock
TI-nspire Lua
Numstrat
TI-nspire Hold 'em Lua
Transport Chooser
Secret Project (at v0.08.2 - 2015/05/08)
Spoiler For Extra To-Be-Sorted Clutter:

Spoiler For Relegated Projects:
TI-nspire BASIC
Battle of 16s (stalled) | sTIck RPG (stalled) | Monopoly (stalled) | Cosmic Legions (stalled)
Axe Parser
Doodle God (stalled while I go and learn some Axe)