Source

TextRPG / simple_story.py

#!/usr/bin/env python
# encoding: utf-8


from rpg_lib.avatarsay import *

# der Befehl avatarsay überprüft auch akfavtterm,
# aber bei einer Gruppe von Aufrufen kann man so etwas Zeit sparen
if akfavtterm:
  avatarsay("datadir media") # should better be an absolute path
  avatarsay("title simple story")
  avatarsay("backgroundcolor #605030")
  avatarsay("scrolling on")
  avatarsay("size 2, 30")

from rpg_lib.textrpg import *

hero = Char() # a generic human :)
peasant = Char(template=True) # A random human with random name. 
enemy = Char() # another generic human :)

#avatarsay("slow on")
avatarsay("size 3, 45")
story("""Welcome to the world of easy RPG scripting. 

I hope you enjoy your stay!
""")

# empty is sometimes needed, when you want to move in later
avatarsay("empty")
avatarsay("avatarimage hero")
avatarsay("move in")
avatarsay("size 6, 65")
hero.say("""And welcome from me, too!
I hope we'll be able to go adventuring, soon!
besides: I'm Darjad Merejn.""")

hero.name = "Darjad Merejn"

name = hero.ask("""So now you know my name. 
Would you tell me yours?""")

while not name: 
    name = hero.ask("""Please tell me your name.""")

player = Char(source="tag:1w6.org,2008:" + name)

avatarsay("avatarimage hero")
avatarsay("height 1")
hero.say("So this time in style: Welcome " + player.name + "!")

avatarsay("empty")
avatarsay("avatarimage bandit")
avatarsay("move in")
avatarsay("size 3, 60")
enemy.say("""How nice to see you. I hope you enjoy your glee. 
It won't last too long.""")

avatarsay("avatarimage hero")
avatarsay("height 3")
hero.say("""How dare you come here! 
I'll splatter your guts, Granash Barn!""")

enemy.name = "Granash Barn"

avatarsay("avatarimage bandit")
avatarsay("height 1")
enemy.say("""Well well, try it!""")

hero.attack = 18 # A quite formidable fighter. 
enemy.attack = 18 # Same goes for him

peasant.attack = 6 # Knows not to grab a dagger from the wrong side. 

avatarsay("empty")
avatarsay("avatarimage peasant")
avatarsay("move in")
avatarsay("height 1")
peasant.act("tries to get out of the way of " + enemy.name)
avatarsay("move out")
avatarsay("avatarimage none")
avatarsay("height 1")
story(enemy.name + " attacks " + peasant.name)

avatarsay("audio fanfare")
won = enemy.fight_round(peasant)[0]
if won: 
   avatarsay("avatarimage peasant")
   avatarsay("height 1")
   avatarsay("audio die")
   peasant.say("""Aaargh!""")
else:
   avatarsay("avatarimage bandit")
   avatarsay("height 1")
   enemy.say("""Damn peasant.""")

avatarsay("avatarimage hero-angry")
avatarsay("size 1, 55")
hero.say("""How dare you! I'll taste your blood!""")

avatarsay("avatarimage none")
avatarsay("height 1")
hero.act("attacks " + enemy.name)

#avatarsay("slow off")
avatarsay("audio fanfare")
while hero.active and enemy.active: 
   hero.fight_round(enemy)
#avatarsay("slow on")

if hero.active:
   hero.act("won.")
   avatarsay("avatarimage hero-angry")
   hero.say("""That's what they call villain these days. 
So now to you. You look kinda sorry for him. 
Seems I'll have to kill you, too.""")

   avatarsay("avatarimage none")
#   avatarsay("slow off")
   avatarsay("audio fanfare")
   won = player.battle(hero)
#   avatarsay("slow on")
   if not won:
       avatarsay("audio die")
       story("""And so the adventure of """ + player.name + """ ended quite early.""")

else:
   enemy.act("won.")
   avatarsay("avatarimage bandit")
   enemy.say("""So much for heroes. 
I hope you didn't stand with that bastard. I'm leaving. 
Want to come with me?""")

   avatarsay("avatarimage none")
   join_the_enemy = ask("""Come with him? (Yes, no)""")

   avatarsay("avatarimage bandit")
   if join_the_enemy.lower() in ["yes", "y", ""]: 
      enemy.say("""A wise decision. Now carry my bag.""")
   else: 
      enemy.say("""That's too bad. Good luck for your future. 
And don't trust the heroes.
Do you want to fight me, then?""")

avatarsay("avatarimage none")
if player.active: 
   fight = ask("Fight him? (Yes, no)")
else:
   fight = "No"
if fight.lower() in ["yes", "y", ""]:
#   avatarsay("slow off")
   avatarsay("audio fanfare")
   won = player.battle(enemy)
#   avatarsay("slow on")
   if not won:
      avatarsay("audio die")
      story("Sorry, you lost.")
else:
   avatarsay("avatarimage bandit")
   enemy.say("""A good fight.""")

avatarsay("move out")
exit()
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.