What happened to the Messenger Plus! forums on msghelp.net?
Shoutbox » MsgHelp Archive » Skype & Technology » Tech Talk » Python help

Python help
Author: Message:
Jarrod
Veteran Member
*****

Avatar
woot simpson

Posts: 1304
Reputation: 20
– / Male / Flag
Joined: Sep 2006
RE: Python help, Solution :)
Python code:
import pyglet as pyg
import random
from pyglet.window import key
window=pyg.window.Window()
 
#map- when arrow keys are pressed in pyglet, the symbol that represents them is a number
#he numbers are:
#65361 = left = 0
#65362 = up = 1
#65363 = right = 2
#65364 = down = 3
#we now have 4 numbers 1-4, each representing an arrow key
#
keys=[False]*4
#so now we have a list of 4 False values, which will represent each arrow,
#python indexes an array/list starting from 0
 
#above we mention 4 numbers, 65361,65362,65363,65364
#instead of mapping each to a dictionary if we get the last digit and subtract 1 we end up with a set like
#0,1,2,3
#so now if we let this number index keys like this
#keys[((int(str(symbol)[-1]))-1)]
#it is the same as saying:
#
#def on_key_press(symbol,modifiers,keys=keys):
#   if symbol == 65361:
#       keys[0]=True    #keys[0] is left
#   if symbol == 65362:
#       keys[1] == True
# #ect,ect
 
#keys are mapped ((int(str(symbol)[-1]))-1)
 
@window.event
def on_key_press(symbol,modifiers,keys=keys):
    #print symbol,((int(str(symbol)[-1]))-1)
    keys[((int(str(symbol)[-1]))-1)] = True
@window.event
 
def on_key_release(symbol,modifiers,keys=keys):
    keys[((int(str(symbol)[-1]))-1)] = False
 
def update(dt,keys=keys):
    #by using this statement we determine more complex events first (left + up) so it fulfils these instead fulfilling a less complex (left)
    if keys[0] and keys[1]:
        print 'left'+'up'
    elif keys[1] and keys[2]:
        print 'right'+'up'
    elif keys[0] and keys[3]:
        print 'down'+'left'
    elif keys[2] and keys[3]:
        print "down"+'right'
    elif keys[0]:
        print "left"    #due to this, if two conflicting keys are help the upper most one will occur
    elif keys[1]:
        print "up"      #up occurs if 'down' and 'up' are down, left occurs if 'left' and 'right' are down
    elif keys[2]:
        print 'right'
    elif keys[3]:
        print "down"
   
 
pyg.clock.schedule_interval(update, 0.1)
pyg.app.run()


try that,
sorry for the delay been a touch busy

This post was edited on 09-20-2009 at 09:30 PM by Jarrod.

[Image: 5344.png]
[Image: sig.png]

A.k.a. The Glad Falconer














09-20-2009 01:33 PM
Profile E-Mail PM Find Quote Report
« Next Oldest Return to Top Next Newest »

Messages In This Thread
Python help - by Chancer on 09-14-2009 at 01:47 AM
RE: Python help - by Ezra on 09-14-2009 at 05:23 PM
RE: Python help - by Chancer on 09-14-2009 at 08:55 PM
RE: Python help - by Jarrod on 09-15-2009 at 08:11 AM
RE: Python help - by Chancer on 09-15-2009 at 08:45 PM
RE: Python help - by matty on 09-16-2009 at 12:36 PM
RE: Python help - by Chancer on 09-16-2009 at 05:55 PM
RE: Python help, Solution :) - by Jarrod on 09-20-2009 at 01:33 PM
RE: Python help - by Chancer on 09-20-2009 at 03:26 PM
RE: Python help - by Jarrod on 09-20-2009 at 09:40 PM
RE: Python help - by Chancer on 09-20-2009 at 10:05 PM
RE: Python help - by Jarrod on 09-20-2009 at 10:08 PM
RE: Python help - by Chancer on 09-21-2009 at 01:06 AM
RE: Python help - by Jarrod on 09-21-2009 at 01:23 AM
RE: Python help - by Chancer on 09-26-2009 at 11:20 PM
RE: Python help - by Jarrod on 09-27-2009 at 09:35 AM
RE: Python help - by Chancer on 09-27-2009 at 02:39 PM
RE: Python help - by Jarrod on 09-27-2009 at 09:12 PM
RE: Python help - by Chancer on 09-27-2009 at 10:47 PM
RE: Python help - by Chancer on 10-04-2009 at 04:05 AM


Threaded Mode | Linear Mode
View a Printable Version
Send this Thread to a Friend
Subscribe | Add to Favorites
Rate This Thread:

Forum Jump:

Forum Rules:
You cannot post new threads
You cannot post replies
You cannot post attachments
You can edit your posts
HTML is Off
myCode is On
Smilies are On
[img] Code is On