Staredit Network > Forums > Technology & Computers > Topic: Text Based RPG in Python
Text Based RPG in Python
Oct 21 2010, 11:07 pm
By: CecilSunkure
Pages: 1 2 3 >
 

Oct 21 2010, 11:07 pm CecilSunkure Post #1



So here I have it. An unfinished text based RPG for Windows written in Python!!



Here is a link to download the .exe. Keep in mind that you need all the other files in the directory to run MiniRPG.exe. Well, go ahead and try it out! It runs within DOS, well cmd.exe actually.

At the moment, I have an easy to use framework for adding in additional enemies, weapons, items, maps, and characters. So really, all this is missing is some code for special boss fights, some code for special environment changes (like hitting a switch to open a large hallway), and the content! Content includes levels, dialog, storyline, etc.

How to Play (hit enter after each key)
w - Move up
a - Move Left
s - Move down
d - Move Right
e - Action button. Use this while standing next to something.
i - Inventory. Read all the text in the inventory, or you may miss an important operation
   (like how to discard an item, or equip an item).

Character key:
O   - This is your character.
/   - This is a wall. Your character cannot move over it
{"} - This is a treasure chest.
{_} - This is an unopened treasure chest.
[/] - This is a door.
S   - This is the store.
&   - This is CecilSunkure!!


Source code ~ 850 lines (open with --> notepad in order to view)

Post has been edited 8 time(s), last time on Oct 24 2010, 4:15 am by CecilSunkure.



None.

Oct 21 2010, 11:45 pm CecilSunkure Post #2



How to Code Rooms

Okay, so I just got a brilliant idea!

Since creating content requires a lot of time, I'm sure you SENers would love to help! I need rooms, and lots of them. The way my coding works, is rooms are actually just arrays of arrays, with each element of each array containing an integer. Depending on what this integer is, that spot on the map is then converted into a specific character and displayed in the command prompt.

Here is some code for the first room in this game:

First Room Code
MAP1 = [
   [1, 1, 1, 1, 1, 1, 1, 1, 1, 3],
   [1, 7, 0, 0, 0, 1, 1, 6, 1, 3], #y2, x7
   [1, 1, 1, 0, 0, 0, 1, 0, 1, 3],
   [1, 6, 1, 0, 0, 0, 1, 0, 1, 3], #y3, x1
   [1, 0, 1, 1, 0, 0, 1, 0, 1, 3],
   [1, 0, 0, 0, 0, 0, 0, 0, 1, 3],
   [1, 0, 0, 1, 1, 0, 1, 1, 1, 3],
   [1, 2, 0, 7, 1, 0, 0, 5, 1, 3],
   [1, 1, 1, 1, 1, 1, 1, 1, 1, 3]
   ]


First Room Displayed in Game


The # is a comment. The integer of 1 is a wall, 0 is a blank space, 3 is an identifier for the end of the string, as in I place a "NEWLINE" character wherever a three is, otherwise when I print out the map image it would all be in one line.

Here is a key for the entire map integers:
Key
0 - Blank walkable space ( )
1 - Wall ( / )
2 - Block (this is currently not usable, DON'T put it in your map)
3 - Newline character, place this at the end of each list
4 - Your character, don't add this to your map ( O )
5 - A store ( S )
6 - Door ( [/] )
7 - Treasure Chest unopened ( {"} )
8 - Treasure Chest opened ( {_} )
9 - CecilSunkure


Take note that I placed text like this: #y2, x7 in the same line as each 6. This is because 6 is a door, and in order to use the door I check to see if the player's coordinates match a list of pre-listed coordinates, and in doing so I need the door's coordinates. You must have at least one door in your map but you don't need to list the coordinates, as the coordinates are reversed in x and y, and are both -1 from the absolute coordinate values; I'll list the coordinates myself.

Example Code for Rooms (these are in the game currently)


Post has been edited 2 time(s), last time on Oct 21 2010, 11:58 pm by CecilSunkure.



None.

Oct 21 2010, 11:46 pm LoTu)S Post #3



I found Cecil and he ko'd me in one hit :hurr: 99999 dmg D:.



None.

Oct 21 2010, 11:57 pm CecilSunkure Post #4



How to Code Items

Also, I would like to have more weapons! If you want to submit a weapon, here is the format:

Weapon Format
ITEM_NAME = item('ITEM_NAME_STRING', [x, y], 'ITEM_SIZE', PRICE)


ITEM_NAME - This is just the identifier I use in my code for your item. This does not have to be the same as ITEM_NAME_STRING. ITEM_NAME_STRING is the string that will actually show up in game for the name of your item. x and y are damage parameters. You can have 0 damage, up to I believe 255. ITEM_SIZE must be one of the following: Small; Medium; or Large. This affects your chance of hitting or missing in a battle. PRICE is the price of the item if it were to be bought or sold.

Example Weapon Code
DAGGER = item('Small Dagger', [1, 4], 'Small', 5)

This dagger would deal anywhere fomr 1-4 damage, and is a small weapon meaning it will not miss often. It costs only 5 gold.

On top of this, I also need ideas for other 1 use items! Potions have the following item format:
Potion
POTION = item('Potion', [0, 0], '1 use', 5)


If you want to design other types of '1 use' items, please do so and post your ideas here!

Post has been edited 1 time(s), last time on Oct 22 2010, 12:02 am by CecilSunkure.



None.

Oct 22 2010, 12:11 am Aristocrat Post #5



Hm, the code you have doesn't look very extensible, unfortunately. If you want to expand this beyond what it is capable of right now, there will be substantial switching costs when you need to recode the way rooms and items are implemented. If it's just a small project that you won't revisit much, I'll be glad to help contribute some ideas.



None.

Oct 22 2010, 12:18 am CecilSunkure Post #6



With the way rooms are coded, changing rooms by adding in additional integer definitions is really easy.

The way items are implemented uses classes, so, that's not going to be hard to change either.

In order to allow for switches to reveal addition portions of the map, you just use two sets of integers for each type of character that can be displayed on the map. One set won't show when the switch is off, the other will when the switch is on. I'd also need a specific integer for a wall that converts to an empty space.

Though, I actually really want more rooms and items, mainly rooms.



None.

Oct 22 2010, 12:22 am ImagoDeo Post #7



Excaliban
EXCALIBAN = item('Excaliban', [1337, 9001], 'Epic', 9001)


:awesome:

Seriously, though, I promise to contribute at least five maps. Unique ones. With stuff in them.



None.

Oct 22 2010, 5:38 pm ImagoDeo Post #8



Maps
MAP = [
  [1, 1, 1, 1, 1, 1, 1, 1, 3],
  [1, 0, 0, 0, 0, 0, 6, 1, 3],
  [1, 0, 1, 1, 1, 1, 1, 1, 3],
  [1, 0, 1, 0, 0, 0, 0, 1, 3],
  [1, 0, 1, 0, 1, 1, 0, 1, 3],
  [1, 0, 1, 0, 7, 1, 0, 1, 3],
  [1, 0, 1, 1, 1, 1, 0, 1, 3],
  [1, 0, 0, 0, 0, 0, 0, 1, 3],
  [1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 3],
  [1, 6, 1, 1, 0, 0, 0, 1, 6, 1, 1, 3],
  [1, 0, 1, 1, 0, 7, 0, 1, 0, 0, 1, 3],
  [1, 0, 0, 0, 0, 0, 0, 1, 0, 7, 1, 3],
  [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 3]
  ]

MAP = [
  [1, 1, 1, 1, 1, 1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1, 0, 1, 0, 1, 0, 1, 3],
  [1, 6, 1, 7, 1, 0, 0, 0, 0, 0, 0, 0, 1, 3],
  [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 3]
  ]


How's that? :)



None.

Oct 22 2010, 5:41 pm CecilSunkure Post #9



I'll be paying 20 minerals per three quality maps!

Maps should have max dimensions of 75x25 (width x height).

I will not pay for a group of maps if I do not like one of them, and I will only pay for groups of three!

Edit: Those look great Imago, thanks.

Imago Preview (Payed 20 minerals for these)


Post has been edited 6 time(s), last time on Oct 22 2010, 6:03 pm by CecilSunkure.



None.

Oct 22 2010, 6:01 pm ImagoDeo Post #10



Template Code

I figured it'd be easier for people to pick a size to start with and fill it in. These templates have walls on all four sides and are totally blank inside.

10x10

13x13

15x15

20x20

75x25


More to come. :)

Post has been edited 2 time(s), last time on Oct 22 2010, 7:10 pm by ImagoDeo.



None.

Oct 22 2010, 6:55 pm ImagoDeo Post #11



Cecil, it might help to know what kind of zones the player will walk through. What types of maps do you want? Rooms? Dungeon-style? Forest? Cave?



None.

Oct 22 2010, 6:55 pm CecilSunkure Post #12



Here are some more maps I made:

Maps
MAP = [
    [1, 1, 1, 1, 3],
    [1, 6, 0, 1, 3],
    [1, 0, 0, 1, 0, 0, 0, 0, 1, 1, 1, 3],
    [1, 1, 0, 1, 0, 0, 0, 1, 1, 6, 1, 3],
    [0, 1, 7, 1, 0, 0, 0, 1, 0, 0, 1, 3],
    [0, 1, 1, 1, 0, 0, 0, 1, 0, 0, 1, 1, 1, 3],
    [0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 1, 3],
    [0, 0, 0, 1, 1, 1, 0, 0, 1, 0, 0, 7, 1, 3],
    [0, 0, 0, 1, 6, 1, 0, 0, 1, 1, 1, 1, 1, 3],
    [0, 0, 1, 1, 0, 1, 1, 1, 3],
    [0, 0, 1, 0, 0, 0, 0, 1, 3],
    [0, 0, 1, 0, 0, 0, 6, 1, 3],
    [0, 0, 1, 1, 1, 1, 1, 1, 3]
    ]
   
MAP = [
    [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 3],
    [1, 0, 1, 0, 0, 0, 0, 0, 0, 1, 3],
    [1, 0, 6, 1, 0, 0, 0, 1, 0, 1, 3],
    [1, 0, 1, 0, 0, 0, 1, 7, 0, 1, 3],
    [1, 0, 0, 0, 0, 0, 1, 0, 0, 1, 3],
    [1, 0, 0, 0, 1, 0, 0, 1, 1, 1, 3],
    [1, 0, 0, 1, 1, 0, 0, 0, 0, 1, 3],
    [1, 0, 1, 0, 0, 0, 0, 1, 7, 1, 3],
    [1, 7, 1, 6, 0, 0, 0, 0, 1, 1, 3],
    [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 3],
    ]
   
MAP = [
    [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 3],
    [1, 6, 0, 0, 0, 0, 0, 0, 6, 1, 3],
    [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 3],
    ]
   
MAP = [
    [1, 1, 1, 1, 1, 1, 1, 1, 3],
    [1, 7, 0, 0, 0, 0, 6, 1, 3],
    [1, 1, 1, 1, 1, 1, 1, 1, 3],
    ]
   
MAP = [
    [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 3],
    [1, 6, 0, 1, 0, 0, 0, 1, 0, 0, 7, 1, 3],
    [1, 0, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 3],
    [1, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 3],
    [1, 1, 0, 1, 1, 1, 0, 1, 0, 1, 0, 1, 3],
    [1, 0, 0, 1, 7, 0, 0, 1, 0, 0, 0, 0, 1, 3],
    [1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 3],
    [1, 0, 0, 0, 0, 1, 0, 0, 0, 7, 1, 0, 1, 3],
    [1, 1, 1, 1, 0, 0, 0, 1, 1, 1, 1, 0, 1, 3],
    [1, 0, 0, 0, 0, 1, 0, 1, 7, 0, 0, 0, 1, 3],
    [1, 0, 1, 1, 1, 1, 0, 1, 0, 1, 1, 0, 1, 3],
    [1, 0, 7, 1, 6, 0, 0, 1, 6, 0, 0, 0, 1, 3],
    [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 3]
    ]


Previews




None.

Oct 22 2010, 7:04 pm CecilSunkure Post #13



Quote from ImagoDeo
Cecil, it might help to know what kind of zones the player will walk through. What types of maps do you want? Rooms? Dungeon-style? Forest? Cave?
Just rooms with walls, that's it. I'm not using anything for graphics except the "/" for walls, and the other characters I've shown.

So, just interesting rooms that are like the ones I've been making.



None.

Oct 22 2010, 9:46 pm Apos Post #14

I order you to forgive yourself!

Are you going to make the game bigger? Make it become graphical? Make a multiplayer mode? Could it turn out to be the new most played open source game?

Edit: (May as well contributed)

MAP1 = [
[1, 1, 1, 1, 1, 1, 1, 1, 1, 3],
[1, 0, 0, 0, 0, 0, 0, 0, 1, 3],
[1, 0, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 3],
[1, 0, 0, 0, 0, 1, 0, 7, 1, 8, 1, 7, 1, 3],
[1, 0, 0, 0, 0, 1, 0, 1, 1, 0, 1, 0, 1, 1, 1, 1, 3],
[1, 0, 1, 1, 0, 1, 0, 1, 0, 0, 0, 0, 1, 0, 0, 1, 3],
[1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 3],
[1, 1, 1, 0, 1, 0, 1, 0, 0, 1, 8, 1, 0, 0, 0, 0, 0, 0, 0, 1, 3],
[1, 0, 0, 0, 1, 0, 1, 0, 0, 1, 1, 1, 1, 1, 1, 0, 1, 0, 0, 1, 3],
[1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 1, 3],
[1, 0, 1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 1, 3],
[1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1,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, 0, 0, 0, 1, 3],
[1, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 1, 3],
[1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 3],
[1, 0, 1, 0, 1, 1, 1, 1, 1, 0, 1, 0, 1, 0, 1, 3],
[1, 0, 1, 0, 1, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 3],
[1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 3],
[1, 0, 1, 0, 1, 0, 1, 0, 0, 0, 1, 0, 1, 0, 1, 3],
[1, 0, 1, 0, 1, 0, 1, 1, 1, 0, 1, 0, 1, 0, 1, 3],
[1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 3],
[1, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 3],
[1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 3],
[1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 3],
[1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 3],
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 3]
]

Edit2:
Previews


Post has been edited 2 time(s), last time on Oct 22 2010, 10:17 pm by Apos.




Oct 22 2010, 9:49 pm CecilSunkure Post #15



No, I've stopped using python and switched over to C/C++.

I'm finishing this up in single player for the heck of it, while running through a coding book on C.

I've switched to C because I'll be attending DigiPen next year (not this year due to personal reasons), and since games are almost only coded in C, and since DigiPen teaches in C/C++, it's best I stick with it.

If I get good enough in time, I'll code a game in DOS before I attend DigiPen ^_^



None.

Oct 22 2010, 10:22 pm FoxWolf1 Post #16



Have you played DoomRL? It's pretty entertaining, so it might be something to check out as an example if you're interested in making text-based games.

Also, if you want to see an example of the genre with graphics added on, but keeping the distinctive "feel" of these games, Omega would be worth a look.



None.

Oct 23 2010, 4:15 am ImagoDeo Post #17



75x25 Masterpiece Preview


code


:awesome:



None.

Oct 23 2010, 4:32 am CecilSunkure Post #18



Oh my god Lol.

Thanks a ton for the help Imago! Much appreciated.



None.

Oct 23 2010, 8:15 pm ImagoDeo Post #19



Two more maps.

Collapsable Box


Preview


I'm also working on a tower set. It'll have a spiraling staircase and some other cool stuff.



None.

Oct 23 2010, 11:51 pm ImagoDeo Post #20



Tower Preview


code




None.

Options
Pages: 1 2 3 >
  Back to forum
Please log in to reply to this topic or to report it.
Members in this topic: None.
[05:00 pm]
lil-Inferno -- benis
[10:41 am]
v9bettel -- Nice
[01:39 am]
Ultraviolet -- no u elky skeleton guy, I'll use em better
[10:50 pm]
Vrael -- Ultraviolet
Ultraviolet shouted: How about you all send me your minerals instead of washing them into the gambling void? I'm saving up for a new name color and/or glow
hey cut it out I'm getting all the minerals
[10:11 pm]
Ultraviolet -- :P
[10:11 pm]
Ultraviolet -- How about you all send me your minerals instead of washing them into the gambling void? I'm saving up for a new name color and/or glow
[2024-4-17. : 11:50 pm]
O)FaRTy1billion[MM] -- nice, now i have more than enough
[2024-4-17. : 11:49 pm]
O)FaRTy1billion[MM] -- if i don't gamble them away first
[2024-4-17. : 11:49 pm]
O)FaRTy1billion[MM] -- o, due to a donation i now have enough minerals to send you minerals
[2024-4-17. : 3:26 am]
O)FaRTy1billion[MM] -- i have to ask for minerals first tho cuz i don't have enough to send
Please log in to shout.


Members Online: Vrael, lil-Inferno, jun3hong, Ultraviolet, Roy