Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # -*- coding: utf-8 -*-
- # s60_screen_menu.py
- # + s60_gamegui ZZZ
- from appuifw import *
- import e32,audio,appuifw,os,sys,key_codes,time,math,random,graphics,copy,sysinfo
- from graphics import *
- from math import *
- from random import *
- from key_codes import *
- def scr(msg):
- txt.set(unicode(msg))
- z_Colors = ((u'RGB_BLACK',(0,0,0)),
- (u'RGB_WHITE',(255,255,255)),
- (u'RGB_GRAYLIGHT',(211,211,211)),
- (u'RGB_GRAY',(128,128,128)),
- (u'RGB_GRAYDARK',(169,169,169)),
- (u'RGB_RED',(255,0,0)),
- (u'RGB_ORANGE',(255,165,0)),
- (u'RGB_YELLOW',(255,255,0)),
- (u'RGB_GREEN',(0,128,0)),
- (u'RGB_BLUE',(0,0,255)),
- (u'RGB_CYAN',(0,255,255)),
- (u'RGB_PURPLE',(128,0,255)),
- (u'RGB_PINK',(255,148,238)),
- (u'RGB_DARKBLUE',(0,0,139)),
- (u'RGB_DARKGREEN',(0,100,0)),
- (u'RGB_DEEPPINK',(255,20,147)),
- (u'RGB_INDIGO',(75,0,130)),
- (u'RGB_LIGHTBLUE',(173,216,230)),
- (u'RGB_LIME',(0,255,0)),
- (u'RGB_OLIVE',(107,142,35)),
- (u'RGB_BROWN',(128,64,0)),
- (u'RGB_GOLD',(255,215,0)),
- (u'RGB_SILVER',(192,192,192)))
- #
- rgb_menu="rgb_menu=["
- for rgb in z_Colors:
- i,ii=rgb[0].replace('RGB_',''),str(rgb[1])
- rgb_menu += "(u'"+i+"',c_"+i+"),"
- exec 'def c_'+i+'(): cv.color='+ii
- exec rgb[0]+'='+ii
- rgb_menu += ']'
- def draw(rect): # >>> draw(())
- if img:
- canvas.blit(img)
- def e_callback(event):
- x,y=event['pos']
- try: timer.cancel()
- except: pass
- cv.x=x
- cv.y=y
- #
- defaultspeed=1200.00
- def sp():
- try:
- e32.ao_sleep(speed/sp)
- speed-=0.9
- except: pass
- return defaultspeed-cv.speed
- #
- def fr_sp(z=0.05): # if glichy or 0.1 for moderate speed
- if time.time() > cv.skip:
- cv.skip=time.time()+z
- return True
- #
- def status(color=RGB_WHITE):
- img.text((5,Y-40),u'Score:',color)
- img.text((5,Y-20),u'%d'%(P.score),color)
- try:
- img.text((X-100,Y-20),u''+str(round(time_limit-secs,2)),color)
- img.text((X-100,Y-40),u'Time Left:',color)
- except: pass
- #
- class cv():
- go=1
- init=1
- skip=0
- color=RGB_WHITE
- xyz=(0,0,0)
- xy=0,0
- x=y=0
- light=0
- evt=None
- tmp=0
- sw=0
- jpad=True
- padx,pady=0,0
- mv='X'
- up=-1
- speed=defaultspeed
- cv=cv()
- app.screen = 'large'
- lg_scr = 576
- app.directional_pad = False
- app.orientation='portrait'
- img=None
- app.body = canvas = Canvas(redraw_callback=draw, event_callback=e_callback) #
- x_scr,y_scr=canvas.size
- X,Y=canvas.size
- img=Image.new((x_scr,y_scr))
- def xout(msg=''):
- if query(u''+msg+'\nExit Game?','query'):
- cv.go=0; return 0
- cv.init=0
- def xout_btn(attr=0):
- attr=str(attr)
- bg,fg=RGB_RED,RGB_WHITE
- a,b=cv.xy
- w,h=180,90
- L=w
- if '1' in attr: h=y_scr # not recommended
- if 'v' in attr:
- img.rectangle((w,h-90,w+L,h),fill=bg)
- img.text((w,h-10),u'EXIT',fg,font=('dense',98))
- if (w < a < w+L) and (h-90 < b < h):
- xout()
- cv.xy=0,0
- def void(): pass
- app.exit_key_handler=void
- run=True
- import sensor
- def xyzsens():
- try:
- cv.xyz=(sens.x,sens.y,sens.z)
- except: pass
- sens=sensor.AccelerometerXYZAxisData(data_filter=sensor.LowPassFilter())
- sens.set_callback(data_callback=xyzsens)
- sens.start_listening()
- ### joypad
- 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
- def mU(event):
- cv.mv='U'
- def mD(event):
- cv.mv='D'
- def mL(event):
- cv.mv='L'
- def mR(event):
- cv.mv='R'
- def bind_jpad():
- canvas.bind(EButton1Down,mU,((jx1,jya),(jx2,jy1))) # up
- canvas.bind(EButton1Down,mD,((jx1,jy2),(jx2,jyb))) # down
- canvas.bind(EButton1Down,mL,((jxa,jy1),(jx1,jy2))) # left
- canvas.bind(EButton1Down,mR,((jx2,jy1),(jxb,jy2))) # right
- def jpad():
- if cv.jpad:
- grey=(220,220,220)
- img.rectangle((jxa,jy1,jxb,jy2),fill=grey) # w
- img.rectangle((jx1,jya,jx2,jyb),fill=grey) # h
- jpad_key()
- def jpad_key():
- if cv.mv is 'U':
- xy_=(jx1,jya,jx2,jy1)
- elif cv.mv is 'D':
- xy_=(jx1,jy2,jx2,jyb)
- elif cv.mv is 'L':
- xy_=(jxa,jy1,jx1,jy2)
- elif cv.mv is 'R':
- xy_=(jx2,jy1,jxb,jy2)
- else: return
- img.rectangle(xy_,fill=0xffff00) # yellow
- #
- if not touch_enabled():
- note(u"This application only works on devices that support touch input")
- #
- def up_event(event):
- cv.up=-1
- def dn_event(event):
- cv.up=1
- #
- def mv_event(event):
- cv.xy=event
- #
- def full_bind():
- canvas.bind(EButton1Up, up_event, ((0,0), (x_scr,720)))
- canvas.bind(EButton1Down, dn_event, ((0,0), (x_scr,720)))
- canvas.bind(EDrag, mv_event, ((0,0), (x_scr,720)))
- full_bind()
- bind_jpad()
- img.clear(0)
- mx,my=10,50
- main_menu=['Start','Score','Rules','Store','Info','Exit']
- kx,ky,k=10,50,0
- #bg=graphics.Image.open(u'e:\\800x600poolwater.jpg').resize(res_xy)
- def scr_menu(k):
- if cv.mv is 'U':
- k-=1
- if k<0: k=len(main_menu)-1
- if cv.mv is 'D':
- k+=1
- if k>len(main_menu)-1: k=0
- if cv.mv is 'R': # 'Exit'
- appuifw.note(u''+main_menu[k])
- if k is len(main_menu)-1: cv.go=0
- m=36
- img.rectangle((mx,my,176-mx,my+m+((len(main_menu)-1)*m)),fill=(0xffffff))
- for i in range(len(main_menu)):
- if i == k: img.rectangle((mx,my+(i*m),176-mx,my+m+(i*m)),fill=0xffff00)
- img.rectangle((mx,my+(i*m),176-mx,my+m+(i*m)),0)
- img.text((mx*2,my+29+(i*m)),unicode(''+main_menu[i]),0xff0000,font=('dense',30))
- return k
- ### enter code below...
- p='p'
- r='r'
- g='g'
- b='b'
- maze='''
- ∎.∎.∎.∎.∎.∎.∎.∎.∎.∎.∎.∎.∎.∎.∎.∎.∎.∎.∎
- ∎.p. . . . . . . . .∎.x. . . . . . .∎
- ∎. .∎. .∎.∎.∎. .∎. .∎. .∎. .∎.∎.∎. .∎
- ∎. . . .∎. . . .∎. . . . . . .b.∎. .∎
- ∎.∎.∎. .∎. .∎. .∎. .∎. .∎. .∎. .∎. .∎
- ∎. . . . . .∎. . . . . .∎. . . . . .∎
- ∎. .∎. .∎. .∎.∎.∎. .∎. .∎.x.∎. .∎.∎.∎
- ∎. . .x.∎. . . . . .∎. . . .∎. . . .∎
- ∎.∎.∎. .∎. .∎. .∎.∎.∎.∎.∎. .∎. .∎. .∎
- ∎. . . . . .∎. . . . . . . . . . . .∎
- ∎. .∎.∎.∎. .∎. .∎. .∎.x.∎. .∎.∎.∎. .∎
- ∎. . . .∎. .∎.x. . . . . . .∎. . . .∎
- ∎.∎.∎. .∎. .∎. .∎. .∎.∎.∎. .∎. .∎.∎.∎
- ∎. . . . . . . .∎. . . .∎. . . . . .∎
- ∎. .∎. .∎.∎.∎.∎.∎. .∎. .∎. .∎.∎.∎. .∎
- ∎. . .r. . .∎. . .x.∎. . . . .g. .x.∎
- ∎. .∎.∎.∎. .∎. .∎. .∎. .∎. .∎. .∎. .∎
- ∎. . . . . . . .∎. . . . . .∎. . . .∎
- ∎.∎.∎.∎.∎.∎.∎.∎.∎.∎.∎.∎.∎.∎.∎.∎.∎.∎.∎
- '''
- def qrepl(zzz,r):
- for z in r:
- zzz=zzz.replace(z[0],z[1])
- zzz=zzz.split()
- r=[]
- for z in zzz:
- r.append([int(x) if x.isdigit() else x for x in list(z)])
- return r
- fix=[['.',''],[' ','0'],['∎','1'],['x','2']]
- retile=qrepl(maze,fix)
- tile=retile[:]
- tileSIZE=X/19
- incr=tileSIZE
- tileX,tileY=15,15
- sb2=tileSIZE/2
- move=[(-incr,0),(incr,0),(0,-incr),(0,incr),(0,0)]
- udlr=move[:-1]
- time_limit=60
- '''
- skip=0
- while run:
- if fr_sp():
- ### CODE ###
- if cv.jpad:
- jpad()
- draw(())
- # @ end of mainloop...
- e32.ao_yield()
- '''
- while cv.go:
- if fr_sp():
- img.clear(RGB_GREEN)
- k=scr_menu(k)
- jpad()
- cv.mv=''
- draw(())
- e32.ao_yield()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement