예제 #1
0
파일: jrpg2demo.py 프로젝트: mcamuzat/jrpg
    def __init__(self):
        size = (width, height) = (1024, 768)
        pygame.display.set_icon(pygame.image.load("images/jrpg-icon.png"))
        self.screen = pygame.display.set_mode(size, pygame.DOUBLEBUF) # |pygame.HWSURFACE
        self.key_pressed_table = [False for i in range(512)]
        self.clock = pygame.time.Clock()
        self.frame_number = 0
        self.map_viewport     = self.screen.subsurface(((32,32),(768,576)))
        self.stats_viewport   = self.screen.subsurface(((768+2*32,32),(1024-768-3*32,576)))
        self.msg_viewport     = self.screen.subsurface(((32,576+2*32),(768,768-576-3*32)))

        self.bg_cache_surface = pygame.Surface((768, 576))
        self.bg_cache         = Cached(lambda: self.refresh_bg_cache(), world.nctl_bg_changed)
        self.stats_cache      = Cached(lambda: self.render_stats(self.stats_viewport), world.stats.nctl_stats_changed)
        self.msg_cache        = Cached(lambda: self.render_msg(), world.nctl_msg_changed)
        # FIXME: The last small square is pretty much unused
        # It will probably be a good idea to take half of stat viewport and
        # that square to make a demon viewport or sth

        self.default_font, self.furi_font, self.big_font = util.load_font(18, 24, 64)

        self.buf       = u""
        self.bs_repeat = 0

        # This is just UI state
        self.in_battle_mode = False
예제 #2
0
파일: jrpg2demo.py 프로젝트: qqmash/jrpg
    def __init__(self):
        size = (width, height) = (1024, 768)
        pygame.display.set_icon(pygame.image.load("images/jrpg-icon.png"))
        self.screen = pygame.display.set_mode(
            size, pygame.DOUBLEBUF)  # |pygame.HWSURFACE
        self.key_pressed_table = [False for i in range(512)]
        self.clock = pygame.time.Clock()
        self.frame_number = 0
        self.map_viewport = self.screen.subsurface(((32, 32), (768, 576)))
        self.stats_viewport = self.screen.subsurface(
            ((768 + 2 * 32, 32), (1024 - 768 - 3 * 32, 576)))
        self.msg_viewport = self.screen.subsurface(
            ((32, 576 + 2 * 32), (768, 768 - 576 - 3 * 32)))

        self.bg_cache_surface = pygame.Surface((768, 576))
        self.bg_cache = Cached(lambda: self.refresh_bg_cache(),
                               world.nctl_bg_changed)
        self.stats_cache = Cached(
            lambda: self.render_stats(self.stats_viewport),
            world.stats.nctl_stats_changed)
        self.msg_cache = Cached(lambda: self.render_msg(),
                                world.nctl_msg_changed)
        # FIXME: The last small square is pretty much unused
        # It will probably be a good idea to take half of stat viewport and
        # that square to make a demon viewport or sth

        self.default_font, self.furi_font, self.big_font = util.load_font(
            18, 24, 64)

        self.buf = u""
        self.bs_repeat = 0

        # This is just UI state
        self.in_battle_mode = False
예제 #3
0
 def __init__(self):
     size = (640, 480)
     #self.screen = pygame.display.set_mode(size, pygame.DOUBLEBUF|pygame.FULLSCREEN)
     self.screen = pygame.display.set_mode(size, pygame.DOUBLEBUF)
     self.font, self.font_med, self.font_big = util.load_font(27, 60, 96)
     self.clock = pygame.time.Clock()
     self.key = [False for i in range(512)]
     self.chara_buf = u""
예제 #4
0
 def __init__(self):
     size = (640, 480)
     #self.screen = pygame.display.set_mode(size, pygame.DOUBLEBUF|pygame.FULLSCREEN)
     self.screen = pygame.display.set_mode(size, pygame.DOUBLEBUF)
     self.font, self.font_med, self.font_big = util.load_font(27, 60, 96)
     self.clock    = pygame.time.Clock()
     self.key = [False for i in range(512)]
     self.chara_buf = u""
