Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # jpadxy.py <<< *generic_demo
- import appuifw,graphics,e32,random,key_codes,time
- running=1
- pos_x=0
- pos_y=0
- go=None
- def mU(event):
- global pos_y,go
- if pos_y > 0:
- pos_y-=1
- go=0
- def mD(event):
- global pos_y,go
- if pos_y < max_rows-2:
- pos_y+=1
- go=1
- def mL(event):
- global pos_x,go
- if pos_x > 0:
- pos_x-=1
- go=2
- def mR(event):
- global pos_x,go
- if pos_x < max_cols-2:
- pos_x+=1
- go=3
- def quit():
- global running
- running=0
- def utf(x):
- return x.decode("utf8")
- def draw(rect):
- try:
- canvas.blit(img)
- except: pass
- appuifw.app.screen = 'large'
- appuifw.app.orientation = 'portrait'
- appuifw.app.directional_pad = False
- appuifw.app.body=canvas=appuifw.Canvas(redraw_callback=draw)
- w,h=canvas.size
- img=graphics.Image.new((w,h))
- appuifw.app.exit_key_handler=quit
- timer = e32.Ao_timer()
- min_padding=6
- x,y=(canvas.size[0],(canvas.size[1]))
- player_size=12
- padx=x-min_padding*2
- max_rows=28
- max_cols=(padx/player_size)
- a=((x-(max_cols*player_size))/2)-1
- b=max_cols*player_size+a
- rows=(player_size)*max_rows
- print
- print x,y,a,b,max_cols
- jxa,jya=70,350 ### <<< jpad xy axis point
- jxb,jyb=jxa+220,jya+220
- jx1,jy1=jxa+70,jya+70
- jx2,jy2=jxa+150,jya+150
- canvas.bind(key_codes.EButton1Down,mU,((jx1,jya),(jx2,jy1))) # up
- canvas.bind(key_codes.EButton1Down,mD,((jx1,jy2),(jx2,jyb))) # down
- canvas.bind(key_codes.EButton1Down,mL,((jxa,jy1),(jx1,jy2))) # left
- canvas.bind(key_codes.EButton1Down,mR,((jx2,jy1),(jxb,jy2))) # right
- def jpad():
- grey=(220,220,220)
- img.rectangle((jxa,jy1,jxb,jy2),fill=grey) # w
- img.rectangle((jx1,jya,jx2,jyb),fill=grey) # h
- draw(())
- def jpad_key():
- if go == 0:
- xy_=(jx1,jya,jx2,jy1) # U
- elif go == 1:
- xy_=(jx1,jy2,jx2,jyb) # D
- elif go == 2:
- xy_=(jxa,jy1,jx1,jy2) # L
- elif go == 3:
- xy_=(jx2,jy1,jxb,jy2) # R
- else: return
- img.rectangle(xy_,fill=0xffff00)
- draw(())
- def play():
- global pos_x,pos_y,step,go
- prev_xy=None
- while running:
- if prev_xy <> (pos_x,pos_y):
- img.clear(0xffffff)
- jpad()
- img.rectangle((a,2,b+1,rows+4),0x000000,width=2)
- img.rectangle((a*21+3,a*21+3,a*21+a-2,a*21+a-2),fill=0xff0000)
- img.point((pos_x*player_size+a+player_size,pos_y*player_size+2+player_size),0x00ff00,width=player_size)
- img.text((20,360),utf('x: %d y: %d' %(pos_x,pos_y)),0x0000ff) ### <<< int to string placeholders
- jpad_key()
- prev_xy=pos_x,pos_y
- try: timer.cancel()
- except: pass
- timer.after(1,jpad)
- draw(())
- e32.ao_yield()
- play()
- timer.cancel()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement