Lemma Soft Forums

Supporting creators of visual novels and story-based games since 2003.


Visit our new games list, blog aggregator, IRC, and wiki.
Activation problem? Email [email protected]
It is currently Wed May 22, 2013 3:53 pm

All times are UTC - 5 hours [ DST ]




Post new topic Reply to topic  [ 50 posts ]  Go to page 1, 2, 3, 4  Next
Author Message
PostPosted: Wed Feb 06, 2013 1:52 am 
Crawling Chaos
User avatar

Joined: Mon Feb 13, 2012 5:37 am
Posts: 1113
Location: Kimashi Tower, Japan
Completed: SMAR,AAA
Projects: DMC
Attachment:
Clipboard 1.png
Clipboard 1.png [ 31.73 KiB | Viewed 1369 times ]
This framework implements a simple Dungeon crawling RPG element into your ren'py game. It's just a basic framework, so you need a certain degree of python knowledge to make a real game with this framework.
Usage of these code is pretty much same to the public domain. No need to credit me.
Here is the full code. Sample game is also available at http://www.mediafire.com/?r9kw1nttg5m231m
Code:
   
label start:
    # Create skills (name, hit, power)
    $Slash = Skill("Slash", 70, 20)   
   
    # Create battle actors (name, max_hp, skills)
    $player = Actor("Hero",100, [Slash])
    $Goblin = Actor("Goblin",40,[Slash])
   
    # Create maps
    $stage1=[
    "1111111111",
    "1111011001",
    "1000000001",
    "1110111101",
    "1000000001",
    "1111111111",
    [Goblin] # Properties outside of a map can be use in events. This is an encounter battle event.
    ]

    # Create a player position (map,y,x,dy,dx).
    # dx,dy means direction. If dy=1, it's down. If dx=-1, it's left.
    $ here=Position(stage1,2,2,0,1)
    jump dungeon
   
label dungeon:
    $ event_check=False
    $ config.rollback_enabled=False
    while 1:
        python:
            # Calculate relative coordinate
            turnback=Position(here.map,here.y,here.x,-here.dy,-here.dx)
            turnright=Position(here.map,here.y,here.x,here.dx,-here.dy)
            turnleft=Position(here.map,here.y, here.x,-here.dx,here.dy)
            right1=Position(here.map,here.y+here.dx,here.x-here.dy,here.dy,here.dx)
            left1=Position(here.map,here.y-here.dx,here.x+here.dy,here.dy,here.dx)
            front1=Position(here.map,here.y+here.dy,here.x+here.dx, here.dy,here.dx)
            right2=Position(front1.map,front1.y+front1.dx,front1.x-front1.dy,front1.dy,front1.dx)
            left2=Position(front1.map,front1.y-front1.dx,front1.x+front1.dy,front1.dy,front1.dx)
            front2=Position(front1.map,front1.y+front1.dy,front1.x+front1.dx, front1.dy,front1.dx)
            right3=Position(front2.map,front2.y+front2.dx,front2.x-front2.dy,front2.dy,front2.dx)
            left3=Position(front2.map,front2.y-front2.dx,front2.x+front2.dy,front2.dy,front2.dx)
           
            # Composite background images. Try-except clauses are used to prevent the List Out of Index Error
            renpy.scene()
            renpy.show("base")
            try:
                if left3.map[left3.y][left3.x]=="1": renpy.show("left3")
            except:
                pass
            try:
                if right3.map[right3.y][right3.x]=="1": renpy.show("right3")
            except:
                pass
            try:
                if front2.map[front2.y][front2.x]=="1": renpy.show("front2")
            except:
                pass
            try:
                if left2.map[left2.y][left2.x]=="1": renpy.show("left2")
            except:
                pass
            try:
                if right2.map[right2.y][right2.x]=="1": renpy.show("right2")
            except:
                pass
            if front1.map[front1.y][front1.x]=="1": renpy.show("front1")
            if left1.map[left1.y][left1.x]=="1":  renpy.show("left1")
            if right1.map[right1.y][right1.x]=="1": renpy.show("right1")
               
            # Check events and jump if happens
            if event_check and not here.map[-1] == [] and renpy.random.random()<.2:
                renpy.jump("battle")
               
            # Else, call the move screen
            event_check = True
            here = renpy.call_screen("move")
               
label battle:
    # Copy monster instances not to modify the originals
    $ enemy=copy(renpy.random.choice(here.map[-1]))
    show screen battle_ui
    "[enemy.name] appeared"
    while enemy.hp>0:
        $ player.command(enemy)
        if player.hp <1:
            "gameover"
            $ renpy.full_restart()
    "You win"
    hide screen battle_ui
    jump dungeon
   
init -1 python:
    # Import the copy module for copying instanses.
    from copy import copy
   
    # Class used for relative coodinate
    class Position():
        def __init__(self,map,y,x,dy,dx):
            self.map=map
            self.y=y
            self.x=x
            self.dy=dy
            self.dx=dx       
           
    # Class used for battle skills
    class Skill():
        def __init__(self, name, hit, power):
            self.name = name
            self.hit = hit
            self.power = power           
           
    # Class used for battle characters. Inherit renpy.store.object for the rollback function.
    class Actor(renpy.store.object):
        def __init__(self, name, max_hp=0, skills=[]):
            self.name=name
            self.max_hp=max_hp
            self.hp=max_hp
            self.skills = skills
           
        def command(self, target):
            self.skill = renpy.call_screen("command")
            target.skill = renpy.random.choice(target.skills)
            self.attack(self.skill, target)
            if target.hp < 1:
                return
            target.attack(target.skill, self)
           
        def attack(self,skill,target):
            if self.skill.hit<renpy.random.randint (0,100):
                narrator ("{} dodged {}'s attack".format(target.name,self.name))
            else:
                target.hp -= self.skill.power
                narrator ("{} got {} damage".format(target.name, self.skill.power))
   
init:
    # Screen used for moving
    screen move:
        fixed:
            if front1.map[front1.y][front1.x] is not "1":
                textbutton "⇧" action Return(value=front1)  xcenter .5 ycenter .34
            textbutton "⇨" action Return(value=turnright) xcenter .57 ycenter .47
            textbutton "⇩" action Return(value=turnback) xcenter .5 ycenter .6
            textbutton "⇦" action Return(value=turnleft) xcenter .43 ycenter .47
               
    # Screen used for selecting skills
    screen command:   
        vbox align (.5,.5):
            for i in player.skills:
                textbutton "[i.name]" action Return (value=i)

    # Screen which shows battle status
    screen battle_ui:   
        use battle_frame(char=player, position=(.95,.05))
        use battle_frame(char=enemy, position=(.05,.05))
       
    screen battle_frame:
        frame area (0, 0, 180, 80) align position:
            vbox yfill True:
                text "[char.name]"
                hbox xfill True:
                    text "HP"
                    text "[char.hp]/[char.max_hp]" xalign 1.0
           
init:
    # Assign background images.
    image base = "base.png"
    image left1 = "left1.png"
    image right1 = im.Flip("left1.png", horizontal=True)
    image front1 = "front1.png"
    image left2 = "left2.png"
    image right2 = im.Flip("left2.png", horizontal=True)
    image front2 ="front2.png"
    image left3 = "left3.png"
    image right3 = im.Flip("left3.png", horizontal=True)
   
    # Here is a visualized relative coordinate in this code. Image here=player and facing top.
    # left3, front2, right3
    # left2, front1, right2
    # left1,  here , right1 

_________________


Last edited by nyaatrap on Mon Apr 15, 2013 12:01 am, edited 7 times in total.

Top
 Profile Send private message  
 
PostPosted: Wed Feb 06, 2013 6:58 am 
Regular

Joined: Sat May 28, 2011 1:15 am
Posts: 120
Projects: Bliss Stage, Orbital Knights
This looks great. I'm really curious about this and I'm willing to help out if you need anything.

With this and the RPG engine you could do some really nice games in the style of the old Gold Box D&D games like Pool of Radiance and the early Ultima series. Nothing beats a good conversation engine welded to a good dungeon crawling engine. :)


Top
 Profile Send private message  
 
PostPosted: Wed Feb 06, 2013 12:10 pm 
Crawling Chaos
User avatar

Joined: Mon Feb 13, 2012 5:37 am
Posts: 1113
Location: Kimashi Tower, Japan
Completed: SMAR,AAA
Projects: DMC
Rewrite the first post a bit. It's easy to add a RPG element so I mixed them while keeping codes short and simple as possible as I can.

