Skip to content

Instantly share code, notes, and snippets.

@sinistersnare
Last active December 25, 2015 15:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sinistersnare/3b67d40634b59c14d3ca to your computer and use it in GitHub Desktop.
Save sinistersnare/3b67d40634b59c14d3ca to your computer and use it in GitHub Desktop.
cant run
sinistersnare@aelita [05:37:00] [~/Development/testing/jython/PyGdx] [master *]
-> % cat __run__.py
'''
Created on Oct 14, 2013
This module can be thought of as the main method. The entry point to the created JAR.
Notice the `if __name__ =='__run__':` as opposed to '__main__' for reference :D
@author: sinistersnare
'''
from com.badlogic.gdx.backends.lwjgl import LwjglApplicationConfiguration, LwjglApplication
from Gdx import PyGdx
def main():
cfg = LwjglApplicationConfiguration()
cfg.title = "PyGdx";
cfg.width = 800
cfg.height = 480
LwjglApplication(PyGdx(), cfg)
if __name__ == '__run__':
"""
notice __run__ as opposed to __main__
think of this as the jar'd equivalent
"""
main()
sinistersnare@aelita [05:36:53] [~/Development/testing/jython/PyGdx] [master *]
-> % java -jar PyGDX-0.1-single.jar
Exception in thread "main" Traceback (most recent call last):
File "__pyclasspath__/__run__.py", line 9, in <module>
ImportError: No module named Gdx
sinistersnare@aelita [06:01:55] [~/Development/testing/jython/PyGdx] [master *]
-> % cat PyGdx/Gdx.py
from com.badlogic.gdx.backends.lwjgl import LwjglApplication, LwjglApplicationConfiguration
from com.badlogic.gdx.utils import TimeUtils, Array
from com.badlogic.gdx.math import MathUtils, Rectangle, Vector3
from com.badlogic.gdx import ApplicationListener, Gdx, Input
from com.badlogic.gdx.graphics.g2d import SpriteBatch
from com.badlogic.gdx.graphics import Texture, OrthographicCamera, GL10
class PyGdx(ApplicationListener):
def __init__(self):
self.camera = None
self.batch = None
self.texture = None
self.bucketimg = None
self.dropsound = None
self.rainmusic = None
self.bucket = None
self.raindrops = None
self.lastdrop = 0
self.width = 800
self.height = 480
def spawndrop(self):
raindrop = Rectangle()
raindrop.x = MathUtils.random(0, self.width - 64)
raindrop.y = self.height
raindrop.width = 64
raindrop.height = 64
self.raindrops.add(raindrop)
self.lastdrop = TimeUtils.nanoTime()
def create(self):
self.camera = OrthographicCamera()
self.camera.setToOrtho(False, self.width, self.height)
self.batch = SpriteBatch()
self.dropimg = Texture("assets/droplet.png")
self.bucketimg = Texture("assets/bucket.png")
self.dropsound = Gdx.audio.newSound(Gdx.files.internal("assets/drop.wav"))
self.rainmusic = Gdx.audio.newSound(Gdx.files.internal("assets/rain.mp3"))
self.bucket = Rectangle()
self.bucket.x = (self.width / 2) - (64 / 2)
self.bucket.y = 20
self.bucket.width = 64
self.bucket.height = 64
self.raindrops = Array()
self.spawndrop()
self.rainmusic.setLooping(True, True)
self.rainmusic.play()
def render(self):
Gdx.gl.glClearColor(0,0,0.2,0)
Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT)
self.camera.update()
self.batch.setProjectionMatrix(self.camera.combined)
self.batch.begin()
self.batch.draw(self.bucketimg, self.bucket.x, self.bucket.y)
for drop in self.raindrops:
self.batch.draw(self.dropimg, drop.x, drop.y)
self.batch.end()
if Gdx.input.isTouched():
touchpos = Vector3()
touchpos.set(Gdx.input.getX(), Gdx.input.getY(), 0)
self.camera.unproject(touchpos)
self.bucket.x = touchpos.x - (64 / 2)
if Gdx.input.isKeyPressed(Input.Keys.LEFT): self.bucket.x -= 200 * Gdx.graphics.getDeltaTime()
if Gdx.input.isKeyPressed(Input.Keys.RIGHT): self.bucket.x += 200 * Gdx.graphics.getDeltaTime()
if self.bucket.x < 0: self.bucket.x = 0
if self.bucket.x > (self.width - 64): self.bucket.x = self.width - 64
if (TimeUtils.nanoTime() - self.lastdrop) > 1000000000: self.spawndrop()
iterator = self.raindrops.iterator()
while iterator.hasNext():
raindrop = iterator.next()
raindrop.y -= 200 * Gdx.graphics.getDeltaTime();
if (raindrop.y + 64) < 0: iterator.remove()
if raindrop.overlaps(self.bucket):
self.dropsound.play()
iterator.remove()
def resize(self, width, height):
pass
def pause(self):
pass
def resume(self):
pass
def dispose(self):
self.batch.dispose()
self.dropimg.dispose()
self.bucketimg.dispose()
self.dropsound.dispose()
self.rainmusic.dispose()
def main():
"""
This shouldnt be run, it should be happening from __run__ module.
"""
cfg = LwjglApplicationConfiguration()
cfg.title = "PyGdx";
cfg.width = 800
cfg.height = 480
LwjglApplication(PyGdx(), cfg)
if __name__ == '__main__':
"""
This shouldnt be run, it should be happening from __run__ module.
"""
main()
sinistersnare@aelita [07:27:22] [~/Development/testing/jython/PyGdx] [master *]
-> % jython-ssl setup.py sdist
zsh: correct 'sdist' to 'dist' [nyae]? n
Validating: clamp ['Gdx']
running sdist
running egg_info
writing PyGDX.egg-info/PKG-INFO
writing requirements to PyGDX.egg-info/requires.txt
writing top-level names to PyGDX.egg-info/top_level.txt
writing dependency_links to PyGDX.egg-info/dependency_links.txt
error: package directory 'Gdx' does not exist
sinistersnare@aelita [06:57:10] [~/Development/testing/jython/PyGdx] [master *]
-> % cat setup.py
#!python
'''
Created on Oct 14, 2013
Stolen from jimbaker/clamped on github because hes smart and got this working
@author: sinistersnare
'''
import ez_setup
ez_setup.use_setuptools()
from setuptools import setup, find_packages
setup(
name = "PyGDX",
version = "0.1",
packages = ['Gdx'], #was find_packages()
install_requires = ["clamp>=0.2"],
clamp = ["Gdx"],
py_modules=['Gdx'],
)
sinistersnare@aelita [06:56:33] [~/Development/testing/jython/PyGdx] [master *]
-> % tree
.
├── assets
│   ├── bucket.png
│   ├── droplet.png
│   ├── drop.wav
│   ├── libgdx.png
│   └── rain.mp3
├── ez_setup.py
├── Gdx.py
├── lib
│   ├── gdx-backend-lwjgl.jar
│   ├── gdx-backend-lwjgl-natives.jar
│   ├── gdx.jar
│   ├── gdx-natives.jar
│   └── gdx-sources.jar
├── LICENSE
├── README.md
├── __run__.py
└── setup.py
7 directories, 31 files
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment