-
Notifications
You must be signed in to change notification settings - Fork 17
Items that can change size
For The House of Highfield Lane, I create a system that would allow the player to shrink or grow any item. This is a complex system, and I thought it worth looking at his it was done.
The system comprises two rooms; a big one and a little. Drop something in the little room, go to the big room and the item is now about ten times the size. This means that pretty much anything in the game that can be picked up can change its size, and can do so repeatedly. There is a natural limit to do big or small a thing can get. Ultimately it will be too heavy to pick up or just to smaller to grab.
The very basics of the system: I am going to use the "size" attribute to track size, and all items will start at 5, and will typically go down to 3 and up to 7, but will vary - these will be stored as "minSize" and "maxSize".
A very important consideration in a system like this is making it easy to use for the author. Do all the tricky stuff once, test it well, and then apply it to all those items. The best way to do that is often a template. But before we get to that, we want to think about the bare minimum we want to put in our items.
Here, as an example, is a phone. We will need t give it the SIZE_CHANGING, and it will need a number of descriptions, but we do not want to have to do anything besides that. Let the template do the rest.
createItem("mobile_phone", SIZE_CHANGING(), {
loc:"school_bag",
synonyms:['cell phone', 'buttons'],
use:function() {
//...
},
desc5:"Mandy looks at her phone. It is soooo old. It even has buttons!",
desc4:"Mandy's phone is now tiny.",
desc3:"Mandy's phone is so small she could hardly see it.",
desc6:"Mandy's phone is now not only way out of date, but also too big to easily carry.",
})
So now we can create a template. This starts from TAKEABLE, and sets some defaults. The "afterCreation" function runs after the item is created, and is used because the template itself has no access to the attributes set by the author. This function, on the other hand, does, so can check what descriptions are set, and set minSize and maxSize based on that.
The template also overrides "take" and "examine", and also defines new "shrink" and "grow" functions.
const SIZE_CHANGING = function() {
const res = Object.assign({}, TAKEABLE_DICTIONARY)
res.size_changing = true
res.size = 5
res.minsize = 4
res.maxsize = 6
res.afterCreation = function(o) {
o.basealias = o.alias
if (!o.desc5) log("WARNING: Size changer " + o.name + " has no desc5.")
if (o.desc4) o.minsize = 3
if (o.desc3) o.minsize = 2
if (o.desc2) o.minsize = 1
if (o.desc1) o.minsize = 0
if (o.desc6) o.maxsize = 7
if (o.desc7) o.maxsize = 8
if (o.desc8) o.maxsize = 9
if (o.desc9) o.maxsize = 10
}
res.examine = function(options) {
if (this.size === this.minsize) {
msg("{nv:item:be:true} too tiny to see properly!", {item:this})
}
else if (this.size === this.maxsize) {
msg("{nv:item:be:true} of gigantic proportions!", {item:this})
}
else {
msg(this['desc' + this.size])
}
return true
}
res.take = function(options) {
if (this.isAtLoc(options.char.name)) {
return falsemsg(lang.already_have, options)
}
if (!options.char.canManipulate(this, "take")) return false
if (this.size === this.maxsize) {
return falsemsg("{nv:item:be:true} far too big to pick up.", {item:this})
}
else if (this.size === this.minsize) {
return falsemsg("Mandy tries to pick up {nm:item:the}, but {pv:item:be} too tiny for her fingers to grasp.", {item:this})
}
msg(this.msgTake, options)
this.moveToFrom(options, "name", "loc")
if (this.scenery) this.scenery = false
return true
}
res.shrink = function() {
this.size--
this.setAlias(this.size === 5 ? this.basealias : sizeAdjectives[this.size] + ' ' + this.basealias)
if (this.afterSizeChange) this.afterSizeChange()
}
res.grow = function() {
this.size++
this.setAlias(this.size === 5 ? this.basealias : sizeAdjectives[this.size] + ' ' + this.basealias)
if (this.afterSizeChange) this.afterSizeChange()
}
return res;
}
Here are the tests I created.
test.title("Shrink/grow phone")
test.assertEqual(true, w.mobile_phone.size_changing)
test.assertEqual(7, w.mobile_phone.maxsize)
test.assertEqual(2, w.mobile_phone.minsize)
w.mobile_phone.shrink()
test.assertEqual('small mobile phone', w.mobile_phone.alias)
test.assertOut(["Mandy's phone is now tiny."], function() {
w.mobile_phone.examine(player, {})
})
test.assertOut(["Mandy looks at her shrunken phone. Maybe it was a bit optimistic thinking it would now be charged, just because it is so much smaller."], function() {
w.mobile_phone.use(player, {})
})
w.mobile_phone.shrink()
test.assertEqual('tiny mobile phone', w.mobile_phone.alias)
test.assertOut(["Her stupid phone is now too small to use!"], function() {
w.mobile_phone.use(player, {})
})
w.mobile_phone.grow()
w.mobile_phone.grow()
test.assertEqual('mobile phone', w.mobile_phone.alias)
test.assertOut(["Mandy looks at her phone. 'Shit.' No charge left. She only charged it last night... No, wait, she had found it on her bedroom floor this morning. 'Shit,' she says again."], function() {
w.mobile_phone.use(player, {})
})
w.mobile_phone.grow()
test.assertEqual('big mobile phone', w.mobile_phone.alias)
test.assertOut(["Her stupid phone is now too big to use!"], function() {
w.mobile_phone.use(player, {})
})
w.mobile_phone.shrink()
Tutorial
- First steps
- Rooms and Exits
- Items
- Templates
- Items and rooms again
- More items
- Locks
- Commands
- Complex mechanisms
- Uploading
QuestJS Basics
- General
- Settings
- Attributes for items
- Attributes for rooms
- Attributes for exits
- Naming Items and Rooms
- Restrictions, Messages and Reactions
- Creating objects on the fly
- String Functions
- Random Functions
- Array/List Functions
- The
respond
function - Other Functions
The Text Processor
Commands
- Introduction
- Basic commands (from the tutorial)
- Complex commands
- Example of creating a command (implementing SHOOT GUN AT HENRY)
- More on commands
- Shortcut for commands
- Modifying existing commands
- Custom parser types
- Note on command results
- Meta-Commands
- Neutral language (including alternatives to "you")
- The parser
- Command matching
- Vari-verbs (for verbs that are almost synonyms)
Templates for Items
- Introduction
- Takeable
- Openable
- Container and surface
- Locks and keys
- Wearable
- Furniture
- Button and Switch
- Readable
- Edible
- Vessel (handling liquids)
- Components
- Countable
- Consultable
- Rope
- Construction
- Backscene (walls, etc.)
- Merchandise (including how to create a shop)
- Shiftable (can be pushed from one room to another)
See also:
- Custom templates (and alternatives)
Handing NPCs
- Introduction
- Attributes
- Allowing the player to give commands
- Conversations
- Simple TALK TO
- SAY
- ASK and TELL
- Dynamic conversations with TALK TO
- TALK and DISCUSS
- Following an agenda
- Reactions
- Giving
- Followers
- Visibility
- Changing the player point-of-view
The User Experience (UI)
The main screen
- Basics
- Printing Text Functions
- Special Text Effects
- Output effects (including pausing)
- Hyperlinks
- User Input
The Side Panes
Multi-media (sounds, images, maps, etc.)
- Images
- Sounds
- Youtube Video (Contribution by KV)
- Adding a map
- Node-based maps
- Image-based maps
- Hex maps
- Adding a playing board
- Roulette!... in a grid
Dialogue boxes
- Character Creation
- Other example dialogs [See also "User Input"]
Other Elements
- Toolbar (status bar across the top)
- Custom UI Elements
Role-playing Games
- Introduction
- Getting started
- Items
- Characters (and Monsters!)
- Spawning Monsters and Items)
- Systema Naturae
- Who, When and How NPCs Attack
- Attributes for characters
- Attacking and guarding
- Communicating monsters
- Skills and Spells
- Limiting Magic
- Effects
- The Attack Object
- [Extra utility functions](https://github.com/ThePix/QuestJS/wiki/RPG-Library-%E2%80%90-Extra Functions)
- Randomly Generated Dungeon
- Quests for Quest
- User Interface
Web Basics
- HTML (the basic elements of a web page)
- CSS (how to style web pages)
- SVG (scalable vector graphics)
- Colours
- JavaScript
- Regular Expressions
How-to
Time
- Events (and Turnscripts)
- Date and Time (including custom calendars)
- Timed Events (i.e., real time, not game time)
Items
- Phone a Friend
- Using the USE verb
- Display Verbs
- Change Listeners
- Ensembles (grouping items)
- How to spit
Locations
- Large, open areas
- Region,s with sky, walls, etc.
- Dynamic Room Descriptions
- Transit system (lifts/elevators, buses, trains, simple vehicles)
- Rooms split into multiple locations
- Create rooms on the fly
- Handling weather
Exits
- Alternative Directions (eg, port and starboard)
- Destinations, Not Directions
Meta
- Customise Help
- Provide hints
- Include Achievements
- Add comments to your code
-
End The Game (
io.finish
)
Meta: About The Whole Game
- Translate from Quest 5
- Authoring Several Games at Once
- Chaining Several Games Together
- Competition Entry
- Walk-throughs
- Unit testing
- Debugging (trouble-shooting)
Releasing Your Game
Reference
- The Language File
- List of settings
- Scope
- The Output Queue
- Security
- Implementation notes (initialisation order, data structures)
- Files
- Code guidelines
- Save/load
- UNDO
- The editor
- The Cloak of Darkness
- Versions
- Quest 6 or QuestJS
- The other Folders
- Choose your own adventure