I was thinking about making a simple ascii game with curses. Here is my very first level editor.
Python snake game!
Blackjack Game in Python 3/curses - Code Review Stack Exchange
I made a terminal based snake game using Python and Curses
Videos
A short video demo A screenshot of the settings menu A screenshot of the barrier mode
Since there were no good-looking snake remakes for the terminal, I made my own. It uses ASCII box drawing characters for the snake, so that you can actually tell different segments of the snake apart from each other. It also features a settings menu, the ability to save and clear high scores, a barrier mode, and a configurable difficulty.
To play it, go to https://replit.com/@UniqueOstrich18/CLI-Snake?v=1 or run the commands below:
git clone https://github.com/ading2210/snake-cli python3 snake-cli/snake.py
Source code is available at: https://github.com/ading2210/snake-cli
Note: The game may have some visual artifacts on MacOS, but I don't own a Mac so I'm not able to fix them.
ยป pip install curses-snake
So back in high school we made games with QBasic and I wanted to see if I could make a game based on ASCII/unicode characters in python instead. As part of that, I want to be able to create maps that the player can move around on without having to hard-code the x/y coordinate for every map object.
This is the first level editor I have made, and since it's going to be a simple little ASCII/unicode game, I figured I would make the levels text-based(at least for now).
Level's are built with text. A token is a character like # that represents something(in this case a wall:
################## # # # # # # # # # # ##################
Each token is converted to the character that will be displayed on the map. Since this is a wall, the Wall object will figure out how to display itself based on its neighbors(and ends up looking like lines โโ).
There are 2 objects for the mapping, MapBuilder & Map. And some objects that inherit from MapObject: Floor, Wall & Door.
MapBuilder builds up a Map object and populates the Map instance with MapObjects based on tokens in the text representing the map.
The MapObject objects actually place themselves on the Map through their place method and have access to the Map being built. MapObjects can also control how they are displayed. The Walls have a mind of their own :P
The MapBuilder supports adding MapObjects through classes(passed in a dict with the build method):
class MapObject(object):
token = str
color = 0
drawing = ''
ch_number = 0
def __init__(self, y, x):
self.y, self.x = y, x
def place(self, game_map): # game_map is instance of `Map`
game_map.objects[self.y, self.x] = self
class Floor(MapObject):
token = ' '
color = 0
drawing = ' '
ch_number = 32
class VerticalDoor(MapObject):
token = '|'
color = 233
drawing = 'โ'
ch_number = 4194401
class HorizontalDoor(MapObject):
token = '-'
color = 233
drawing = 'โ'
ch_number = 4194401so adding and editing map objects is really flexible.
Here is an imgur gallery with a better example. Those wouldn't be levels in the game, but it shows how it converts everything to the appropriate box character :D Here is what an outline of a room might look like.
Here is the code. You might need to make your terminal window larger to run it since it might try to draw outside of the terminal window otherwise. There are 2 files, editor.py and map_objects.py
Let me know what you think! It could probably be improved, so feedback is more than welcome! My next step will be to write another curses app that lets me use the mouse to draw out the map templates so I don't have to do it in PyCharm.
Bonus ASCII Hero I made. Might need to use pygame to use him, but what should I name him?
Edit: Updated link to the current code. Added more info on how things work under the hood.
This is perfect for beginners to learn some python code!
Uses the curses library.
I try to break down each line of code so you understand what is happening. You will still need to do some research if you want more in depth knowledge.
https://github.com/jsterling23/snake-game.py/blob/master/snake-game.py
Make sure you have python installed lol...
Oh and make sure terminal window is at least 200 columns 60 rows. The game needs at least 50x120. But obv~ you can recode that.