def Paint(self, drw, x, y, w, h, focused): img = Widget.Paint(self, drw, x, y, w, h, focused) # Arrows if self.first != 0: img.blit(self.up, dx=(w - 16) // 2, dy=0, blend=True) if self.first + self.height < len(self.choices): img.blit(self.down, dx=(w - 16) // 2, dy=h - 16, blend=True) # Choices dy = (h - 32) // self.height curY = 16 bg = psp2d.Image(w, dy) for idx in xrange(self.first, min(self.first + self.height, len(self.choices))): if idx == self.selection: bg.clear(psp2d.Color(255, 0, 0, 200)) else: bg.clear(psp2d.Color(0, 0, 0, 0)) self.font.drawText(bg, 0, 0, str(self.choices[idx])) img.blit(bg, dx=0, dy=curY, blend=True) curY += dy drw.blit(img, dx=x, dy=y, blend=True)
def Clear(self, img, focused): if focused: self.count = (self.count + 8) % 256 if self.count <= 127: img.clear(psp2d.Color(0, 0, 255, 128 + self.count)) else: img.clear(psp2d.Color(0, 0, 255, 255 - (self.count - 128))) else: img.clear(psp2d.Color(0, 0, 0, 200))
def main(): screen = psp2d.Screen() screen.fillRect(10, 10, 60, 30, psp2d.Color(255, 0, 0)) screen.drawText(15, 45, 'Hello, world!', psp2d.Color(0, 0, 255)) screen.drawLine(0, 200, 200, 0, psp2d.Color(0, 255, 0)) screen.swap() while True: pad = psp2d.Controller() if pad.circle: break
def main(): scr = psp2d.Screen() fnt = psp2d.Font('font_small.png') dy = fnt.textHeight('') + 5 while True: pad = psp2d.Controller() img = psp2d.Image(480, 272) img.clear(psp2d.Color(0, 0, 0)) fnt.drawText(img, 0, 0, 'Analog X: %d' % pad.analogX) fnt.drawText(img, 0, dy, 'Analog Y: %d' % pad.analogY) fnt.drawText(img, 0, 2 * dy, 'Square: %d' % int(pad.square)) fnt.drawText(img, 0, 3 * dy, 'Circle: %d' % int(pad.circle)) fnt.drawText(img, 0, 4 * dy, 'Cross: %d' % int(pad.cross)) fnt.drawText(img, 0, 5 * dy, 'Triangle: %d' % int(pad.triangle)) fnt.drawText(img, 0, 6 * dy, 'Left: %d' % int(pad.left)) fnt.drawText(img, 0, 7 * dy, 'Right: %d' % int(pad.right)) fnt.drawText(img, 0, 8 * dy, 'Up: %d' % int(pad.up)) fnt.drawText(img, 0, 9 * dy, 'Down: %d' % int(pad.down)) fnt.drawText(img, 0, 10 * dy, 'Left trigger: %d' % int(pad.l)) fnt.drawText(img, 0, 11 * dy, 'Right trigger: %d' % int(pad.r)) scr.blit(img) scr.swap()
def action(self): screen.clear(psp2d.Color(0, 0, 0, 255)) state = "WLAN switch OFF" ip = "Unavailable" if pspnet.wlanSwitchState(): state = apctl_states[pspnet.getAPCTLState()] try: ip = pspnet.getIP() except: pass if pspnet.getAPCTLState() == 0: apConnectThread = threading.Thread( target=pspnet.connectToAPCTL, args=(1, )) apConnectThread.daemon = True apConnectThread.start() font.drawText(screen, 10, 10, "State: %s" % state) font.drawText(screen, 10, 25, "IP: %s" % ip) font.drawText(screen, 10, 45, "Press X to exit") for agent in self.entities: if hasattr(agent, 'sprite'): screen.blit(agent.sprite, 0, 0, agent.sprite.width, agent.sprite.height, agent.posX, agent.posY, True) screen.swap()
def draw(self, drw, x, y): drw.drawText(x, y, self.msg + ('%.2f%%' % (100 * self.frac)), psp2d.Color(255, 0, 0)) drw.blit(self.bgi, dx=x, dy=y + 16) drw.blit(self.img, dx=x, dy=y + 16, dw=int(self.frac * self.w), blend=True)
def test_to_image(self): "Draw text to image (with alpha != 0)" img = psp2d.Image(200, 200) img.clear(psp2d.Color(127, 127, 127, 127)) self.font.drawText(img, 0, 0, 'Jérôme') img.saveToFile('test.png') h = self.hashFile('test.png') self.failIf(h != '9757122d8962cac6317da2f561b3a822', h)
def test_to_screen(self): "Draw text to screen, with accented characters" self.screen.clear(psp2d.Color(127, 127, 127)) self.font.drawText(self.screen, 0, 0, 'Jérôme') self.screen.swap() self.screen.saveToFile('test.png') h = self.hashFile('test.png') self.failIf(h != '3f5273009ee9ec5eadd0385aeaf2e27d', h)
def main(): img = psp2d.Image('sprite.png') sprites = [Sprite(img) for unused in xrange(30)] screen = psp2d.Screen() batch = psp2d.BlitBatch() for sprite in sprites: batch.add(sprite) batching = False while True: if batching: while True: screen.clear(psp2d.Color(0, 0, 0)) for sprite in sprites: sprite.nextFrame() batch.blit() screen.swap() pad = psp2d.Controller() if pad.cross: batching = False time.sleep(0.2) break else: while True: screen.clear(psp2d.Color(0, 0, 0)) for sprite in sprites: sprite.nextFrame() img, x, y = sprite.data screen.blit(img, dx=x, dy=y, blend=True) screen.swap() pad = psp2d.Controller() if pad.cross: batching = True time.sleep(0.2) break
def realize(self, font): """You should call this when you're finished adding items to the menu.""" self.w = 0 self.h = 0 for item in self.items: w, h = item.getDimension(font) w += 20 h += 10 self.w = max(self.w, w) self.h = max(self.h, h) self.abg = psp2d.Image(self.w, self.h) self.abg.clear(psp2d.Color(0, 0, 255, 200)) self.bg = psp2d.Image(self.w, self.h) self.bg.clear(psp2d.Color(0, 0, 255, 100))
def fire(self): scr = psp2d.Screen() scr.clear(psp2d.Color(0, 0, 0)) scr.blit(self.img, dx = self.x, dy = self.y, blend = True) scr.swap() self.x += self.u if self.x <= 0 or self.x + self.img.width >= 480: self.u = -self.u pad = psp2d.Controller() return not pad.circle
def __init__(self): self.logic = Logic() self.marked_option = 0 self.menu_opt = [{ 'opt_name': 'Start', 'yposition': 170, 'reaction': self.start_game }, { 'opt_name': 'High Score', 'yposition': 200, 'reaction': self.high_score }, { 'opt_name': 'Exit', 'yposition': 230, 'reaction': self.exit }] self.OPTIONS_NUMBER = len(self.menu_opt) self.quit = False self.font = psp2d.Font('buttons/res/font.png') self.BLACK = psp2d.Color(0, 0, 0, 255) self.GREEN = psp2d.Color(0, 50, 0, 255) self.RED = psp2d.Color(50, 0, 0, 255) self._initialize_screen() self.database = anydbm.open('scores.db', 'c')
def main(): scr = psp2d.Screen() img = psp2d.Image('background.png') img2 = psp2d.Image(200, 200) img2.clear(psp2d.Color(255, 0, 0, 128)) img.blit(img2, dx = 30, dy = 30, blend = True) scr.blit(img) scr.swap() while True: pad = psp2d.Controller() if pad.circle: break
def inicializa_estrelas(lista_estrelas, nivel): ''' inicializa_estrelas(L)-> lista_estrelas junta estrelas à lista L #--------------------------- # Função para iniciar a iniciar estrelas de fundo. # Cada estrela é um vector [x,y,r,v,c] onde: # x,y são as coordenadas # r é o raio # v é a velocidade com que se deslocam # c é a cor #-------------------------- ''' # Junta 20 estrelas de fundo tendo raio, velocidades e #coordenadas x,y aleatórias for i in range(20): x = random.randrange(10, 470) # x é um inteiro aleatório entre 0 e 400 y = random.randrange(10, 262) # y é um inteiro aleatório entre 0 e 400 r = random.randrange(1, 3) # raio aleatório v = random.randrange(0, 4) # raio aleatório fact = random.randrange(-50, 50) # pequena alteração na cor da estrela c = psp2d.Color(243, 110 + fact, 110 + fact) lista_estrelas.append([x, y, r, v, c]) # junta nova estrela à lista return lista_estrelas
def Paint(self, drw, x, y, w, h, focused): img = psp2d.Image(w, h) img.clear(psp2d.Color(0, 0, 0, 0)) totalStretch = reduce(operator.add, [k[1] for k in self.widgets], 0) minW, minH = self.GetMinSize() remainW = w - minW remainH = h - minH curX = self.border curY = self.border for idx, (widget, stretch, flags) in enumerate(self.widgets): minW, minH = widget.GetMinSize() if self.direction == HORIZONTAL: if flags & self.EXPAND: ch = h - self.border * 2 else: ch = minH if stretch: cw = minW + remainW * stretch // totalStretch else: cw = minW if flags & self.ALIGN_CENTER: cx = (cw - minW) // 2 cy = (h - minH) // 2 else: if flags & self.ALIGN_RIGHT: cx = cw - minW else: # Default left cx = 0 if flags & self.ALIGN_BOTTOM: cy = h - minH else: # Default top cy = 0 widget.Paint(img, curX + cx, curY + cy, cw, ch, focused and self.focus == idx) curX += cw + self.border else: if flags & self.EXPAND: cw = w - self.border * 2 else: cw = minW if stretch: ch = minH + remainH * stretch // totalStretch else: ch = minH if flags & self.ALIGN_CENTER: cx = (w - minW) // 2 cy = (ch - minH) // 2 else: if flags & self.ALIGN_RIGHT: cx = cw - minW else: # Default left cx = 0 if flags & self.ALIGN_BOTTOM: cy = h - minH else: # Default top cy = 0 widget.Paint(img, curX + cx, curY + cy, cw, ch, focused and self.focus == idx) curY += ch + self.border drw.blit(img, dx=x, dy=y, blend=True)
import psp2d, pspos pspos.setclocks(333,166) # To set both CPU and Bus clock screen = psp2d.Screen() BLANK = psp2d.Color(0,0,0) state=x=y=0 image = psp2d.Image(480, 272) image.clear(BLANK) screen.blit(image); screen.swap() snake="pg.png" def draw(pgName): image = psp2d.Image(480, 272) image.clear(BLANK) screen.blit(image); screen.swap() image = psp2d.Image(pgName) screen.blit(image, dx=x, dy=y); screen.swap() while state==0: pad = psp2d.Controller() if pad.right: x = x + 5 draw(snake) elif pad.left: x = x - 5 draw(snake) elif pad.up: y = y - 5 draw(snake) elif pad.down: y = y + 5 draw(snake) elif pad.circle: state=1
#import datetime #import sys #import stackless # Importa funções para gerar números aleatórios import random import math # Set processor and bus speed pspos.setclocks(333, 166) # Texto font = psp2d.Font("font.png") # Define algumas cores black = psp2d.Color(0, 0, 0) white = psp2d.Color(255, 255, 255) red = psp2d.Color(220, 0, 0) def inicializa_estrelas(lista_estrelas, nivel): ''' inicializa_estrelas(L)-> lista_estrelas junta estrelas à lista L #--------------------------- # Função para iniciar a iniciar estrelas de fundo. # Cada estrela é um vector [x,y,r,v,c] onde: # x,y são as coordenadas # r é o raio # v é a velocidade com que se deslocam # c é a cor #--------------------------
import pspogg from time import time, localtime import datetime import sys import stackless import os import threading import urlparse pspos.setclocks(333, 166) print "Localtime: ", localtime() print "Datetime: ", datetime.datetime.now() screen = psp2d.Screen() screen.clear(psp2d.Color(0, 0, 0, 255)) font = psp2d.Font('font.png') apctl_states = [ "PSP_NET_APCTL_STATE_DISCONNECTED", "PSP_NET_APCTL_STATE_SCANNING", "PSP_NET_APCTL_STATE_JOINING", "PSP_NET_APCTL_STATE_GETTING_IP", "PSP_NET_APCTL_STATE_GOT_IP", "PSP_NET_APCTL_STATE_EAP_AUTH", "PSP_NET_APCTL_STATE_KEY_EXCHANGE", "PSP_NET_APCTL_EVENT_CONNECT_REQUEST", "PSP_NET_APCTL_EVENT_SCAN_REQUEST", "PSP_NET_APCTL_EVENT_SCAN_COMPLETE", "PSP_NET_APCTL_EVENT_ESTABLISHED", "PSP_NET_APCTL_EVENT_GET_IP", "PSP_NET_APCTL_EVENT_DISCONNECT_REQUEST", "PSP_NET_APCTL_EVENT_ERROR", "PSP_NET_APCTL_EVENT_INFO", "PSP_NET_APCTL_EVENT_EAP_AUTH", "PSP_NET_APCTL_EVENT_KEY_EXCHANGE", "PSP_NET_APCTL_EVENT_RECONNECT", "PSP_NET_APCTL_INFO_PROFILE_NAME", "PSP_NET_APCTL_INFO_BSSID", "PSP_NET_APCTL_INFO_SSID", "PSP_NET_APCTL_INFO_SSID_LENGTH",
def draw(self, img, color=psp2d.Color(255, 0, 0)): img.fillRect(self.x1, self.y1, self.x2 - self.x1 + 1, self.y2 - self.y1 + 1, color)
def update(self, value, total): super(CBProgress, self).update(value, total) scr.clear(psp2d.Color(0, 0, 0)) self.draw(scr, 0, 0) scr.swap()
def ON_TICK(self, DELTA): GLOBAL.SCREEN.clear(psp2d.Color(0,0,0,255)) ACTORS = self.FIND_OBJECTS_OF_TYPE("Actor") for a in ACTORS: if ACTORS[a].VISIBLE: ACTORS[a].DRAW() GLOBAL.SCREEN.swap()
if pad.l: font.drawText(image, 0, 60, "LEFT TRIG") if pad.r: font.drawText(image, 160, 60, "RIGHT TRIG") if pad.start: font.drawText(image, 120, 130, "START") if pad.select: font.drawText(image, 60, 130, "SELECT") if pad.analogX: font.drawText(image, 0, 150, "ANALOG_X= " + str(pad.analogX)) if pad.analogY: font.drawText(image, 0, 170, "ANALOG_Y= " + str(pad.analogY)) return image font = psp2d.Font("font.png") image = psp2d.Image(480, 272) screen = psp2d.Screen() CLEAR_COLOR = psp2d.Color(0, 0, 0) image.clear(CLEAR_COLOR) x = True while x == True: image.clear(CLEAR_COLOR) font.drawText(image, 70, 0, "--PSP CONTROLLER TEST--") font.drawText(image, 50, 30, "------------------------------------") font.drawText(image, 70, 210, "WRITTEN BY: SUPROTIK DEY") pad = psp2d.Controller() image = drawGamePadTest(pad, image) screen.blit(image) screen.swap()