コード例 #1
0
ファイル: main.py プロジェクト: Lyreem/ransack-python
def main():
    while True:
        for event in pygame.event.get():
            if event.type == pygame.MOUSEBUTTONDOWN:
                selection = None
                (mX, mY) = pygame.mouse.get_pos()
                for b in buttons:
                    if b.hit(mX, mY):
                        selection = b.msg
                if selection == 'Begin New Game':
                    print('Begin New Game {}x{}'.format(screenSize[0],
                          screenSize[1]))
                    launchNewGame(pygame.Surface((screenSize[0],
                                  screenSize[1])))
                elif selection == 'Load Saved Game':
                    loadSavedGame(pygame.Surface((screenSize[0],
                                  screenSize[1])))
                elif selection == 'Credits':
                    showCredits()
                elif selection == 'Exit':
                    FX.fadeOut(0)
                    os.sys.exit()
                elif selection is None:
                    pass
        font = pygame.font.Font(os.getcwd()+"/FONTS/courier.ttf", 28)
        if android:
            screen.blit(font.render(str(android.get_dpi()), 1, colors.white,
                        colors.black), (0, 0))
        updateDisplay()
        pygame.display.flip()
コード例 #2
0
ファイル: main.py プロジェクト: JaHIY/renpy
def choose_variants():

    if "RENPY_VARIANT" in os.environ:
        renpy.config.variants = list(os.environ["RENPY_VARIANT"].split()) + [ None ]
    else:
        renpy.config.variants = [ None ]
    
    if renpy.android: #@UndefinedVariable
        import android #@UnresolvedImport
        import math
        import pygame
        
        pygame.display.init()
        
        info = pygame.display.Info()        
        diag = math.hypot(info.current_w, info.current_h) / android.get_dpi()
        
        print "Screen diagonal is", diag, "inches."
        
        renpy.config.variants.insert(0, 'touch')
        
        if diag >= 6:
            renpy.config.variants.insert(0, 'tablet')
        else:
            renpy.config.variants.insert(0, 'phone')
        
    else:
        renpy.config.variants.insert(0, 'pc')
コード例 #3
0
ファイル: metrics.py プロジェクト: 15huangtimothy/kivy
    def dpi(self):
        '''Return the DPI of the screen. Depending on the platform, the DPI can
        be taken from the Window provider (Desktop mainly) or from a
        platform-specific module (like android/ios).
        '''
        custom_dpi = environ.get('KIVY_DPI')
        if custom_dpi:
            return float(custom_dpi)

        if platform == 'android':
            if USE_SDL2:
                import jnius
                Hardware = jnius.autoclass('org.renpy.android.Hardware')
                return Hardware.getDPI()
            else:
                import android
                return android.get_dpi()
        elif platform == 'ios':
            import ios
            return ios.get_dpi()

        # for all other platforms..
        from kivy.base import EventLoop
        EventLoop.ensure_window()
        return EventLoop.window.dpi
コード例 #4
0
ファイル: main.py プロジェクト: duanemoody/renpy
def choose_variants():

    if "RENPY_VARIANT" in os.environ:
        renpy.config.variants = list(os.environ["RENPY_VARIANT"].split()) + [ None ]
        return

    renpy.config.variants = [ None ]

    if renpy.android: #@UndefinedVariable

        renpy.config.variants.insert(0, 'android')

        import android #@UnresolvedImport
        import math
        import pygame

        from jnius import autoclass  # @UnresolvedImport

        # Are we running on an OUYA?
        try:
            OuyaFacade = autoclass("tv.ouya.console.api.OuyaFacade")
            of = OuyaFacade.getInstance()

            if of.isRunningOnOUYAHardware():
                print "Running on an OUYA."
                renpy.config.variants.insert(0, "ouya")
        except:
            pass

        # Are we running on OUYA or Google TV or something similar?
        PythonActivity = autoclass('org.renpy.android.PythonActivity')
        mActivity = PythonActivity.mActivity
        package_manager = mActivity.getPackageManager()

        if package_manager.hasSystemFeature("android.hardware.type.television"):
            print "Running on a television."
            renpy.config.variants.insert(0, "tv")
            renpy.config.variants.insert(0, "small")
            return

        # Otherwise, a phone or tablet.
        renpy.config.variants.insert(0, 'touch')

        pygame.display.init()

        info = renpy.display.get_info()
        diag = math.hypot(info.current_w, info.current_h) / android.get_dpi()
        print "Screen diagonal is", diag, "inches."

        if diag >= 6:
            renpy.config.variants.insert(0, 'tablet')
            renpy.config.variants.insert(0, 'medium')
        else:
            renpy.config.variants.insert(0, 'phone')
            renpy.config.variants.insert(0, 'small')

    else:
        renpy.config.variants.insert(0, 'pc')
        renpy.config.variants.insert(0, 'large')
コード例 #5
0
ファイル: core.py プロジェクト: hansgillis/PygameOuya
    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()
コード例 #6
0
ファイル: factory.py プロジェクト: King-Zwambo/Kz-Pyweek18
    def __init__(self,
                 color='white',
                 font=None,
                 font_size=22,
                 FPS=32,
                 size=(800,480)):

        pygame.init()
        pygame.display.init()

        #=======================================================
        # Cross-platform Support
        #=======================================================
        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.SW = width  / size[0]
            self.SH = height / size[1]
            self.window = pygame.display.set_mode((width, height))

        except AttributeError:
            self.window = pygame.display.set_mode(size)
            self.SW = 1
            self.SH = 1

        if android:
            android.init()
            android.map_key(android.KEYCODE_BACK, pygame.K_ESCAPE)

        #=======================================================
        # Attributes
        #=======================================================
        self.x = 0
        self.y = 0
        self.font = pygame.font.Font(font, font_size)
        self.color = get_color(color)
        self.black = get_color('black')
        self.width = self.window.get_width()
        self.height = self.window.get_height()
        self.alpha = 255
        self.mouse = (0, 0)
        self.touch = False
        self.clock = pygame.time.Clock()
        self.FPS = FPS
        
        self.audio = Audio()
        self.image = Image()
        self.strip = Stripify()
コード例 #7
0
ファイル: droid.py プロジェクト: fragtalg/OpenSesame
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()
コード例 #8
0
ファイル: metrics.py プロジェクト: bussiere/kivy
    def dpi(self):
        '''Return the DPI of the screen. Depending of the platform, the DPI can
        be taken from the Window provider (Desktop mainly), or from
        platform-specific module (like android/ios).
        '''
        custom_dpi = environ.get('KIVY_DPI')
        if custom_dpi:
            return float(custom_dpi)

        if platform() == 'android':
            import android
            return android.get_dpi()

        # for all other platforms..
        from kivy.base import EventLoop
        EventLoop.ensure_window()
        return EventLoop.window.dpi
コード例 #9
0
ファイル: main.py プロジェクト: devforfu/pycon2014
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

    icon_size = 64
    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()
コード例 #10
0
ファイル: base.py プロジェクト: Ghopper21/kivy
    def dpi(self):
        '''Return the DPI of the screen. Depending of the platform, the DPI can
        be taken from the Window provider (Desktop mainly), or from
        platform-specific module (like android/ios).

        On desktop, you can overload the value returned by the Window object
        (96 by default), by setting the environ KIVY_DPI::

            KIVY_DPI=200 python main.py

        .. versionadded:: 1.4.0
        '''
        custom_dpi = environ.get('KIVY_DPI')
        if custom_dpi:
            return float(custom_dpi)

        plat = platform()
        if plat == 'android':
            import android
            return android.get_dpi()

        # for all other platforms..
        self.ensure_window()
        return self.window.dpi
コード例 #11
0
ファイル: main.py プロジェクト: emmeken/renpy
def choose_variants():

    if "RENPY_VARIANT" in os.environ:
        renpy.config.variants = list(os.environ["RENPY_VARIANT"].split()) + [ None ]
        return

    renpy.config.variants = [ None ]

    if renpy.android: #@UndefinedVariable

        renpy.config.variants.insert(0, 'android')

        import android #@UnresolvedImport
        import math
        import pygame_sdl2 as pygame

        from jnius import autoclass  # @UnresolvedImport


        # Manufacturer/Model-specific variants.
        try:
            Build = autoclass("android.os.Build")

            manufacturer = Build.MANUFACTURER
            model = Build.MODEL

            print "Manufacturer", manufacturer, "model", model

            if manufacturer == "Amazon" and model.startswith("AFT"):
                print "Running on a Fire TV."
                renpy.config.variants.insert(0, "firetv")
        except:
            pass

        # Are we running on an OUYA?
        try:
            OuyaFacade = autoclass("tv.ouya.console.api.OuyaFacade")
            of = OuyaFacade.getInstance()

            if of.isRunningOnOUYAHardware():
                print "Running on an OUYA."
                renpy.config.variants.insert(0, "ouya")
        except:
            pass


        # Are we running on OUYA or Google TV or something similar?
        package_manager = android.activity.getPackageManager()

        if package_manager.hasSystemFeature("android.hardware.type.television"):
            print "Running on a television."
            renpy.config.variants.insert(0, "tv")
            renpy.config.variants.insert(0, "small")
            return

        # Otherwise, a phone or tablet.
        renpy.config.variants.insert(0, 'touch')

        pygame.display.init()

        info = renpy.display.get_info()
        diag = math.hypot(info.current_w, info.current_h) / android.get_dpi()
        print "Screen diagonal is", diag, "inches."

        if diag >= 6:
            renpy.config.variants.insert(0, 'tablet')
            renpy.config.variants.insert(0, 'medium')
        else:
            renpy.config.variants.insert(0, 'phone')
            renpy.config.variants.insert(0, 'small')

    elif renpy.ios:
        renpy.config.variants.insert(0, 'ios')
        renpy.config.variants.insert(0, 'touch')

        from pyobjus import autoclass # @UnresolvedImport @Reimport
        UIDevice = autoclass("UIDevice")

        idiom = UIDevice.currentDevice().userInterfaceIdiom

        print "iOS device idiom", idiom

        # idiom 0 is iPhone, 1 is iPad. We assume any bigger idiom will
        # be tablet-like.
        if idiom >= 1:
            renpy.config.variants.insert(0, 'tablet')
            renpy.config.variants.insert(0, 'medium')
        else:
            renpy.config.variants.insert(0, 'phone')
            renpy.config.variants.insert(0, 'small')

    else:
        renpy.config.variants.insert(0, 'pc')
        renpy.config.variants.insert(0, 'large')
コード例 #12
0
ファイル: core.py プロジェクト: HasnG/APEngine
    def __init__(self, portrait=True, font=None,
                 font_size= 22, color='white', FPS=32):

        pygame.init()
        pygame.font.init()
        pygame.display.init()
        self.debug = False
        if portrait == True:
            try:
                info = pygame.display.Info()        
                diag = math.hypot(info.current_w,
                                  info.current_h) / android.get_dpi()
                
                if diag >= 6:
                    self.screen = pygame.display.set_mode((515, 800))
                    self.SH =  1
                    self.SW =  515.0/480.0
                else:
                    width, height = (info.current_w, info.current_h)
                    self.SW   = width/480.0
                    self.SH  = height/800.0
                    self.screen = pygame.display.set_mode((width, height))
                
            except AttributeError:
                self.screen = pygame.display.set_mode((480, 800))
                self.SH = 1
                self.SW = 1
                self.debug = True

        else:
            try:
                info = pygame.display.Info()        
                diag = math.hypot(info.current_w,
                                  info.current_h) / android.get_dpi()
                
                if diag >= 6:
                    self.screen = pygame.display.set_mode((800, 470))
                    self.SH = 470.0/480.0
                    self.SW =  1
                else:
                    width, height = (info.current_w, info.current_h)
                    self.SH = height/480.0
                    self.SW = width/800.0
                    self.screen = pygame.display.set_mode((width, height))
                
            except AttributeError:
                self.screen = pygame.display.set_mode((800, 480))
                self.SH = 1
                self.SW = 1
                self.debug = True

        if android:
            android.init()
            android.map_key(android.KEYCODE_BACK, pygame.K_ESCAPE)

        #=======================================================================
        # Standard Font
        #=======================================================================
        font_size = int((font_size*self.SW + self.SH*font_size)/2)
        if font != None and os.path.exists(font):
            font = pygame.font.Font(font, font_size)
        else:
            font = pygame.font.Font('assets/font/font.ttf', font_size)

        #=======================================================================
        # Standard Color
        #=======================================================================
        try:
            color = pygame.color.Color(color)
        except ValueError:
            pass

        #=======================================================================
        # Position | font | color | fade transition | mouse state
        #=======================================================================
        self.x      = 0
        self.y      = 0
        self.font   = font
        self.color  = color
        self.black  = self.return_color('black')
        self.white  = self.return_color('white')
        self.width  = self.screen.get_width()
        self.height = self.screen.get_height()
        self.alpha  = 255
        self.fin    = True
        self.fout   = False
        self.old    = pygame.Surface(self.screen.get_size())
        self.cover  = pygame.Surface(self.screen.get_size())
        self.mouse  = (0,0)
        self.touch  = False
        self.seconds= 0.5
        self.cover.fill((0,0,0))

        #=======================================================================
        # FPS / Timer
        #=======================================================================
        self.clock  = pygame.time.Clock()
        self.FPS    = FPS

        #=======================================================================
        # Built-in functionality
        #=======================================================================
        self.images     = Images()
        self.strips     = Strips()
        self.audio      = Audio()
        
        if android:
            if android.check_pause():
                android.wait_for_resume()
コード例 #13
0
ファイル: main.py プロジェクト: 469ma1101/fattypy
def choose_variants():

    if "RENPY_VARIANT" in os.environ:
        renpy.config.variants = list(
            os.environ["RENPY_VARIANT"].split()) + [None]
        return

    renpy.config.variants = [None]

    if renpy.android:  # @UndefinedVariable

        renpy.config.variants.insert(0, 'mobile')
        renpy.config.variants.insert(0, 'android')

        import android  # @UnresolvedImport
        import math
        import pygame_sdl2 as pygame

        from jnius import autoclass  # @UnresolvedImport

        # Manufacturer/Model-specific variants.
        try:
            Build = autoclass("android.os.Build")

            manufacturer = Build.MANUFACTURER
            model = Build.MODEL

            print("Manufacturer", manufacturer, "model", model)

            if manufacturer == "Amazon" and model.startswith("AFT"):
                print("Running on a Fire TV.")
                renpy.config.variants.insert(0, "firetv")
        except:
            pass

        # Are we running on OUYA or Google TV or something similar?
        package_manager = android.activity.getPackageManager()

        if package_manager.hasSystemFeature(
                "android.hardware.type.television"):
            print("Running on a television.")
            renpy.config.variants.insert(0, "tv")
            renpy.config.variants.insert(0, "small")
            return

        # Otherwise, a phone or tablet.
        renpy.config.variants.insert(0, 'touch')

        pygame.display.init()

        info = renpy.display.get_info()
        diag = math.hypot(info.current_w, info.current_h) / android.get_dpi()
        print("Screen diagonal is", diag, "inches.")

        if diag >= 6:
            renpy.config.variants.insert(0, 'tablet')
            renpy.config.variants.insert(0, 'medium')
        else:
            renpy.config.variants.insert(0, 'phone')
            renpy.config.variants.insert(0, 'small')

    elif renpy.ios:
        renpy.config.variants.insert(0, 'ios')
        renpy.config.variants.insert(0, 'touch')

        from pyobjus import autoclass  # @UnresolvedImport @Reimport
        UIDevice = autoclass("UIDevice")

        idiom = UIDevice.currentDevice().userInterfaceIdiom

        print("iOS device idiom", idiom)

        # idiom 0 is iPhone, 1 is iPad. We assume any bigger idiom will
        # be tablet-like.
        if idiom >= 1:
            renpy.config.variants.insert(0, 'tablet')
            renpy.config.variants.insert(0, 'medium')
        else:
            renpy.config.variants.insert(0, 'phone')
            renpy.config.variants.insert(0, 'small')

    else:
        renpy.config.variants.insert(0, 'pc')
        renpy.config.variants.insert(0, 'large')
コード例 #14
0
ファイル: main.py プロジェクト: theseraphim/renpy
def choose_variants():

    if "RENPY_VARIANT" in os.environ:
        renpy.config.variants = list(
            os.environ["RENPY_VARIANT"].split()) + [None]
        return

    renpy.config.variants = [None]

    if renpy.android:  # @UndefinedVariable

        renpy.config.variants.insert(0, 'mobile')
        renpy.config.variants.insert(0, 'android')

        import android  # @UnresolvedImport
        import math
        import pygame_sdl2 as pygame

        from jnius import autoclass  # @UnresolvedImport

        # Manufacturer/Model-specific variants.
        try:
            Build = autoclass("android.os.Build")

            manufacturer = Build.MANUFACTURER
            model = Build.MODEL

            print("Manufacturer", manufacturer, "model", model)

            if manufacturer == "Amazon" and model.startswith("AFT"):
                print("Running on a Fire TV.")
                renpy.config.variants.insert(0, "firetv")
        except:
            pass

        # Are we running on OUYA or Google TV or something similar?
        package_manager = android.activity.getPackageManager()

        if package_manager.hasSystemFeature(
                "android.hardware.type.television"):
            print("Running on a television.")
            renpy.config.variants.insert(0, "tv")
            renpy.config.variants.insert(0, "small")
            return

        # Otherwise, a phone or tablet.
        renpy.config.variants.insert(0, 'touch')

        pygame.display.init()

        info = renpy.display.get_info()
        diag = math.hypot(info.current_w, info.current_h) / android.get_dpi()
        print("Screen diagonal is", diag, "inches.")

        if diag >= 6:
            renpy.config.variants.insert(0, 'tablet')
            renpy.config.variants.insert(0, 'medium')
        else:
            renpy.config.variants.insert(0, 'phone')
            renpy.config.variants.insert(0, 'small')

    elif renpy.ios:
        renpy.config.variants.insert(0, 'mobile')
        renpy.config.variants.insert(0, 'ios')
        renpy.config.variants.insert(0, 'touch')

        from pyobjus import autoclass  # @UnresolvedImport @Reimport
        UIDevice = autoclass("UIDevice")

        idiom = UIDevice.currentDevice().userInterfaceIdiom

        print("iOS device idiom", idiom)

        # idiom 0 is iPhone, 1 is iPad. We assume any bigger idiom will
        # be tablet-like.
        if idiom >= 1:
            renpy.config.variants.insert(0, 'tablet')
            renpy.config.variants.insert(0, 'medium')
        else:
            renpy.config.variants.insert(0, 'phone')
            renpy.config.variants.insert(0, 'small')

    elif renpy.emscripten:
        import emscripten
        import re

        # web
        renpy.config.variants.insert(0, 'web')

        # mobile
        userAgent = emscripten.run_script_string(r'''navigator.userAgent''')
        mobile = re.search('Mobile|Android|iPad|iPhone', userAgent)
        if mobile:
            renpy.config.variants.insert(0, 'mobile')
        # Reserve android/ios for when the OS API is exposed
        # if re.search('Android', userAgent):
        #    renpy.config.variants.insert(0, 'android')
        # if re.search('iPad|iPhone', userAgent):
        #    renpy.config.variants.insert(0, 'ios')

        # touch
        touch = emscripten.run_script_int(r'''
          ('ontouchstart' in window) ||
            (navigator.maxTouchPoints > 0) ||
            (navigator.msMaxTouchPoints > 0)''')
        if touch == 1:
            # mitigate hybrids (e.g. ms surface) by restricting touch to mobile
            if mobile:
                renpy.config.variants.insert(0, 'touch')

        # large/medium/small
        # tablet/phone
        # screen.width/height is auto-adjusted by browser,
        # so it can be used as a physical sizereference
        # (see also window.devicePixelRatio)
        # e.g. Galaxy S5:
        # - physical / OpenGL: 1080x1920
        # - web screen: 360x640 w/ devicePixelRatio=3
        ref_width = emscripten.run_script_int(r'''screen.width''')
        ref_height = emscripten.run_script_int(r'''screen.height''')
        # medium reference point: ipad 1024x768, ipad pro 1336x1024 (browser "pixels")
        if mobile:
            if (ref_width < 768 or ref_height < 768):
                renpy.config.variants.insert(0, 'small')
                renpy.config.variants.insert(0, 'phone')
            else:
                renpy.config.variants.insert(0, 'medium')
                renpy.config.variants.insert(0, 'tablet')
        else:
            renpy.config.variants.insert(0, 'large')

    else:
        renpy.config.variants.insert(0, 'pc')

        renpy.config.variants.insert(0, 'large')
コード例 #15
0
def choose_variants():

    if "RENPY_VARIANT" in os.environ:
        renpy.config.variants = list(
            os.environ["RENPY_VARIANT"].split()) + [None]
        return

    renpy.config.variants = [None]

    if renpy.android:  #@UndefinedVariable

        renpy.config.variants.insert(0, 'android')

        import android  #@UnresolvedImport
        import math
        import pygame

        from jnius import autoclass  # @UnresolvedImport

        # Manufacturer/Model-specific variants.
        try:
            Build = autoclass("android.os.Build")

            manufacturer = Build.MANUFACTURER
            model = Build.MODEL

            print "Manufacturer", manufacturer, "model", model

            if manufacturer == "Amazon" and model.startswith("AFT"):
                print "Running on a Fire TV."
                renpy.config.variants.insert(0, "firetv")
        except:
            pass

        # Are we running on an OUYA?
        try:
            OuyaFacade = autoclass("tv.ouya.console.api.OuyaFacade")
            of = OuyaFacade.getInstance()

            if of.isRunningOnOUYAHardware():
                print "Running on an OUYA."
                renpy.config.variants.insert(0, "ouya")
        except:
            pass

        # Are we running on OUYA or Google TV or something similar?
        PythonActivity = autoclass('org.renpy.android.PythonActivity')
        mActivity = PythonActivity.mActivity
        package_manager = mActivity.getPackageManager()

        if package_manager.hasSystemFeature(
                "android.hardware.type.television"):
            print "Running on a television."
            renpy.config.variants.insert(0, "tv")
            renpy.config.variants.insert(0, "small")
            return

        # Otherwise, a phone or tablet.
        renpy.config.variants.insert(0, 'touch')

        pygame.display.init()

        info = renpy.display.get_info()
        diag = math.hypot(info.current_w, info.current_h) / android.get_dpi()
        print "Screen diagonal is", diag, "inches."

        if diag >= 6:
            renpy.config.variants.insert(0, 'tablet')
            renpy.config.variants.insert(0, 'medium')
        else:
            renpy.config.variants.insert(0, 'phone')
            renpy.config.variants.insert(0, 'small')

    else:
        renpy.config.variants.insert(0, 'pc')
        renpy.config.variants.insert(0, 'large')
コード例 #16
0
    def __init__(self, size=(640, 480), font=None,
                 font_size= 22, color='white', FPS=32, 
				 stretch=False, stretch_size=(1024, 640)):
        pygame.init()
        pygame.display.init()
        self.debug = False
        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.SW = width  / float(size[0])
            self.SH = height / float(size[1])
            self.screen = pygame.display.set_mode((width, height))

        except AttributeError:
            if not stretch:
                self.screen = pygame.display.set_mode(size)
                self.SH = 1
                self.SW = 1
            else:
                width, height = (1024, 640)
                self.SW = width  / float(size[0])
                self.SH = height / float(size[1])
                self.screen = pygame.display.set_mode((width, height))
            self.debug = True

        if android:
            android.init()
            android.map_key(android.KEYCODE_BACK, pygame.K_ESCAPE)

        font_size = int((font_size*self.SW + self.SH*font_size)/2)
        if font != None and os.path.exists(font):
            font = pygame.font.Font(font, font_size)
        else:
            font = pygame.font.Font(None, font_size)

        try:
            color = pygame.color.Color(color)
        except ValueError:
            pass

        self.x      = 0
        self.y      = 0
        self.font   = font
        self.color  = color
        self.black  = pygame.color.Color('black')
        self.width  = self.screen.get_width()
        self.height = self.screen.get_height()
        self.alpha  = 255
        self.speed  = 2
        self.fin    = True
        self.fout   = False
        self.old    = pygame.Surface(self.screen.get_size())
        self.cover  = pygame.Surface(self.screen.get_size())
        self.mouse  = (0,0)
        self.touch  = False
        self.clock  = pygame.time.Clock()
        self.FPS    = FPS
        self.image  = Image()
        self.slice  = Slice()
        self.audio  = Audio()
        self.button = Button()
        self.toggle = Toggle()
        self.events = EventHandler()
        self.cover.fill((0,0,0))
        self.shade  = pygame.Surface(self.screen.get_size())
        self.shade.fill((0,0,0))
        self.shade.set_alpha(50)
        
        if android:
            if android.check_pause():
                android.wait_for_resume()
コード例 #17
0
ファイル: main.py プロジェクト: malini/renpy
def choose_variants():

    if "RENPY_VARIANT" in os.environ:
        renpy.config.variants = list(os.environ["RENPY_VARIANT"].split()) + [None]
        return

    renpy.config.variants = [None]

    if renpy.android:  # @UndefinedVariable

        renpy.config.variants.insert(0, "android")

        import android  # @UnresolvedImport
        import math
        import pygame

        from jnius import autoclass  # @UnresolvedImport

        # Manufacturer/Model-specific variants.
        try:
            Build = autoclass("android.os.Build")

            manufacturer = Build.MANUFACTURER
            model = Build.MODEL

            print "Manufacturer", manufacturer, "model", model

            if manufacturer == "Amazon" and model.startswith("AFT"):
                print "Running on a Fire TV."
                renpy.config.variants.insert(0, "firetv")
        except:
            pass

        # Are we running on an OUYA?
        try:
            OuyaFacade = autoclass("tv.ouya.console.api.OuyaFacade")
            of = OuyaFacade.getInstance()

            if of.isRunningOnOUYAHardware():
                print "Running on an OUYA."
                renpy.config.variants.insert(0, "ouya")
        except:
            pass

        # Are we running on OUYA or Google TV or something similar?
        PythonActivity = autoclass("org.renpy.android.PythonActivity")
        mActivity = PythonActivity.mActivity
        package_manager = mActivity.getPackageManager()

        if package_manager.hasSystemFeature("android.hardware.type.television"):
            print "Running on a television."
            renpy.config.variants.insert(0, "tv")
            renpy.config.variants.insert(0, "small")
            return

        # Otherwise, a phone or tablet.
        renpy.config.variants.insert(0, "touch")

        pygame.display.init()

        info = renpy.display.get_info()
        diag = math.hypot(info.current_w, info.current_h) / android.get_dpi()
        print "Screen diagonal is", diag, "inches."

        if diag >= 6:
            renpy.config.variants.insert(0, "tablet")
            renpy.config.variants.insert(0, "medium")
        else:
            renpy.config.variants.insert(0, "phone")
            renpy.config.variants.insert(0, "small")

    else:
        renpy.config.variants.insert(0, "pc")
        renpy.config.variants.insert(0, "large")
コード例 #18
0
ファイル: main.py プロジェクト: lomogoto/Scripts
def main():
    
    try:
        with open('records.txt'):pass
    except IOError:
        with open('records.txt','w') as records:
            records.write('0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n')
    total=-1
    level=-1
    bottom=-1
    easyMode=-1
    
    records_=[]
    with open('records.txt') as records:
        for line in records:
            if level==-1:
                level=int(line.rstrip())
            elif total==-1:
                total=int(line.rstrip())
            elif bottom==-1:
                bottom=int(line.rstrip())
            elif easyMode==-1:
                easyMode=int(line.rstrip())
            else:
                records_.append(int(line.rstrip()))
        
    records=records_
    #print records
    
    pygame.init()
    
    if android:
        android.init()
        android.map_key(android.KEYCODE_BACK, pygame.K_ESCAPE)
        #android.map_key(176, pygame.K_s)
        info=pygame.display.Info()
        sx=info.current_w
        sy=info.current_h
        dpi=android.get_dpi()
        
    else:
        sx=640
        sy=360
        dpi=120
        
    screen = pygame.display.set_mode((sx,sy))
    clock=pygame.time.Clock()
    
    su=sx/128
    
    font=pygame.font.Font('DroidSansMono.ttf',4*su)
    
    x1=4*su
    x2=132*su
    
    DOCK=(0,0,0)
    LINES=(31,31,31)#(63,63,63)
    GROUND=(63,63,63)#(63,31,0)
    GRASS=(255,255,255)#(0,127,0)
    ENEMY=(255,0,0)#(255,0,0)
    INNERENEMY=(255,127,127)#(0,0,0)
    GHOST=(0,0,0)
    INNERGHOST=(0,0,0)
    BAT=(0,0,0)
    INNERBAT=(255,0,0)
    PLAYER=(255,255,255)
    SHOT=(255,0,0)
    SKY=(127,127,255)
    TEXT=(255,255,255)
    
    if level==1:
        SKY=(31,31,31)
    elif level==2:
        SKY=(0,0,0)
        GROUND=(0,0,0)
        GRASS=(31,31,31)
        PLAYER=(31,31,31)
    
    
    
    while True:
        savehighscore=0
        menu=True
        pygame.event.clear()
        while menu:
            
            if android and android.check_pause():
                '''with open('records.txt','w') as records_:
                    records_.write(str(total)+'\n')
                    for record in records:
                        records_.write(str(record)+'\n')'''
                android.wait_for_resume()
            
            events = pygame.event.get()
            
            #manage events
            for event in events:
                #get touches
                if event.type == pygame.MOUSEBUTTONDOWN:
                    x,y=event.pos
                    if x!=0:
                        if y<32*su:
                            menu=False
                            howtoplay=False
                            running=True
                            showrecords=False
                            settings=False
                        elif y<64*su:
                            menu=False
                            howtoplay=False
                            running=False
                            showrecords=True
                            settings=False
                        elif x<sx/2:
                            menu=False
                            howtoplay=True
                            running=False
                            showrecords=False
                            settings=False
                        else:
                            menu=False
                            howtoplay=False
                            running=False
                            showrecords=False
                            settings=True
                    
                            
            x1-=su*0.25
            x2-=su*0.25
            if x1<-128*su:x1=128*su
            if x2<-128*su:x2=128*su
            screen.fill(SKY)
            screen.fill(GROUND,((x1,36*su),(124*su,28*su)))
            screen.fill(GRASS,((x1,36*su),(124*su,su)))
            screen.fill(GROUND,((x2,32*su),(124*su,32*su)))
            screen.fill(GRASS,((x2,32*su),(124*su,su)))
            screen.fill(DOCK,((0,64*su),(sx,sy-64*su)))
            screen.fill(DOCK,((128*su,0),(sx,sy)))
            screen.blit(font.render(('Play'),True,TEXT),(su,su))
            screen.blit(font.render(('Highscores'),True,TEXT),(su,57*su))
            screen.blit(font.render(('Controls'),True,TEXT),(su,65*su))
            screen.blit(font.render(('Settings'),True,TEXT),(sx-font.size('Settings')[0]-su,65*su))
            clock.tick(FPS)
            pygame.display.flip()
        
        while settings:
            
            if android and android.check_pause():
                '''with open('records.txt','w') as records_:
                    records_.write(str(total)+'\n')
                    for record in records:
                        records_.write(str(record)+'\n')'''
                android.wait_for_resume()
            
            events = pygame.event.get()
            
            #manage events
            for event in events:
                #get touches
                if event.type == pygame.MOUSEBUTTONDOWN:
                    x,y=event.pos
                    if x!=0:
                        if y<32*su:
                            if easyMode:
                                easyMode=0
                            else:
                                easyMode=1
                        elif y<64*su:
                            level=0
                            botton=0
                        else:
                            total=0
                            records=[0,0,0,0,0,0,0,0,0,0]
                elif event.type == pygame.KEYDOWN and (event.key==pygame.K_s or event.key==pygame.K_ESCAPE):
                    menu=True
                    howtoplay=False
                    running=False
                    showrecords=False
                    settings=False
                        
            x1-=su*0.25
            x2-=su*0.25
            if x1<-128*su:x1=128*su
            if x2<-128*su:x2=128*su
            screen.fill(SKY)
            screen.fill(GROUND,((x1,36*su),(124*su,28*su)))
            screen.fill(GRASS,((x1,36*su),(124*su,su)))
            screen.fill(GROUND,((x2,32*su),(124*su,32*su)))
            screen.fill(GRASS,((x2,32*su),(124*su,su)))
            screen.fill(DOCK,((0,64*su),(sx,sy-64*su)))
            screen.fill(DOCK,((128*su,0),(sx,sy)))
            if easyMode:
                screen.blit(font.render(('Easy Mode (On)'),True,TEXT),(su,su))
            else:
                screen.blit(font.render(('Easy Mode (Off)'),True,TEXT),(su,su))
            if level==0:
                screen.blit(font.render(('Reset Layer (Done)'),True,TEXT),(su,57*su))
            else:
                screen.blit(font.render(('Reset Layer'),True,TEXT),(su,57*su))
            if total==0:
                screen.blit(font.render(('Reset Highscores (Done)'),True,TEXT),(su,65*su))
            else:
                screen.blit(font.render(('Reset Highscores'),True,TEXT),(su,65*su))
            clock.tick(FPS)
            pygame.display.flip()
        
        if easyMode:
            level=0
            bottom=0
        
        with open('records.txt','w') as records_:
            records_.write(str(level)+'\n')
            records_.write(str(total)+'\n')
            records_.write(str(bottom)+'\n')
            records_.write(str(easyMode)+'\n')
            for record in records:
                records_.write(str(record)+'\n')
        
        pygame.event.clear()
        if howtoplay:
            screen.fill((0,0,63),((0,0),(0.75*dpi,sy)))
            screen.blit(pygame.transform.rotate(font.render(('Left'),True,TEXT),-90),(su,su))
            screen.fill((0,0,127),((0.75*dpi,0),(0.5*dpi,sy)))
            screen.blit(pygame.transform.rotate(font.render(('Stop'),True,TEXT),-90),(0.75*dpi+su,su))
            screen.fill((0,0,191),((1.25*dpi,0),(0.75*dpi,sy)))
            screen.blit(pygame.transform.rotate(font.render(('Right'),True,TEXT),-90),(1.25*dpi+su,su))
            screen.fill((0,0,63),((2*dpi,0),(sx-2*dpi,sy-dpi)))
            screen.blit(font.render(('Double Jump'),True,TEXT),(2*dpi+su,su))
            screen.blit(font.render((' (Lose Health)'),True,TEXT),(2*dpi+su,8*su))
            #screen.blit(font.render(('  Gain 50pts'),True,TEXT),(2*dpi+su,13*su))
            screen.fill((0,0,127),((2*dpi,sy-dpi),(sx-2*dpi,dpi)))
            screen.blit(font.render(('Jump'),True,TEXT),(2*dpi+su,sy-dpi+su))
            
            pygame.display.flip()
            event=pygame.event.poll()
            while not (event.type==pygame.MOUSEBUTTONDOWN or (event.type == pygame.KEYDOWN and event.key == pygame.K_ESCAPE)):
                if android and android.check_pause():
                    '''with open('records.txt','w') as records_:
                        records_.write(str(total)+'\n')
                        for record in records:
                            records_.write(str(record)+'\n')'''
                    android.wait_for_resume()
                clock.tick(FPS)
                event=pygame.event.poll()
            event=pygame.event.clear()
            howtoplay=False
            menu=True
            
        hole=None
        
        land=[hole,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,hole,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,hole,9]
        #land=[hole,5,5,5,5,hole,7,7,7,7,hole,8,8,8,8,hole,6,6,6,6,hole,9,9,9,9,hole,10,10,10,10,hole,12,12,12,12,hole,11,11,11,11,hole]
        
        offset=[0,0]
        shift=[0,0]
        ghostpos=(0,0)
        batpos=(0,0)
        batshift=(0,0)
        
        fall=0.25
        
        mouseclick=left=right=jump=hard=killed=bat=ghost=ghostfade=boss=False
        fullhealth=True
        jumppos=sy
        enemies=[]
        shots=[]
        body=0
        shotclock=0
        score=0
        highscore=0
        
        pygame.event.clear()
        
        #run game
        while running:
            #pause if closed
            if android and android.check_pause():
                '''with open('records.txt','w') as records_:
                    records_.write(str(total)+'\n')
                    for record in records:
                        records_.write(str(record)+'\n')'''
                android.wait_for_resume()
            
            #get events
            events = pygame.event.get()
            
            #manage events
            for event in events:
                #get touches
                if event.type == pygame.MOUSEBUTTONDOWN or event.type == pygame.MOUSEMOTION:
                    x,y=event.pos
                    if x!=0:
                        if x<dpi*2:
                            mousepos=x
                            mouseclick=True
                        else:
                            jumppos=y
                            jump=True
                
                #end touch
                elif event.type == pygame.MOUSEBUTTONUP:
                    x,ignore=event.pos
                    if x!=0:
                        if x<dpi*2:
                            mouseclick=False
                        else:
                            jump=False
                
                #simulate touch
                elif event.type == pygame.KEYDOWN:
                    if event.key == pygame.K_ESCAPE:
                        running=False
                    elif event.key == pygame.K_LEFT:
                        mousepos=0.5*dpi
                        mouseclick=True
                    elif event.key == pygame.K_RIGHT:
                        mousepos=1.5*dpi
                        mouseclick=True
                    elif event.key == pygame.K_UP:
                        jump=True
                    elif event.key == pygame.K_SPACE:
                        jumppos=1
                
                #turn off touch simulation
                elif event.type == pygame.KEYUP:
                    if event.key == pygame.K_LEFT or event.key == pygame.K_RIGHT:
                        mouseclick=False
                    elif event.key == pygame.K_UP:
                        jump=False
                        jumppos=sy-1
            
            #jump
            if jump:
                offset[1]+=4.125
            
            if jumppos<sy-dpi and fullhealth and fall>4:
                fall=-0.75
                fullhealth=False
            
            #gravity
            if fall!=-1 and ((land[8]<7 or(land[8]==7 and offset[1]!=0)or land[8]==hole) and (offset[0]==0 or (offset[0]!=0 and (land[9]<7 or(land[9]==7 and offset[1]!=0)or land[9]==hole)))):
                offset[1]-=fall
                fall+=0.5
            else:
                offset[1]=0
                fall=0.25
            
            #check for vertical shifting
            shift[1]=0
            while offset[1]>3:
                offset[1]-=4
                shift[1]-=1
            while offset[1]<0:
                offset[1]+=4
                shift[1]+=1
            if land[8] !=hole and land[8]+shift[1]>7:
                shift[1]=7-land[8]
                offset[1]==0
                fall=-1
            
            if offset[0]!=0 and land[9] !=hole and land[9]+shift[1]>7:
                shift[1]=7-land[9]
                offset[1]==0
                fall=-1
            
            land_=[]
            for height in land:
                if height!=hole:
                    land_.append(height+shift[1])
                else:
                    land_.append(hole)
                land=land_
            
            #touch button locations
            if mouseclick:
                if mousepos<0.75*dpi:
                    left=True
                elif mousepos>1.25*dpi:
                    right=True
                else:
                    left=right=False
            else:
                left=right=False
            
            if left and (land[7]<=7 or land[7]==hole or offset[0]!=0):
                offset[0]-=1
            elif right and (land[9]<=7 or land[9]==hole):
                offset[0]+=1
                
            if offset[0]>3:
                offset[0]-=4
                shift[0]=1
                score+=1
            elif offset[0]<0:
                offset[0]+=4
                shift[0]=-1
                score-=1
            else:
                shift[0]=0
            
            #right shift
            if shift[0]==1:
                land_=[]
                for height in land[1:]:
                    land_.append(height)
                
                rand=random.randint(-5,5)
                
                if rand<-2 and not hard:
                    rand=random.randint(1,2)
                   
                if land[-3:]==[hole,hole,hole] or max(land[-6+rand:])==hole:
                    height=land[-4]
                elif rand==5:
                    height=hole
                elif rand<-2 and hard:
                    height=hole
                else:
                    height=max(land[-6+rand:])+rand-random.randint(0,1)
                    
                if random.randint(0,99)==0:
                    hard=not hard
                    #print hard
                
                land_.append(height)
                land=land_
                
                enemies_=[]
                for enemy in enemies:
                    if enemy>1:
                        enemies_.append(enemy-1)
                    enemies=enemies_
                
                if land[-1]>land[-2] and random.randint(0,4)==0 and not easyMode:
                    enemies.append(len(land)-1)
                
                #print enemies
                
            #left shift
            elif shift[0]==-1:
                land_=[hole]
                for height in land[:-1]:
                    land_.append(height)
                land=land_
                
                enemies_=[]
                for enemy in enemies:
                    if enemy<len(land)-1:
                        enemies_.append(enemy+1)
                    enemies=enemies_
                #print enemies
            
            if land[8]==hole and shift[1]>=10:
                if highscore>=500+savehighscore and level!=2 and not easyMode:# and random.randint(0,1)==0:
                    fall=4.25
                    offset[0]=3
                    shift[1]=0
                    hard=True
                    shotclock=0
                    savehighscore=highscore
                    level+=1    
                    fullhealth=False
                    if level==1:
                        enemies=[0,]
                        bat=5
                        batpos=(130,68)
                        boss=True
                    else:
                        enemies=[0,14]
                        ghost=True
                        ghosthealth=5
                        GHOST=(-1,-1,-1)
                        ghostpos=(random.randint(7,9),random.randint(7,12))
                        ghostfade=False
                        boss=True
                    land=[-8,hole,hole,hole,hole,-6,hole,-10,-10,-10,-10,-10,-10,hole,0,-19,-19,-19,-19,-19,-19,-19,-19,-19,-19,-19,-19,-19,-19,-19,-19,-19,-19,-19,-19,-19,-19,-19,-19,-19,]
                else:
                    running=False
            elif highscore>=1000+savehighscore and level!=0:
                level-=1
                savehighscore=highscore
            elif highscore>=1000+savehighscore and bottom and not boss:
                enemies=[]
                boss=True
                #level=-1
                land=[land[0],land[1],land[2],land[3],land[5],land[6],land[7],land[8],land[9],land[10],land[11],hole,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,hole,hole,hole,hole,hole,hole,hole,hole,hole,hole,hole,hole]
            
            if boss and level==2:
                bat=False
                ghost=True
            
            if level==0:
                SKY=(SKY[0]+(SKY[0]<127),SKY[1]+(SKY[1]<127),SKY[2]+(SKY[2]<255))
            elif level==1:
                SKY=(SKY[0]+(SKY[0]<31)-(SKY[0]>31),SKY[1]+(SKY[1]<31)-(SKY[1]>31),SKY[2]+(SKY[2]<31)-(SKY[2]>31))
                GROUND=(GROUND[0]+(GROUND[0]<63),GROUND[1]+(GROUND[1]<63),GROUND[2]+(GROUND[2]<63))
                GRASS=(GRASS[0]+(GRASS[0]<255),GRASS[1]+(GRASS[1]<255),GRASS[2]+(GRASS[2]<255))
                PLAYER=(PLAYER[0]+(PLAYER[0]<255),PLAYER[1]+(PLAYER[1]<255),PLAYER[2]+(PLAYER[2]<255))
            else:
                SKY=(SKY[0]-(SKY[0]>0),SKY[1]-(SKY[1]>0),SKY[2]-(SKY[2]>0))
                GROUND=(GROUND[0]-(GROUND[0]>0),GROUND[1]-(GROUND[1]>0),GROUND[2]-(GROUND[2]>0))
                GRASS=(GRASS[0]-(GRASS[0]>31),GRASS[1]-(GRASS[1]>31),GRASS[2]-(GRASS[2]>31))
                PLAYER=(PLAYER[0]-(PLAYER[0]>31),PLAYER[1]-(PLAYER[1]>31),PLAYER[2]-(PLAYER[2]>31))
            
            if level>=1 and random.randint(0,799)==0 and not bat:
                bat=random.randint(1,3)
                batpos=(130,68)
            
            if level==2 and random.randint(0,799)==0 and not ghost:
                ghost=True
                ghosthealth=3
                GHOST=(-1,-1,-1)
                ghostpos=(random.randint(7,9),random.randint(7,12))
                ghostfade=False
            
                
            screen.fill(SKY)
            
            heightcount=0
            for height in land:
                if height!=hole:
                    p1=(4*su*heightcount-offset[0]*su,64*su-4*su*height+offset[1]*su)
                    p2=(4*su, 4*su*height+offset[1]*su)
                    screen.fill(GROUND,(p1,p2))
                    screen.fill(GRASS,(p1,(4*su,su)))
                heightcount+=1
            
            shots_=[]
            for shot in shots:
                shot_=(shot[0]-4*su*shift[0]-2*su,shot[1]-4*su*shift[1])
                if shot[0]>0 and not (land[(shot_[0]-shot_[0]%(4*su))/(4*su)] !=hole and 64*su-land[(shot_[0]-shot_[0]%(4*su))/(4*su)]*4*su<shot_[1] and shot[0]%(4*su)==3*su):
                    shots_.append(shot_)
            shots=shots_
            
            shotclock+=1
            if shotclock==1*FPS:
                shotclock=0
                for enemy in enemies:
                    if enemy<=28:
                        shots.append(((4*enemy+1)*su,(64-4*land[enemy]+1)*su))
            
            
            
            enemies_=[]
            for enemy in enemies:
                enemyx=4*su*enemy-offset[0]*su
                enemyy=64*su-4*su*land[enemy]+offset[1]*su
                screen.fill(ENEMY,((enemyx,enemyy),(4*su,4*su)))
                screen.fill(INNERENEMY,((enemyx+su,enemyy+su),(2*su,2*su)))
                screen.fill(INNERENEMY,((enemyx+su,enemyy-su),(2*su,1*su)))
                screen.fill(ENEMY,((enemyx,enemyy-2*su+(shotclock<=1 and enemy<=28)*su),(4*su,1*su)))
                if ((land[8]==7 and enemy==8) or (land[9]==7 and offset[0]!=0 and enemy==9)) and offset[1]==0:
                    if random.randint(0,9)==0:
                        screen.fill(INNERENEMY,((enemyx-2*su,enemyy-2*su),(8*su,8*su)))
                        screen.fill(ENEMY,((enemyx,enemyy),(4*su,4*su)))
                        if fullhealth:
                            offset[1]=2
                            score+=100
                            highscore+=100
                            if random.randint(0,9)==0:
                                score+=200
                                highscore+=200
                                screen.fill(INNERENEMY,((enemyx-3*su,enemyy-3*su),(10*su,10*su)))
                                screen.fill(ENEMY,((enemyx-su,enemyy-su),(6*su,6*su)))
                                fullhealth=False
                                offset[1]=3
                        else:
                            fullhealth=True
                        #print 'good'
                    else:
                        screen.fill(INNERENEMY,((enemyx-su,enemyy-su),(6*su,6*su)))
                        screen.fill(ENEMY,((enemyx,enemyy),(4*su,4*su)))
                        score+=10
                        highscore+=10
                else:
                    enemies_.append(enemy)
                enemies=enemies_
            
            if bat:
                if random.randint(0,2)!=0:
                    if batpos[0]>=32 and batpos[1]>=32:
                        batshift=(-2,-2)
                    elif batpos[0]<32 and batpos[1]>=32:
                        batshift=(2,-2)
                    elif batpos[0]<32 and batpos[1]<32:
                        batshift=(2,2)
                    else:# batpos[0]<=16 and batpos[1]<=16:
                        batshift=(-2,2)
                else:
                    rand=random.randint(0,3)
                    if rand==0:
                        batshift=(-1,1)
                    elif rand==1:
                        batshift=(-1,-1)
                    elif rand==2:
                        batshift=(1,-1)
                    else:# rand==3:
                        batshift=(1,1)
                
                #print batpos
                batpos=(batpos[0]+batshift[0],batpos[1]+batshift[1])
                batpos=(batpos[0]-4*shift[0],batpos[1]+4*shift[1])
                
                screen.fill(BAT,((su*batpos[0]-su*offset[0]+su,64*su-su*batpos[1]+su*offset[1]+su),(7*su,su)))
                screen.fill(BAT,((su*batpos[0]-su*offset[0]+3*su,64*su-su*batpos[1]+su*offset[1]),(su,su)))
                screen.fill(BAT,((su*batpos[0]-su*offset[0]+5*su,64*su-su*batpos[1]+su*offset[1]),(su,su)))
                screen.fill(BAT,((su*batpos[0]-su*offset[0]+3*su,64*su-su*batpos[1]+su*offset[1]+2*su),(3*su,su)))
                screen.fill(BAT,((su*batpos[0]-su*offset[0],64*su-su*batpos[1]+su*offset[1]+su*(shotclock%4>1)),(2*su,su)))
                screen.fill(BAT,((su*batpos[0]-su*offset[0]+su*7,64*su-su*batpos[1]+su*offset[1]+su*(shotclock%4>1)),(2*su,su)))
                screen.fill(INNERBAT,((su*batpos[0]-su*offset[0]+3*su,64*su-su*batpos[1]+su*offset[1]+su),(su,su)))
                screen.fill(INNERBAT,((su*batpos[0]-su*offset[0]+5*su,64*su-su*batpos[1]+su*offset[1]+su),(su,su)))
                
                if batpos[0]-offset[0]>25 and batpos[0]-offset[0]<36 and batpos[1]+offset[1]>32 and batpos[1]+offset[1]<40:
                    #if batpos[1]+offset[1]<31 and batpos[1]+offset[1]+fall>28 and fall>0.5:
                    if fall-4.125*jump>0.25:
                        bat-=1
                        batpos=(130,68)
                        screen.fill(BAT,((31*su,33*su),(6*su,6*su)))
                        if not fullhealth and (not bat or not boss):
                            fullhealth=True
                        else:
                            highscore+=25
                            score+=25
                    #elif batpos[1]>23 and batpos[1]<36:
                    else:
                        if fullhealth:
                            fullhealth=False
                        else:
                            killed=True
                        batpos=(130,68)
            if boss and level==1 and not bat:
                boss=False
                        
            if ghost:
                GHOST=(GHOST[0]+8-16*ghostfade,GHOST[1]+8-16*ghostfade,GHOST[2]+8-16*ghostfade)
                if GHOST[0]>255:
                    GHOST=(255,255,255)
                    ghostfade=True
                elif GHOST[0]<0:
                    GHOST=(0,0,0)
                    ghostfade=False
                    ghostpos=(random.randint(7,9),random.randint(7,12))
                ghostpos=(ghostpos[0]-shift[0],ghostpos[1]+shift[1])
                screen.fill(GHOST,((4*su*ghostpos[0]-su*offset[0],64*su-4*su*ghostpos[1]+su*offset[1]),(8*su,8*su)))
                screen.fill(INNERGHOST,((4*su*ghostpos[0]-su*offset[0]+su,64*su-4*su*ghostpos[1]+su*offset[1]+su),(2*su,2*su)))
                screen.fill(INNERGHOST,((4*su*ghostpos[0]-su*offset[0]+5*su,64*su-4*su*ghostpos[1]+su*offset[1]+su),(2*su,2*su)))
                screen.fill(INNERGHOST,((4*su*ghostpos[0]-su*offset[0]+3*su,64*su-4*su*ghostpos[1]+su*offset[1]+4*su),(2*su,3*su)))
                
                if GHOST[0]>=191 and 4*su*ghostpos[0]-su*offset[0]>24*su and 4*su*ghostpos[0]-su*offset[0]<36*su and 64*su-4*su*ghostpos[1]+su*offset[1]<36*su and 64*su-4*su*ghostpos[1]+su*offset[1]>24*su-4*su*fullhealth:
                    if fullhealth:
                        fullhealth=not fullhealth
                    else:
                        killed=True
                    ghost=False
            
            
            if fullhealth and body<8:
                body+=1
            elif not fullhealth and body>4:
                body-=1
            
            screen.fill(PLAYER,((32*su,(36-body)*su),(4*su,body*su)))
            
            shots_=[]
            for shot in shots:
                screen.fill(SHOT, ((shot[0]-su*offset[0],shot[1]+su*offset[1]),(2*su,2*su)))
                
                #(shot[0]-su*offset[0],shot[1]+su*offset[1])
                
                if shot[0]-su*offset[0]>30*su and shot[0]-su*offset[0]<36*su:
                    if fullhealth and shot[1]+su*offset[1]>26*su and shot[1]+su*offset[1]<36*su:
                        fullhealth=False
                        #print 'hurt'
                    elif not fullhealth and shot[1]+su*offset[1]>30*su and shot[1]+su*offset[1]<36*su:
                        #print 'dead'
                        killed=True
                    else:
                        shots_.append(shot)
                elif ghost and shot[0]-su*offset[0]>=4*su*ghostpos[0]-su*offset[0] and shot[0]-su*offset[0]<4*su*ghostpos[0]-su*offset[0]+su*8 and shot[1]+su*offset[1]>=64*su-4*su*ghostpos[1]+su*offset[1] and shot[1]+su*offset[1]<64*su-4*su*ghostpos[1]+su*offset[1]+8*su:
                    ghosthealth-=1
                    if ghosthealth==0:
                        ghost=False
                        if not fullhealth:
                            fullhealth=True
                        else:
                            score+=100
                            highscore+=100
                        if boss:
                            boss=False
                            enemies=[]
                            bottom=1
                    GHOST=(-1,-1,-1)
                    ghostpos=(random.randint(7,9),random.randint(7,12))
                    ghostfade=False
                else:
                    shots_.append(shot)
            shots=shots_
            
            if score>highscore:
                highscore=score
                #print highscore
            
            screen.fill(DOCK,((0,64*su),(sx,sy-64*su)))
            pygame.draw.line(screen, LINES, (0.75*dpi,64*su),(0.75*dpi,sy),su)
            pygame.draw.line(screen, LINES, (1.25*dpi,64*su),(1.25*dpi,sy),su)
            pygame.draw.line(screen, LINES, (2*dpi,64*su),(2*dpi,sy),su)
            pygame.draw.line(screen, LINES, (122*su,sy-dpi),(sx,sy-dpi),su)
            screen.fill(DOCK,((128*su,0),(sx,sy)))
            screen.blit(font.render(str(highscore),True,TEXT),(2*dpi+3*su,66*su))
            
            pygame.display.flip()
            if killed:
                clock.tick(0.5)
                running=False
                
            clock.tick(FPS)
            
        score=highscore
        total+=highscore
        records_=[]
        for record in records:
            if record>=highscore:
                records_.append(record)
            else:
                records_.append(highscore)
                highscore=-1
                records_.append(record)
                showrecords=True
        records=records_[:10]
        
        if boss:
            if level!=-1:
                level-=1
            else:
                level=0
                
        with open('records.txt','w') as records_:
            records_.write(str(level)+'\n')
            records_.write(str(total)+'\n')
            records_.write(str(bottom)+'\n')
            records_.write(str(easyMode)+'\n')
            for record in records:
                records_.write(str(record)+'\n')
                
        
        
        pygame.event.clear()
        while showrecords:
            if android and android.check_pause():
                '''with open('records.txt','w') as records_:
                    records_.write(str(total)+'\n')
                    for record in records:
                        records_.write(str(record)+'\n')'''
                android.wait_for_resume()
            
            events = pygame.event.get()
            
            #manage events
            for event in events:
                #get touches
                if event.type == pygame.MOUSEBUTTONDOWN or (event.type == pygame.KEYDOWN and event.key == pygame.K_ESCAPE):
                    showrecords=False
                    menu=True
                            
            x1-=su*0.25
            x2-=su*0.25
            if x1<-128*su:x1=128*su
            if x2<-128*su:x2=128*su
            screen.fill(SKY)
            screen.fill(GROUND,((x1,36*su),(124*su,28*su)))
            screen.fill(GRASS,((x1,36*su),(124*su,su)))
            screen.fill(GROUND,((x2,32*su),(124*su,32*su)))
            screen.fill(GRASS,((x2,32*su),(124*su,su)))
            screen.fill(DOCK,((0,64*su),(sx,sy-64*su)))
            screen.fill(DOCK,((128*su,0),(sx,sy)))
            
            screen.blit(font.render((str(records[0])),True,TEXT),(su,su))
            screen.blit(font.render((str(records[1])),True,TEXT),(su,13*su))
            screen.blit(font.render((str(records[2])),True,TEXT),(su,2*13*su))
            screen.blit(font.render((str(records[3])),True,TEXT),(su,3*13*su))
            screen.blit(font.render((str(records[4])),True,TEXT),(su,4*13*su))
            
            screen.blit(font.render((str(records[5])),True,TEXT),(sx/2,su))
            screen.blit(font.render((str(records[6])),True,TEXT),(sx/2,13*su))
            screen.blit(font.render((str(records[7])),True,TEXT),(sx/2,2*13*su))
            screen.blit(font.render((str(records[8])),True,TEXT),(sx/2,3*13*su))
            screen.blit(font.render((str(records[9])),True,TEXT),(sx/2,4*13*su))
            
            if score>0:
                banner=('Total '+str(total)+'    New Ranked Score '+str(score))
            else:
                banner=('Total '+str(total))
            screen.blit(font.render(banner,True,TEXT),(su,65*su))
            
            
            clock.tick(FPS)
            pygame.display.flip()