Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # s60_img_blit_bg_tilemap.py
- import appuifw, e32, graphics
- import base64, os, time, random
- import tempfile
- img=None
- def draw(rect):
- if img:
- canvas.blit(img)
- canvas = appuifw.Canvas(redraw_callback=draw)
- appuifw.app.directional_pad=False
- appuifw.app.orientation='portrait'
- appuifw.app.screen='large'
- appuifw.app.body=canvas
- w,h = canvas.size
- img=graphics.Image.new((w,h))
- bgi=graphics.Image.new((w,h))
- run=1
- def quit():
- global run
- lock.signal()
- run=0
- lock = e32.Ao_lock()
- appuifw.app.exit_key_handler = quit
- map=[
- [1,1,1,0,0],
- [1,1,1,1,1],
- [1,0,0,0,1],
- [1,1,1,1,1],
- [2,2,2,2,2],
- [2,0,0,0,2],
- [2,2,2,2,2],
- [0,0,2,2,2]
- ]
- x,y=5,5
- jarak=60
- lbr,kx,ky=60,0,0
- pl = {
- 'R' : ( 1, 0),
- 'L' : (-1, 0),
- 'D' : ( 0, 1),
- 'U' : ( 0,-1)
- }
- bgi.clear(0)
- for yy in range(len(map)):
- for xx in range(len(map[yy])):
- if map[yy][xx]==2:
- bgi.rectangle((x+(xx*jarak),y+(yy*jarak),x+jarak+(xx*jarak),y+jarak+(yy*jarak)),0xda0000,width=4)
- if map[yy][xx]==1:
- bgi.point((x+(xx*jarak),y+(yy*jarak)),0xda,width=4)
- bgi.rectangle((x+(xx*jarak),y+(yy*jarak),x+jarak+(xx*jarak),y+jarak+(yy*jarak)),0xda,width=4)
- p=0
- wait=0
- while run:
- if not p:
- p=kx,ky
- xm,ym=pl[random.choice(list(pl))]
- kx+=xm
- ky+=ym
- kx,ky=max(1,kx),max(1,ky)
- kx,ky=min(len(map[0])-1,kx),min(len(map)-1,ky)
- if not map[ky][kx]:
- kx,ky=p
- p=0
- img.text((5,h-20),u'map location: '+str(map[ky][kx]),0xffffff)
- img.rectangle((x+(kx*lbr),y+(ky*lbr),x+lbr+(kx*lbr),y+lbr+(ky*lbr)),0x00dd00,fill=0x00dd00)
- '''
- if key.press.pressed(key.EScancodeRightArrow):kx+=1;pos_akhir=[kx-1,ky]
- if key.press.pressed(key.EScancodeLeftArrow):kx-=1;pos_akhir=[kx+1,ky]
- if key.press.pressed(key.EScancodeDownArrow): ky+=1;pos_akhir=[kx,ky-1]
- if key.press.pressed(key.EScancodeUpArrow):ky-=1;pos_akhir=[kx,ky+1]
- '''
- if time.time() > wait:
- wait=time.time()+0.04
- draw(())
- img.blit(bgi)
- p=0
- e32.ao_yield()
- lock.wait()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement