Coder Social home page Coder Social logo

pycraft's Introduction

Run on Repl.it

Pycraft

A command line based 2D Minecraft, runs best on *nix with Python 3.3+. Built by geraintwhite and olls.

Usage: python3 main.py

Pycraft gameplay image

Controls

For the best control, set keyboard repeat time to around 200-300ms.

Menus:
   Move up                    - W or UP
   Move down                  - S or DOWN
   Select                     - SPACE or RETURN
   Pause                      - SPACE or RETURN
Blocks:
   Break/place block          - K
   Move cursor clockwise      - L
   Move cursor anti-clockwise - J
Inventory:
   Cycle inventory down       - O
   Cycle inventory up         - U
   Toggle crafting menu       - C
   Craft selected item        - I
Movement:
   Move left                  - A
   Move right                 - D
   Jump                       - W

Crafting

A number of items are only obtainable through the crafting system. Items that can be crafted with the materials in the player inventory will automatically show up in the crafting grid. Press C to toggle selection between inventory and crafting grid. Press I to craft the currently selected item.

Recipes:

  • 6 sticks:
    • 1 wood
  • 4 torches:
    • 1 stick
    • 1 coal
  • ladder:
    • 3 sticks
  • wooden pickaxe:
    • 2 sticks
    • 3 wood
  • stone pickaxe:
    • 2 sticks
    • 3 stone
  • iron pickaxe:
    • 2 sticks
    • 3 iron
  • diamond pickaxe:
    • 2 sticks
    • 3 diamonds

Tools:

