Skip to content

Commit

Permalink
Added PEX build script
Browse files Browse the repository at this point in the history
  • Loading branch information
orneo1212 committed May 22, 2022
1 parent c360742 commit 7eee31b
Show file tree
Hide file tree
Showing 43 changed files with 111 additions and 64 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@ field.json
game.lock
.vscode
dev/
build/
PythonFarmGame.pex
9 changes: 9 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
@@ -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 .
42 changes: 21 additions & 21 deletions data/images.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
}
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
3 changes: 2 additions & 1 deletion farmlib/gamewindow.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
2 changes: 1 addition & 1 deletion farmlib/helpwindow.py
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
30 changes: 17 additions & 13 deletions pyFarmGame.py → farmlib/main.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -36,7 +37,6 @@ def events(self):
def redraw(self, surface):
self.activescr.redraw(surface)


def run(self):
"""
Run game. Remove lock when error
Expand All @@ -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()
Expand All @@ -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:
Expand All @@ -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()
2 changes: 1 addition & 1 deletion farmlib/menuwindow.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion pygameui/button.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
42 changes: 42 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
@@ -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
26 changes: 0 additions & 26 deletions readme.txt

This file was deleted.

15 changes: 15 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -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",
],
},
)

0 comments on commit 7eee31b

Please sign in to comment.