-
Notifications
You must be signed in to change notification settings - Fork 7
Creating Your First Game
To use IntFicPy, first make sure you have Python 3 installed, and you are familiar with how to run Python files on your system. python.org has excellent resources for installing and using Python.
You also need to have the PyQt5 library installed in order to create a game with a graphical interface. Instructions for creating a terminal game will not be covered here.
All other libraries used in IntFicPy are standard.
Create a folder for your game, and copy the intficpy folder inside of it. Create a new .py file for your game.
To create a game with a graphical interface, import the following files:
import sys
from PyQt5.QtWidgets import QApplication
from intficpy.room import Room
from intficpy.thing import Thing, Surface, Container, Clothing
from intficpy.actor import Actor, Player
import intficpy.parser as parser
import intficpy.gui as gui
To create to GUI application, and set your main file, add the following code below your imports:
app = QApplication(sys.argv)
gui.Prelim(__name__)
At the bottom of your file, add the following lines to create the main screen, and start the application.
# type your game code before this
screen = app.primaryScreen()
screen = screen.size()
ex = gui.App(me)
ex.show()
sys.exit(app.exec_())
Create an instance of IntFicPy's Room class with the following syntax:
room_name = Room("Room Title", "Description to print when the player arrives in the room.")
Create a player in the room like so:
me = Player("name")
me.setPlayer()
room_name.addThing(me)
If you choose to use a variable name other than 'me', make sure to modify the argument passed to gui.App in step 3.
Warning: Do not create new items or rooms inside of loops, conditional statements, or functions as this will break the save/load system. Placing items in a room through room_name.addThing(item_name) in such constructs is permissible. IntFicPy supports dynamic creation of identical items through item_name.copyThing(). This should be safe to use pretty much anywhere.
Create items for the Room using the Thing class.
thing_name = Thing("noun")
The quoted string should be a one word noun, by which you want your players to refer to the item. For instance, call a rock "rock". You can add synonyms ("stone", "pebble") one by one with the following syntax:
rock1.addSynonym("pebble")
You can also add adjectives to your item. Pass setAdjectives a list of strings containing all adjectives you wish to apply.
rock1.setAdjectives(["round", "grey"])
Our rock will now be described as 'a round, grey rock.'
You can create any number of rooms in the same way you created the first. Connect them together by setting each room's direction properties.
forest7.east = beach2
beach2.west = forest7
Make sure to set the direction property AFTER the definition of BOTH rooms.
See examples for how to define Actors, Surfaces, Containers, and Clothing.
Game creators can embed functions inside any text that's printed during the game. This could be used to randomize descriptions, respond to an item being seen for the first time, etc. If the return value is a string, it will be printed.
def somefunc():
return "hello"
app.printToGUI("Say <<somefunc()>>")
Prints "Say hello" to the GUI
NOTE: do not pass non-object variables as arguments. You can usually create an object with a property for this.
Game creators can also have functions run every turn. This could be used to count turns, describe weather and atmosphere, etc. To create such a function, create a Python function with a single argument app, then add it to parser.daemons.
def windFunc(app):
p = random.randint(1,7)
if p>6:`<br>
app.newBox(1) # creates a new textbox with style 1
app.printToGUI("The wind whistles against the shack.")
parser.daemons.add(windFunc)
IntFicPy has many more capabilities than what's described here. Feel free to explore the source code, and the examples. IntFicPy is also still in early development, and contains bugs. In addition, some features are not yet completely implemented, and some features standard to IF are not yet implemented at all. Please check back often, as development is very rapid at this stage. Thank you! -JSMaika