×

Discussion Board

Results 1 to 7 of 7

Hybrid View

  1. #1
    Registered User
    Join Date
    Feb 2005
    Location
    Belgium (Europe)
    Posts
    1,352

    Thumbs up 1.1.3 prealpha version released !

    Hello everybody ,

    Please note that today a new pre-alpha version has been released !!!!

    Many changes but attention only download 1stEd for installing on phone the 2ndEd has an error in the file !

    There are other apps : Tetris , ball , keyviewer , image viewer :-)

    There are new modules :
    1) an advanced camera module (flash , exposure mode etc :-) for supported models !
    2) calendar db access
    3) audio (play and record sound )
    4) telephone (dial number and hang up)
    5) image (load , save , resize )

    There are also changes in the api (no use of app.screen = appuifw.MAIN_PANE now it becomes app.screen = 'full' ;-)

    What a pity I don't find any doc :-(

    It's very good to see and try it !

    Have fun with python series 60 !

  2. #2
    Regular Contributor
    Join Date
    Aug 2004
    Posts
    66
    Great but where is tetris application ?
    I don't see it

    Regards

  3. #3
    Regular Contributor
    Join Date
    Aug 2004
    Posts
    66
    Sorry i found Tetris on 1stEd, there is not on 2stEd.

    ;-)

  4. #4
    Regular Contributor
    Join Date
    Jan 2005
    Location
    Bangkok, Thailand
    Posts
    148
    I can't find the 1st edition for phone to download.

    I download all 3 packages available
    - 1st ed (1.2) SDK
    - 2nd ed (2.0) SDK
    - 2nd ed (2.0) Phone
    But can't find any tetris example.
    Can you post the tetris example here?

    I install the 2nd ed on my phone just fine. What's the problm? (or have they fixed it?)

  5. #5
    Regular Contributor
    Join Date
    Aug 2004
    Posts
    66

    tetris.py

    import appuifw
    from graphics import *
    import e32
    import random
    import time
    from key_codes import *

    appuifw.app.screen='full'
    backup_img=Image.new((176,208))
    draw=Draw(backup_img)

    def handle_redraw(param):
    canvas_draw.blit(backup_img)

    class Keyboard(object):
    def __init__(self,onevent=lambda:None):
    self._keyboard_state={}
    self._downs={}
    self._onevent=onevent
    def handle_event(self,event):
    if event['type'] == appuifw.EEventKeyDown:
    code=event['scancode']
    if not self.is_down(code):
    self._downs[code]=self._downs.get(code,0)+1
    self._keyboard_state[code]=1
    elif event['type'] == appuifw.EEventKeyUp:
    self._keyboard_state[event['scancode']]=0
    self._onevent()
    def is_down(self,scancode):
    return self._keyboard_state.get(scancode,0)
    def pressed(self,scancode):
    if self._downs.get(scancode,0):
    self._downs[scancode]-=1
    return True
    return False

    running=1
    def quit():
    global running
    running=0
    appuifw.app.exit_key_handler=quit


    class Playfield(object):
    def __init__(self,size,draw,bordercolor=0xc0c0c0):
    self._data={}
    self._size=size
    self._draw=draw
    for x in range(0,size[0]):
    for y in range(0,size[1]):
    self[(x,y)]=0
    # Initialize playing field borders
    for y in range(-1,size[1]+1):
    self[(-1,y)]=bordercolor
    self[(size[0],y)]=bordercolor
    for x in range(-1,size[0]+1):
    self[(x,-1)]=bordercolor
    self[(x,size[1])]=bordercolor
    self.draw()
    def __getitem__(self,loc):
    return self._data.setdefault(tuple(loc),0)
    def __setitem__(self,loc,value):
    self._data[loc]=value
    self.update_loc(loc)
    def remove_row(self,row):
    for x in range(0,self._size[0]):
    self[(x,0)]=0
    for y in range(row,0,-1):
    for x in range(0,self._size[0]):
    self[(x,y)]=self[(x,y-1)]
    def row_is_full(self,row):
    for x in range(0,self._size[0]):
    if not self[(x,row)]:
    return False
    return True
    def update_loc(self,loc):
    w=8
    x,y=((loc[0]+1)*w,(loc[1]+1)*w)
    self._draw.rectangle((x,y,x+w,y+w),None,self[loc])
    def draw(self):
    w=8
    for loc in self._data:
    self.update_loc(loc)
    # with draw.rectangle((x,y,x+w,y+w),fill=self[loc]) 472 ms
    # without 89 ms
    # draw.rectangle((x,y,x+w,y+w),fill=0xff0000,outline=0x00ff00) 375 ms
    # draw.rectangle((x,y,x+w,y+w)) without params setting, kw parsing 125 ms

    class Piece(object):
    def __init__(self,squares,color):
    self._squares=squares
    self._color=color
    def fits_in(self,loc,angle,field):
    for s in self._squares[angle]:
    if field[(s[0]+loc[0],s[1]+loc[1])]:
    return False
    return True
    def put_to(self,loc,angle,field):
    for s in self._squares[angle]:
    field[(s[0]+loc[0],s[1]+loc[1])]=self._color
    def remove_from(self,loc,angle,field):
    for s in self._squares[angle]:
    field[(s[0]+loc[0],s[1]+loc[1])]=0

    pieces=(
    Piece({0: ((1,0),(0,1),(1,1),(2,1)), # _|_ block
    1: ((1,0),(1,1),(2,1),(1,2)),
    2: ((0,1),(1,1),(2,1),(1,2)),
    3: ((1,0),(0,1),(1,1),(1,2))}, 0x808080),
    Piece({0: ((1,0),(1,1),(1,2),(1,3)), # ---- block
    1: ((0,1),(1,1),(2,1),(3,1)),
    2: ((1,0),(1,1),(1,2),(1,3)),
    3: ((0,1),(1,1),(2,1),(3,1))}, 0xff0000),
    Piece({0: ((0,0),(1,0),(0,1),(1,1)), # square block
    1: ((0,0),(1,0),(0,1),(1,1)),
    2: ((0,0),(1,0),(0,1),(1,1)),
    3: ((0,0),(1,0),(0,1),(1,1))}, 0x00ffff),
    Piece({0: ((0,0),(1,0),(1,1),(2,1)), # -_ block
    1: ((2,0),(1,1),(2,1),(1,2)),
    2: ((0,0),(1,0),(1,1),(2,1)),
    3: ((2,0),(1,1),(2,1),(1,2))}, 0x00ff00),
    Piece({0: ((1,0),(2,0),(0,1),(1,1)), # _- block
    1: ((0,0),(0,1),(1,1),(1,2)),
    2: ((1,0),(2,0),(0,1),(1,1)),
    3: ((0,0),(0,1),(1,1),(1,2))}, 0xff8000),
    Piece({0: ((1,0),(1,1),(1,2),(2,2)), # L-block
    1: ((1,1),(2,1),(3,1),(1,2)),
    2: ((1,1),(2,1),(2,2),(2,3)),
    3: ((2,1),(0,2),(1,2),(2,2))}, 0x0080ff),
    Piece({0: ((2,0),(2,1),(2,2),(1,2)), # J-block
    1: ((1,1),(1,2),(2,2),(3,2)),
    2: ((1,1),(2,1),(1,2),(1,3)),
    3: ((0,1),(1,1),(2,1),(2,2))}, 0xffff00))


    lock=e32.Ao_lock()
    keyboard=Keyboard(onevent=lock.signal)
    canvas=appuifw.Canvas(event_callback=keyboard.handle_event,
    redraw_callback=handle_redraw)
    canvas_draw=Draw(canvas)
    appuifw.app.body=canvas
    draw_time=0
    draw_count=0
    fieldsize=(10,20)
    playing=1
    def draw_score(draw):
    draw.rectangle((102,6,169,31),None,0x103010)
    draw.text((107,26),u'Lines: %d'%lines,0xc0ffc0,font=u'LatinBold19')
    draw.rectangle((102,31,169,56),None,0x103010)
    draw.text((107,51),u'Level: %d'%level,0xc0ffc0,font=u'LatinBold19')

    try:
    logo=Image.open(u'e:\\system\\apps\\python\\pythonpowered.png')
    except:
    logo=Image.new((100,16))
    drl=Draw(logo)
    drl.clear(0)

    while playing:
    lines=0
    level=1
    x,y=3,0
    angle=0
    piece=pieces[random.randint(0,len(pieces)-1)]
    drop_interval=0.5
    draw.clear(0x000000)
    draw.blit(logo,target=(106,100))
    draw_score(draw)
    field=Playfield(fieldsize,draw)
    previous_drop=time.clock()
    e32.ao_sleep(drop_interval,lock.signal)
    running=1
    while running:
    piece.remove_from((x,y),angle,field)
    while keyboard.pressed(EScancodeLeftArrow) and piece.fits_in((x-1,y),angle,field):
    x-=1
    lock.signal()
    while keyboard.pressed(EScancodeRightArrow) and piece.fits_in((x+1,y),angle,field):
    x+=1
    lock.signal()
    while keyboard.pressed(EScancodeUpArrow) and piece.fits_in((x,y),(angle-1)%4,field):
    angle=(angle-1)%4
    if keyboard.pressed(EScancodeDownArrow):
    while piece.fits_in((x,y+1),angle,field):
    y+=1
    if time.clock()-previous_drop >= drop_interval:
    if piece.fits_in((x,y+1),angle,field):
    y+=1
    else:
    piece.put_to((x,y),angle,field)
    removed_lines=0
    for y in range(fieldsize[1]):
    if field.row_is_full(y):
    field.remove_row(y)
    removed_lines += 1
    if removed_lines:
    lines += removed_lines
    level=int(lines/10)+1
    drop_interval=0.5*(0.85**(level-1))
    draw_score(draw)
    x,y=3,0
    angle=0
    piece=pieces[random.randint(0,len(pieces)-1)]
    if not piece.fits_in((x,y),angle,field):
    appuifw.note(u'Game over!','info')
    running=0
    previous_drop=time.clock()
    e32.ao_sleep(drop_interval,lock.signal)
    piece.put_to((x,y),angle,field)
    start_draw=time.clock()
    handle_redraw(())
    end_draw=time.clock()
    draw_time += end_draw-start_draw
    draw_count += 1
    e32.ao_yield()
    lock.wait()
    playing=appuifw.query(u'Play again?','query')

    print "%d draws, %f s total, avg time %f ms"%(draw_count,
    draw_time,
    draw_time/draw_count*1000)
    appuifw.app.screen='normal'

  6. #6
    Regular Contributor
    Join Date
    Jan 2005
    Location
    Bangkok, Thailand
    Posts
    148
    Thanks for the code!

    I view source and remove all <br /> and change some '&' code. Then it run fine.

    Are there any other scripts removed?
    I think the more examples the better.

  7. #7
    Regular Contributor
    Join Date
    Dec 2004
    Location
    Czech Republic
    Posts
    50
    and where can I download it ? There are just those: S60 v1 SDK (there's just an udeb build that doesn't work - that doesn't surprise me, but I had to try everything...), S60 v2 SDK (again just udeb) and S60 v2 Phone (That's for 2.0 and really doesn't work on my 1.0 device)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×