_________________


Top
 Profile Send private message  
 
PostPosted: Thu Feb 07, 2013 7:53 am 
Regular

Joined: Fri Nov 02, 2012 8:41 am
Posts: 173
Projects: Red eyes in the darkness
It is a very neat framework.
One thing I just saw that could enhance it even (as it will be something that will have to be added there when the scenes,... follow) would be to make another array there
which holds event locations (thus jump locations).
stageEvents=[[null,null,null,"event1",null,null,"event2",...],...]

If then when the player moves after the move it is looked if the location on the map has a stageEvent associated even the planed events can be used dynamically thus
the whole code can be used easily for multiple parts of the game again and again.


Top
 Profile Send private message  
 
PostPosted: Thu Feb 07, 2013 9:26 am 
Crawling Chaos
User avatar

Joined: Mon Feb 13, 2012 5:37 am
Posts: 1113
Location: Kimashi Tower, Japan
Completed: SMAR,AAA
Projects: DMC
Yes. It should have external lists of events outside of maps.
However, I think the top post should have the minimum and simplest code. So I might not add more functions on the top post (other than bug fixes. I also trimmed some additional codes from the top post to make the code look clear. Full code is still available in the sample game).
Anyway It's welcome to discuss more ideas, functions, e.t.c here. I wrote this code as a reference more than framework, so I'm happy if you get some hints for your original game from this code.

_________________


Top
 Profile Send private message  
 
PostPosted: Thu Feb 14, 2013 7:03 am 
Crawling Chaos
User avatar

Joined: Mon Feb 13, 2012 5:37 am
Posts: 1113
Location: Kimashi Tower, Japan
Completed: SMAR,AAA
Projects: DMC
[/merged in the top code]

_________________


Last edited by nyaatrap on Sun Feb 17, 2013 9:55 am, edited 1 time in total.

Top
 Profile Send private message  
 
PostPosted: Fri Feb 15, 2013 2:50 am 
Lemma-Class Veteran

Joined: Tue Aug 01, 2006 12:39 pm
Posts: 4051
I have got to try this and combine it with Battle Engine.

Now I have an excuse to join Nanoreno.


Top
 Profile Send private message  
 
PostPosted: Fri Feb 15, 2013 1:11 pm 
Miko-Class Veteran
User avatar

Joined: Fri Mar 16, 2012 11:38 am
Posts: 926
Location: Tokyo, Japan
Projects: Untitled Japanese study game
Organization: Pure Anarchy
The mediafire link isn't working. Sometime about an alleged ToS violation.

_________________
Working on a VN to teach lower-conversational Japanese, and a guide to living in Japan.
It's a very long dev process.

You could help me with my game A LOT by filling out this anonymous 10 question survey: http://www.surveymonkey.com/s/6GR57YB
Massive thanks to everyone who has already filled it out!
You can see a Q&A about the survey here: http://tinyurl.com/SurveyQandA


Top
 Profile Send private message  
 
PostPosted: Fri Feb 15, 2013 7:54 pm 
Crawling Chaos
User avatar

Joined: Mon Feb 13, 2012 5:37 am
Posts: 1113
Location: Kimashi Tower, Japan
Completed: SMAR,AAA
Projects: DMC
I didn't met that issue. If it's not just a connection error, maybe your provider or browser shut it arbitrarily?

_________________


Top
 Profile Send private message  
 
PostPosted: Fri Feb 15, 2013 8:47 pm 
Miko-Class Veteran
User avatar

Joined: Fri Mar 16, 2012 11:38 am
Posts: 926
Location: Tokyo, Japan
Projects: Untitled Japanese study game
Organization: Pure Anarchy
Okay, I'll try it with a different browser tonight and post the result.

_________________
Working on a VN to teach lower-conversational Japanese, and a guide to living in Japan.
It's a very long dev process.

You could help me with my game A LOT by filling out this anonymous 10 question survey: http://www.surveymonkey.com/s/6GR57YB
Massive thanks to everyone who has already filled it out!
You can see a Q&A about the survey here: http://tinyurl.com/SurveyQandA


Top
 Profile Send private message  
 
PostPosted: Sat Feb 16, 2013 9:36 pm 
Crawling Chaos
User avatar

