Esempio n. 1
0
 def __init__(self, runner, mainmenuState, rows, col):
     super().__init__(runner)
     self.mainmenuState = mainmenuState
     self.minesImage = pygame.image.load("assets/mine.png")
     self.openedImage = pygame.image.load("assets/opened.png")
     self.hiddenImage = pygame.image.load("assets/hidden.png")
     self.font = BitmapFont("assets/colorfont.png", 12, 12)
     self.rows = rows
     self.col = col
     self.endFlag = False
Esempio n. 2
0
def test2():
	e.init()
	fb_black.fill(WHITE)
	fb_red.fill(WHITE)
	fb_black.set_rotate(FrameBufferExtended.ROTATE_270)
	fb_red.set_rotate(FrameBufferExtended.ROTATE_270)
	MSG = 'It Works!'
	with BitmapFont(fb_black.width, fb_black.height, fb_black.set_pixel) as bfb:	
		with BitmapFont(fb_red.width, fb_red.height, fb_red.set_pixel) as bfr:	
			# message_width = bfb.width(MSG)   # Message width in pixels.
			bfb.text("It Works!",1,0,1)   
			bfr.text("Awesome, now we can have fun!",1,10,1)       
	
			e.display_frame(buf_b, buf_r)
Esempio n. 3
0
class InGame(GameState):
    def __init__(self, runner, mainmenuState, rows, col):
        super().__init__(runner)
        self.mainmenuState = mainmenuState
        self.minesImage = pygame.image.load("assets/mine.png")
        self.openedImage = pygame.image.load("assets/opened.png")
        self.hiddenImage = pygame.image.load("assets/hidden.png")
        self.font = BitmapFont("assets/colorfont.png", 12, 12)
        self.rows = rows
        self.col = col
        self.endFlag = False

    def on_enter(self, OptionMenuState):
        self.mines = OptionMenuState.mines
        self.board = Board(self.col, self.rows, self.mines)
        self.endFlag = False
        #self.board.openCell(5,5)

    def draw(self, surface):
        for i in range(self.rows):
            for j in range(self.col):
                x, y = j * 32, i * 32
                rect = Rect(x, y, 32, 32)
                currentCell = self.board.arr[j][i]
                if currentCell.state == game.CLOSED:
                    surface.blit(self.hiddenImage, rect)
                elif currentCell.blockType == game.MINES:
                    surface.blit(self.minesImage, rect)
                else:
                    surface.blit(self.openedImage, rect)
                    if currentCell.num > 0:
                        self.font.draw(surface, str(currentCell.num), x + 10,
                                       y + 10)

    def update(self, deltatime):
        if self.runner.mouseClick is not None and not self.endFlag:
            mouseX, mouseY = self.runner.mouseClick
            x = int(mouseX / 32)
            y = int(mouseY / 32)

            openCell = self.board.openCell(x, y)
            #print(openCell)
            if openCell != game.CONTINUE:
                self.endFlag = True
        elif self.endFlag:
            keys = pygame.key.get_pressed()
            if keys[K_ESCAPE]:
                self.runner.change_state(self.mainmenuState)
Esempio n. 4
0
def test6():
    e.init()
    fb_black.fill(WHITE)
    #fb_red.fill(WHITE)
    #fb_black.set_rotate(FrameBufferExtended.ROTATE_270)
    #fb_red.set_rotate(FrameBufferExtended.ROTATE_270)
    with BitmapFont(fb_black.width, fb_black.height,
                    fb_black.set_pixel) as bfb:
        bfb.text("ABCDEFGHIJKLMNOPQRSTUVWXYZ", 1, 0, BLACK)
        bfb.text("abcdefghijklmnopqrstuvwxyz", 1, 10, BLACK)
        bfb.text("0123456789.", 1, 20, 1)

        bfb.text_proportional("ABCDEFGHIJKLMNOPQRSTUVWXYZ", 1, 30, BLACK)
        bfb.text_proportional("abcdefghijklmnopqrstuvwxyz", 1, 40, BLACK)
        bfb.text_proportional("0123456789.", 1, 50, 1)

        mydisplay_frame(e, buf_b)
        time.sleep(1)
        fb_black.scroll(0, 5)
        mydisplay_frame(e, buf_b)
        fb_black.scroll(0, 5)
        mydisplay_frame(e, buf_b)
        fb_black.scroll(0, 5)
        mydisplay_frame(e, buf_b)
        fb_black.scroll(0, 5)
        mydisplay_frame(e, buf_b)
        fb_black.scroll(0, 5)
        mydisplay_frame(e, buf_b)
        fb_black.scroll(0, 5)
        mydisplay_frame(e, buf_b)
Esempio n. 5
0
def test3():
	""" Test char boundaries """
	e.init()
	fb_black.fill(WHITE)
	fb_black.set_rotate(FrameBufferExtended.ROTATE_270)
	with BitmapFont(fb_black.width, fb_black.height, fb_black.set_pixel) as bfb:	
		for c in ['A', '.', '-', ':', ' ']:
			print (c, '->',bfb.char_boundaries(c), bfb.char_width(c))   
Esempio n. 6
0
def test1():
	e.init()
	fb_black.fill(WHITE)
	fb_red.fill(WHITE)
	fb_black.set_rotate(FrameBufferExtended.ROTATE_270)
	fb_red.set_rotate(FrameBufferExtended.ROTATE_270)
	with BitmapFont(fb_black.width, fb_black.height, fb_black.set_pixel) as bfb:	
		with BitmapFont(fb_red.width, fb_red.height, fb_red.set_pixel) as bfr:	
			for i in range (6):
				for j in range(45):
					val = i * 45 + j 
					if val < 256:
						# print("print char", val)
						if i % 2:
							bfb.draw_char(chr(val),j * (bfb._font_width +1 ),i * (bfb._font_height +1),1)   
						else:
							bfr.draw_char(chr(val),j * (bfr._font_width +1 ),i * (bfr._font_height +1),1)   

	e.display_frame(buf_b, buf_r)
Esempio n. 7
0
 def __init__(self, name, width):
     self.name = name
     self.width = width
     pygame.init()
     pygame.display.set_caption(self.name)
     self.WINDOWS = pygame.display.set_mode((self.width, self.width))
     self.fpsClock = pygame.time.Clock()
     self.font = BitmapFont("fasttracker2-style_12x12.png", 12, 12)
     self.BLACK = pygame.Color(0,0,0)
     self.state = None
     self.mouseClick = None
Esempio n. 8
0
def test2():
    e.init()
    fb_black.fill(WHITE)
    #fb_red.fill(WHITE)
    #fb_black.set_rotate(FrameBufferExtended.ROTATE_270)
    #fb_red.set_rotate(FrameBufferExtended.ROTATE_270)
    MSG = 'It Works!'
    with BitmapFont(fb_black.width, fb_black.height,
                    fb_black.set_pixel) as bfb:
        bfb.text("It Works!", 1, 0, BLACK)
        bfb.text("Awesome, now we can have fun!", 1, 10, BLACK)
        mydisplay_frame(e, buf_b)
Esempio n. 9
0
def test5():
	e.init()
	fb_black.fill(WHITE)
	fb_red.fill(WHITE)
	fb_black.set_rotate(FrameBufferExtended.ROTATE_270)
	fb_red.set_rotate(FrameBufferExtended.ROTATE_270)
	y = 0
	with BitmapFont(fb_black.width, fb_black.height, fb_black.set_pixel) as bfb:	
		with BitmapFont(fb_red.width, fb_red.height, fb_red.set_pixel) as bfr:	
			bfr.text("Non Proportional font demo:",1,y,1); y += 8 + 1
			bfb.text("ABCDEFGHIJKLMNOPQRSTUVWXYZ",1,y,1); y += 8 + 1   
			bfb.text("abcdefghijklmnopqrstuvwxyz",1,y,1); y += 8 + 1       
			bfb.text("0123456789.",1,y,1); y += 8 + 1
			y += 8 + 1       
			
			bfr.text_proportional("Proportional font demo:",1,y,1); y += 8 + 1   
			bfb.text_proportional("ABCDEFGHIJKLMNOPQRSTUVWXYZ",1,y,1); y += 8 + 1   
			bfb.text_proportional("abcdefghijklmnopqrstuvwxyz",1,y,1); y += 8 + 1       
			bfb.text_proportional("0123456789.",1,y,1); y += 8 + 1       
	
			e.display_frame(buf_b, buf_r)
Esempio n. 10
0
	def toBitmapFont(self):
		bitmapfont = BitmapFont(fontinfo=self.fontinfo, outlineCfg=self.outlineCfg, generateBitmap=self.generateBitmap, glyphs=[])
		for glyphsrc in self.glyphsources:
			bitmapfont.appendGlyph(glyphsrc.toGlyph(bitmapfont))

		for gopts, effname, effargs in self.effects:
			for goptname, val in gopts:
				if goptname == "codepoint":
					glyphs = [bitmapfont.getGlyphByCodepoint(val)]
					if glyphs[0] is None:
						print("Warning: glyph to apply effect '{}' (U+{:04x}) was not found.".format(effname, val))
						continue
				elif goptname == "name":
					glyphs = [bitmapfont.getGlyphByName(val)]
					if glyphs[0] is None:
						print("Warning: glyph to apply effect '{}' (name='{}') was not found.".format(effname, val))
						continue
				elif goptname == "allglyphs":
					glyphs = bitmapfont.glyphs
				for glyph in glyphs:
					getattr(glyph.bitmap, effname)(*effargs)

		return bitmapfont
Esempio n. 11
0
def test4():
	e.init()
	fb_black.fill(WHITE); fb_red.fill(WHITE)

	fb_black.set_rotate(FrameBufferExtended.ROTATE_270)
	with BitmapFont(fb_black.width, fb_black.height, fb_black.set_pixel) as bfb:	
		MSG = "AA...-::ZBCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
		bfb.text(MSG,0,0,1)   		
		bfb.text_proportional(MSG,0,10,1) 
		MSG = 'The quick brown fox jumps over the lazy dog'  
		bfb.text(MSG,0,20,1)   		
		bfb.text_proportional(MSG,0,30,1) 

	e.display_frame(buf_b, buf_r)
