Advertisement
here2share

# jpadxy.py <<< *generic_demo

May 24th, 2015
346
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # jpadxy.py <<< *generic_demo
  2.  
  3. import appuifw,graphics,e32,random,key_codes,time
  4. running=1
  5. pos_x=0
  6. pos_y=0
  7. go=None
  8.  
  9. def mU(event):
  10.     global pos_y,go
  11.     if pos_y > 0:
  12.         pos_y-=1
  13.         go=0
  14. def mD(event):
  15.     global pos_y,go
  16.     if pos_y < max_rows-2:
  17.         pos_y+=1
  18.         go=1
  19. def mL(event):
  20.     global pos_x,go
  21.     if pos_x > 0:
  22.         pos_x-=1
  23.         go=2
  24. def mR(event):
  25.     global pos_x,go
  26.     if pos_x < max_cols-2:
  27.         pos_x+=1
  28.         go=3
  29.  
  30. def quit():
  31.     global running
  32.     running=0
  33. def utf(x):
  34.     return x.decode("utf8")
  35. def draw(rect):
  36.     try:
  37.         canvas.blit(img)
  38.     except: pass
  39.  
  40. appuifw.app.screen = 'large'
  41. appuifw.app.orientation = 'portrait'
  42. appuifw.app.directional_pad = False
  43. appuifw.app.body=canvas=appuifw.Canvas(redraw_callback=draw)
  44. w,h=canvas.size
  45.  
  46. img=graphics.Image.new((w,h))
  47. appuifw.app.exit_key_handler=quit
  48. timer = e32.Ao_timer()
  49.  
  50. min_padding=6
  51. x,y=(canvas.size[0],(canvas.size[1]))
  52. player_size=12
  53. padx=x-min_padding*2
  54. max_rows=28
  55. max_cols=(padx/player_size)
  56. a=((x-(max_cols*player_size))/2)-1
  57. b=max_cols*player_size+a
  58. rows=(player_size)*max_rows
  59. print
  60. print x,y,a,b,max_cols
  61.  
  62. jxa,jya=70,350 ### <<< jpad xy axis point
  63. jxb,jyb=jxa+220,jya+220
  64. jx1,jy1=jxa+70,jya+70
  65. jx2,jy2=jxa+150,jya+150
  66. canvas.bind(key_codes.EButton1Down,mU,((jx1,jya),(jx2,jy1)))     # up
  67. canvas.bind(key_codes.EButton1Down,mD,((jx1,jy2),(jx2,jyb)))     # down
  68. canvas.bind(key_codes.EButton1Down,mL,((jxa,jy1),(jx1,jy2)))     # left
  69. canvas.bind(key_codes.EButton1Down,mR,((jx2,jy1),(jxb,jy2)))     # right
  70.  
  71. def jpad():
  72.     grey=(220,220,220)
  73.     img.rectangle((jxa,jy1,jxb,jy2),fill=grey) # w
  74.     img.rectangle((jx1,jya,jx2,jyb),fill=grey) # h
  75.     draw(())
  76. def jpad_key():
  77.     if   go == 0:
  78.         xy_=(jx1,jya,jx2,jy1) # U
  79.     elif go == 1:
  80.         xy_=(jx1,jy2,jx2,jyb) # D
  81.     elif go == 2:
  82.         xy_=(jxa,jy1,jx1,jy2) # L
  83.     elif go == 3:
  84.         xy_=(jx2,jy1,jxb,jy2) # R
  85.     else: return
  86.     img.rectangle(xy_,fill=0xffff00)
  87.     draw(())
  88.  
  89. def play():
  90.   global pos_x,pos_y,step,go
  91.   prev_xy=None
  92.   while running:
  93.     if prev_xy <> (pos_x,pos_y):
  94.         img.clear(0xffffff)
  95.         jpad()
  96.         img.rectangle((a,2,b+1,rows+4),0x000000,width=2)
  97.         img.rectangle((a*21+3,a*21+3,a*21+a-2,a*21+a-2),fill=0xff0000)
  98.         img.point((pos_x*player_size+a+player_size,pos_y*player_size+2+player_size),0x00ff00,width=player_size)
  99.         img.text((20,360),utf('x: %d   y: %d' %(pos_x,pos_y)),0x0000ff) ### <<< int to string placeholders
  100.         jpad_key()
  101.         prev_xy=pos_x,pos_y
  102.         try: timer.cancel()
  103.         except: pass
  104.         timer.after(1,jpad)
  105.         draw(())
  106.     e32.ao_yield()
  107. play()
  108.  
  109. timer.cancel()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement