Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
An equipment screen for my RPG game
#1
Brick 
Hello team!

Here is my first message on this forum.
I have been asking a few questions on the Discord and thanks to people, I have been able to get this far, but this one requires a forum post.

First of all, I would like to mention that I'm quite a beginner and that I have still a lot to learn - and I'm eager to.

I am currently programming a survival text-based game with RPG elements.
It is basically a loop, with several SELECT CASE. Many functionalities are already in place and working properly : status bars, exploration, building, crafting etc...
There is also a draft for an inventory system, basically only displaying owned items (no interaction with them yet).
I programmed a simple combat system as well, however for it to be fully-fledged, I would need an equipment screen to add weapons and armor which add damage and defense in order to defeat stronger enemies.

This equipment screen would be comprised of about 6 slots, with two-handed weapons taking two slots at once and would look like that :

Code: (Select All)

FUNCTION equipScreen()
  CLS
  PRINT "Equipment Screen"
  PRINT "  [Right Hand] " 'here maybe show the variables of the equipment ? equipmentname; equipmentdamage; equipmentdefense; equipmentdurability ?
  PRINT "  [Left Hand] "
  PRINT "  [Gloves] "
  PRINT "  [Armor] "
  PRINT "  [Shoes] "
  PRINT "  [Helmet] "
  PRINT
  PRINT "  (E)quip  (U)nequip  (B)ack"
END FUNCTION


For that, I think I would need arrays, but I don't know in which category to put what and what.
Here is the code I have so far. Let me know how I could improve it, as it doesn't work at the moment.
Would you know what I'm missing/doing wrong, please? I receive the error "Illegal SUB/FUNCTION parameter". I think I'm confused between all those variables, TYPEs and Arrays Undecided
 
Thank you in advance for your help!

Code: (Select All)

DIM enemy (20) as STRING  '----- DIM Array or Type?
DIM Shared playername as STRING
DIM Shared damage as INTEGER
DIM Shared defense as INTEGER
DIM Shared health as INTEGER

'base combat stats
playername = ""
damage = 2
defense = 0
health = 100

DIM equip(50) AS equipment '----- DIM Array or Type?

'TYPE equipment                 ' -------Type or DIM Array ?
 ' shownname AS STRING
  'damage AS INTEGER
  'defense AS INTEGER
  'durability AS INTEGER
  'slot AS INTEGER
'END TYPE

dim rabbitname as string 'rabbit enemy ---------- Shall I perhaps use a TYPE for "enemy" ?
dim rabbitdamage as integer
dim rabbitdefense as integer
dim rabbithealth as integer
rabbitname = "Rabbit"
rabbitdamage = 2
rabbitdefense = 0
rabbithealth = 6
dim crabname as string 'crab enemy
dim crabdamage as integer
dim crabdefense as integer
dim crabhealth as integer
crabname = "Crab"
crabdamage = 3
crabdefense = 1
crabhealth = 6

TYPE equipment
  equipmentname AS STRING
  equipmentdamage AS INTEGER
  equipmentdefense AS INTEGER
  equipmentdurability AS INTEGER
END TYPE

bonespear.equipmentname = "Bone spear" ' ---------- Will this work with TYPE ?
bonespear.equipmentdamage = 2
bonespear.equipmentdefense = 0
bonespear.equipmentdurability = 20
bonespearcount = 0

flintspear.equipmentname = "Flint spear"
flintspear.equipmentdamage = 4
flintspear.equipmentdefense = 0
flintspear.equipmentdurability = 30
flintspearcount = 0

copperspear.equipmentname = "Copper spear"
copperspear.equipmentdamage = 6
copperspear.equipmentdefense = 0
copperspear.equipmentdurability = 40
copperspearcount = 0

ironspear.equipmentname = "Iron spear"
ironspear.equipmentdamage = 8
ironspear.equipmentdefense = 0
ironspear.equipmentdurability = 50
ironspearcount = 0

stoneaxe.equipmentname = "Stone axe"
stoneaxe.equipmentdamage = 1
stoneaxe.equipmentdefense = 1
stoneaxe.equipmentdurability = 20
stoneaxecount = 0

copperaxe.equipmentname = "Copper axe"
copperaxe.equipmentdamage = 3
copperaxe.equipmentdefense = 2
copperaxe.equipmentdurability = 35
copperaxecount = 0

ironaxe.equipmentname = "Iron axe"
ironaxe.equipmentdamage = 4
ironaxe.equipmentdefense = 4
ironaxe.equipmentdurability = 50
ironaxecount = 0



After that, I would need several more FUNCTIONs I guess, to select equipment, see its stats, put it in a slot, see the new player stats and remove it from the slots.

I have tried to write the code for that, but I don't understand what I'm really doing, as I don't know if I should use TYPE or DIM Arrays, and in what order.

Code: (Select All)


DIM slot as INTEGER

FUNCTION displayEquipment()
  PRINT "Equipment:"
  PRINT "  Weapon: "; equip(0).shownname; " (Damage: "; equip(0).damage; ", Defense: "; equip(0).defense; ", Durability: "; equip(0).durability; ")"
  PRINT "  Left Hand: "; equip(1).shownname ; " (Damage: "; equip(1).damage; ", Defense: "; equip(1).defense; ", Durability: "; equip(1).durability; ")"
  PRINT "  Gloves: "; equip(2).shownname ; " (Damage: "; equip(2).damage; ", Defense: "; equip(2).defense; ", Durability: "; equip(2).durability; ")"
  PRINT "  Armor: "; equip(3).shownname ; " (Damage: "; equip(3).damage; ", Defense: "; equip(3).defense; ", Durability: "; equip(3).durability; ")"
  PRINT "  Shoes: "; equip(4).shownname ; " (Damage: "; equip(4).damage; ", Defense: "; equip(4).defense; ", Durability: "; equip(4).durability; ")"
  PRINT "  Helmet: "; equip(5).shownname ; " (Damage: "; equip(5).damage; ", Defense: "; equip(5).defense; ", Durability: "; equip(5).durability; ")"
END FUNCTION

FUNCTION equipItem (slot AS INTEGER, item AS equipment)
  ' Equip the item in the specified slot
  equip(slot) = item
END FUNCTION

FUNCTION unequipItem(slot AS INTEGER)
  ' Unequip the item in the specified slot
  equip(slot).name = ""
  equip(slot).damage = 0
  equip(slot).defense = 0
  equip(slot).durability = 0
END FUNCTION

DIM equipmentchoice$                   'AS STRING in that case
DIM selectedSlot AS INTEGER
DIM selectedItem AS eqItem

initEquip()

DO
  equipScreen()
  INPUT "Enter your choice: "; equipmentchoice$

  SELECT CASE equipmentchoice$
    CASE "E"
      INPUT "Enter the slot number: "; selectedSlot
      IF selectedSlot >= 0 AND selectedSlot < 6 THEN
        INPUT "Enter the item number: "; selectedItem
        equipItem(selectedSlot, selectedItem)
      END IF

    CASE "U"
      INPUT "Enter the slot number: "; selectedSlot
      IF selectedSlot >= 0 AND selectedSlot < 6 THEN
        unequipItem(selectedSlot)
      END IF

    CASE "B"
      EXIT DO
  END SELECT

  displayEquipment()
LOOP



Reply


Messages In This Thread
An equipment screen for my RPG game - by Delsus - 03-26-2024, 09:41 AM



Users browsing this thread: 1 Guest(s)