예제 #5
0
    def __init__(self, screen, gametype_select = False):
        self.screen = screen

        self.gametype_select = gametype_select

        self.sky = util.load_image("taivas")

        self.water = Water.global_water
        self.water_sprite = pygame.sprite.Group()
        self.water_sprite.add(self.water)

        self.logo = util.load_image("logo")

        self.font = util.load_font("Cosmetica", 28)

        self.url_font = util.load_font("Cosmetica", 14)

        self.selection = 0
        self.t = 0
예제 #6
0
    def __init__(self, screen, gametype_select = False):
        self.screen = screen

        self.gametype_select = gametype_select

        self.sky = util.load_image("taivas")

        self.water = Water.global_water
        self.water_sprite = pygame.sprite.Group()
        self.water_sprite.add(self.water)

        self.logo = util.load_image("logo")

        self.font = util.load_font("Cosmetica", 28)

        self.url_font = util.load_font("Cosmetica", 14)
        self.option_rects = {}
        self.selection = 0
        self.t = 0
예제 #7
0
    def __init__(self):
        pygame.sprite.Sprite.__init__(self)

        self.score = 0
        self.target_score = 0

        self.font = util.load_font("Cosmetica", 14)

        self.image = self.font.render("Score: 0", True, (10,10,10))

        self.rect = self.image.get_rect()
        self.rect.left = 100
        self.rect.top = 5
예제 #8
0
파일: score.py 프로젝트: rkuklins/funnyboat
    def __init__(self):
        pygame.sprite.Sprite.__init__(self)

        self.score = 0
        self.target_score = 0

        self.font = util.load_font("Cosmetica", 14)

        self.image = self.font.render("Score: 0", True, (10, 10, 10))

        self.rect = self.image.get_rect()
        self.rect.left = 100
        self.rect.top = 5
예제 #9
0
파일: game.py 프로젝트: rkuklins/funnyboat
    def draw(self):
        self.screen.blit(self.sky, self.screen.get_rect())
        self.health_sprite.draw(self.screen)
        self.score_sprite.draw(self.screen)
        self.player_sprite.draw(self.screen)
        self.powerup_sprites.draw(self.screen)
        self.pirate_sprites.draw(self.screen)
        if self.titanic:
            self.titanic_sprite.draw(self.screen)
        self.seagull_sprites.draw(self.screen)
        cloud.draw(self.screen)
        self.shark_sprites.draw(self.screen)
        self.mine_sprites.draw(self.screen)
        self.cannonball_sprites.draw(self.screen)
        self.water_sprite.draw(self.screen)
        if not self.noparticles:
            self.particle_sprite.draw(self.screen)

        if self.pause:
            self.screen.blit(self.pause_image, self.pause_rect)

        if self.gameover:
            self.screen.blit(self.gameover_image, self.gameover_rect)

        if self.level.t < 120:
            font = util.load_font("Cosmetica", 16)
            image = None
            i = 0
            if self.level.phase < len(self.level.phase_messages):
                for text in self.level.phase_messages[self.level.phase].split(
                        "\n"):
                    image = font.render(text, True, (0, 0, 0))
                    rect = image.get_rect()
                    rect.centerx = self.screen.get_rect().centerx
                    rect.top = 100 + rect.height * i
                    blit_image = pygame.Surface(
                        (image.get_width(), image.get_height()))
                    blit_image.fill((166, 183, 250))
                    blit_image.set_colorkey((166, 183, 250))
                    blit_image.blit(image, image.get_rect())
                    if self.level.t > 60:
                        blit_image.set_alpha(255 -
                                             (self.level.t - 60) * 255 / 60)
                    self.screen.blit(blit_image, rect)
                    i += 1

        pygame.display.flip()