Esempio n. 12
0
    window = pygame.display.set_mode((WIN_W, WIN_H), 0)

screen = pygame.Surface((SCR_W, SCR_H))

clock = pygame.time.Clock()

pygame.mixer.init(44100)
pygame.joystick.init()

for i in range(pygame.joystick.get_count()):
    pygame.joystick.Joystick(i).init()

pygame.mouse.set_visible(False)

font = BitmapFont('gfx/heimatfont.png',
                  scr_w=SCR_W,
                  scr_h=SCR_H,
                  colors=[(255, 255, 255), (240, 0, 240)])

level = [
    '                    ', '                    ', '    ############    ',
    '                    ', '                    ', '                    ',
    '#######      #######', '                    ', '                    ',
    '                    ', '####################'
]


def load_level(path):
    file = io.open(path, "r")
    lvl = file.read().splitlines()
    file.close()
Esempio n. 13
0
 def __init__(self, runner, mainmenuState):
     super().__init__(runner)
     self.mainmenuState = mainmenuState
     self.endFlag = False
     self.font = BitmapFont("fasttracker2-style_12x12.png", 12, 12)
     self.delayTime = 200
Esempio n. 14
0
class InGame(GameState):
    def __init__(self, runner, mainmenuState):
        super().__init__(runner)
        self.mainmenuState = mainmenuState
        self.endFlag = False
        self.font = BitmapFont("fasttracker2-style_12x12.png", 12, 12)
        self.delayTime = 200

    def on_enter(self, OptionMenuState):
        self.size = optionmenu.size
        self.useSolver = optionmenu.useSolver
        self.slidingPuzzle = SlidingPuzzle(self.size)
        self.endFlag = False
        self.slidingPuzzle.shuffle()
        self.slidingPuzzle.canbeSolved()
        if self.useSolver == "Yes":
            self.astar = AStar(self.slidingPuzzle)
            self.answer = self.astar.solved()
            self.i = 1

    def draw(self, surface):
        self.width = 600 / self.size
        for i in range(self.size):
            for j in range(self.size):
                x, y = j * self.width, i * self.width
                rect = Rect(x, y, self.width, self.width)
                pygame.draw.rect(surface, (100, 100, 100), rect, 3)
                currentCell = self.slidingPuzzle.arr[i][j]
                fontWidth = 12 * len(str(currentCell))
                self.font.draw(surface, str(currentCell),
                               x + ((self.width - fontWidth) / 2),
                               y + ((self.width - 12) / 2))

    def update(self, deltatime):
        keys = pygame.key.get_pressed()
        self.endFlag = self.slidingPuzzle.isSolved()
        if self.delayTime > 0:
            self.delayTime -= deltatime
        else:
            if keys[K_ESCAPE]:
                self.runner.change_state(self.mainmenuState)
                self.delayTime = 200
            if not self.endFlag:
                if self.useSolver == "No":
                    if keys[K_UP]:
                        self.slidingPuzzle.moves((0, -1))
                        self.delayTime = 200
                    if keys[K_LEFT]:
                        self.slidingPuzzle.moves((-1, 0))
                        self.delayTime = 200
                    if keys[K_DOWN]:
                        self.slidingPuzzle.moves((0, 1))
                        self.delayTime = 200
                    if keys[K_RIGHT]:
                        self.slidingPuzzle.moves((1, 0))
                        self.delayTime = 200
                else:
                    #print(self.answer)
                    if keys[K_n]:
                        if self.answer[self.i] is not None:
                            self.slidingPuzzle.moves(self.answer[self.i])
                        self.delayTime = 200
                        if self.i < len(self.answer) - 1:
                            self.i += 1
                    if keys[K_p]:
                        directionA = self.answer[self.i - 1]
                        if directionA is not None:
                            if directionA == (1, 0):
                                directionA = (-1, 0)
                            elif directionA == (-1, 0):
                                directionA = (1, 0)
                            elif directionA == (0, 1):
                                directionA = (0, -1)
                            elif directionA == (0, -1):
                                directionA = (0, 1)
                            self.slidingPuzzle.moves(directionA)
                        self.delayTime = 200
                        if self.i > 1:
                            self.i -= 1

        if self.runner.mouseClick is not None:
            mouseX, mouseY = self.runner.mouseClick

            if self.useSolver == "No":
                #distance from mousepress position to space position
                x = int(mouseX / self.width)
                y = int(mouseY / self.width)
                directionX = x - self.slidingPuzzle.space[0]
                directionY = y - self.slidingPuzzle.space[1]

                #make directionX into 1 or -1 and no diagonal
                if directionX > 0:
                    directionX = 1
                if directionX < 0:
                    directionX = -1
                if directionY > 0:
                    directionY = 1
                if directionY < 0:
                    directionY = -1
                for i in direction:
                    if (directionX, directionY) == i:
                        self.slidingPuzzle.moves((directionX, directionY))
                        break