diff --git a/.gitignore b/.gitignore index 0293371..bb96cc8 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,5 @@ field.json game.lock .vscode dev/ +build/ +PythonFarmGame.pex diff --git a/build.sh b/build.sh new file mode 100755 index 0000000..a611a32 --- /dev/null +++ b/build.sh @@ -0,0 +1,9 @@ +#!/usr/bin/bash +cd "$(dirname "$0")" + +rm -R build/ +mkdir build/ +cp -r data build/ +cp dejavusansmono.ttf build/ +pex . pygame -c main -o build/PythonFarmGame.pex +cp build/PythonFarmGame.pex . \ No newline at end of file diff --git a/data/images.json b/data/images.json index d7a2b74..84cecc7 100644 --- a/data/images.json +++ b/data/images.json @@ -1,23 +1,23 @@ { - "imagesdata":{ - "seed":"images/seedstartgrow.png", - "seedhalfgrow":"images/seedhalfgrow.png", - "seedfullgrow":"images/seedfullgrow.png", - "dryground":"images/dryground.png", - "wetground":"images/wetground.png", - "background":"images/gui/background.png", - "mainmenubg":"images/gui/mainmenubg.png", - "sickle":"images/sickle.png", - "plant":"images/plant.png", - "wateringcan":"images/wateringcan.png", - "shovel":"images/shovel.png", - "pickaxe":"images/pickaxe.png", - "axe":"images/axe.png", - "inventory":"images/gui/inventory.png", - "grid":"images/grid.png", - "grid2":"images/grid2.png", - "marketbutton":"images/gui/marketbutton.png", - "inventorybutton":"images/gui/inventorybutton.png", - "marketbg":"images/gui/marketbg.png" + "imagesdata": { + "seed": "data/images/seedstartgrow.png", + "seedhalfgrow": "data/images/seedhalfgrow.png", + "seedfullgrow": "data/images/seedfullgrow.png", + "dryground": "data/images/dryground.png", + "wetground": "data/images/wetground.png", + "background": "data/images/gui/background.png", + "mainmenubg": "data/images/gui/mainmenubg.png", + "sickle": "data/images/sickle.png", + "plant": "data/images/plant.png", + "wateringcan": "data/images/wateringcan.png", + "shovel": "data/images/shovel.png", + "pickaxe": "data/images/pickaxe.png", + "axe": "data/images/axe.png", + "inventory": "data/images/gui/inventory.png", + "grid": "data/images/grid.png", + "grid2": "data/images/grid2.png", + "marketbutton": "data/images/gui/marketbutton.png", + "inventorybutton": "data/images/gui/inventorybutton.png", + "marketbg": "data/images/gui/marketbg.png" } -} +} \ No newline at end of file diff --git a/images/axe.png b/data/images/axe.png similarity index 100% rename from images/axe.png rename to data/images/axe.png diff --git a/images/dryground.png b/data/images/dryground.png similarity index 100% rename from images/dryground.png rename to data/images/dryground.png diff --git a/images/grid.png b/data/images/grid.png similarity index 100% rename from images/grid.png rename to data/images/grid.png diff --git a/images/grid2.png b/data/images/grid2.png similarity index 100% rename from images/grid2.png rename to data/images/grid2.png diff --git a/images/gui/background.png b/data/images/gui/background.png similarity index 100% rename from images/gui/background.png rename to data/images/gui/background.png diff --git a/images/gui/buttonbg.png b/data/images/gui/buttonbg.png similarity index 100% rename from images/gui/buttonbg.png rename to data/images/gui/buttonbg.png diff --git a/images/gui/inventory.png b/data/images/gui/inventory.png similarity index 100% rename from images/gui/inventory.png rename to data/images/gui/inventory.png diff --git a/images/gui/inventorybutton.png b/data/images/gui/inventorybutton.png similarity index 100% rename from images/gui/inventorybutton.png rename to data/images/gui/inventorybutton.png diff --git a/images/gui/mainmenubg.png b/data/images/gui/mainmenubg.png similarity index 100% rename from images/gui/mainmenubg.png rename to data/images/gui/mainmenubg.png diff --git a/images/gui/marketbg.png b/data/images/gui/marketbg.png similarity index 100% rename from images/gui/marketbg.png rename to data/images/gui/marketbg.png diff --git a/images/gui/marketbutton.png b/data/images/gui/marketbutton.png similarity index 100% rename from images/gui/marketbutton.png rename to data/images/gui/marketbutton.png diff --git a/images/objects/object0.png b/data/images/objects/object0.png similarity index 100% rename from images/objects/object0.png rename to data/images/objects/object0.png diff --git a/images/objects/object1.png b/data/images/objects/object1.png similarity index 100% rename from images/objects/object1.png rename to data/images/objects/object1.png diff --git a/images/objects/object10.png b/data/images/objects/object10.png similarity index 100% rename from images/objects/object10.png rename to data/images/objects/object10.png diff --git a/images/objects/object11.png b/data/images/objects/object11.png similarity index 100% rename from images/objects/object11.png rename to data/images/objects/object11.png diff --git a/images/objects/object2.png b/data/images/objects/object2.png similarity index 100% rename from images/objects/object2.png rename to data/images/objects/object2.png diff --git a/images/objects/object3.png b/data/images/objects/object3.png similarity index 100% rename from images/objects/object3.png rename to data/images/objects/object3.png diff --git a/images/objects/object4.png b/data/images/objects/object4.png similarity index 100% rename from images/objects/object4.png rename to data/images/objects/object4.png diff --git a/images/objects/object5.png b/data/images/objects/object5.png similarity index 100% rename from images/objects/object5.png rename to data/images/objects/object5.png diff --git a/images/objects/object6.png b/data/images/objects/object6.png similarity index 100% rename from images/objects/object6.png rename to data/images/objects/object6.png diff --git a/images/objects/object7.png b/data/images/objects/object7.png similarity index 100% rename from images/objects/object7.png rename to data/images/objects/object7.png diff --git a/images/objects/object8.png b/data/images/objects/object8.png similarity index 100% rename from images/objects/object8.png rename to data/images/objects/object8.png diff --git a/images/objects/object9.png b/data/images/objects/object9.png similarity index 100% rename from images/objects/object9.png rename to data/images/objects/object9.png diff --git a/images/pickaxe.png b/data/images/pickaxe.png similarity index 100% rename from images/pickaxe.png rename to data/images/pickaxe.png diff --git a/images/plant.png b/data/images/plant.png similarity index 100% rename from images/plant.png rename to data/images/plant.png diff --git a/images/seedfullgrow.png b/data/images/seedfullgrow.png similarity index 100% rename from images/seedfullgrow.png rename to data/images/seedfullgrow.png diff --git a/images/seedhalfgrow.png b/data/images/seedhalfgrow.png similarity index 100% rename from images/seedhalfgrow.png rename to data/images/seedhalfgrow.png diff --git a/images/seedstartgrow.png b/data/images/seedstartgrow.png similarity index 100% rename from images/seedstartgrow.png rename to data/images/seedstartgrow.png diff --git a/images/shovel.png b/data/images/shovel.png similarity index 100% rename from images/shovel.png rename to data/images/shovel.png diff --git a/images/sickle.png b/data/images/sickle.png similarity index 100% rename from images/sickle.png rename to data/images/sickle.png diff --git a/images/wateringcan.png b/data/images/wateringcan.png similarity index 100% rename from images/wateringcan.png rename to data/images/wateringcan.png diff --git a/images/wetground.png b/data/images/wetground.png similarity index 100% rename from images/wetground.png rename to data/images/wetground.png diff --git a/farmlib/gamewindow.py b/farmlib/gamewindow.py index f1524f3..395d122 100644 --- a/farmlib/gamewindow.py +++ b/farmlib/gamewindow.py @@ -41,7 +41,8 @@ # merge objects images data (objects image have objects/objects+id.png) for gobject in objects: name = "object" + str(gobject['id']) + ".png" - objectsimagepath = os.path.join("images", os.path.join("objects", name)) + objectsimagepath = os.path.join( + "data", "images", os.path.join("objects", name)) imagesdata["object" + str(gobject['id'])] = objectsimagepath diff --git a/farmlib/helpwindow.py b/farmlib/helpwindow.py index 30f3273..6ad9752 100644 --- a/farmlib/helpwindow.py +++ b/farmlib/helpwindow.py @@ -24,7 +24,7 @@ def create_gui(self): messages = [] currpath = os.path.join(os.path.dirname(__file__)) - with open(os.path.join(currpath, '../data/help.txt'), 'r') as help_file: + with open('data/help.txt', 'r') as help_file: lines = help_file.readlines() for l in lines: messages.append(l.strip()) diff --git a/pyFarmGame.py b/farmlib/main.py similarity index 84% rename from pyFarmGame.py rename to farmlib/main.py index bc3c9ed..10d6df5 100755 --- a/pyFarmGame.py +++ b/farmlib/main.py @@ -1,21 +1,22 @@ #!/usr/bin/env python -#-*- coding:utf-8 -*- +# -*- coding:utf-8 -*- import os import pygame -from farmlib import __VERSION__ -from farmlib import PluginSystem -from farmlib.menuwindow import MenuWindow +from . import __VERSION__ +from . import PluginSystem +from .menuwindow import MenuWindow pygame.init() pygame.key.set_repeat(400, 100) + class FarmGamePygame: def __init__(self): """Init game""" self.screen = pygame.display.set_mode((800, 600), pygame.DOUBLEBUF) pygame.display.set_caption("PyFarmGame " + "v. " + __VERSION__) - #timer + # timer self.timer = pygame.time.Clock() self.activescr = None @@ -36,7 +37,6 @@ def events(self): def redraw(self, surface): self.activescr.redraw(surface) - def run(self): """ Run game. Remove lock when error @@ -51,8 +51,8 @@ def run(self): def check_game_lock(self): if os.path.isfile("game.lock"): - print("Game is already running. If not manualy"\ - " remove game.lock file and try again") + print("Game is already running. If not manualy" + " remove game.lock file and try again") exit(0) else: open("game.lock", "w").close() @@ -63,10 +63,10 @@ def remove_game_lock(self): def main(self): """Main""" - #check for lock file + # check for lock file self.check_game_lock() - #IN GAME + # IN GAME if self.ingame: self.activescr.init() elif not self.ingame and self.inmenu: @@ -80,15 +80,19 @@ def main(self): self.timer.tick(30) pygame.display.flip() - #Save game + # Save game if self.ingame: self.activescr.deinit() - #remove lock + # remove lock self.remove_game_lock() -if __name__ == '__main__': + +def main(): f = FarmGamePygame() f.set_active_screen(MenuWindow()) f.run() + +if __name__ == '__main__': + main() diff --git a/farmlib/menuwindow.py b/farmlib/menuwindow.py index c9bfe7a..4123dfb 100644 --- a/farmlib/menuwindow.py +++ b/farmlib/menuwindow.py @@ -22,7 +22,7 @@ def __init__(self): self.maxmenupos = 1 # background - imgpath = os.path.join("images", "gui", "mainmenubg.png") + imgpath = os.path.join("data", "images", "gui", "mainmenubg.png") bgimage = pygame.image.load(imgpath).convert_alpha() bg = Image(bgimage, (0, 0)) self.addwidget(bg) diff --git a/pygameui/button.py b/pygameui/button.py index 328e317..b9e286a 100644 --- a/pygameui/button.py +++ b/pygameui/button.py @@ -3,7 +3,7 @@ from .widget import Widget -buttonbgpath = os.path.join("images", "gui", "buttonbg.png") +buttonbgpath = os.path.join("data", "images", "gui", "buttonbg.png") class Button(Widget): diff --git a/readme.md b/readme.md new file mode 100644 index 0000000..04ad9bb --- /dev/null +++ b/readme.md @@ -0,0 +1,42 @@ +# Python farm game +Writen in python using pygame game library + +**Creator:** orneo1212 orneo1212 [at] gmail.com + +**GitHub (source)**: https://github.com/orneo1212/PythonFarmGame + +**Licence**: GPL v3 ( http://gplv3.fsf.org or gpl-3.0.txt included with game) + +## Game help +``` +Keys: + S - Show/hide Market + I - Show/hide inventory + M - Mute/Unmute sound + H - Help window + +Tools: + Sickle - Use it to harvest seeds. + Plant - Plant new seed selected in inventory + Watercan - Use it to water a seed. (grow time decrease) + Shovel - Use it to remove planted seeds. + Pickaxe - Use it to remove stones. + Axe - Use it to cut off the planks. +``` + +## Build +``` +pip install pex +./build.sh +``` + +## Running +Run game by executing ```python -m farmlib.main``` in console +or ```./PythonFarmGame.pex``` if you have a pex file + +## Changes +* Uppdated to Python 3 + + +## Donate +**Paypal**: orneo1212@gmail.com \ No newline at end of file diff --git a/readme.txt b/readme.txt deleted file mode 100644 index b5d472c..0000000 --- a/readme.txt +++ /dev/null @@ -1,26 +0,0 @@ -Python farm game writen in python using pygame game library - -Creator: orneo1212 orneo1212 [at] gmail.com -GitHub (source): https://github.com/orneo1212/PythonFarmGame -Licence: GPL v3 ( http://gplv3.fsf.org or gpl-3.0.txt included with game) - -Keys: - S - Show/hide Market - I - Show/hide inventory - M - Mute/Unmute sound - H - Help window - -Tools: - Sickle - Use it to harvest seeds. - Plant - Plant new seed selected in inventory - Watercan - Use it to water a seed. (grow time decrease) - Shovel - Use it to remove planted seeds. - Pickaxe - Use it to remove stones. - Axe - Use it to cut off the planks. - - -Uppdated to Python 3 - - -Donate: - Paypal: orneo1212 [at] gmail.com \ No newline at end of file diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..2a829c5 --- /dev/null +++ b/setup.py @@ -0,0 +1,15 @@ +from setuptools import setup + +setup( + name="Python Farm Game", + version="0.5.2", + description="Python farm game ", + author="orneo1212", + author_email="orneo1212@gmail.com", + packages=["farmlib", "pygameui"], # same as name + entry_points={ + "console_scripts": [ + "main=farmlib.main:main", + ], + }, +)