예제 #10
0
    def draw(self):
        self.screen.blit(self.sky, self.screen.get_rect())
        self.screen.blit(self.pause_icon, (SCREEN_WIDTH - 32, 0))
        self.health_sprite.draw(self.screen)
        self.score_sprite.draw(self.screen)
        self.player_sprite.draw(self.screen)
        self.powerup_sprites.draw(self.screen)
        self.pirate_sprites.draw(self.screen)
        if self.titanic:
            self.titanic_sprite.draw(self.screen)
        self.seagull_sprites.draw(self.screen)
        cloud.draw(self.screen)
        self.shark_sprites.draw(self.screen)
        self.mine_sprites.draw(self.screen)
        self.cannonball_sprites.draw(self.screen)
        self.water_sprite.draw(self.screen)
        if not self.noparticles:
            self.particle_sprite.draw(self.screen)

        if self.pause:
            self.screen.blit(self.pause_image, self.pause_rect)

        if self.gameover:
            self.screen.blit(self.gameover_image, self.gameover_rect)

        if self.level.t < 120:
            font = util.load_font("Cosmetica", 16)
            image = None
            i = 0
            if self.level.phase < len(self.level.phase_messages):
              for text in self.level.phase_messages[self.level.phase].split("\n"):
                image = font.render(text, True, (0,0,0))
                rect = image.get_rect()
                rect.centerx = self.screen.get_rect().centerx
                rect.top = 100 + rect.height * i
                blit_image = pygame.Surface((image.get_width(), image.get_height()))
                blit_image.fill((166,183,250))
                blit_image.set_colorkey((166,183,250))
                blit_image.blit(image, image.get_rect())
                if self.level.t > 60:
                    blit_image.set_alpha(255 - (self.level.t - 60) * 255 / 60)
                self.screen.blit(blit_image, rect)
                i += 1

        pygame.display.flip()
예제 #11
0
    def set_gameover(self, message = "Game Over"):
        self.gameover = True
        images = []
        font = util.load_font("Cosmetica", 40) #pygame.font.Font(pygame.font.get_default_font(), 36)
        height = 0
        width = 0
        for text in message.split("\n"):
            images.append(font.render(text, True, (0,0,0)))
            height += images[-1].get_height()
            if images[-1].get_width() > width:
                width = images[-1].get_width()
        self.gameover_image = pygame.Surface((width, height), SRCALPHA, 32)
        self.gameover_image.fill((0,0,0,0))
        for i in range(len(images)):
            rect = images[i].get_rect()
            rect.top = i * images[i].get_height()
            rect.centerx = width / 2
            self.gameover_image.blit(images[i], rect)

        self.gameover_rect = self.gameover_image.get_rect()
        self.gameover_rect.center = self.screen.get_rect().center
예제 #12
0
파일: game.py 프로젝트: rkuklins/funnyboat
    def set_gameover(self, message="Game Over"):
        self.gameover = True
        images = []
        font = util.load_font(
            "Cosmetica",
            40)  #pygame.font.Font(pygame.font.get_default_font(), 36)
        height = 0
        width = 0
        for text in message.split("\n"):
            images.append(font.render(text, True, (0, 0, 0)))
            height += images[-1].get_height()
            if images[-1].get_width() > width:
                width = images[-1].get_width()
        self.gameover_image = pygame.Surface((width, height), SRCALPHA, 32)
        self.gameover_image.fill((0, 0, 0, 0))
        for i in range(len(images)):
            rect = images[i].get_rect()
            rect.top = i * images[i].get_height()
            rect.centerx = width / 2
            self.gameover_image.blit(images[i], rect)

        self.gameover_rect = self.gameover_image.get_rect()
        self.gameover_rect.center = self.screen.get_rect().center
예제 #13
0
    def __init__(self, screen, new_score=-1, endless=False):
        self.screen = screen

        # using HOME doesn't work on Windows :-(
        self.pathname = ""
        try:
            self.pathname = os.environ["HOME"] + "/.funnyboat"
        except:
            try:
                self.pathname = os.environ["APPDATA"] + "/Funny Boat"
            except:
                print "Couldn't get environment variable for home directory"
                self.pathname = "."
                #self.done = True
                #return
        if not endless:
            self.filename = self.pathname + "/scores"
        else:
            self.filename = self.pathname + "/endless_scores"

        self.scores = []
        self.done = False

        try:
            if not os.path.exists(self.pathname):
                os.mkdir(self.pathname)
        except:
            print "Can't make directory " + self.pathname
            self.done = True
            return

        if not os.path.exists(self.filename):
            #print "Creating dummy high scores"
            self.dummy_scores()
        else:
            try:
                f = codecs.open(self.filename, "r", "utf_8")
                i = 0
                name, score = "", 0
                for line in f:
                    if i % 2 == 0:
                        name = line.strip()
                    else:
                        try:
                            score = int(line)
                        except:
                            print "Corrupt high score file."
                            self.dummy_scores()
                            break
                        self.scores.append((name, score))
                    i += 1
            except:
                self.dummy_scores()
                print "Can't open file " + self.filename + " or file corrupt"

        if len(self.scores) < 10:
            print "Corrupt high score file."
            self.dummy_scores()

        #self.font = pygame.font.Font(pygame.font.get_default_font(), 12)
        self.font = util.load_font("Cosmetica", 14)
        #self.title_font = pygame.font.Font(pygame.font.get_default_font(), 24)
        self.title_font = util.load_font("Cosmetica", 28)
        self.title = self.title_font.render("High Scores", True, (0, 0, 0))

        self.sky = util.load_image("taivas")

        self.inputting = False
        self.input_score = -1

        if new_score > self.scores[9][1]:
            #print "It's a new high score!"
            self.inputting = True
            for i in range(10):
                if self.scores[i][1] < new_score:
                    self.input_score = i
                    for j in range(9 - i):
                        self.scores[9 - j] = self.scores[8 - j]
                    self.scores[i] = ["", new_score]
                    break
예제 #14
0
    def __init__(self, screen, usealpha = True, noparticles = False, endless = False):
        self.screen = screen
        self.usealpha = usealpha
        self.noparticles = noparticles

        self.sharks = []
        self.shark_sprites = pygame.sprite.Group()

        self.player = Steamboat()
        self.player_sprite = pygame.sprite.Group()
        self.player_sprite.add(self.player)

        self.health = Health()
        self.health_sprite = pygame.sprite.Group()
        self.health_sprite.add(self.health)

        self.damage_count = 0

        self.t = 0

        self.water = Water.global_water #Water(self.usealpha)
        #Water.global_water = self.water
        self.water_sprite = pygame.sprite.Group()
        self.water_sprite.add(self.water)

        self.sky = util.load_image("taivas")
        self.sky = pygame.transform.scale(self.sky, (SCREEN_WIDTH, SCREEN_HEIGHT))

        self.pause_icon = util.load_image("pause")
        
        self.cannonballs = []
        self.cannonball_sprites = pygame.sprite.Group()

        self.pirates = []
        self.pirate_sprites = pygame.sprite.Group()

        self.titanic = None
        self.titanic_sprite = pygame.sprite.Group()

        self.seagulls = []
        self.seagull_sprites = pygame.sprite.Group()

        self.particles = Particles(self.usealpha)
        self.particle_sprite = pygame.sprite.Group()
        self.particle_sprite.add(self.particles)

        self.mines = []
        self.mine_sprites = pygame.sprite.Group()

        self.score = Score()
        self.score_sprite = pygame.sprite.Group()
        self.score_sprite.add(self.score)

        self.powerups = []
        self.powerup_sprites = pygame.sprite.Group()

        self.level = Level(endless)
        self.cheat_current = 0
        
        self.lastshot = MIN_FIRE_DELAY + 1

        self.gameover = False
        self.gameover_image = None
        self.gameover_rect = None
        self.done = False

        self.pause = False
        font = util.load_font("Cosmetica", 40) #pygame.font.Font(pygame.font.get_default_font(), 36)
        self.pause_image = font.render("Pause", True, (0,0,0))
        self.pause_rect = self.pause_image.get_rect()
        self.pause_rect.center = self.screen.get_rect().center
예제 #15
0
파일: game.py 프로젝트: rkuklins/funnyboat
    def __init__(self,
                 screen,
                 usealpha=True,
                 noparticles=False,
                 endless=False):
        self.screen = screen
        self.usealpha = usealpha
        self.noparticles = noparticles

        self.sharks = []
        self.shark_sprites = pygame.sprite.Group()

        self.player = Steamboat()
        self.player_sprite = pygame.sprite.Group()
        self.player_sprite.add(self.player)

        self.health = Health()
        self.health_sprite = pygame.sprite.Group()
        self.health_sprite.add(self.health)

        self.damage_count = 0

        self.t = 0

        self.water = Water.global_water  #Water(self.usealpha)
        #Water.global_water = self.water
        self.water_sprite = pygame.sprite.Group()
        self.water_sprite.add(self.water)

        self.sky = util.load_image("taivas")
        self.sky = pygame.transform.scale(self.sky,
                                          (SCREEN_WIDTH, SCREEN_HEIGHT))

        self.cannonballs = []
        self.cannonball_sprites = pygame.sprite.Group()

        self.pirates = []
        self.pirate_sprites = pygame.sprite.Group()

        self.titanic = None
        self.titanic_sprite = pygame.sprite.Group()

        self.seagulls = []
        self.seagull_sprites = pygame.sprite.Group()

        self.particles = Particles(self.usealpha)
        self.particle_sprite = pygame.sprite.Group()
        self.particle_sprite.add(self.particles)

        self.mines = []
        self.mine_sprites = pygame.sprite.Group()

        self.score = Score()
        self.score_sprite = pygame.sprite.Group()
        self.score_sprite.add(self.score)

        self.powerups = []
        self.powerup_sprites = pygame.sprite.Group()

        self.level = Level(endless)

        self.lastshot = MIN_FIRE_DELAY + 1

        self.gameover = False
        self.gameover_image = None
        self.gameover_rect = None
        self.done = False

        self.pause = False
        font = util.load_font(
            "Cosmetica",
            40)  #pygame.font.Font(pygame.font.get_default_font(), 36)
        self.pause_image = font.render("Pause", True, (0, 0, 0))
        self.pause_rect = self.pause_image.get_rect()
        self.pause_rect.center = self.screen.get_rect().center
예제 #16
0
    def __init__(self, screen, new_score=-1, endless=False):
        self.screen = screen

        # using HOME doesn't work on Windows :-(
        self.pathname = ""
        try:
            self.pathname = os.environ["HOME"] + "/.funnyboat"
        except:
            try:
                self.pathname = os.environ["APPDATA"] + "/Funny Boat"
            except:
                print "Couldn't get environment variable for home directory"
                self.pathname = "."
                # self.done = True
                # return
        if not endless:
            self.filename = self.pathname + "/scores"
        else:
            self.filename = self.pathname + "/endless_scores"

        self.scores = []
        self.done = False

        try:
            if not os.path.exists(self.pathname):
                os.mkdir(self.pathname)
        except:
            print "Can't make directory " + self.pathname
            self.done = True
            return

        if not os.path.exists(self.filename):
            # print "Creating dummy high scores"
            self.dummy_scores()
        else:
            try:
                f = codecs.open(self.filename, "r", "utf_8")
                i = 0
                name, score = "", 0
                for line in f:
                    if i % 2 == 0:
                        name = line.strip()
                    else:
                        try:
                            score = int(line)
                        except:
                            print "Corrupt high score file."
                            self.dummy_scores()
                            break
                        self.scores.append((name, score))
                    i += 1
            except:
                self.dummy_scores()
                print "Can't open file " + self.filename + " or file corrupt"

        if len(self.scores) < 10:
            print "Corrupt high score file."
            self.dummy_scores()

        # self.font = pygame.font.Font(pygame.font.get_default_font(), 12)
        self.font = util.load_font("Cosmetica", 14)
        # self.title_font = pygame.font.Font(pygame.font.get_default_font(), 24)
        self.title_font = util.load_font("Cosmetica", 28)
        self.title = self.title_font.render("High Scores", True, (0, 0, 0))

        self.sky = util.load_image("taivas")

        self.inputting = False
        self.input_score = -1

        if new_score > self.scores[9][1]:
            # print "It's a new high score!"
            self.inputting = True
            for i in range(10):
                if self.scores[i][1] < new_score:
                    self.input_score = i
                    for j in range(9 - i):
                        self.scores[9 - j] = self.scores[8 - j]
                    self.scores[i] = ["", new_score]
                    break