Joined: Mon Feb 13, 2012 5:37 am
Posts: 1113
Location: Kimashi Tower, Japan
Completed: SMAR,AAA
Projects: DMC
[/merged in the top code]

_________________


Last edited by nyaatrap on Sun Feb 17, 2013 9:56 am, edited 1 time in total.

Top
 Profile Send private message  
 
PostPosted: Sat Feb 16, 2013 10:21 pm 
Miko-Class Veteran
User avatar

Joined: Fri Mar 16, 2012 11:38 am
Posts: 926
Location: Tokyo, Japan
Projects: Untitled Japanese study game
Organization: Pure Anarchy
The download link worked, even though I used the same browser. Must have been a temporary hiccup on the server's end.
This looks fantastic. I've had something in mind for about 6 months, and this could provide the ideal framework to make it a reality. Many thanks.

_________________
Working on a VN to teach lower-conversational Japanese, and a guide to living in Japan.
It's a very long dev process.

You could help me with my game A LOT by filling out this anonymous 10 question survey: http://www.surveymonkey.com/s/6GR57YB
Massive thanks to everyone who has already filled it out!
You can see a Q&A about the survey here: http://tinyurl.com/SurveyQandA


Top
 Profile Send private message  
 
PostPosted: Sun Feb 17, 2013 9:53 am 
Crawling Chaos
User avatar

Joined: Mon Feb 13, 2012 5:37 am
Posts: 1113
Location: Kimashi Tower, Japan
Completed: SMAR,AAA
Projects: DMC
Shortened and Simplified the code, and added some comments a bit. I removed some functions I think they're not important. The demo is also replaced.

_________________


Top
 Profile Send private message  
 
PostPosted: Mon Feb 18, 2013 4:06 pm 
Regular
User avatar

Joined: Thu Jan 31, 2013 7:27 pm
Posts: 25
Projects: Pokemon: Final Evolution
I'm trying to extract just the battle elements from the map, and I got this error:

I'm sorry, but an uncaught exception occurred.

While running game code:
ScriptError: could not find label '(u"C:\\Users\\Dick Chappey\\Desktop\\Ren'py Projects\\Pokemon Final Evolution/game/script.rpy", 1361216315, 1)'.

-- Full Traceback ------------------------------------------------------------

Full traceback:
File "C:\Program Files\renpy-6.14.1-sdk\renpy\execution.py", line 266, in run
File "C:\Program Files\renpy-6.14.1-sdk\renpy\ast.py", line 1149, in execute
File "C:\Program Files\renpy-6.14.1-sdk\renpy\execution.py", line 353, in lookup_return
File "C:\Program Files\renpy-6.14.1-sdk\renpy\script.py", line 477, in lookup
ScriptError: could not find label '(u"C:\\Users\\Dick Chappey\\Desktop\\Ren'py Projects\\Pokemon Final Evolution/game/script.rpy", 1361216315, 1)'.

Windows-7-6.1.7601-SP1
Ren'Py 6.14.1.366
A Ren'Py Game 0.0


Do you know what I did wrong and how to fix it?

Edit* When I rolled back, it disapeared and asked me instead about the 'name', saying 'function' object has no attribute to 'name'. It refers me to this line: "[enemy.name] appeared". Although I have changed Goblin to Skitty, I have not changed any instance of 'enemy' from the original script.


I replaces all instances of Goblin and enemy with my designated enemy (Skitty) and it worked fine. I'll leave this post here in case someone lse makes a similar mistake.

*Edit again* It only worked right once. It went back to the function problem, which moved on to complain about hp.


Top
 Profile Send private message  
 
PostPosted: Mon Feb 18, 2013 9:12 pm 
Crawling Chaos
User avatar

Joined: Mon Feb 13, 2012 5:37 am
Posts: 1113
Location: Kimashi Tower, Japan
Completed: SMAR,AAA
Projects: DMC
The above code is using simple variables/classes/instances names which can cause contradiction easily. It's more safe to rename more complicated names.

_________________


Top
 Profile Send private message  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 50 posts ]  Go to page 1, 2, 3, 4  Next

All times are UTC - 5 hours [ DST ]


Who is online

Users browsing this forum: No registered users


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Protected by Anti-Spam ACP
Powered by phpBB® Forum Software © phpBB Group