Example #1
0
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
Example #2
0
    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)
Example #3
0
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)
Example #4
0
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)
Example #5
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():
    """ 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()
Example #7
0
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.")
Example #8
0
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.")
Example #9
0
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
Example #10
0
def main():
    pygame.init()
    if android:
        android.init()
        android.map_key(android.KEYCODE_BACK, pygame.K_r)
        android.map_key(android.KEYCODE_W, pygame.K_UP)
        android.map_key(android.KEYCODE_A, pygame.K_LEFT)
        android.map_key(android.KEYCODE_D, pygame.K_RIGHT)
        #android.mixer.pre_init(44100, 16, 2, 4096) ##i know this isnt correct
    else:
        os.environ["SDL_VIDEO_CENTERED"] = "1"
        pygame.mixer.pre_init(44100, 16, 2, 4096)
    pygame.font.init()
    clock = pygame.time.Clock()

    game = Game(["server", "client"], levelFile, tilesetFile)
    #--- Main Loop
    while game.on:
        if android:
            if android.check_pause():
                android.wait_for_resume()
        game.tick()
        clock.tick(FPS)
        pygame.display.flip()
    pygame.quit()
    sys.exit()
Example #11
0
	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						
Example #12
0
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
Example #13
0
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()
Example #14
0
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
Example #15
0
    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)
Example #16
0
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)
Example #17
0
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.")
Example #18
0
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
Example #19
0
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
Example #20
0
 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)
Example #21
0
 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)
Example #22
0
 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)
Example #23
0
    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)
Example #24
0
def init(engine):
    global platformsArgs
    platformsArgs = engine.args

    if "android" in platformsArgs:
        android.init(platformsArgs["android"])

    if "ios" in platformsArgs:
        ios.init(platformsArgs["ios"])
Example #25
0
def init(engine):
	global platformsArgs
	platformsArgs = engine.args

	if "android" in platformsArgs:
		android.init(platformsArgs["android"])

	if "ios" in platformsArgs:
		ios.init(platformsArgs["ios"])
Example #26
0
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)
Example #27
0
    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()
Example #28
0
def menu(top):
	pygame.init()
	#screen=pygame.display.set_mode((WIDTH,HEIGHT))
	info=pygame.display.Info()
	screen=pygame.display.set_mode((info.current_w,info.current_h))
	pygame.display.set_caption('Square Game')
	opcion1=Texto('New Game',info.current_w/2,info.current_h/4)
	opcion2=Texto('Rewards (Useless)',info.current_w/2,info.current_h/2)
	opcion3=Texto('Rankings (Useless)',info.current_w/2,info.current_h*0.75)
	max=Texto('Max: ' + str(top),info.current_w*0.8,info.current_h/2,(255,255,0))
	clock=pygame.time.Clock()
	contador = 0
	print 'pene'
	if android:
		android.init()
		android.map_key(android.KEYCODE_BACK, K_ESCAPE)
	
	while True:
		keys=pygame.key.get_pressed()
		clic=pygame.mouse.get_pressed()
		contador += 1
		i=Texto(str(contador),50,50)
		time=clock.tick(144)
		#print pygame.mouse.get_pos()
	
		for event in pygame.event.get():
			if event.type == QUIT:
				pygame.quit()
				break
			if event.type==KEYDOWN and keys[K_ESCAPE]:
				pygame.quit()
				break
		
		if pygame.Rect.collidepoint(opcion1.text_rect,pygame.mouse.get_pos()):
			clock=pygame.time.Clock()
			timer=pygame.time.get_ticks()
			return timer
			break
		if pygame.Rect.collidepoint(opcion2.text_rect,pygame.mouse.get_pos()):
			rewards.rewards()
			pass
		if pygame.Rect.collidepoint(opcion3.text_rect,pygame.mouse.get_pos()):
			pass
			
		if keys[K_ESCAPE]:
			pygame.quit()
			break
		
		screen.fill((0,0,0))
		#screen.blit(background,(0,0))
		#screen.blit(i.text,i.text_rect)
		screen.blit(opcion1.text,opcion1.text_rect)
		screen.blit(opcion2.text,opcion2.text_rect)
		screen.blit(opcion3.text,opcion3.text_rect)
		screen.blit(max.text,max.text_rect)
		pygame.display.flip()
		
Example #29
0
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)
Example #30
0
    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()
Example #31
0
    def __init__(self, size=(1280, 720), FPS=32):
        pygame.init()
        pygame.display.init()
        
        try:
            info = pygame.display.Info()        
            diag = math.hypot(info.current_w,
                              info.current_h) / android.get_dpi()
            
            width, height = (info.current_w, info.current_h)
            self.scale_width = width / float(size[0])
            self.scale_height = height / float(size[1])
            self.screen = pygame.display.set_mode((width, height))

            print(width, height, size)
            print(self.scale_width, self.scale_height)
            
        except AttributeError:
            self.screen = pygame.display.set_mode(size)
            self.scale_width = 1
            self.scale_height = 1

        if android:
            android.init()

        self.red  = pygame.color.Color('red')
        self.black  = pygame.color.Color('black')
        self.width  = self.screen.get_width()
        self.height = self.screen.get_height()
        self.clock  = pygame.time.Clock()
        self.FPS    = FPS
        self.image  = Image()
        self.audio  = Audio()
        self.events = EventHandler()
        self.controller = OuyaController()

        self.safe_percentage = 0.05
        self.vertical_safe_zone = pygame.Surface((int(self.width * self.safe_percentage), int(self.height)))
        self.vszwidth = self.vertical_safe_zone.get_width()
        self.vszheight = self.vertical_safe_zone.get_height() * self.safe_percentage
        self.horizontal_safe_zone = pygame.Surface((int(self.width - 2 * self.vszwidth), int(self.vszheight)))

        self.sz_left = (0,0)
        self.sz_right = (self.width / self.scale_width - self.vszwidth / self.scale_width, 0)
        self.sz_up = (self.vszwidth / self.scale_width, 0)
        self.sz_down = (self.vszwidth / self.scale_width,
                        self.height / self.scale_height - self.vszheight / self.scale_height)

        self.vertical_safe_zone.fill(self.red)
        self.vertical_safe_zone.set_alpha(92)
        self.horizontal_safe_zone.fill(self.red)
        self.horizontal_safe_zone.set_alpha(92)
        
        if android:
            if android.check_pause():
                android.wait_for_resume()
Example #32
0
    def __init__(self, evm):
        self.evm = evm
        self.evm.register(self)
                
        self.fps_clock = pygame.time.Clock()

        if android:
            android.init()
            android.map_key(android.KEYCODE_BACK, pygame.K_ESCAPE)
            android.map_key(android.KEYCODE_MENU, pygame.K_SPACE)
Example #33
0
def main():
    if android:
        android.init()
        android.accelerometer_enable(True)
    pygame.init()

    screen = pygame.display.set_mode((800, 480))
    
    c = game.Controls(screen)
    space = game.Space(load_image('background.png'))
    camera = game.Camera(space)
    direction = game.DIR_STOP

    in_game = True
    while in_game:
        
        print c.angle, c.angle%(2*math.pi), c.press
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                in_game = False
            elif (event.type == pygame.KEYDOWN and
                  event.key == pygame.K_ESCAPE):
                in_game = False
            elif (event.type == pygame.KEYDOWN and
                  event.key == pygame.K_LEFT):
                direction = game.DIR_LEFT
            elif (event.type == pygame.KEYDOWN and
                  event.key == pygame.K_RIGHT):
                direction = game.DIR_RIGHT
            elif ((event.type == pygame.KEYUP) and
                  (event.key == pygame.K_LEFT) and
                  (direction == game.DIR_LEFT)):
                direction = game.DIR_STOP
            elif ((event.type == pygame.KEYUP) and
                  (event.key == pygame.K_RIGHT) and
                  (direction == game.DIR_RIGHT)):
                direction = game.DIR_STOP
            elif (event.type == pygame.KEYDOWN and
                  event.key == pygame.K_UP):
                direction = game.DIR_UP
            elif (event.type == pygame.KEYDOWN and
                  event.key == pygame.K_DOWN):
                direction = game.DIR_DOWN
            elif ((event.type == pygame.KEYUP) and
                  (event.key == pygame.K_UP) and
                  (direction == game.DIR_UP)):
                direction = game.DIR_STOP
            elif ((event.type == pygame.KEYUP) and
                  (event.key == pygame.K_DOWN) and
                  (direction == game.DIR_DOWN)):
                direction = game.DIR_STOP

        camera.move_camera(direction)
        dirty = screen.blit(camera.view, (0, 0))
        pygame.display.flip()
Example #34
0
File: main.py Project: eckamm/rut
def main():
    if android:
        android.init()
        android.map_key(android.KEYCODE_BACK, pygame.K_p)

    GAMEDIR = os.path.dirname(os.path.abspath(sys.argv[0]))
    if os.environ.get("PROFILE", "") == "1":
        import profile
        profile.run("main2()")
    else:
        sys.exit(main2())
Example #35
0
    def __init__(self, title, fullscreen=False,
     resolutions=[(1024, 768), (960, 640), (854, 480), (800, 480), (640, 480), (480, 320)],
     appstates=[], fps=30, version="0.1"):
        global on_android

        os.environ['SDL_VIDEO_CENTERED'] = '1'

        pygame.init()

        vidinfo = pygame.display.Info()

        for r in resolutions:
            if r[0] <= vidinfo.current_w and r[1] <= vidinfo.current_h:
                break

        self.screen_w, self.screen_h = r

        if fullscreen:
            pygame.display.set_mode((vidinfo.current_w, vidinfo.current_h))
            self.fullscreen = pygame.display.get_surface()
            self.screen = pygame.Surface((self.screen_w, self.screen_h))
            self.x = 0
            self.y = 0
            self.b_fullscreen = True
        else:
            pygame.display.set_mode((self.screen_w, self.screen_h))
            self.screen = pygame.display.get_surface()
            self.b_fullscreen = False

        pygame.display.set_caption(title)

        self.is_running = True  # used to trigger exit by ESC

        # Map the back button to the escape key.
        if on_android:
            android.init()
            android.map_key(android.KEYCODE_BACK, pygame.K_ESCAPE)

        self.clock = pygame.time.Clock()
        self._fps = fps

        self.resman = ResourceManager(self)
        self.audioman = AudioManager(self)

        self._dirty_rects = []
        self.init()

        self.version = version

        self._appstates = []
        for asc in appstates:
            s = asc(self)
            self._appstates.append(s)
        self.appstate = self._appstates[0]
Example #36
0
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()
    if android:
        android.init()
        android.map_key(android.KEYCODE_BACK, pygame.K_ESCAPE)
    while True:
        screen =  get_screen()
        pygame.display.set_caption(TITLE)
        pygame.display.set_icon(load_image(os.path.join('blocks', 'lightgreen.png')))
        menu = Menu(screen)
Example #37
0
	def __init__(self):
		print '%s here' % self.__name__()
		if android:
			android.init()
			android.map_key(android.KEYCODE_MENU, K_ESCAPE)

		init()
		display.set_mode((X_MAX, Y_MAX))

		font.init()

		self.location = Location(self.location_index)
Example #38
0
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()
Example #39
0
def main():
    pygame.init()
    pantalla = pygame.display.set_mode((ANCHO, ALTO))
    pygame.display.set_caption("BricksT 4")

    if android:
        android.init()

    pelota = Pelota()
    base = Base()
    ladrillos = pygame.sprite.Group()

    t = 0
    for i in range(90 / 10):
        e = 0
        for s in range(ANCHO / 25):
            ladrillo = Ladrillo(e, t)
            ladrillos.add(ladrillo)
            e += 50
        t += 23

    reloj = pygame.time.Clock()
    puntuacion = 0

    salir = False

    while salir != True:
        time = reloj.tick(60)

        for eventos in pygame.event.get():
            if eventos.type == QUIT:
                salir = True
                sys.exit()

        pantalla.fill((0, 0, 0))
        lista_impacto_ladrillos = pygame.sprite.spritecollide(
            pelota, ladrillos, True)
        pelota.actualizar(time, base, lista_impacto_ladrillos, pantalla)

        ladrillos.draw(pantalla)
        pantalla.blit(pelota.image, pelota.rect)

        pantalla.blit(base.image, (base.rect.x, base.rect.y))

        base.rect.x, ejey = pygame.mouse.get_pos()

        pygame.display.flip()
        for bloque in lista_impacto_ladrillos:
            puntuacion += 1
            if puntuacion == 99:
                ganarJuego(pantalla)

    return 0
Example #40
0
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
Example #41
0
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():
    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)
Example #43
0
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()
Example #44
0
def main():
    pygame.init()

    if android:
        android.init()

    # Set the screen size.
    screen = pygame.display.set_mode((480, 800))

    # 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()

        # Handle application state events.
        if ev.type == pygame.APP_WILLENTERBACKGROUND:
            print "Will enter background."
            pygame.time.set_timer(TIMEREVENT, 0)
        elif ev.type == pygame.APP_DIDENTERFOREGROUND:
            print "Did enter foreground."
            screen = pygame.display.set_mode((480, 800))
            pygame.time.set_timer(TIMEREVENT, 1000 / FPS)
        elif ev.type == pygame.APP_TERMINATING:
            break

        # Draw the screen based on the timer.
        elif ev.type == TIMEREVENT:
            screen.fill(color)
            pygame.display.flip()

        # When the touchscreen is pressed, change the color to green.
        elif ev.type == pygame.MOUSEBUTTONDOWN:
            color = GREEN
            if android:
                android.vibrate(.1)

        # When it's released, change the color to RED.
        elif ev.type == pygame.MOUSEBUTTONUP:
            color = RED

        # Escape or the back button quits.
        elif ev.type == pygame.KEYDOWN and (ev.key == pygame.K_ESCAPE or ev.key == pygame.K_AC_BACK):
            break
Example #45
0
File: main.py Project: nithramus/42
def main():
    pygame.init()

    fenetre = pygame.display.set_mode(Constante.TAILLE_FENETRE)

    if android:
        android.init()

    serverIsKnown = False

    if android:
        android.vibrate(10)

    print "Labyrinth - android is set " + str(android)

    reponse = lancerServeur(fenetre)
    serverLaunch = (reponse == 'y')

    print "server launch: " + str(serverLaunch)

    if (serverLaunch):
        print "server = " + str(socket.gethostname())
        executerServeur()
        ip = socket.gethostbyname(socket.gethostname())
        ip2 = str(socket.gethostbyname_ex(socket.gethostname())[2])
        demandeUtilisateur(fenetre,
                           "l'adresse du serveur est " + ip2 + " [y] ")
        serverIsKnown = True
    else:
        ip = demandeUtilisateur(fenetre,
                                "rentrez adresse ip (puis entree)",
                                answer="192.168.1.")
        serverIsKnown = True

    print "ip " + ip

    if (serverIsKnown == True):
        client = Client(ip, Constante.SERVER_PORT)
        nomJoueur = demandeUtilisateur(fenetre, "Nom du joueur (puis entree)")
        labyrinthC.start.start(client, nomJoueur, fenetre, ip)

    if (serverLaunch):
        demandeUtilisateur(fenetre, "Arret du serveur [entree]")
        reponse = client.arretServeur()
        print "arret du serveur reponse: " + str(reponse)

    pygame.quit()
Example #46
0
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()

    # 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()

        # Handle application state events.
        if ev.type == pygame.APP_WILLENTERBACKGROUND:
            pygame.time.set_timer(TIMEREVENT, 0)
        elif ev.type == pygame.APP_DIDENTERFOREGROUND:
            screen = pygame.display.set_mode((info.current_w, info.current_h))
            pygame.time.set_timer(TIMEREVENT, 1000 / FPS)
        elif ev.type == pygame.APP_TERMINATING:
            break

        # 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_AC_BACK:
            break
Example #47
0
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
Example #48
0
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
Example #49
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()
Example #50
0
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
Example #51
0
File: main.py Project: nithramus/42
def demandeUtilisateur(screen, question, answer=None):
    "ask(screen, question) -> answer"
    if android:
        android.init()
        android.show_keyboard()

    entryAnswer = False
    pygame.font.init()

    current_string = []

    if not answer == None:
        for i in answer:
            current_string.append(i)

    question = question + " : "
    afficherDialog(screen, question + string.join(current_string, ""))
    while entryAnswer == False:

        event = pygame.event.wait()

        if event.type == pygame.KEYDOWN:

            inkey = event.key

            if inkey == pygame.K_BACKSPACE:
                current_string = current_string[0:-1]
            elif inkey == pygame.K_RETURN:
                entryAnswer = True
            elif inkey == pygame.K_MINUS:
                current_string.append("_")
            elif inkey <= 127:
                current_string.append(chr(inkey))

            afficherDialog(screen,
                           question + " " + string.join(current_string, ""))

    if android:
        android.hide_keyboard()

    return string.join(current_string, "")
Example #52
0
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()
Example #53
0
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():
    android.init()

    projects = {}
    for folder in glob.glob("/mnt/*"):
        if os.path.isdir(folder):
            for project in glob.glob(folder + "/expyriment/*"):
                if os.path.isdir(project):
                    path = project + "/*.py"
                else:
                    path = folder + "expyriment/*.py"
                for pyfile in glob.glob(path):
                    projects[os.path.split(pyfile)[-1]] = pyfile

    pygame.font.init()
    for font in glob.glob("/system/fonts/*"):
        if font[-4:].lower() in ['.ttf', '.ttc']:
            font = unicode(font)
            name = os.path.split(font)[1]
            bold = name.find('Bold') >= 0
            italic = name.find('Italic') >= 0
            oblique = name.find('Oblique') >= 0
            name = name.replace(".ttf", "")
            if name.endswith("Regular"):
                name = name.replace("Regular", "")
            if name.endswith("Bold"):
                name = name.replace("Bold", "")
            if name.endswith("Italic"):
                name = name.replace("Italic", "")
            if name.endswith("Oblique"):
                name = name.replace("Oblique", "")
            name = ''.join([c.lower() for c in name if c.isalnum()])
            pygame.sysfont._addfont(name, bold, italic or oblique, font,
                                    pygame.sysfont.Sysfonts)

    aliases = (
        ('monospace', 'misc-fixed', 'courier', 'couriernew', 'console',
         'fixed', 'mono', 'freemono', 'bitstreamverasansmono', 'verasansmono',
         'monotype', 'lucidaconsole', 'droidsansmono'),
        ('sans', 'arial', 'helvetica', 'swiss', 'freesans',
         'bitstreamverasans', 'verasans', 'verdana', 'tahoma', 'droidsans'),
        ('serif', 'times', 'freeserif', 'bitstreamveraserif', 'roman',
         'timesroman', 'timesnewroman', 'dutch', 'veraserif', 'georgia',
         'droidserif'),
    )
    for set in aliases:
        found = None
        fname = None
        for name in set:
            if name in pygame.sysfont.Sysfonts:
                found = pygame.sysfont.Sysfonts[name]
                fname = name
                break
        if not found:
            continue
        for name in set:
            if name not in pygame.sysfont.Sysfonts:
                pygame.sysfont.Sysalias[name] = found

    expyriment.control.defaults.event_logging = 0
    exp = expyriment.control.initialize()
    mouse = expyriment.io.Mouse(show_cursor=False)
    if projects == {}:
        info_box = expyriment.stimuli.TextScreen(
            "No experiments found!",
            "Please put your experiments into a folder called 'expyriment', " +
            "located on the internal or external sdcard.\n\n" +
            "[Touch the screen to exit]")
        info_box.present()
        mouse.wait_press()
    else:
        items = projects.keys()
        items.sort()
        menu = expyriment.io.TextMenu("Run experiment:",
                                      items,
                                      320,
                                      scroll_menu=5,
                                      mouse=mouse)
        py_file = projects[menu.get()]
        expyriment.control.defaults.event_logging = 1
        expyriment.control.defaults.initialize_delay = 0
        os.chdir(os.path.split(py_file)[0])
        sys.argv[0] = py_file
        execfile("{0}".format(py_file), globals())
Example #55
0
def init(winname,
         appname,
         gamedir,
         icon="sys_icon.png",
         poster_pattern="poster_*.png",
         display_font="Anita semi square.ttf"):
    global INIT_DONE
    if not INIT_DONE:
        util.init(appname, gamedir)
        # Init image.py
        image.init_image(util.image_dir(""))

        pygame.init()
        my_state.audio_enabled = not util.config.getboolean(
            "TROUBLESHOOTING", "disable_audio_entirely")
        if my_state.audio_enabled:
            try:
                pygame.mixer.init()
            except pygame.error:
                my_state.audio_enabled = False
                print("Error: pygame.mixer failed to load.")
        pygame.display.set_caption(winname, appname)
        pygame.display.set_icon(pygame.image.load(util.image_dir(icon)))
        # Set the screen size.
        if util.config.getboolean("GENERAL", "stretchy_screen"):
            if util.config.getboolean("GENERAL", "fullscreen"):
                my_state.physical_screen = pygame.display.set_mode(
                    FULLSCREEN_RES, FULLSCREEN_FLAGS)
            else:
                #my_state.physical_screen = pygame.display.set_mode((800, 600), WINDOWED_FLAGS)
                my_state.physical_screen = pygame.display.set_mode(
                    (1280, 720), WINDOWED_FLAGS)
            my_state.resize()
        else:
            if util.config.getboolean("GENERAL", "fullscreen"):
                my_state.screen = pygame.display.set_mode(
                    FULLSCREEN_RES, FULLSCREEN_FLAGS)
            else:
                my_state.screen = pygame.display.set_mode((800, 600),
                                                          WINDOWED_FLAGS)

        global INPUT_CURSOR
        INPUT_CURSOR = image.Image("sys_textcursor.png", 8, 16)

        global SMALLFONT
        SMALLFONT = pygame.font.Font(
            util.image_dir("DejaVuSansCondensed-Bold.ttf"), 12)
        my_state.small_font = SMALLFONT

        global TINYFONT
        TINYFONT = pygame.font.Font(
            util.image_dir("DejaVuSansCondensed-Bold.ttf"), 9)
        my_state.tiny_font = TINYFONT

        global ANIMFONT
        ANIMFONT = pygame.font.Font(
            util.image_dir("DejaVuSansCondensed-Bold.ttf"), 16)
        my_state.anim_font = ANIMFONT

        global MEDIUMFONT
        MEDIUMFONT = pygame.font.Font(
            util.image_dir("DejaVuSansCondensed-Bold.ttf"), 14)
        my_state.medium_font = MEDIUMFONT

        global ALTTEXTFONT

        ALTTEXTFONT = pygame.font.Font(
            util.image_dir("DejaVuSansCondensed-BoldOblique.ttf"), 15)
        my_state.alt_text_font = ALTTEXTFONT

        global ITALICFONT
        ITALICFONT = pygame.font.Font(
            util.image_dir("DejaVuSansCondensed-BoldOblique.ttf"), 12)

        global BIGFONT
        BIGFONT = pygame.font.Font(util.image_dir(display_font), 16)
        my_state.big_font = BIGFONT

        my_state.huge_font = pygame.font.Font(util.image_dir(display_font), 24)

        global POSTERS
        POSTERS += glob.glob(util.image_dir(poster_pattern))

        global FPS
        FPS = util.config.getint("GENERAL", "frames_per_second")
        pygame.time.set_timer(TIMEREVENT, int(1000 / FPS))

        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
Example #56
0
def init():
    """The init function is used to initialize all PyGame dependent
    systems. This is primarily implemented to allow sphinx-apidoc
    to autogenerate documentation without initializing a PyGame
    window.

    :param None:

    :rtype: None
    :returns: None

    """

    # These variables will persist throughout the module so they
    # can be called externally. E.g. "prepare.SCREEN", etc.
    global SCREEN
    global SCREEN_RECT
    global JOYSTICKS
    global player1
    global FONTS
    global MUSIC
    global SFX
    global GFX

    # Initialize PyGame and our screen surface.
    pg.init()
    pg.display.set_caption(ORIGINAL_CAPTION)
    SCREEN = pg.display.set_mode(SCREEN_SIZE, CONFIG.fullscreen, 32)
    SCREEN_RECT = SCREEN.get_rect()

    # Disable the mouse cursor visibility
    pg.mouse.set_visible(False)

    # Set up any gamepads that we detect
    # The following event types will be generated by the joysticks:
    # JOYAXISMOTION JOYBALLMOTION JOYBUTTONDOWN JOYBUTTONUP JOYHATMOTION
    pg.joystick.init()
    JOYSTICKS = [
        pg.joystick.Joystick(x) for x in range(pg.joystick.get_count())
    ]

    # Initialize the individual joysticks themselves.
    for joystick in JOYSTICKS:
        joystick.init()

    # Map the appropriate android keys if we're on android
    if android:
        android.init()
        android.map_key(android.KEYCODE_MENU, pg.K_ESCAPE)

    # Create an instance of the player and list of NPCs
    from .components import player
    player1 = player.Player()

    # Scale the sprite and its animations
    for key, animation in player1.sprite.items():
        animation.scale(tuple(i * SCALE for i in animation.getMaxSize()))

    for key, image in player1.standing.items():
        player1.standing[key] = pg.transform.scale(
            image, (image.get_width() * SCALE, image.get_height() * SCALE))

    # Set the player's width and height based on the size of our scaled
    # sprite.
    player1.playerWidth, player1.playerHeight = \
        player1.standing["front"].get_size()
    player1.playerWidth = TILE_SIZE[0]
    player1.playerHeight = TILE_SIZE[1]
    player1.tile_size = TILE_SIZE

    # Put the player right in the middle of our screen.
    player1.position = [(SCREEN_SIZE[0] / 2) - (player1.playerWidth / 2),
                        (SCREEN_SIZE[1] / 2) - (player1.playerHeight / 2)]

    # Set the player's collision rectangle
    player1.rect = pg.Rect(player1.position[0], player1.position[1],
                           TILE_SIZE[0], TILE_SIZE[1])

    # Set the walking and running pixels per second based on the scale
    player1.walkrate *= SCALE
    player1.runrate *= SCALE
Example #57
0
def install_android():
    '''Install hooks for the android platform.

    * Automatically sleep when the device is paused.
    * Automatically kill the application when the return key is pressed.
    '''
    try:
        import android
    except ImportError:
        print('Android lib is missing, cannot install android hooks')
        return

    from kivy.clock import Clock
    from kivy.logger import Logger
    import pygame

    Logger.info('Support: Android install hooks')

    # Init the library
    android.init()
    android.map_key(android.KEYCODE_MENU, pygame.K_MENU)
    android.map_key(android.KEYCODE_BACK, pygame.K_ESCAPE)

    # Check if android should be paused or not.
    # If pause is requested, just leave the app.
    def android_check_pause(*largs):
        # do nothing until android asks for it.
        if not android.check_pause():
            return

        from kivy.app import App
        from kivy.base import stopTouchApp
        from kivy.logger import Logger
        from kivy.core.window import Window
        global g_android_redraw_count

        # try to get the current running application
        Logger.info('Android: Must go into sleep mode, check the app')
        app = App.get_running_app()

        # no running application, stop our loop.
        if app is None:
            Logger.info('Android: No app running, stop everything.')
            stopTouchApp()
            return

        # try to go to pause mode
        if app.dispatch('on_pause'):
            Logger.info('Android: App paused, now wait for resume.')

            # app goes in pause mode, wait.
            android.wait_for_resume()

            # is it a stop or resume ?
            if android.check_stop():
                # app must stop
                Logger.info('Android: Android wants to close our app.')
                stopTouchApp()
            else:
                # app resuming now !
                Logger.info('Android: Android has resumed, resume the app.')
                app.dispatch('on_resume')
                Window.canvas.ask_update()
                g_android_redraw_count = 25  # 5 frames/seconds for 5 seconds
                Clock.unschedule(_android_ask_redraw)
                Clock.schedule_interval(_android_ask_redraw, 1 / 5)
                Logger.info('Android: App resume completed.')

        # app doesn't support pause mode, just stop it.
        else:
            Logger.info('Android: App doesn\'t support pause mode, stop.')
            stopTouchApp()

    Clock.schedule_interval(android_check_pause, 0)
Example #58
0
def main():
    class Player:
        def __init__(self):
            self.x = 47
            self.y = 45
            self.image = pygame.image.load('player.png')
            #self.score = 0
        def draw(self):
            screen.blit(self.image, (self.x, self.y))

        def move(self, move):
            if 0 <= self.x + move <= 84:
                player.x += move
            #elif self.

    class Block:
        def __init__(self):
            global current_block
            #self.x = random.choice(range(0,196,4))
            self.y = 0
            current_block = random.choice(block_images)
            self.image = pygame.image.load(current_block)
            self.already_passed_line = False

        def draw(self):
            screen.blit(self.image, (0, self.y))

        def move(self):
            self.y += block_speed

        def off_screen(self):
            return self.y > 64

        def passed_line(self):
            if (not self.already_passed_line) and (self.y >= 32):
                self.already_passed_line = True
                return True

    def player_top_collided():
        for x in range(player.x, player.x + 12):
            if screen.get_at((x, player.y)) != (1, 1, 1, 255):
                #print screen.get_at((x,player.y))
                print 'top'
                return True
        '''for y in range(player.y,player.y+8):
            if screen.get_at((player.x,y)) != (1, 1, 1, 255):
                return True
            elif screen.get_at((player.x+11, y)) != (1, 1, 1, 255):
                return True'''
        return False

    def player_left_collided():
        for y in range(player.y + 1, player.y + 8):
            if screen.get_at((player.x, y)) != (1, 1, 1, 255):
                print 'left'
                return True
        return False

    def player_right_collided():
        for y in range(player.y + 1, player.y + 8):
            if screen.get_at((player.x + 11, y)) != (1, 1, 1, 255):
                print 'right'
                return True
        return False

    pygame.init()
    display = pygame.display.set_mode((384, 256))
    screen = pygame.Surface((96, 64))
    fps_clock = pygame.time.Clock()

    if android:
        android.init()

    PIXEL_SIZE = 1
    #FPS = 30

    font = pygame.font.Font('LCD_Solid.ttf', 24)
    big_font = pygame.font.Font('LCD_Solid.ttf', 32)

    map_image = pygame.image.load('map3.png')
    map_prime = pygame.image.load('map2.png')

    while 1:
        move = 0
        #block_images = ['block%i.png'%i for i in range(2,9) if 'block%i.png'%i ] #create a list of all the block image names
        player = Player()
        #blocks = [Block()]
        game_over = False
        restart = False
        player_speed = 2
        block_speed = 1
        k = -3159
        fps = 30
        start_time = time.time()
        level_up = False
        score = 0

        while not restart:
            #block_images = ['block%i.png'%i for i in range(2,9) if 'block%i.png'%i != current_block] #list of available blocks so there's no repetition
            screen.fill(Color(239, 254, 221))  #light green
            player.draw()
            '''for block in blocks:
                block.draw()'''
            screen.blit(map_image, (0, k))
            if not game_over: k += 1

            display.blit(
                font.render('LEVEL: %i' % (block_speed), False,
                            Color('black')), (260, 0))
            display.blit(
                font.render('TIME: %s' % str(score)[:str(score).find('.') + 2],
                            False, Color('black')), (0, 0))
            if game_over:
                display.blit(
                    big_font.render('GAME OVER!', False, Color('black')),
                    (100, 120))

            for event in pygame.event.get():  #event loop
                if event.type == QUIT:
                    pygame.quit()
                    sys.exit()
                if event.type == KEYDOWN:
                    if event.key == K_RIGHT:
                        move = player_speed  #player moves 4*player_speed px right
                    elif event.key == K_LEFT:
                        move = -player_speed
                    elif event.key == K_r:
                        restart = True
                if event.type == KEYUP:
                    if event.key == K_RIGHT and move > 0:
                        move = 0
                    if event.key == K_LEFT and move < 0:
                        move = 0
                if event.type == MOUSEBUTTONDOWN:
                    if game_over:
                        restart = True
                    mouse_x, mouse_y = event.pos
                    if mouse_x < 192:
                        move = -player_speed
                    else:
                        move = player_speed
                if event.type == MOUSEBUTTONUP:
                    if mouse_x < 192 and move < 0:
                        move = 0
                    if mouse_x >= 192 and move > 0:
                        move = 0

            if player.y > 55:
                game_over = True

            if not game_over and player_top_collided():
                #pygame.display.update()
                #game_over = True
                player.y += 1

            if move and not game_over:
                player.move(move)
            '''if blocks[0].off_screen():
                blocks = blocks[1:]

            if blocks[0].passed_line():
                blocks.append(Block())'''
            '''if not game_over:
                for block in blocks:
                    block.move()
                player.score += 1'''
            '''if not game_over and int(time.time() - start_time) and int(time.time() - start_time) % 10 == 0 and not level_up:
                block_speed += 1
                fps += 1
                level_up = True'''
            if not game_over and score > 30 and not level_up:
                fps = 40
            if level_up and not int(time.time() - start_time) % 10 == 0:
                level_up = False
            if not game_over:
                score = round(time.time() - start_time, 2)
            #print int(time.time() - start_time)

            pygame.display.update()
            fps_clock.tick(fps)
            display.blit(pygame.transform.scale(screen, (384, 256)), (0, 0))
Example #59
0
def main():

    class Player:
        def __init__(self):
            self.x = 188
            self.y = 180
            self.image = pygame.image.load('player.png')
            self.score = 0
        def draw(self):
            screen.blit(self.image,(self.x,self.y))
        def move(self,move):
            if 0 <= self.x + move <= 336:
                self.x += move
            #elif self.

    class Block:
        def __init__(self):
            global current_block
            #self.x = random.choice(range(0,196,4))
            self.y = 0
            current_block = random.choice(block_images)
            self.image = pygame.image.load(current_block)
            self.already_passed_line = False
        def draw(self):
            screen.blit(self.image, (0,self.y))
        def move(self):
            self.y += block_speed
        def off_screen(self):
            return self.y > 256
        def passed_line(self):
            if (not self.already_passed_line) and (self.y >= 128):
                self.already_passed_line = True
                return True

    def player_collided():
        for x in range(player.x,player.x+48):
            if screen.get_at((x,180)) not in ((52, 52, 52, 255),(49, 52, 49, 255)):
                return True
        for y in range(180,212):
            if screen.get_at((player.x,y)) not in ((52, 52, 52, 255),(49, 52, 49, 255)):
                return True
            elif screen.get_at((player.x+47, y)) not in ((52, 52, 52, 255),(49, 52, 49, 255)):
                return True
        return False


    pygame.init()
    screen = pygame.display.set_mode((384,256))
    fps_clock = pygame.time.Clock()

    if android:
        android.init()

    PIXEL_SIZE = 4
    FPS = 30

    font = pygame.font.Font('LCD_Solid.ttf',24)
    big_font = pygame.font.Font('LCD_Solid.ttf',32)


    map_image = pygame.image.load('map3.png')
    while 1:
        move = 0
        block_images = ['block%i.png'%i for i in range(2,9) if 'block%i.png'%i ] #create a list of all the block image names
        player = Player()
        blocks = [Block()]
        game_over = False
        restart = False
        player_speed = 2
        block_speed = 3
        k = 4800

        while not restart:
            block_images = ['block%i.png'%i for i in range(2,9) if 'block%i.png'%i != current_block] #list of available blocks so there's no repetition
            screen.fill(Color(239,254,221)) #light green
            player.draw()
            #for block in blocks:
                #block.draw()
            screen.blit(map_image,(0,k))
            if not game_over: k+= 1

            screen.blit(font.render('LEVEL: %i'%(block_speed-2),False,Color('black')),(260,0))
            screen.blit(font.render('SCORE: %i'%player.score,False,Color('black')),(0,0))
            if game_over:
                screen.blit(big_font.render('GAME OVER!',False,Color('black')),(100,120))

            for event in pygame.event.get(): #event loop
                if event.type == QUIT:
                        pygame.quit()
                        sys.exit()
                if event.type == KEYDOWN:
                    if event.key == K_RIGHT:
                        move = PIXEL_SIZE * player_speed #player moves 4*player_speed px right
                    elif event.key == K_LEFT:
                        move = -PIXEL_SIZE * player_speed
                    elif event.key == K_r:
                        restart = True
                if event.type == KEYUP:
                    if event.key == K_RIGHT and move > 0:
                        move = 0
                    if event.key == K_LEFT and move < 0:
                        move = 0
                if event.type == MOUSEBUTTONDOWN:
                    if game_over:
                        restart = True
                    mouse_x, mouse_y = event.pos
                    if mouse_x < 192:
                        move = -PIXEL_SIZE * player_speed
                    else:
                        move = PIXEL_SIZE * player_speed
                if event.type == MOUSEBUTTONUP:
                    if mouse_x < 192 and move < 0:
                        move = 0
                    if mouse_x >= 192 and move > 0:
                        move = 0

            if player_collided():
                pygame.display.update()
                game_over = True

            if move and not game_over:
                player.move(move)

            if blocks[0].off_screen():
                blocks = blocks[1:]

            if blocks[0].passed_line():
                blocks.append(Block())

            if not game_over:
                for block in blocks:
                    block.move()
                player.score += 1

            if player.score % 500 == 0 and block_speed < 7:
                block_speed += 1

            pygame.display.update()
            fps_clock.tick(FPS)