Advertisement
here2share

# s60_img_blit_bg_tilemap.py

Jul 29th, 2017
464
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # s60_img_blit_bg_tilemap.py
  2.  
  3. import appuifw, e32, graphics
  4. import base64, os, time, random
  5. import tempfile
  6.  
  7. img=None
  8. def draw(rect):
  9.     if img:
  10.         canvas.blit(img)
  11.  
  12. canvas = appuifw.Canvas(redraw_callback=draw)
  13. appuifw.app.directional_pad=False
  14. appuifw.app.orientation='portrait'
  15. appuifw.app.screen='large'
  16. appuifw.app.body=canvas
  17. w,h = canvas.size
  18. img=graphics.Image.new((w,h))
  19. bgi=graphics.Image.new((w,h))
  20.  
  21. run=1
  22. def quit():
  23.  global run
  24.  lock.signal()
  25.  run=0
  26. lock = e32.Ao_lock()
  27. appuifw.app.exit_key_handler = quit
  28.  
  29. map=[
  30.  [1,1,1,0,0],
  31.  [1,1,1,1,1],
  32.  [1,0,0,0,1],
  33.  [1,1,1,1,1],
  34.  [2,2,2,2,2],
  35.  [2,0,0,0,2],
  36.  [2,2,2,2,2],
  37.  [0,0,2,2,2]
  38.  ]
  39. x,y=5,5
  40. jarak=60
  41. lbr,kx,ky=60,0,0
  42.  
  43.  
  44.  
  45. pl = {
  46. 'R' : ( 1, 0),
  47. 'L' : (-1, 0),
  48. 'D' : ( 0, 1),
  49. 'U' : ( 0,-1)
  50. }
  51.  
  52. bgi.clear(0)
  53. for yy in range(len(map)):
  54.     for xx in range(len(map[yy])):
  55.         if map[yy][xx]==2:
  56.             bgi.rectangle((x+(xx*jarak),y+(yy*jarak),x+jarak+(xx*jarak),y+jarak+(yy*jarak)),0xda0000,width=4)
  57.         if map[yy][xx]==1:
  58.             bgi.point((x+(xx*jarak),y+(yy*jarak)),0xda,width=4)
  59.             bgi.rectangle((x+(xx*jarak),y+(yy*jarak),x+jarak+(xx*jarak),y+jarak+(yy*jarak)),0xda,width=4)
  60. p=0
  61. wait=0
  62. while run:
  63.     if not p:
  64.         p=kx,ky
  65.         xm,ym=pl[random.choice(list(pl))]
  66.         kx+=xm
  67.         ky+=ym
  68.         kx,ky=max(1,kx),max(1,ky)
  69.         kx,ky=min(len(map[0])-1,kx),min(len(map)-1,ky)
  70.         if not map[ky][kx]:
  71.             kx,ky=p
  72.             p=0
  73.     img.text((5,h-20),u'map location: '+str(map[ky][kx]),0xffffff)
  74.     img.rectangle((x+(kx*lbr),y+(ky*lbr),x+lbr+(kx*lbr),y+lbr+(ky*lbr)),0x00dd00,fill=0x00dd00)
  75.     '''
  76.     if key.press.pressed(key.EScancodeRightArrow):kx+=1;pos_akhir=[kx-1,ky]
  77.     if key.press.pressed(key.EScancodeLeftArrow):kx-=1;pos_akhir=[kx+1,ky]
  78.     if key.press.pressed(key.EScancodeDownArrow): ky+=1;pos_akhir=[kx,ky-1]
  79.     if key.press.pressed(key.EScancodeUpArrow):ky-=1;pos_akhir=[kx,ky+1]
  80.     '''
  81.     if time.time() > wait:
  82.         wait=time.time()+0.04
  83.         draw(())
  84.         img.blit(bgi)
  85.         p=0
  86.     e32.ao_yield()
  87. lock.wait()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement