Advertisement
here2share

# s60_orbits.py

Oct 2nd, 2016
282
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # -*- coding: utf-8 -*-
  2.  
  3. # s60_orbits.py
  4. # + s60_gamegui ZZZ
  5.  
  6. from appuifw import *
  7. import e32,audio,appuifw,os,sys,key_codes,time,math,random,graphics,copy,sysinfo
  8. from graphics import *
  9. from math import *
  10. from random import *
  11. from key_codes import *
  12.  
  13. def scr(msg):
  14.     txt.set(unicode(msg))
  15.  
  16. z_Colors =  ((u'RGB_BLACK',(0,0,0)),
  17.             (u'RGB_WHITE',(255,255,255)),
  18.             (u'RGB_GRAYLIGHT',(211,211,211)),
  19.             (u'RGB_GRAY',(128,128,128)),
  20.             (u'RGB_GRAYDARK',(169,169,169)),
  21.             (u'RGB_RED',(255,0,0)),
  22.             (u'RGB_ORANGE',(255,165,0)),
  23.             (u'RGB_YELLOW',(255,255,0)),
  24.             (u'RGB_GREEN',(0,128,0)),
  25.             (u'RGB_BLUE',(0,0,255)),
  26.             (u'RGB_CYAN',(0,255,255)),
  27.             (u'RGB_PURPLE',(128,0,255)),
  28.  
  29.             (u'RGB_PINK',(255,148,238)),
  30.             (u'RGB_DARKBLUE',(0,0,139)),
  31.             (u'RGB_DARKGREEN',(0,100,0)),
  32.             (u'RGB_DEEPPINK',(255,20,147)),
  33.             (u'RGB_INDIGO',(75,0,130)),
  34.             (u'RGB_LIGHTBLUE',(173,216,230)),
  35.             (u'RGB_LIME',(0,255,0)),
  36.             (u'RGB_OLIVE',(107,142,35)),
  37.  
  38.             (u'RGB_BROWN',(128,64,0)),
  39.             (u'RGB_GOLD',(255,215,0)),
  40.             (u'RGB_SILVER',(192,192,192)))
  41. #
  42. rgb_menu="rgb_menu=["
  43. for rgb in z_Colors:
  44.     i,ii=rgb[0].replace('RGB_',''),str(rgb[1])
  45.     rgb_menu += "(u'"+i+"',c_"+i+"),"
  46.     exec 'def c_'+i+'(): cv.color='+ii
  47.     exec rgb[0]+'='+ii
  48. rgb_menu += ']'
  49.  
  50. def draw(rect): # >>> draw(())
  51.     if img:
  52.         canvas.blit(img)
  53. def e_callback(event):
  54.     x,y=event['pos']
  55.     try: timer.cancel()
  56.     except: pass
  57.     cv.x=x
  58.     cv.y=y
  59. #
  60. defaultspeed=1200.00
  61. def sp():
  62.     try:
  63.         e32.ao_sleep(speed/sp)
  64.         speed-=0.9
  65.     except: pass
  66.     return defaultspeed-cv.speed
  67. #
  68. def fr_sp(z=0.05): # if glichy or 0.1 for moderate speed
  69.     if time.time() > cv.skip:
  70.         cv.skip=time.time()+z
  71.         return True
  72. #
  73. def status(color=RGB_WHITE):
  74.     img.text((5,Y-40),u'Score:',color)
  75.     img.text((5,Y-20),u'%d'%(P.score),color)
  76.     try:
  77.         img.text((X-100,Y-20),u''+str(round(time_limit-secs,2)),color)
  78.         img.text((X-100,Y-40),u'Time Left:',color)
  79.     except: pass
  80. #
  81. class cv():
  82.     go=1
  83.     init=1
  84.     skip=0
  85.     color=RGB_WHITE
  86.     xyz=(0,0,0)
  87.     xy=0,0
  88.     x=y=0
  89.     light=0
  90.     evt=None
  91.     tmp=0
  92.     sw=0
  93.     jpad=True
  94.     padx,pady=0,0
  95.     mv='X'
  96.     up=-1
  97.     speed=defaultspeed
  98. cv=cv()
  99.  
  100. app.screen = 'large'
  101. lg_scr = 576
  102. app.directional_pad = False
  103. app.orientation='portrait'
  104. img=None
  105. app.body = canvas = Canvas(redraw_callback=draw, event_callback=e_callback) #
  106. x_scr,y_scr=canvas.size
  107. X,Y=canvas.size
  108. img=Image.new((x_scr,y_scr))
  109. def xout(msg=''):
  110.     if query(u''+msg+'\nExit Game?','query'):
  111.         cv.go=0; return 0
  112.     cv.init=0
  113. def xout_btn(attr=0):
  114.     attr=str(attr)
  115.     bg,fg=RGB_RED,RGB_WHITE
  116.     a,b=cv.xy
  117.     w,h=180,90
  118.     L=w
  119.     if '1' in attr: h=y_scr # not recommended
  120.     if 'v' in attr:
  121.         img.rectangle((w,h-90,w+L,h),fill=bg)
  122.         img.text((w,h-10),u'EXIT',fg,font=('dense',98))
  123.     if (w < a < w+L) and (h-90 < b < h):
  124.         xout()
  125.         cv.xy=0,0
  126. def void(): pass
  127. def oExit(): cv.go=False
  128. def exit_btn(): app.exit_key_handler=oExit
  129. run=True
  130.  
  131. import sensor
  132. def xyzsens():
  133.     try:
  134.         cv.xyz=(sens.x,sens.y,sens.z)
  135.     except: pass
  136. sens=sensor.AccelerometerXYZAxisData(data_filter=sensor.LowPassFilter())
  137. sens.set_callback(data_callback=xyzsens)
  138. sens.start_listening()
  139.  
  140. ### joypad
  141. jxa,jya=70,350 ### <<< jpad xy axis point
  142. jxb,jyb=jxa+220,jya+220
  143. jx1,jy1=jxa+70,jya+70
  144. jx2,jy2=jxa+150,jya+150
  145. def mU(event):
  146.     cv.mv='U'
  147. def mD(event):
  148.     cv.mv='D'
  149. def mL(event):
  150.     cv.mv='L'
  151. def mR(event):
  152.     cv.mv='R'
  153. def bind_jpad():
  154.     canvas.bind(EButton1Down,mU,((jx1,jya),(jx2,jy1)))   # up
  155.     canvas.bind(EButton1Down,mD,((jx1,jy2),(jx2,jyb)))   # down
  156.     canvas.bind(EButton1Down,mL,((jxa,jy1),(jx1,jy2)))   # left
  157.     canvas.bind(EButton1Down,mR,((jx2,jy1),(jxb,jy2)))   # right
  158. def jpad():
  159.     if cv.jpad:
  160.         grey=(220,220,220)
  161.         img.rectangle((jxa,jy1,jxb,jy2),fill=grey) # w
  162.         img.rectangle((jx1,jya,jx2,jyb),fill=grey) # h
  163.     jpad_key()
  164. def jpad_key():
  165.     if   cv.mv is 'U':
  166.         xy_=(jx1,jya,jx2,jy1)
  167.     elif cv.mv is 'D':
  168.         xy_=(jx1,jy2,jx2,jyb)
  169.     elif cv.mv is 'L':
  170.         xy_=(jxa,jy1,jx1,jy2)
  171.     elif cv.mv is 'R':
  172.         xy_=(jx2,jy1,jxb,jy2)
  173.     else: return
  174.     img.rectangle(xy_,fill=0xffff00) # yellow
  175. #
  176. if not touch_enabled():
  177.     note(u"This application only works on devices that support touch input")
  178. #
  179. def up_event(event):
  180.     cv.up=-1
  181. def dn_event(event):
  182.     cv.up=1
  183. #
  184. def mv_event(event):
  185.     cv.xy=event
  186. #
  187. def full_bind():
  188.     canvas.bind(EButton1Up, up_event, ((0,0), (x_scr,720)))
  189.     canvas.bind(EButton1Down, dn_event, ((0,0), (x_scr,720)))
  190.     canvas.bind(EDrag, mv_event, ((0,0), (x_scr,720)))
  191. full_bind()
  192. bind_jpad()
  193. img.clear(0)
  194.  
  195. mx,my=10,50
  196. main_menu=['Start','Score','Rules','Store','Info','Exit']
  197. kx,ky,k=10,50,0
  198. #bg=graphics.Image.open(u'e:\\800x600poolwater.jpg').resize(res_xy)
  199.  
  200. def scr_menu(k):
  201.     if cv.mv is 'U':
  202.         k-=1
  203.         if k<0: k=len(main_menu)-1
  204.     if cv.mv is 'D':
  205.         k+=1
  206.         if k>len(main_menu)-1: k=0
  207.     if cv.mv is 'R': # 'Exit'
  208.         appuifw.note(u''+main_menu[k])
  209.         if k is len(main_menu)-1: cv.go=0
  210.     m=36
  211.     img.rectangle((mx,my,176-mx,my+m+((len(main_menu)-1)*m)),fill=(0xffffff))
  212.     for i in range(len(main_menu)):
  213.         if i == k: img.rectangle((mx,my+(i*m),176-mx,my+m+(i*m)),fill=0xffff00)
  214.         img.rectangle((mx,my+(i*m),176-mx,my+m+(i*m)),0)
  215.         img.text((mx*2,my+29+(i*m)),unicode(''+main_menu[i]),0xff0000,font=('dense',30))
  216.     return k
  217.  
  218. ### enter code below...
  219.  
  220. p='p'
  221. r='r'
  222. g='g'
  223. b='b'
  224.  
  225. maze='''
  226. ∎.∎.∎.∎.∎.∎.∎.∎.∎.∎.∎.∎.∎.∎.∎.∎.∎.∎.∎
  227. ∎.p. . . . . . . . .∎.x. . . . . . .∎
  228. ∎. .∎. .∎.∎.∎. .∎. .∎. .∎. .∎.∎.∎. .∎
  229. ∎. . . .∎. . . .∎. . . . . . .b.∎. .∎
  230. ∎.∎.∎. .∎. .∎. .∎. .∎. .∎. .∎. .∎. .∎
  231. ∎. . . . . .∎. . . . . .∎. . . . . .∎
  232. ∎. .∎. .∎. .∎.∎.∎. .∎. .∎.x.∎. .∎.∎.∎
  233. ∎. . .x.∎. . . . . .∎. . . .∎. . . .∎
  234. ∎.∎.∎. .∎. .∎. .∎.∎.∎.∎.∎. .∎. .∎. .∎
  235. ∎. . . . . .∎. . . . . . . . . . . .∎
  236. ∎. .∎.∎.∎. .∎. .∎. .∎.x.∎. .∎.∎.∎. .∎
  237. ∎. . . .∎. .∎.x. . . . . . .∎. . . .∎
  238. ∎.∎.∎. .∎. .∎. .∎. .∎.∎.∎. .∎. .∎.∎.∎
  239. ∎. . . . . . . .∎. . . .∎. . . . . .∎
  240. ∎. .∎. .∎.∎.∎.∎.∎. .∎. .∎. .∎.∎.∎. .∎
  241. ∎. . .r. . .∎. . .x.∎. . . . .g. .x.∎
  242. ∎. .∎.∎.∎. .∎. .∎. .∎. .∎. .∎. .∎. .∎
  243. ∎. . . . . . . .∎. . . . . .∎. . . .∎
  244. ∎.∎.∎.∎.∎.∎.∎.∎.∎.∎.∎.∎.∎.∎.∎.∎.∎.∎.∎
  245. '''
  246.  
  247. def qrepl(zzz,r):
  248.     for z in r:
  249.         zzz=zzz.replace(z[0],z[1])
  250.     zzz=zzz.split()
  251.     r=[]
  252.     for z in zzz:
  253.         r.append([int(x) if x.isdigit() else x for x in list(z)])
  254.     return r
  255. fix=[['.',''],[' ','0'],['∎','1'],['x','2']]
  256.  
  257. retile=qrepl(maze,fix)
  258. tile=retile[:]
  259.  
  260. tileSIZE=X/19
  261. incr=tileSIZE
  262. tileX,tileY=15,15
  263. sb2=tileSIZE/2
  264.  
  265. move=[(-incr,0),(incr,0),(0,-incr),(0,incr),(0,0)]
  266. udlr=move[:-1]
  267. time_limit=60
  268.  
  269. '''
  270. skip=0
  271. while run:
  272.     if fr_sp():
  273.         ### CODE ###
  274.         if cv.jpad:
  275.             jpad()
  276.         draw(())
  277.     # @ end of mainloop...
  278.     e32.ao_yield()
  279. '''
  280.  
  281. px = 300/2
  282. py = 500/2
  283. z = 1
  284.  
  285. exit_btn()
  286. while cv.go:
  287.     if fr_sp(0.03):
  288.         raz = z*math.pi/180
  289.         sin = math.sin(raz)
  290.         cos = math.cos(raz)
  291.         img.clear(0)
  292.         x=px*cos+px
  293.         y=py*sin+py
  294.         x1=px*sin+px
  295.         y1=py*cos+py
  296.         img.point((x+30,y+30),0xffffff,width=25)
  297.         img.point((x1+30,y1+30),0x00ff00,width=25)
  298.         z+=1
  299.         draw(())
  300.     e32.ao_yield()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement