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.

AppGameKit Classic Chat / Implementing a random treasure chest

Author
Message
anwserman
12
Years of Service
User Offline
Joined: 20th May 2011
Location: Wisconsin
Posted: 7th Feb 2012 09:06
In my app -which is a tile based game - im trying to come up with how to generate the contents of my treasure boxes. I have the collision detection set, but the part of storing what goes in what box is confusing me.

Each tile i programmed a 'TAG' value that i can set and edit. Im just confused on how to effeciently use this string value. Preferably, each treasure chest would vary in values (randomness).

Items that can be in a chest:
*Gems
*Whips
*Potions
*Traps
*Switches

Any suggestions? My best idea so far involves storing a string with delimiters and splitting it to get its values:
5:9:G;3:7:W;0:1;0:0T

First number is min value, second is max, third is item type....

Hi there. My name is Dug. I have just met you, and I love you.
baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 7th Feb 2012 11:09 Edited at: 7th Feb 2012 11:10
Use a UDT array with set to your map size:
IE.


bitJericho
21
Years of Service
User Offline
Joined: 9th Oct 2002
Location: United States
Posted: 7th Feb 2012 15:18 Edited at: 7th Feb 2012 15:21
Generally you don't want to work with strings except to output to the user, (because arrays are slow, require parsing, can't randomly pick a string from a group of strings without a boatload of code). In developing, I use constants to give meaningful names to specific pieces of data.

#constant gold 1
#constant doubloons 2
#constant emeralds 3

map[x,y].treasure = gold

map[x,y].treasure = random(1,3) //random treasure!

map[x,y].quantity = random(1,5)

Do you need multiple things in one chest? AppGameKit doesn't offer arrays in types, so something like that would be really cumbersome to implment, but you could setup another array with the first element being the number of chests on the map, the second number is the "slot" in the chest that an item can reside in... like this

map[x,y].chest = chest_number
map_chests[chest_number, slot_number).treasure = gold

kamac
13
Years of Service
User Offline
Joined: 30th Nov 2010
Location: Poland
Posted: 7th Feb 2012 16:08
Quote: "AGK doesn't offer arrays in types,"


I'd say AGK's Tier 1. Tier 2 ofcourse does.

Like that (C++):



Then just put this somewhere:



This reminds me why I prefer C++

Login to post a reply

Server time is: 2024-05-06 10:29:40
Your offset time is: 2024-05-06 10:29:40