Skip to content

Instantly share code, notes, and snippets.

View hortonew's full-sized avatar

Erik Horton hortonew

View GitHub Profile
@hortonew
hortonew / pygame7_mouseHandling.py
Last active December 10, 2015 23:18
Pygame - Mouse Handling
import pygame, sys
running = True
pygame.init()
screen = pygame.display.set_mode((800,600))
clock = pygame.time.Clock()
def handleEvents():
for event in pygame.event.get():
#print current mouse position
@hortonew
hortonew / pyglet6_batchGroup.py
Last active December 10, 2015 23:09
Pyglet - Batch Group
import pyglet
#index all resources
pyglet.resource.path = ['resources']
pyglet.resource.reindex()
#create window object
screen = pyglet.window.Window(800, 600)
#create batch group to put all objects in
@hortonew
hortonew / pygame6_imageGroup.py
Last active December 10, 2015 23:09
Pygame - Image group
import pygame, sys, os
running = True
pygame.init()
screen = pygame.display.set_mode((800,600))
clock = pygame.time.Clock()
#calculate current path + location of player image
mypath = os.path.dirname( os.path.realpath( __file__) )
p_path = os.path.join(mypath, 'player.png')
@hortonew
hortonew / pyglet5_imageText.py
Last active December 10, 2015 23:09
Pyglet - Sprite image and Text label
import pyglet
#index all resources. Resources folder must be on same level as this file.
pyglet.resource.path = ['resources']
pyglet.resource.reindex()
#create window object
screen = pyglet.window.Window(800, 600)
#create player object. Player image must be in resource folder.
@hortonew
hortonew / pygame5_imageText.py
Last active December 10, 2015 23:09
Pygame - Sprite image and Text label
import pygame, sys, os
running = True
pygame.init()
screen = pygame.display.set_mode((800,600))
clock = pygame.time.Clock()
#calculate current path + location of player image. Image must be on same level as this file
mypath = os.path.dirname( os.path.realpath( __file__) )
p_path = os.path.join(mypath, 'player.png')
@hortonew
hortonew / pyglet4_handleEvents.py
Created January 11, 2013 00:38
Pyglet - Handle Events
import pyglet
from pyglet.window import key
screen = pyglet.window.Window(800,600)
@screen.event
def on_key_press(symbol, modifiers):
if symbol == key.A:
print 'You pressed A'
@hortonew
hortonew / pygame4_handleEvents.py
Created January 11, 2013 00:38
Pygame - Handle Events
import pygame, sys
from pygame.locals import *
running = True
pygame.init()
screen = pygame.display.set_mode((800,600))
clock = pygame.time.Clock()
def handleEvents():
global running
@hortonew
hortonew / pyglet3_controlFPS.py
Created January 11, 2013 00:37
Pyglet - Control FPS
import pyglet
screen = pyglet.window.Window(800,600)
def update(dt):
#update objects here
if __name__ == "__main__":
pyglet.clock.schedule_interval(update, 1/120.0)
pyglet.app.run()
@hortonew
hortonew / pygame3_controlFPS.py
Created January 11, 2013 00:36
Pygame - Control FPS
import pygame
pygame.init()
screen = pygame.display.set_mode((800,600))
clock = pygame.time.Clock()
def update():
#update objects here
if __name__ == "__main__":
while True:
@hortonew
hortonew / pyglet2_clearScreen.py
Last active December 10, 2015 23:08
Pyglet - Clear Screen
import pyglet
screen = pyglet.window.Window(800,600)
@screen.event
def on_draw():
screen.clear()
if __name__ == "__main__":
pyglet.app.run()