def __init__(self): self.pause = True self.fps = 30 self.time_between_frames = 1000/self.fps # time between frames in ms self.frame_id = None self.display = Display() score_height = 30 self.top_display = {"min_x": 0, "min_y": 0, "max_x": self.display.width, "max_y": score_height} self.bottom_display = {"min_x": 0, "min_y": score_height, "max_x": self.display.width, "max_y": self.display.height} brick_area = {"min_x": 0, "min_y": score_height+100, "max_x": self.display.width, "max_y": self.display.height-200} self.make_level = MakeLevel(ctx=self.display.background_canvas_ctx, area=brick_area, send_msg=self.receive_message) self.level = 1 self.player = Player(lives=3) self.add_game_objects() # doc.bind("mousemove", self.paddle.mouse_move) doc.bind("keydown", self.handle_keydown_events) # self.display.clear_all() self.display.draw_far_background() self.info.write_help()
def __init__(self, width, height, title="", fps=60): self.width = width self.height = height self.title = title self.done = False self.fps = fps self.listeners = [] self.draw_func = None self.init_func = None self.keys = dict([(a, False) for a in range(255)] + [(a, False) for a in range(0xff00, 0xffff)]) c = html.CANVAS(width=self.width, height=self.height, id="canvas") doc <= c self.canvas = doc["canvas"] self.ctx = self.canvas.getContext('2d') doc <= html.TITLE(self.title) doc.bind("keydown", self._keydown) doc.bind("keyup", self._keyup) #doc.bind('load', self.pageshow) self.soundPlayers = {}
def __init__(self): def joga(peca, xyz): tipo, cor = peca x, y, z = xyz #tipo(pos=xyz, size=(4, 4, 4), color= cor) #box(pos=xyz, size=(6, 6, 6), color= RBOW[z//VAO], opacity=0.2) self.angle = 0 self.sentido = None self.jogadas = { OESTE: self.oeste, NORTE: self.norte, LESTE: self.leste, SUL: self.sul, JOGA: self.joga } doc.bind('keypress', self.teclou) _gs = glow('main') cena = self.cena = canvas() cena.width = 1000 cena.height = 800 pecas = [(box, color.blue), (sphere, color.red)] * 4 * 4 * 2 self.casas = {(coluna, linha, camada): Casa(pos=(coluna, linha, camada)) for linha in CASAS for coluna in CASAS for camada in CASAS} shuffle(pecas) jogadas = [ joga(pecas.pop(), (coluna * VAO, linha * VAO, camada * VAO)) for linha in CASAS for coluna in CASAS for camada in CASAS ] self.joga()
def __init__(self): def joga(peca, xyz): tipo, cor = peca x, y, z = xyz #tipo(pos=xyz, size=(4, 4, 4), color= cor) #box(pos=xyz, size=(6, 6, 6), color= RBOW[z//VAO], opacity=0.2) self.angle = 0 self.sentido = None self.jogadas = { OESTE: self.oeste, NORTE: self.norte, LESTE: self.leste, SUL: self.sul, JOGA: self.joga } doc.bind('keypress', self.teclou) _gs = glow('main') cena = self.cena = canvas() cena.width = 1000 cena.height = 800 pecas = [(box, color.blue), (sphere, color.red)] * 4 * 4 * 2 self.casas = { (coluna, linha, camada): Casa(pos=(coluna, linha, camada)) for linha in CASAS for coluna in CASAS for camada in CASAS} shuffle(pecas) jogadas = [joga(pecas.pop(), (coluna*VAO, linha*VAO, camada*VAO)) for linha in CASAS for coluna in CASAS for camada in CASAS] self.joga()
def __init__(self): self.pause = True self.fps = 30 self.time_between_frames = 1000 / self.fps # time between frames in ms self.frame_id = None self.display = Display() score_height = 30 self.top_display = { "min_x": 0, "min_y": 0, "max_x": self.display.width, "max_y": score_height } self.bottom_display = { "min_x": 0, "min_y": score_height, "max_x": self.display.width, "max_y": self.display.height } brick_area = { "min_x": 0, "min_y": score_height + 100, "max_x": self.display.width, "max_y": self.display.height - 200 } self.make_level = MakeLevel(ctx=self.display.background_canvas_ctx, area=brick_area, send_msg=self.receive_message) self.level = 1 self.player = Player(lives=3) self.add_game_objects() # doc.bind("mousemove", self.paddle.mouse_move) doc.bind("keydown", self.handle_keydown_events) # self.display.clear_all() self.display.draw_far_background() self.info.write_help()
def show(path,zone,page=0): src = open(path).read() title = '' page_num = False while src.startswith('@'): line_end = src.find('\n') key,value = src[:line_end].split(' ',1) if key=='@title': title = value elif key=='@pagenum': page_num = True src = src[line_end+1:] zone.html = '' pages = src.split('../..\n') if page<0: page = 0 elif page >= len(pages): page = len(pages)-1 doc.unbind('keydown') doc.bind('keydown',lambda ev:keydown(ev,path,zone,page)) body = html.DIV() body.html = markdown.mark(pages[page])[0] footer = html.DIV(Id="footer") if title: footer <= html.DIV(title,style=dict(display='inline')) if page_num: footer <= html.SPAN(' (%s/%s)' %(page+1,len(pages)), style=dict(display='inline')) timeline = html.DIV(Id='timeline') tl_pos = html.DIV(Id='tl_pos') timeline <= tl_pos timeline.bind('click',lambda ev:move_to(ev,path,zone,len(pages))) tl_pos.bind('click',click_on_tl_pos) zone <= body+footer+timeline tl_pos.style.left = '%spx' %(timeline.width*page/len(pages))
def mouseDown(e): self._element.style.position = 'absolute' self._deltaX = e.clientX - self._element.offsetLeft self._deltaY = e.clientY - self._element.offsetTop doc.bind('mousemove', drag)
def show(path, zone, page_num=0): src = open(path).read() title = '' show_page_num = False # table of contents : matches matter with page number contents = [] # directives for the document while src.startswith('@'): line_end = src.find('\n') key, value = src[:line_end].split(' ', 1) if key == '@title': title = value elif key == '@pagenum': show_page_num = True elif key == "@index": contents.append([value, 0]) src = src[line_end + 1:] zone.html = '' pages = src.split('../..\n') # table of contents for num, _page in enumerate(pages): if num == 0: continue if _page.startswith('@index'): line_end = _page.find('\n') key, value = _page[:line_end].split(' ', 1) contents.append([value, num]) pages[num] = _page[line_end + 1:] if page_num < 0: page_num = 0 elif page_num >= len(pages): page_num = len(pages) - 1 doc.unbind('keydown') doc.bind('keydown', lambda ev: keydown(ev, path, zone, page_num)) # if table of contents is not empty, add it if contents: toc = html.SELECT(name="toc") toc.bind( 'change', lambda ev: show( path, zone, int(ev.target.options[ev.target.selectedIndex].value))) for content in contents: toc <= html.OPTION( content[0], value=content[1], selected=page_num >= content[1]) body = html.DIV() body.html = markdown.mark(pages[page_num])[0] if contents: body = html.DIV(toc + body) footer = html.DIV(Id="footer") if title: footer <= html.DIV(title, style=dict(display='inline')) if show_page_num: footer <= html.SPAN(' (%s/%s)' % (page_num + 1, len(pages)), style=dict(display='inline')) timeline = html.DIV(Id='timeline') tl_pos = html.DIV(Id='tl_pos') timeline <= tl_pos timeline.bind('click', lambda ev: move_to(ev, path, zone, len(pages))) tl_pos.bind('click', click_on_tl_pos) zone <= body + footer + timeline tl_pos.style.left = '%spx' % (timeline.width * page_num / len(pages))
def show(path, zone, page_num=0): src = open(path).read() title = '' show_page_num = False # table of contents : matches matter with page number contents = [] # directives for the document while src.startswith('@'): line_end = src.find('\n') key,value = src[:line_end].split(' ',1) if key=='@title': title = value elif key=='@pagenum': show_page_num = True elif key=="@index": contents.append([value, 0]) src = src[line_end+1:] zone.html = '' pages = src.split('../..\n') # table of contents for num, _page in enumerate(pages): if num==0: continue if _page.startswith('@index'): line_end = _page.find('\n') key,value = _page[:line_end].split(' ',1) contents.append([value, num]) pages[num] = _page[line_end+1:] if page_num<0: page_num = 0 elif page_num >= len(pages): page_num = len(pages)-1 doc.unbind('keydown') doc.bind('keydown',lambda ev:keydown(ev, path, zone, page_num)) # if table of contents is not empty, add it if contents: toc = html.SELECT(name="toc") toc.bind('change', lambda ev: show(path, zone, int(ev.target.options[ev.target.selectedIndex].value))) for content in contents: toc <= html.OPTION(content[0], value=content[1], selected=page_num>=content[1]) body = html.DIV() body.html = markdown.mark(pages[page_num])[0] if contents: body = html.DIV(toc+body) footer = html.DIV(Id="footer") if title: footer <= html.DIV(title,style=dict(display='inline')) if show_page_num: footer <= html.SPAN(' (%s/%s)' %(page_num+1, len(pages)), style=dict(display='inline')) timeline = html.DIV(Id='timeline') tl_pos = html.DIV(Id='tl_pos') timeline <= tl_pos timeline.bind('click', lambda ev:move_to(ev, path, zone, len(pages))) tl_pos.bind('click', click_on_tl_pos) zone <= body+footer+timeline tl_pos.style.left = '%spx' %(timeline.width*page_num/len(pages))
def mouseDown(e): self._element.style.position='absolute' self._deltaX=e.clientX - self._element.offsetLeft self._deltaY=e.clientY - self._element.offsetTop doc.bind('mousemove', drag)