def init(): global INIT_DONE if not INIT_DONE: global INPUT_CURSOR INPUT_CURSOR = image.Image("sys_textcursor.png", 8, 16) global SMALLFONT SMALLFONT = pygame.font.Font(util.image_dir("VeraBd.ttf"), 12) global TINYFONT TINYFONT = pygame.font.Font(util.image_dir("VeraBd.ttf"), 9) global ANIMFONT ANIMFONT = pygame.font.Font( util.image_dir("DejaVuSansCondensed-Bold.ttf"), 16) global ITALICFONT ITALICFONT = pygame.font.Font(util.image_dir("VeraBI.ttf"), 12) global BIGFONT BIGFONT = pygame.font.Font(util.image_dir("Gamaliel.otf"), 23) global POSTERS POSTERS += glob.glob(util.image_dir("poster_*.png")) if android: android.init() android.map_key(android.KEYCODE_BACK, pygame.K_ESCAPE) # Set key repeat. pygame.key.set_repeat(200, 75) INIT_DONE = True
def __init__(self, width, height): pygame.init() pygame.font.init() if android: android.init() android.map_key(android.KEYCODE_BACK, pygame.K_ESCAPE) self.width = width self.height = height os.environ["SDL_VIDEO_CENTERED"] = "1" pygame.display.set_caption("Freefall") self.screen = SCREEN.video_mode #self.screen = pygame.display.set_mode((self.width, self.height), DOUBLEBUF | FULLSCREEN) self.fpsClock = pygame.time.Clock() self.state = STATE.title_screen self.score = 0 self.best = 0 self.retries = 0 self.avg = 0 self.total = 0 self.screen_number = 1 self.capture_video = False #self.bg = grid_image self.bg = bg self.stage = Stage(player) self.hud = Hud(0, 0, HUD.width, HUD.height) self.menu = Menu(0, 0, SCREEN.width, SCREEN.height) self.gameover = GameOverScreen(0, 0, MENU.width, MENU.height) self.ripple = HudObject(64, 120, RIPPLE.width, RIPPLE.height, HUD.ripple) self.overlay = Overlay(0, 0, SCREEN.width/2, SCREEN.height, HUD.overlay)
def main(): pygame.init() mixer.init() screen = pygame.display.set_mode([480, 700]) if android: android.init() android.map_key(android.KEYCODE_BACK, pygame.K_ESCAPE) android.accelerometer_enable(True) game = Game(screen, "images") ret = game.startScreen() if ret == False: pygame.quit() sys.exit(1) while 1: game.init() for life in range(3): ball = game.createBall() game.balls.append(ball) ret = game.play() if ret == False: pygame.quit() sys.exit(1) ret = game.gameOver() if ret == False: pygame.quit() sys.exit(1)
def main(): # Mapeando o botao voltar do android como K_ESCAPE (ESC) if android: android.init() android.map_key(android.KEYCODE_BACK, pygame.K_ESCAPE) # Usando timer para controlar os FPS pygame.time.set_timer(TIMEREVENT, 1000 / FPS) # A cor da tela global color controle = Controle(LARGURA, ALTURA) while True: ev = pygame.event.wait() # Especifico para android if android: if android.check_pause(): android.wait_for_resume() if ev.type == TIMEREVENT: screen.fill(color) controle.desenha(screen) pygame.display.flip() else: controle.evento(ev, color) if (ev.type == pygame.KEYDOWN and ev.key == pygame.K_ESCAPE) or ev.type == pygame.QUIT: break
def main(): # create configuration object if android is not None or len(sys.argv) == 1: # Map the back button to the escape key. if android is not None: pygame.init() android.init() android.map_key(android.KEYCODE_BACK, pygame.K_ESCAPE) else: icon = pygame.image.load(os.path.join('res', 'icon', 'ico256.png')) pygame.display.set_icon(icon) configo = classes.config.Config(android) # create the language object lang = classes.lang.Language(configo, path) # create the Thread objects and start the threads speaker = classes.speaker.Speaker(lang, configo, android) #cancel out checking for updates so that the PC does not have to connect to the Internet updater = None #classes.updater.Updater(configo, android) app = GamePlay(speaker, lang, configo, updater) if android is None: speaker.start() app.run() elif len(sys.argv) == 2: if sys.argv[1] == "v" or sys.argv[1] == "version": from classes.cversion import ver print("eduactiv8-%s" % ver) else: print("Sorry arguments not recognized.")
def post_build_init(self,ev): import android import pygame android.map_key(android.KEYCODE_BACK, 1001) win = self._app_window win.bind(on_keyboard=self._key_handler)
def main(): """ Initializes PyGame and pgs4a and starts the game loop. """ # Variables. screen = None # Init PyGame. pygame.init() pygame.font.init() mixer.init() if android: # Init pgs4a and map Android's back button to PyGame's escape key. android.init() android.map_key(android.KEYCODE_BACK, pygame.K_ESCAPE) # Get the device's screen size and request a surface of that size. screen_size = (pygame.display.Info().current_w, pygame.display.Info().current_h) screen = pygame.display.set_mode(screen_size) else: screen = pygame.display.set_mode((1024, 768), pygame.FULLSCREEN | pygame.HWSURFACE) pygame.display.set_caption("Super HUGS Revolution 98") pygame.mouse.set_visible(False) # Create the game object and start the main game loop. game = Game(screen) game.game_loop() # Cleanly terminate PyGame. database.scores.close() pygame.quit()
def post_build_init(self, ev): import android import pygame android.map_key(android.KEYCODE_BACK, 1001) win = self._app_window win.bind(on_keyboard=self._key_handler)
def post_build_init(self, ev): if platform == 'android': import android android.map_key(android.KEYCODE_BACK, 1000) android.map_key(android.KEYCODE_MENU, 1001) win = self._app_window win.bind(on_keyboard=self._key_handler)
def main(): pygame.init() screen = pygame.display.set_mode() if android: android.init() ## setup the android exit button android.map_key(android.KEYCODE_BACK, pygame.K_ESCAPE) ## Event constant. TIMEREVENT = pygame.USEREVENT FPS = 30 pygame.time.set_timer(TIMEREVENT, 1000 / FPS) while True: ev = pygame.event.wait() ## Allows Android_OS to take control (ex. pause for phone call) if android: if android.check_pause(): android.wait_for_resume() ## refresh Screen if ev.type == TIMEREVENT: pygame.display.flip() ## Draw a blue circle where the screen is touched pygame.draw.circle(screen, (0, 128, 255), pygame.mouse.get_pos(), 10) ## Break the while loop to exit if android-back button pressed if ev.type == pygame.KEYDOWN and ev.key == pygame.K_ESCAPE: break
def main(): # create configuration object if android is not None or len(sys.argv) == 1: # Map the back button to the escape key. if android is not None: pygame.init() android.init() android.map_key(android.KEYCODE_BACK, pygame.K_ESCAPE) configo = classes.config.Config(android) # create the language object lang = classes.lang.Language(configo, path) # create the Thread objects and start the threads speaker = classes.speaker.Speaker(lang, configo, android) updater = classes.updater.Updater(configo, android) app = GamePlay(speaker, lang, configo, updater) if android is None: speaker.start() app.run() elif len(sys.argv) == 2: if sys.argv[1] == "v" or sys.argv[1] == "version": from classes.cversion import ver print("eduactiv8-%s" % ver) else: print("Sorry arguments not recognized.")
def init(self): flags = 0 if not ANDROID: os.environ['SDL_VIDEO_CENTERED'] = '1' WINSIZE = 480, 800 else: WINSIZE = 0, 0 flags |= pygame.FULLSCREEN pygame.init() mixer.init() # Map the back button to the escape key. if ANDROID: android.init() android.map_key(android.KEYCODE_BACK, pygame.K_b) self.clock = pygame.time.Clock() if not ANDROID: self.icon = pygame.image.load(get_resource('android-icon.png')) pygame.display.set_icon(self.icon) screen = self.screen = pygame.display.set_mode(WINSIZE, flags) self.width, self.height = screen.get_width(), screen.get_height() pygame.display.set_caption('Mazenum') self.score_font = pygame.font.Font(get_resource(join("fonts", "FreeSans.ttf")), 25) self.completed_font = pygame.font.Font(get_resource(join("fonts", "FreeSans.ttf")), 40) self.start_button = Button("Start game") self.playboard = PlayBoard(screen, self.COLUMNS, self.ROWS, self.header_height) self._set_background() self.is_game_over = False
def post_build_init(self, *args): if platform() == 'android': import android android.map_key(android.KEYCODE_BACK, 1001) win = Window win.bind(on_keyboard=self.my_key_handler)
def post_build_init(self, ev): if platform() == 'android': import android android.map_key(android.KEYCODE_BACK, 1001) win = Window win.bind(on_keyboard=self.my_key_handler)
def __init__(self): self.heigth = 480 self.width = 800 # self.heigth=1024 # self.width=1280 self.csize = 20 self.xmargin = 0 self.ymargin = 0 self.sel = 0 self.defy = get_random_defykub(**param_random) self.update_const() # self.defy=defykub() # self.load_from_file('test.xml') # set start loop to menu self.loop = l_play self.imgs = load_images() self.screen = pygame.display.set_mode((self.width, self.heigth), pygame.SWSURFACE) # pygame.display.set_caption("Defykub") if android: android.init() android.map_key(android.KEYCODE_BACK, pygame.K_ESCAPE)
def on_start(self): Logger.debug("%s: on_start %s" % (APP, datetime.now())) from kivy.core.window import Window Window.bind(on_keyboard=self.on_keypress) if platform == 'android': android.map_key(android.KEYCODE_BACK, 1001) import android.activity as python_activity python_activity.bind(on_new_intent=self.on_new_intent) self.on_new_intent(activity.getIntent()) self.server_url = self.config.get('general', 'server_url') self.root.bind( on_touch_down=lambda *a: setattr(self, 'delay_image_loading', True ), on_touch_up=lambda *a: setattr(self, 'delay_image_loading', False)) imagedir = ImageDir(server_url=self.server_url) wp = 'with_previous' imagedir.bind( on_navigate_top=lambda *a: setattr(self.root, wp, False), on_navigate_down=lambda *a: setattr(self.root, wp, True), on_img_selected=self.load_carousel, path=lambda w, v: setattr(self.root, 'title', v), on_loading_start=lambda *a: setattr(self.root, 'loading', True), on_loading_stop=lambda *a: setattr(self.root, 'loading', False)) self.imagedir = imagedir self.root.container.add_widget(imagedir) self.root.bind(on_touch_down=lambda *a: Loader.pause(), on_touch_up=lambda *a: Loader.resume()) Loader.max_upload_per_frame = 1 # Maximize interactivity
def main(): try: adv=advertise.advertise('http://ammar.pythonanywhere.com/adv/snake',g.canvas,(0,0),(240,320)) while adv.show: adv.adv_cont.read_input() pygame.display.update() except: pass #print "running1" if android: android.init() android.map_key(android.KEYCODE_BACK, pygame.QUIT) while g.running: if android: android.accelerometer_enable(bool(accelerometer)) if accelerometer: d=check_dir_acc() if d=="up": g.up() elif d=="down": g.down() elif d=="left": g.left() elif d=="right": g.right() else: pass #print "running2" g.move() #print "moved" try: ao_sleep(slow) except: pass ao_yield()
def on_start(self): Logger.debug("%s: on_start %s" % (APP, datetime.now())) from kivy.core.window import Window Window.bind(on_keyboard=self.on_keypress) if platform == 'android': android.map_key(android.KEYCODE_BACK, 1001) import android.activity as python_activity python_activity.bind(on_new_intent=self.on_new_intent) self.on_new_intent(activity.getIntent()) self.server_url = self.config.get('general', 'server_url') self.root.bind( on_touch_down=lambda *a: setattr(self, 'delay_image_loading', True), on_touch_up=lambda *a: setattr(self, 'delay_image_loading', False)) imagedir = ImageDir(server_url=self.server_url) wp = 'with_previous' imagedir.bind( on_navigate_top=lambda *a: setattr(self.root, wp, False), on_navigate_down=lambda *a: setattr(self.root, wp, True), on_img_selected=self.load_carousel, path=lambda w,v: setattr(self.root, 'title', v), on_loading_start=lambda *a: setattr(self.root, 'loading', True), on_loading_stop=lambda *a: setattr(self.root, 'loading', False)) self.imagedir = imagedir self.root.container.add_widget(imagedir) self.root.bind(on_touch_down=lambda *a: Loader.pause(), on_touch_up=lambda *a: Loader.resume()) Loader.max_upload_per_frame = 1 # Maximize interactivity
def main(): pygame.init() screen = pygame.display.set_mode([480, 800]) if android: android.init() android.map_key(android.KEYCODE_BACK, pygame.K_ESCAPE) android.accelerometer_enable(True) game = Game(screen, "images") ret = game.startScreen() if ret == False: pygame.quit() sys.exit(1) while 1: game.init() ret = game.play() if ret == False: pygame.quit() sys.exit(1) ret = game.gameOver() if ret == False: pygame.quit() sys.exit(1)
def post_build_init(self, *args): if platform() == 'android': import android android.map_key(android.KEYCODE_BACK, 1001) window = EventLoop.window window.bind(on_keyboard=self.on_keyboard)
def init(): global INIT_DONE if not INIT_DONE: global INPUT_CURSOR INPUT_CURSOR = image.Image( "sys_textcursor.png" , 8 , 16 ) global SMALLFONT SMALLFONT = pygame.font.Font( util.image_dir( "VeraBd.ttf" ) , 12 ) global TINYFONT TINYFONT = pygame.font.Font( util.image_dir( "VeraBd.ttf" ) , 9 ) global ANIMFONT ANIMFONT = pygame.font.Font( util.image_dir( "DejaVuSansCondensed-Bold.ttf" ) , 16 ) global ITALICFONT ITALICFONT = pygame.font.Font( util.image_dir( "VeraBI.ttf" ) , 12 ) global BIGFONT BIGFONT = pygame.font.Font( util.image_dir( "Gamaliel.otf" ) , 23 ) global POSTERS POSTERS += glob.glob( util.image_dir("poster_*.png") ) if android: android.init() android.map_key(android.KEYCODE_BACK, pygame.K_ESCAPE) # Set key repeat. pygame.key.set_repeat( 200 , 75 ) INIT_DONE = True
def main(): # Mapeando o botao voltar do android como K_ESCAPE (ESC) if android: android.init() android.map_key(android.KEYCODE_BACK, pygame.K_ESCAPE) # Usando timer para controlar os FPS pygame.time.set_timer(TIMEREVENT, 1000 / FPS) # A cor da tela global color controle = Controle(LARGURA,ALTURA) while True: ev = pygame.event.wait() # Especifico para android if android: if android.check_pause(): android.wait_for_resume() if ev.type == TIMEREVENT: screen.fill(color) controle.desenha(screen) pygame.display.flip() else: controle.evento(ev, color) if (ev.type == pygame.KEYDOWN and ev.key == pygame.K_ESCAPE) or ev.type == pygame.QUIT: break
def main(): # create configuration object if android is not None or len(sys.argv) == 1: # Map the back button to the escape key. # initialize pygame pygame.init() if android is not None: android.init() android.map_key(android.KEYCODE_BACK, pygame.K_ESCAPE) configo = classes.config.Config(android) # create the language object lang = classes.lang.Language(configo) # create the Thread objects and start the threads speaker = classes.speaker.Speaker(lang, configo, android) app = GamePlay(speaker, lang, configo) if android is None: speaker.start() app.start() else: app.run() elif len(sys.argv) == 2: if sys.argv[1] == "v" or sys.argv[1] == "version": from classes.cversion import ver print("pysiogame-%s" % ver) else: print("Sorry arguments not recognized.")
def post_build_init(self, *args): # Map Android keys if platform == 'android': android.map_key(android.KEYCODE_BACK, 1000) android.map_key(android.KEYCODE_MENU, 1001) win = self._app_window win.bind(on_keyboard=self._key_handler)
def install_android(): '''Install hooks for android platform. * Automaticly sleep when the device is paused * Auto kill the application is the return key is hitted ''' try: import android except ImportError: print 'Android lib is missing, cannot install android hooks' return from kivy.clock import Clock import pygame print '==========+> Android install hooks' # Init the library android.init() android.map_key(android.KEYCODE_MENU, pygame.K_MENU) # Check if android must be paused or not # If pause is asked, just leave the app. def android_check_pause(*largs): if not android.check_pause(): return from kivy.base import stopTouchApp stopTouchApp() #android.wait_for_resume() Clock.schedule_interval(android_check_pause, 0)
def __init__(self): self.loopFlag = True #Display if not ANDROID: os.environ['SDL_VIDEO_CENTERED'] = '1' pygame.init() if ANDROID: android.init() android.accelerometer_enable(True) android.map_key(android.KEYCODE_BACK, pygame.K_ESCAPE) width, height = 800, 480 self.displaySize = width, height self.display = pygame.display.set_mode(self.displaySize) self.fps = 60 #Peripherals self.keyboard = Keyboard() self.mouse = Mouse() # world self.world = World(width, height) #Other objects self.clock = pygame.time.Clock()
def main(): pygame.init() print pygame.display.list_modes() if not android: # Pick a size one smaller than our desktop to save room for WM stuff. modes = pygame.display.list_modes() if len(modes) > 1: mode = modes[1] else: mode = modes[0] screen_w, screen_h = mode else: # Fullscreen always _info = pygame.display.Info() screen_w = _info.current_w screen_h = _info.current_h global WIDTH, HEIGHT WIDTH = screen_w HEIGHT = screen_h #This means we must scale everything horizontally by screen_ratio global RATIO RATIO = WIDTH/HEIGHT # Set the screen size. pygame.display.set_mode((screen_w, screen_h)) # Map the back button to the escape key. if android: android.init() android.map_key(android.KEYCODE_BACK, pygame.K_ESCAPE) # Use a timer to control FPS. pygame.time.set_timer(TIMEREVENT, int(1000 / FPS)) # Set up our scenegraph setup() while True: ev = pygame.event.wait() # Android-specific: if android: if android.check_pause(): android.wait_for_resume() # Draw the screen based on the timer. if ev.type == TIMEREVENT: update() draw() # When the touchscreen is pressed, change the color to green. elif ev.type == pygame.MOUSEBUTTONDOWN: handle_click() # When the user hits back, ESCAPE is sent. Handle it and end # the game. elif ev.type == pygame.KEYDOWN and ev.key == pygame.K_ESCAPE: break
def load(self): if android: android.init() android.map_key(android.KEYCODE_BACK, pygame.K_ESCAPE) self.clock = pygame.time.Clock() gfx.fontSmall = pygame.font.Font(main.cwd+"/font/CALIBRI.TTF", 30) gfx.font = pygame.font.Font(main.cwd+"/font/CALIBRI.TTF", 50) gfx.fontBig = pygame.font.Font(main.cwd+"/font/CALIBRI.TTF", 75)
def post_build_init(self): """ Bind the android or the keyboard key """ if platform() == "android": import android android.map_key(android.KEYCODE_BACK, 1001) win = Window win.bind(on_keyboard=self.key_handler)
def post_build_init(self, instance): # voláno po spuštění programu, namapuje systémové klávesy Androidu android.map_key(android.KEYCODE_MENU, 1000) android.map_key(android.KEYCODE_BACK, 1001) android.map_key(android.KEYCODE_HOME, 1002) android.map_key(android.KEYCODE_SEARCH, 1003) android.map_key(android.KEYCODE_APP_SWITCH, 1004) win = self._app_window win.bind(on_keyboard=self._key_handler)
def load(self): if android: android.init() android.map_key(android.KEYCODE_BACK, pygame.K_ESCAPE) self.clock = pygame.time.Clock() gfx.fontSmall = pygame.font.Font(main.cwd + "/font/CALIBRI.TTF", 30) gfx.font = pygame.font.Font(main.cwd + "/font/CALIBRI.TTF", 50) gfx.fontBig = pygame.font.Font(main.cwd + "/font/CALIBRI.TTF", 75)
def __init__ (self, mdl): self.state = True #used to see if anything in model was changed due to Controller self.drag = False #used to determine if a click and drag is being established Controller.model = mdl # Map the back button to the escape key. if android: android.init() android.map_key(android.KEYCODE_BACK, pygame.K_ESCAPE)
def post_build_init(self, *args): if constants.PLATFORM_ANDROID: import android android.map_key(android.KEYCODE_BACK, 1001) win = Window win.bind(on_keyboard=self.my_key_handler)
def do_main(no_intro=0, the_level=0): global flags print("hello from zanthor do_main") pygame.mixer.pre_init(22050, -16, 2, 1024) pygame.init() pygame.font.init() #pygame.display.set_caption("The Wrath of ZANTHOR") #It's powered by steam!") pygame.display.set_caption( "The Wrath of ZANTHOR! It's powered by steam! h key for help") #flags = FULLSCREEN print flags print(SW, SH) screen = pygame.display.set_mode((SW, SH), flags) # Map the back button to the escape key. if android: android.map_key(android.KEYCODE_BACK, pygame.K_ESCAPE) print("initialising joystick module") pygame.joystick.init() joystics = [] num_joys = pygame.joystick.get_count() print "initialising joys", num_joys for x in range(num_joys): print "x joy is:", x j = pygame.joystick.Joystick(x) j.init() joystics.append(j) print "initialising joys: done." game = Game() game.should_restore_stats = True game.backup_upgradable_amounts = None game.backup_castle_stats = None # the intro is not done first. #game.run(states.Title(game),screen) if no_intro == 0: game.run(intro.Intro(game), screen) elif no_intro == 1: #game.run(level.Level(game, 0,100),screen) game.run(menu.Menu(game), screen) elif no_intro == 3: # we load the level number from the levels defined in menu. n = menu.data[no_intro][4] perc = menu.data[no_intro][5] music = menu.data[no_intro][7] game.run(level.Level(game, n, perc, music), screen) else: game.run(level.Level(game, no_intro, 100, None), screen)
def __init__(self, info): self.info = info pygame.mixer.init() # is this necessary? pygame.mixer.pre_init(44100, -16, 2, 2048) pygame.init() # Set the screen size. size = self.width, self.height = 480, 800 self.screen = pygame.display.set_mode(size) # Map the back button to the escape key. if android: android.init() android.map_key(android.KEYCODE_BACK, pygame.K_ESCAPE) # load our sounds snddir = 'sounds' self.soundtrack \ = pygame.mixer.Sound(os.path.join(snddir, 'soundtrack.wav')) self.soundtrack.set_volume(0.3) self.soundtrack.play(-1, 0, 2000) self.win_sound \ = pygame.mixer.Sound(os.path.join(snddir, 'win2.wav')) self.click_sound \ = pygame.mixer.Sound(os.path.join(snddir, 'plug.wav')) self.lose_sound \ = pygame.mixer.Sound(os.path.join(snddir, 'lose.wav')) self.gameover_sound \ = pygame.mixer.Sound(os.path.join(snddir, 'gameover.wav')) # load our images imgdir = 'images' self.or_img = [load_image('or0.png').convert_alpha(), \ load_image('or1.png').convert_alpha() ] self.notr_img = [load_image('not0.png').convert_alpha(), \ load_image('not1.png').convert_alpha() ] self.notl_img = [pygame.transform.flip(self.notr_img[i], True, False) \ for i in range(2)] self.var_img = [load_image('var0.png').convert_alpha(), \ load_image('var1.png').convert_alpha()] # load our font fontfile = pygame.font.match_font('gfsneohellenic,sans') self.font = pygame.font.Font(fontfile, 40) if self.font == None: # always have a backup plan self.font = pygame.font.SysFont(None, 40) self.font = pygame.font.SysFont(None, 40) # pick colors self.bg_color = BLACK self.wire_colors = [BROWN, LIGHTGREEN] # compute on-screen locations of everything self.updated_formula() # start up some timers pygame.time.set_timer(TIMEREVENT, 1000 // FPS)
def main(): if android: android.init() android.map_key(android.KEYCODE_BACK, pygame.K_ESCAPE) respawn = Respawn() turn = Turn() background = pygame.Surface((DISPLAYHEIGHT, DISPLAYWIDTH)) drawBoard(background) shouldUpdate = 1 pygame.init() pygame.display.set_caption("Keys") keys = pygame.Surface((DISPLAYHEIGHT, DISPLAYWIDTH)) drawKeysOnBoard(keys, BOARD) DISP.blit(background, (0, 0)) DISP.blit(keys, (0, 0)) while True: if android: if android.check_pause(): android.wait_for_resume() for event in pygame.event.get(): if event.type == QUIT: pygame.quit() sys.exit() if event.type == MOUSEBUTTONDOWN: handleKeyPress(event, turn, respawn) if event.type == pygame.KEYDOWN and event.key == pygame.K_ESCAPE: pygame.quit() sys.exit() #for i in SQUARESTOHIGHLIGHT: # highlightSquare((i[1],i[0]),DISP,(213,23,12)) shouldUpdate = 1 #pygame.display.update() shouldUpdate = 1 if shouldUpdate: DISP.blit(background, (0, 0)) drawLockedKeysOnBoard(DISP, BOARD) drawKeysOnBoard(DISP, BOARD) for i in ROTATEPOINTS: highlightSquare((i[1], i[0]), DISP, (23, 223, 12)) for i in SQUARESTOHIGHLIGHT: highlightSquare((i[1], i[0]), DISP, (213, 23, 12)) for i in RESPAWNPOINTS: highlightSquare((i[1], i[0]), DISP, (233, 34, 223)) if gameover: drawGameOverScreen(DISP, background, winner="none") pygame.display.update() fpsclock.tick(FPS)
def __init__(self,width,height): pygame.init() if android: android.init() android.map_key(android.KEYCODE_DPAD_CENTER,pygame.K_SPACE) android.map_key(android.KEYCODE_B,pygame.K_ESCAPE) self.width = width self.height = height self.done = False self.oldTime = time.time() self.totalGameTime = 0 self.pointsSinceLastCopSequence = 0 self.copsCreated = False self.moveSpeed = 40 self.mouseActive = False # initialize pygame random.seed() pygame.font.init() self.screen = pygame.display.set_mode((width,height)) self.mainMenu = MainMenu([width/2,height/2],width,height) surface = pygame.image.load('resources/levelBig.png').convert() self.background = pygame.transform.scale(surface,(width,surface.get_rect().height)) self.backRect = self.background.get_rect() # establish lane info: self.laneWidth = width *.1033 self.lanes = [] self.lanes.append(self.width * 0.25) self.lanes.append(self.width * 0.35) self.lanes.append(self.width * 0.45) self.lanes.append(self.width * 0.56) self.lanes.append(self.width * 0.66) self.lanes.append(self.width * 0.77) self.currentLaneIndex = 4 # initialize game entities self.player = Player([self.lanes[self.currentLaneIndex], self.height / 2.0],30,50) self.citizens = [] self.cops = [] self.makeRandomCitizen() self.makeRandomCitizen() # initialize input objects self.inGameMenu = InGameMenu(self.player,[self.width / 2,self.height / 2],self.width,self.height) self.sidearmStick = Thumbstick(self.player,[self.width - (self.width/ 12), 5 *(self.height/6)],self.width / 6,self.height / 8) self.weaponStick = Thumbstick(self.player,[self.width/ 12, 5 *(self.height/6)],self.width / 6,self.height / 8) self.sidearmStick.deactivate() #initialize all variable text that will be used self.scoreText = Text("0" + str(self.inGameMenu.score), [self.width / 15,self.height / 20], self.width / 15,self.height / 15,(255,255,255)) # start game self.gameLoop()
def main(): if android: android.init() android.map_key(android.KEYCODE_BACK, pygame.K_ESCAPE) respawn = Respawn() turn = Turn() background = pygame.Surface((DISPLAYHEIGHT,DISPLAYWIDTH)) drawBoard(background) shouldUpdate = 1 pygame.init() pygame.display.set_caption("Keys") keys = pygame.Surface((DISPLAYHEIGHT,DISPLAYWIDTH)) drawKeysOnBoard(keys,BOARD) DISP.blit(background,(0,0)) DISP.blit(keys,(0,0)) while True: if android: if android.check_pause(): android.wait_for_resume() for event in pygame.event.get(): if event.type == QUIT: pygame.quit() sys.exit() if event.type == MOUSEBUTTONDOWN: handleKeyPress(event,turn,respawn) if event.type == pygame.KEYDOWN and event.key == pygame.K_ESCAPE: pygame.quit() sys.exit() #for i in SQUARESTOHIGHLIGHT: # highlightSquare((i[1],i[0]),DISP,(213,23,12)) shouldUpdate= 1 #pygame.display.update() shouldUpdate=1 if shouldUpdate: DISP.blit(background,(0,0)) drawLockedKeysOnBoard(DISP,BOARD) drawKeysOnBoard(DISP,BOARD) for i in ROTATEPOINTS: highlightSquare((i[1],i[0]),DISP,(23,223,12)) for i in SQUARESTOHIGHLIGHT: highlightSquare((i[1],i[0]),DISP,(213,23,12)) for i in RESPAWNPOINTS: highlightSquare((i[1],i[0]),DISP,(233,34,223)) if gameover: drawGameOverScreen(DISP,background,winner="none") pygame.display.update() fpsclock.tick(FPS)
def post_build_init(self,ev): if platform() == 'android': import android android.map_key(android.KEYCODE_BACK,1001) win = Window win.bind(on_keyboard=self.my_key_handler) Clock.schedule_interval(self.save_all_boards,150)
def __init__(self, size): pygame.init() if android: android.init() android.map_key(android.KEYCODE_BACK, pygame.K_ESCAPE) self.screen = pygame.display.set_mode(size) self.purge()
def post_build_init( self, instance ): # voláno po spuštění programu, namapuje systémové klávesy Androidu android.map_key(android.KEYCODE_MENU, 1000) android.map_key(android.KEYCODE_BACK, 1001) android.map_key(android.KEYCODE_HOME, 1002) android.map_key(android.KEYCODE_SEARCH, 1003) android.map_key(android.KEYCODE_APP_SWITCH, 1004) win = self._app_window win.bind(on_keyboard=self._key_handler)
def build(self): #Android back mapping android.map_key(android.KEYCODE_BACK, 1001) win = Window win.bind(on_keyboard=self.key_handler) #globalvars.init() self.nfc_init() self.HomeScr.getStoredMedia() return self.sm
def main(): settings = Settings.Instance() pygame.init() if settings.android: settings.android = True android.init() android.map_key(android.KEYCODE_SEARCH, pygame.K_ESCAPE) nback = NBack() pygame.display.set_caption('N-Back v' + settings.version) nback.run()
def main(): pygame.init() if android: android.init() android.mixer.music.load("click.wav") android.mixer.music.play(-1) # Set the screen size. screen = pygame.display.set_mode((480, 800)) # Map the back button to the escape key. if android: android.map_key(android.KEYCODE_BACK, pygame.K_ESCAPE) # Use a timer to control FPS. pygame.time.set_timer(TIMEREVENT, 1000 / FPS) # The color of the screen. color = RED while True: ev = pygame.event.wait() # Android-specific: if android: if android.check_pause(): android.wait_for_resume() # Draw the screen based on the timer. if ev.type == TIMEREVENT: screen.fill(color) pygame.display.flip() android.mixer.periodic() # When the touchscreen is pressed, change the color to green. elif ev.type == pygame.MOUSEBUTTONDOWN: color = GREEN if android: android.vibrate(.25) print "Open URL Version 2" webbrowser.open("http://www.renpy.org/") # When it's released, change the color to RED. elif ev.type == pygame.MOUSEBUTTONUP: color = RED # When the user hits back, ESCAPE is sent. Handle it and end # the game. elif ev.type == pygame.KEYDOWN and ev.key == pygame.K_ESCAPE: break
def main(): pygame.init() if android: android.init() # Set the screen size. screen = pygame.display.set_mode((480, 800), pygame.FULLSCREEN) test = pygame.image.load("test.jpg").convert() test.set_alpha(128) # Map the back button to the escape key. if android: android.map_key(android.KEYCODE_BACK, pygame.K_ESCAPE) # Use a timer to control FPS. pygame.time.set_timer(TIMEREVENT, 1000 / FPS) # The color of the screen. color = RED while True: ev = pygame.event.wait() # Android-specific: if android: if android.check_pause(): android.wait_for_resume() # Draw the screen based on the timer. if ev.type == TIMEREVENT: screen.fill(color) screen.blit(test, (100, 100)) pygame.display.flip() # When the touchscreen is pressed, change the color to green. elif ev.type == pygame.MOUSEBUTTONDOWN: color = GREEN if android: android.vibrate(.25) # When it's released, change the color to RED. elif ev.type == pygame.MOUSEBUTTONUP: color = RED # When the user hits back, ESCAPE is sent. Handle it and end # the game. elif ev.type == pygame.KEYDOWN and ev.key == pygame.K_ESCAPE: break
def on_start(self): #PERHAPS THIS CAN BE PLACED UP ABOVE SIMPLY print('my platfooooooooooorm is ' + str(platform)) if displayAd: pass AdBuddiz.setPublisherKey("TEST_PUBLISHER_KEY") if platform == 'android': import android android.map_key(android.KEYCODE_BACK, 1000) android.map_key(android.KEYCODE_MENU, 1001) win = self._app_window win.bind(on_keyboard=self._key_handler)
def _on_these_settings(self, window, *largs): key = largs[0] setting_key = 282 # F1 if platform() == 'android': import android import pygame android.map_key(android.KEYCODE_MENU, 1000) android.map_key(android.KEYCODE_BACK, 1001) android.map_key(android.KEYCODE_HOME, 1002) android.map_key(android.KEYCODE_SEARCH, 1003) # android hack, if settings key is pygame K_MENU if platform == 'android': import pygame setting_key = pygame.K_MENU if key == setting_key: # toggle settings panel Logger.info("This is the F1 key") self.open_settings = None if not self._menu_down: self._app_menu.open() self._menu_down = True Logger.info("State is true") else: self._app_menu.dismiss() self._menu_down = False Logger.info("State is false") return True if key == 27: return self.close_menu()
def main(): mixer.pre_init( 44100, -16, 2, 1024 ) #sound effects are delayed on my windows machine without this, I think the buffer is initialized too large by default pygame.init() screen = get_screen() pygame.display.set_caption(TITLE) pygame.display.set_icon( load_image(os.path.join('blocks', 'lightgreen.png'))) if android: android.init() android.map_key(android.KEYCODE_BACK, pygame.K_ESCAPE) while True: menu(screen)
def init_display(experiment): """See openexp._canvas.legacy""" if experiment.resolution() != resolution: raise canvas_error( \ 'The droid back-end requires a resolution of %d x %d. Your display will be scaled automatically to fit devices with different resolutions.' \ % resolution) # Intialize PyGame if not pygame.display.get_init(): pygame.init() experiment.window = pygame.display.set_mode(resolution) experiment.surface = pygame.display.get_surface() # Set the time functions to use pygame experiment._time_func = pygame.time.get_ticks experiment._sleep_func = pygame.time.delay experiment.time = experiment._time_func experiment.sleep = experiment._sleep_func # Initialze the Android device if necessary if android != None: android.init() android.map_key(android.KEYCODE_BACK, pygame.K_ESCAPE) dpi = android.get_dpi() else: # A dummy dpi if we are not on Android dpi = 96 # Log the device characteristics info = pygame.display.Info() diag = hypot(info.current_w, info.current_h) / dpi if diag < 6: # 6" is the minimum size to be considered a tablet is_tablet = 'yes' else: is_tablet = 'no' experiment.set('device_resolution_width', info.current_w) experiment.set('device_resolution_height', info.current_h) experiment.set('device_dpi', dpi) experiment.set('device_screen_diag', diag) experiment.set('device_is_tablet', is_tablet) # Start with a splash screen splash = pygame.image.load(experiment.resource('android-splash.jpg')) x = resolution[0] / 2 - splash.get_width() / 2 y = resolution[1] / 2 - splash.get_height() / 2 experiment.surface.blit(splash, (x, y)) for i in range(10): pygame.display.flip() pygame.time.delay(100) if android != None and android.check_pause(): android.wait_for_resume()
def main(): pygame.init() if android: android.init() # Set the screen size. screen = pygame.display.set_mode((480, 800)) # Map the back button to the escape key. if android: android.map_key(android.KEYCODE_BACK, pygame.K_ESCAPE) android.accelerometer_enable(True) # Use a timer to control FPS. pygame.time.set_timer(TIMEREVENT, 1000 / FPS) font = pygame.font.Font("FreeSans.ttf", 30) def text(s, x, y): surf = font.render(s, True, (200, 200, 200, 255)) screen.blit(surf, (x, y)) while True: ev = pygame.event.wait() if android.check_pause(): android.wait_for_resume() # Draw the screen based on the timer. if ev.type == TIMEREVENT: x, y, z = android.accelerometer_reading() screen.fill((0, 0, 0, 255)) text("X: %f" % x, 10, 10) text("Y: %f" % y, 10, 50) text("Z: %f" % z, 10, 90) pygame.display.flip() # When the user hits back, ESCAPE is sent. Handle it and end # the game. elif ev.type == pygame.KEYDOWN and ev.key == pygame.K_ESCAPE: break
def main(): flags = 0 if RELEASE: flags |= pygame.FULLSCREEN if not android: flags |= pygame.HWSURFACE display.set_mode((VWIDTH, VHEIGHT), flags) if android: android.init() android.map_key(android.KEYCODE_BACK, pygame.K_ESCAPE) while 1: clock = pygame.time.Clock() choice = MenuScreen(clock).show() if choice == "exit": return 0 else: play_game(clock, choice) return 0
def init_display(experiment): if experiment.resolution() != resolution: raise osexception( (u'The droid back-end requires a resolution of %d x %d. Your ' u'display will be scaled automatically to fit devices with ' u'different resolutions.') % resolution ) # Intialize PyGame if not pygame.display.get_init(): pygame.init() experiment.window = pygame.display.set_mode(resolution) experiment.surface = pygame.display.get_surface() # Set the time functions to use pygame experiment._time_func = pygame.time.get_ticks experiment._sleep_func = pygame.time.delay experiment.time = experiment._time_func experiment.sleep = experiment._sleep_func # Initialze the Android device if necessary if android is not None: android.init() android.map_key(android.KEYCODE_BACK, pygame.K_ESCAPE) dpi = android.get_dpi() else: # A dummy dpi if we are not on Android dpi = 96 # Log the device characteristics info = pygame.display.Info() diag = hypot(info.current_w, info.current_h) / dpi experiment.var.device_resolution_width = info.current_w experiment.var.device_resolution_height = info.current_h experiment.var.device_dpi = dpi experiment.var.device_screen_diag = diag experiment.var.device_is_tablet = u'yes' if diag >= 6 else u'no' # Start with a splash screen splash = pygame.image.load(experiment.resource('android-splash.jpg')) x = resolution[0]/2 - splash.get_width()/2 y = resolution[1]/2 - splash.get_height()/2 experiment.surface.blit(splash, (x, y)) for i in range(10): pygame.display.flip() pygame.time.delay(100) if android is not None and android.check_pause(): android.wait_for_resume()
def main(): pygame.init() info = pygame.display.Info() # Set the screen size. screen = pygame.display.set_mode((info.current_w, info.current_h)) # Map the back button to the escape key. if android: android.init() android.map_key(android.KEYCODE_BACK, pygame.K_ESCAPE) # Use a timer to ensure the Android events get regularly # called. pygame.time.set_timer(TIMEREVENT, 1000 / FPS) im = pygame.image.load(android.assets.open("icon.png")) w, h = im.get_size() x = -w y = -h while True: ev = pygame.event.wait() # Android-specific: if android: if android.check_pause(): android.wait_for_resume() # Draw the screen based on the timer. if ev.type == TIMEREVENT: screen.fill((0, 0, 0, 0)) screen.blit(im, (x - w / 2, y - h / 2)) pygame.display.flip() if ev.type == pygame.MOUSEBUTTONDOWN: x, y = ev.pos elif ev.type == pygame.KEYDOWN and ev.key == pygame.K_ESCAPE: break
def post_build_init(self, ev): try: import android except: pass else: android.map_key(android.KEYCODE_MENU, 1000) android.map_key(android.KEYCODE_BACK, 1001) android.map_key(android.KEYCODE_HOME, 1002) android.map_key(android.KEYCODE_SEARCH, 1003) win = self._app_window win.bind(on_keyboard=self._key_handler)
def on_start(self): Config.set('kivy', 'log_level', self.config.get('general', 'log_level')) Logger.debug("%s: on_start %s" % (APP, datetime.now())) self.scmgr = self.root.scmgr # scmgr identificado con id en el kv if self.config.get('general', 'nucleo') not in ('Ruta', 'TMA'): self.pedir_nucleo() numero = int(self.config.get('general', 'numero')) try: planilla = self.config.get('general', 'planilla') except: planilla = "" # failsafe try: final = datetime.strptime(self.config.get('general', 'final'), "%d/%m/%y %H:%M") except Exception: final = None Logger.debug("Final %s" % final) if numero != 0 and final and final > datetime.now() and planilla != "": # 0 indica que no estamos rearrancando # Evita que cambiar s1 y s2 arranque el servicio self.restarting = True self.asigna_numero(planilla, numero) else: self.toast(u"Escoge tu número de planilla") from kivy.core.window import Window Window.bind(on_keyboard=self.on_keypress) if platform == 'android': android.map_key(android.KEYCODE_BACK, 1001) import android.activity as python_activity python_activity.bind(on_new_intent=self.on_new_intent) # on_new_intent sólo se llama cuando la aplicación ya está # arrancada. Para no duplicar código la llamamos desde aquí self.on_new_intent(activity.getIntent()) self.restarting = False
def main(): global BASICFONT, FPS, SCREENSIZE, BACKGROUNDCOLOR, BLACK, WHITE, DISPLAYSURF, DISPLAYRECT, BLUEPLANET, BLACKPLANET, REDPLANET, SHUTTLE, LAUNCHEDSHUTTLE, FLAG, GAUGE1, GAUGE2 pygame.init() pygame.font.init() if android: android.init() android.map_key(android.KEYCODE_BACK, pygame.K_ESCAPE) BASICFONT = pygame.font.SysFont("comicsansms", 20) FPS = 30 SCREENSIZE = (1280, 720) BACKGROUNDCOLOR = (0, 0, 0) BLACK = (0, 0, 0) WHITE = (255, 255, 255) pygame.display.set_caption("galaxyExplorer") DISPLAYSURF = pygame.display.set_mode(SCREENSIZE) DISPLAYRECT = DISPLAYSURF.get_rect() BLUEPLANET = pygame.image.load("blueplanet.png") BLACKPLANET = pygame.image.load("blackplanet.png") REDPLANET = pygame.image.load("redplanet.png") SHUTTLE = pygame.image.load("shuttle.png") LAUNCHEDSHUTTLE = pygame.image.load("launchedshuttle.png") FLAG = pygame.image.load("flag.png") FLAG = pygame.transform.scale(FLAG, (30, 30)) SHUTTLE = pygame.transform.scale(SHUTTLE, (50, 75)) LAUNCHEDSHUTTLE = pygame.transform.scale(LAUNCHEDSHUTTLE, (55, 78)) GAUGE1 = pygame.image.load("gauge1.png") GAUGE2 = pygame.image.load("gauge2.png") GAUGE1 = pygame.transform.scale(GAUGE1, (150, 150)) GAUGE2 = pygame.transform.scale(GAUGE2, (150, 150)) run = Control(1, 0, 100) #초기 레벨 1, 초기 점수 0, 초기 연료 100
def main(): pygame.init() if android: screen = pygame.display.set_mode() width, height = screen.get_size() dpi = android.get_dpi() if dpi >= 320: density = 'xhdpi' elif dpi >= 240: density = 'hdpi' elif dpi >= 160: density = 'mdpi' else: density = 'ldpi' dp = dpi / 160. android.init() # map the back button to the escape key android.map_key(android.KEYCODE_BACK, pygame.K_ESCAPE) else: dpi = 160 dp = 1 width = 480 height = 800 screen = pygame.display.set_mode((width, height)) density = 'mdpi' # figure the game icon size based on the available real-estate - allow 10 # rows so there's some whitespace border target = width // 10 for size in [24, 32, 48, 64, 72, 96, 128]: if size > target: break icon_size = size print 'dimensions=%r; dpi=%r; density=%r; dp=%r; icon_size=%r' % ( screen.get_size(), dpi, density, dp, icon_size) Game(screen, density, dp, icon_size).main()
def post_build_init(self, ev): global isAndroid if isAndroid: #android.map_key(android.KEYCODE_MENU, 1000) android.map_key(android.KEYCODE_BACK, 1001) android.map_key(android.KEYCODE_HOME, 1002) android.map_key(android.KEYCODE_SEARCH, 1003) win = self._app_window win.bind(on_keyboard=self._key_handler) # regist update function Clock.schedule_interval(self.update, fUpdateTime)