Certain blocks require the right tool before being able to mine it. The tool has to be selected in inventory to be able to use it. Each tier of pickaxe can break more blocks than the previous tier.

  • fist (i.e. don't need a tool):
    • grass
    • tall grass
    • wood
    • leaves
    • torch
    • ladder
  • wooden pickaxe:
    • stone
  • stone pickaxe:
    • coal
    • iron
  • iron pickaxe:
    • redstone
    • gold
    • diamond
  • diamond pickaxe:
    • emerald

Using the C Renderer

The C renderer is likely to be faster than the Python renderer. To use the C renderer, it must be compiled first. To complile, run the command: python3 setup.py build in the root of the repository. Then run the game as normal and go into settings to switch the renderers.

Please report any bugs in the C renderer, or differences between the Python renderer and the C renderer in issues.

Contributing

We welcome pull requests or issues for bug reports/fixes or new feature ideas! Help us make the game more fun :D

pycraft's People

Contributors

devmaxiss avatar geraintwhite avatar isidentical avatar olls avatar sullyjhf avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

pycraft's Issues

Windows

It would be nice if we could get it running on most platforms. I sorta got it running on Windows, the main hurdle to get it running was input, then it is playable. The issues we have are:

  • The Windows input is only blocking which means we can't use arrow keys on the menu, and the game only runs while the user is inputting.
    Fixed with 48b1629 - non blocking input works on windows.
  • There is a problem with msvcrt.getch returning bytes instead of a string, this causes problems with arrow keys.
    Fixed with 3a0df67 - fix for Windows arrow keys input.
  • Colours are the only real problem although it is playable without them.
  • In Windows the clear screen code (and all escape codes...) doesn't work, and arrow keys don't work (No longer used). Add support for turning them off.

Add block placing rules

Only allow certain blocks to be placed on others.

E.g:

  • tall grass can only be placed on grass blocks or other tall grass
  • torches can only be placed on solid blocks

Terrain Gen Ideas

More terrain generation features would be a good idea. This is an issue to collect a list of possible ideas and work out how to implement them. Due to the limitations of the terminal we'll have to be careful which features we add and how they work.

  • Caves
  • Bigger hills (mountains) / more interesting
  • Forests
  • Biomes
  • Structures (Villages?)

Coloured String Length

There are a few places where we might need to get the length of a string which may have been coloured. (For example in the first row, title, of the inventory/crafting grids) This causes a problem, because the escape codes add to the length of the string. Maybe we should make a function which strips the escape codes to get the correct length of a string

Biomes

The current implementation of biomes is just identified by the spawn rate of trees. This makes it hard to use for anything else, it should be rewritten to identify biomes properly, and maybe add more types (eg grass rates, ore rates?).

Hierarchy of Blocks

There should be a hierarchy which shows which blocks are allowed to replace other blocks during the spawning process, for example to stop leaves spawning in other blocks.

Proper chunking

Rewrite save handling to work with chunks rather than keeping the whole map in memory.

Ghosts

All the players in meta are always displayed, this would probably be fixed as a part of #36.

Inventory grid scroll position changes

If the inventory selector makes the inventory scroll down, when you go into the crafting grid the inventory will scroll back up because the inventory selector isn't being passed into render grid.

CLS

The current CLS variable in console.py is chr(27) + '[2J', which is equivalent to the clear command in bash, which just scrolls the console down (at least in gnome-terminal). The code \033c actually clears the terminal, which makes the game much smoother. Unfortunately this conflicts with something in the program, probably the colors module, and causes like: ;37m to be printed out in the middle of the terminal. There is lots of info here but I can't find one which works.

Multiplayer

In order to do this:

  • rewrite save handling to use chunking in memory #23
  • write a server program to handle distributing chunks to clients, keeping track of player locations (we will need something similar for keeping track of mobs)
  • modify client code to accept chunks from the server and render other players
  • combine server and client code #36

Escape codes

In windows the clear screen code doesn't work, and arrow keys don't work.

Tree Leave Positioning

The positioning of the leaves is still broken :( If you add the following tree, for some reason it places the leaves one block up from where they should be:

# These works:
((0, 1, 1),
 (0, 1, 0),
 (0, 1, 1)),
((0, 1, 1),
 (1, 1, 0),
 (0, 1, 1)),
#This dosn't:
((1, 1),
 (1, 0),
 (1, 1))

Investigate chunk sizes

The chunk sizes for a world generated in the multiplayer branch:

[('12.chunk', 16), ('4.chunk', 16), ('8.chunk', 16), ('18.chunk', 16), ('0.chunk', 64), ('7.chunk', 16), ('3.chunk', 16), ('5.chunk', 16), ('14.chunk', 16), ('17.chunk', 16), ('20.chunk', 16), ('6.chunk', 16), ('-1.chunk', 64), ('11.chunk', 16), ('1.chunk', 64), ('10.chunk', 16), ('9.chunk', 16), ('16.chunk', 16), ('-2.chunk', 64), ('19.chunk', 16), ('13.chunk', 16), ('15.chunk', 16), ('2.chunk', 16)]

A world from the master branch:

[('12.chunk', 16), ('4.chunk', 16), ('21.chunk', 16), ('8.chunk', 16), ('18.chunk', 16), ('0.chunk', 16), ('7.chunk', 16), ('3.chunk', 16), ('5.chunk', 16), ('14.chunk', 16), ('17.chunk', 16), ('20.chunk', 16), ('6.chunk', 16), ('-1.chunk', 16), ('11.chunk', 16), ('22.chunk', 3), ('1.chunk', 16), ('10.chunk', 16), ('9.chunk', 16), ('16.chunk', 16), ('-2.chunk', 11), ('19.chunk', 16), ('13.chunk', 16), ('15.chunk', 16), ('2.chunk', 16)]

Comments

The comments in the source code need some work. Lines like this:

inp = char if char in 'wadkjlh;b'+chr(2) else None

shouldn't exist without a comment.

Unicode Blocks

Using Unicode we can probably create a much better looking blocks, the problem is finding the correct characters to use, I have found a few possibilities using this site. We also have to be careful to use single character width characters.

Player

These are some ideas for the player, but they aren't quite right.

Top

o
๐™พ
โพ
โš˜
โŸŸ
๐Œ’
๐Ÿ˜’๐Ÿ˜”๐Ÿ˜ต๐Ÿ˜ฃ๐Ÿ˜ฑ๐Ÿต

(Maybe the player can have different states: expressions, move arms, legs etc...)

Bottom

ฮ› แดง
แฑ ^
โดท โ‘ƒ
โ‹€ ๐ 
๐Œก ๊˜
สŒ ฦ›
ษ… โŽ
โˆง โšป
๐ค‚ โต…
โ•ณ 

This would be nice, but not really going to work: ์›ƒ.
(Hand (Cursor): โ˜Ÿ) :P

Grass

โŒ’
๐ค†
~
โ”‰
โ”ˆ
แจ
แš‡
เทด
โ–‘ (Current)

Ores

โ ซ โ‹
โˆท โšซ
แข ๐Œน
โข โ˜€
โฃ’ โŽ”
๊–œ โœด
โˆต โŒ˜
๊—ท โ–ฆ
โ€ข โ–ข

Leaves

โ™ง
โ‹
โœป
โ‡

Feature Ideas

We should add more features at some point to make the game something you can actually play for longer than ten minutes before getting bored.

I think the design is quite scalable, it's more a question of working out how to add cool features within the restrictions of the terminal. For example a crafting system is relatively doable, the harder part would be figuring out the recipes because we've got such a limited range of blocks. The other sort-of barrier at the moment is the frame updates, anything that needs to be continuously moving without interaction with the player, is kind of out of the question. So we need to find ways to implement features like this without continuous movement, like the sun, it moves so slowly, it doesn't really matter that it only updates when the player moves. (As of 4746469 we have proved continuous movement is possible)

Some brainstorming:

Crafting Ideas

Some recipes to maybe make it worth implementing:

  • Wood > sticks > torches, ladders 139ae03 (torches 49c7b09)
  • Wood > doors
  • Stone > bricks
  • Sticks + stone > tools 39f90f0
  • Wood > Amour

Tools

We could give different blocks different durabilities, so you need different tools to break them, e.g.: pick needed for stone, axe needed for wood, at minimum. 39f90f0

Health (Hunger?)

Plants -> Food?
Amour would be a nice easy feature to add visually to this, just need to change the characters of the player.
Killing animals can increase health, (ae1d878 Eat mob drops to restore health) ~~ mobs can decrease your health. ~~ (ff427e0 Mobs attack players)

Light levels

Maybe we could add light levels and a day/night cycle to the game. We would have limitation with the colours, but I think even if we can get two or three levels it will be worth it. Or maybe it could use denser characters to represent darker light levels? Torches are another feature which would go with this. I think the limitations of the colours will be too much to make this work. It works! (49c7b09) Maybe there could be a sun to represent the time? There is!

Worlds

Things like the Nether, End... This feature would be less susceptible to the limitations of the terminal as it does not need to fit in to the current world (other than a portal, but maybe you could access them another way , e.g.: crafting something?).

Mobs?

Zombies: take your health
Sheep: give you food

Blocks

Plants? e.g.: long grass a0dfa73

Loading from the save file on server

The load_chunks method in both RemoteServer and Server assume the chunks passed are not already loaded in memory, this is checked in the main loop. But now the server has different chunks loaded in memory to the client, so the server might have chunks already loaded in memory, but it will always reload them when load_chunks is called externally.

I'm not sure what would be the best way to fix this. If we add checks to the Server.load_chunks function then it will be doing the checks twice unnecessarily on the host, but we need to do the checks on the clients and the server.

Improve ui.py menus

We need to allow different types of menu items:

  • spacer entries
  • label entries that have no click action

Config

I don't like that we've now got some config in JSON and the rest in Python, it should probably all be in JSON. We should also be using the JSON data to generate the help and to detect key presses.

Pausing

Pause on a server shouldn't pause anything, related: #48

Generic Structure Generation

As we add more structures to the game ( #10 ), it is going to get messy with each of them having roughly the same code, just with some different rules. It would be good if we could define the placement rules in the data.py along with the structures, and then have one function which generates the structures based on that data.

Network Communication Buggy

It keeps missing bits! Why are we still losing bits of the data? TCP should be reliable!

From Wikipedia:

TCP detects these problems, requests retransmission of lost data, rearranges out-of-order data, and even helps minimize network congestion to reduce the occurrence of the other problems. If the data still remains undelivered, its source is notified of this failure

TCP Definition:

TCP uses error correction and data stream control techniques to ensure that packets to arrive at their intended destinations uncorrupted and in the correct sequence, thereby making the point-to-point connection virtually error-free. Packets are the most fundamental unit of data transmission on TCP/IP networks.

We need to figure out why it's not.

Unicode

If we are going to start using more Unicode characters (#9) we need to make sure we are encoding them properly when saving and reading (The save files already use plain ASCII), and we need to provide fallbacks for terminals which don't support the chars. We should be using supported_chars to find a supported character for every character that gets printed.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.