Exemple #1
0
	def __init__(self, game ):
		self.game = game
		self.bubblePopSprites =  pygame.sprite.RenderPlain()

		# load game assets
		try:
			# images
			self.imgBackground = pygame.image.load( os.path.join('gfx', 'playfield.png') ).convert()
			self.imgPlayerAim = pygame.image.load( os.path.join('gfx', 'player_aim.png') ).convert_alpha()
			self.imgGameCompleted = pygame.image.load( os.path.join('gfx', 'completed.png') )
			self.imgGameOver = pygame.image.load( os.path.join('gfx', 'completed.png') )
			self.imgPowerBar = pygame.image.load( os.path.join('gfx', 'power_bar.png') ).convert_alpha()
			self.imgButtons = pygame.image.load( os.path.join('gfx', 'buttons.png') ).convert_alpha()

			# bubble assets are store in the playfield so each bubble does not have to load it separately
			self.imgPop = pygame.image.load( os.path.join('gfx', 'bubble16.png') ).convert_alpha()
			self.imgPlayer = pygame.image.load( os.path.join('gfx', 'player52.png') ).convert_alpha()
			self.imgBubble = pygame.image.load( os.path.join('gfx', 'bubble52.png') ).convert_alpha()

			# sound fx
			self.sfxPop = pygame.mixer.Sound( os.path.join('sfx', 'pop.ogg') )
			self.sfxBounce = pygame.mixer.Sound( os.path.join('sfx', 'ball.ogg') )
			self.sfxWallBounce = pygame.mixer.Sound( os.path.join('sfx', 'wall.ogg') )
			self.sfxComplete = pygame.mixer.Sound( os.path.join('sfx', 'complete.ogg') )
			self.sfxShoot = pygame.mixer.Sound( os.path.join('sfx', 'shoot.ogg') )
			self.sfxClick = pygame.mixer.Sound( os.path.join('sfx', 'click.ogg') )
			self.sfxBubble = pygame.mixer.Sound( os.path.join('sfx', 'bubble.ogg') )
			self.sfxGameOver = pygame.mixer.Sound( os.path.join('sfx', 'gameover.ogg') )

		except:
			self.game.fatalError(self.game.strings["error_game_assets"])

		# init power bar
		self.powerCounter = 0
		self.powerIncrement = POWER_BAR_SPEED
		self.rectPower = Rect(0 , 0 , 0 , 23)

		# pre-render game over & game completed popups
		text.drawText( self.imgGameCompleted, self.game.strings["well_done_1"],  self.imgGameCompleted.get_rect().centerx , 32  , 24 , COLOR_BLACK , 'freesansbold.ttf' , text.ALIGN_CENTER )
		text.drawText( self.imgGameCompleted, self.game.strings["well_done_2"],  self.imgGameCompleted.get_rect().centerx , 64  , 16 , COLOR_GAME_COMPLETED , 'freesansbold.ttf' , text.ALIGN_CENTER )
		text.drawText( self.imgGameCompleted, self.game.strings["well_done_3"],  self.imgGameCompleted.get_rect().centerx , 84  , 16 , COLOR_GAME_COMPLETED , 'freesansbold.ttf' , text.ALIGN_CENTER )

		text.drawText( self.imgGameOver, self.game.strings["game_over_1"],  self.imgGameOver.get_rect().centerx , 38 , 24 , COLOR_BLACK , 'freesansbold.ttf' , text.ALIGN_CENTER )
		text.drawText( self.imgGameOver, self.game.strings["game_over_2"],  self.imgGameOver.get_rect().centerx , 72 , 16 , COLOR_GAME_COMPLETED , 'freesansbold.ttf' , text.ALIGN_CENTER )

		self.gameCompletedRect = Rect(0, 0, SCREEN_WIDTH, 0 )   # this is used to animate ("popup") the game completed of game over box

		# setup restart button
		self.rectButtonRestart = Rect(9, 513, 102, 33)
		btn = button.Button(self.game, self.rectButtonRestart.topleft, self.imgButtons, Rect(0, 352, 102, 33), Rect(112, 352, 102, 33), self.btnRestart_Click, self.sfxClick )
		btn.setText(self.game.strings["restart"] ,  15 , COLOR_BUTTON_TEXT , 'freesansbold.ttf' )
		btn.setTextPosition(text.ALIGN_LEFT, 29, 2)
		self.game.buttonHandler.append(btn)

		# setup exit button
		self.rectButtonExit = Rect(9, 553, 102, 33)
		btn = button.Button(self.game, self.rectButtonExit.topleft, self.imgButtons, Rect(0, 400, 102, 33), Rect(112, 400, 102, 33), self.btnExit_Click, self.sfxClick )
		btn.setText(self.game.strings["exit"],  15, COLOR_BUTTON_TEXT, 'freesansbold.ttf' )
		btn.setTextPosition(text.ALIGN_LEFT, 29, 2)
		self.game.buttonHandler.append(btn)
Exemple #2
0
	def draw(self):
		self.game.screen.blit(self.sourceImage, self.destRect, self.sourceRect)
		if self.textString != "":
			x = self.destRect.centerx
			if self.textAlign == text.ALIGN_LEFT: x = self.destRect.left
			if self.textAlign == text.ALIGN_RIGHT: x = self.destRect.right
			text.drawText(self.game.screen, self.textString, x + self.textOffsetX, self.destRect.centery + self.textOffsetY, self.textSize, self.textColor, self.textFont, self.textAlign)
Exemple #3
0
def hide():
    mc.setBlocks(left, bottom, plane, left + WIDTH - 1, bottom + HEIGHT - 1,
                 plane, GLASS)
    text.drawText(mc,
                  FONTS['nicefontbold'],
                  Vec3(left + WIDTH // 2, bottom + 5, plane),
                  Vec3(1, 0, 0),
                  Vec3(0, 1, 0),
                  "P",
                  block.SEA_LANTERN,
                  align=text.ALIGN_CENTER)
Exemple #4
0
def text_to_block(word, colour):
    foreground = eval("block.WOOL_{}".format(colour.upper()))
    background = block.AIR

    mc = Minecraft()
    pos = mc.player.getTilePos()
    rot = mc.player.getRotation()
    rot_p = rot + 90
    forward = text.angleToTextDirectionCardinal(rot)
    perp = text.angleToTextDirectionCardinal(rot_p)

    text.drawText(mc, fonts.FONTS['8x8'], pos - forward * 20 - perp * 25,
                  forward, Vec3(0, 1, 0), word, foreground, background)
def updateText(buffer,x,y,s,align):
    newBuffer = {}
    if s is not None:
        text.drawText(mc, FONTS['thin9pt'], 
                        Vec3(x,y,plane), 
                        Vec3(1,0,0), Vec3(0,1,0), 
                        s, SEA_LANTERN, background=None, align=align, buffer=newBuffer)
    for pos in buffer:
        if pos not in newBuffer:
            mc.setBlock(pos, AIR)
    for pos in newBuffer:
        if pos not in buffer:
            mc.setBlock(pos, SEA_LANTERN)
    return newBuffer        
def updateText(buffer,x,y,s,align):
    newBuffer = {}
    if s is not None:
        text.drawText(mc, FONTS['thin9pt'], 
                        Vec3(x,y,plane), 
                        Vec3(1,0,0), Vec3(0,1,0), 
                        s, SEA_LANTERN, background=None, align=align, buffer=newBuffer)
    for pos in buffer:
        if pos not in newBuffer:
            mc.setBlock(pos, AIR)
    for pos in newBuffer:
        if pos not in buffer:
            mc.setBlock(pos, SEA_LANTERN)
    return newBuffer        
 def text(self,
          x,
          y,
          s,
          foreground=block.WOOL_BLACK,
          background=block.AIR,
          font="metrix7pt",
          center=False):
     text.drawText(self.fakeMC,
                   FONTS[font],
                   Vec3(x, 0, y),
                   Vec3(1, 0, 0),
                   Vec3(0, 0, 1),
                   s,
                   foreground=foreground,
                   background=background,
                   align=text.ALIGN_CENTER if center else text.ALIGN_LEFT)
Exemple #8
0
import datetime
import time

import fonts
import text
from mine import *

foreground = block.SEA_LANTERN
background = block.AIR

mc = Minecraft()
pos = mc.player.getTilePos()
forward = text.angleToTextDirection(mc.player.getRotation())

prevTime = ""

while True:
    curTime = datetime.datetime.now().strftime("%I:%M:%S %p")
    if curTime[0] == '0':
        curTime = ' ' + curTime[1:]
    if prevTime != curTime:
        for i in range(len(curTime)):
            if i >= len(prevTime) or prevTime[i] != curTime[i]:
                text.drawText(mc, fonts.FONTS['8x8'], pos + forward * (8 * i), forward, Vec3(0, 1, 0), curTime[i:],
                              foreground, background)
                break
        prevTime = curTime
    time.sleep(0.1)
foreground = block.SEA_LANTERN # this needs Minecraft 1.8
background = block.AIR

try:
    foreground = Block.byName(sys.argv[1])
except:
    pass

try:
    background = Block.byName(sys.argv[2])
except:
    pass

mc = Minecraft()
pos = mc.player.getTilePos()
forward = text.angleToTextDirection(mc.player.getRotation())

prevTime = ""

while True:
    curTime = datetime.datetime.now().strftime("%I:%M:%S %p")
    if curTime[0]=='0':
        curTime = ' ' + curTime[1:]
    if prevTime != curTime:
        for i in range(len(curTime)):
            if i >= len(prevTime) or prevTime[i] != curTime[i]:
                text.drawText(mc, fonts.FONTS['8x8'], pos + forward * (8*i), forward, Vec3(0,1,0), curTime[i:], foreground, background)
                break
        prevTime = curTime
    time.sleep(0.1)
Exemple #10
0
    (colors.DitheringMethod(rng=lambda: random.uniform(-10, 10)),
     'uniform 10'),
    (colors.DitheringMethod(rng=lambda: random.uniform(-20, 20)),
     'uniform 20'),
    (colors.DitheringMethod(rng=lambda: random.uniform(-40, 40)),
     'uniform 40'),
    (colors.DitheringMethod(rng=lambda: clamp(random.gauss(0, 10), -30, 30)),
     'gaussian 10/30'),
    (colors.DitheringMethod(rng=lambda: clamp(random.gauss(0, 20), -30, 30)),
     'gaussian 20/30')
]

x0 = pos.x

for dither, name in dithers:
    for (x, y, block) in colors.imageToBlocks(getPixel,
                                              width,
                                              height,
                                              dither=dither):
        mc.setBlock(x + x0, y + pos.y, pos.z, block)

    text.drawText(mc,
                  FONTS['thin9pt'],
                  Vec3(x0, pos.y + height + 1, pos.z),
                  Vec3(1, 0, 0),
                  Vec3(0, 1, 0),
                  name,
                  block.SEA_LANTERN,
                  background=None)
    x0 += width + 2
Exemple #11
0
	def draw(self):
		# draw backdrop & credits text at bottom
		self.game.screen.blit(self.imgTitleBG, (0, 0))
		text.drawText(self.game.screen, self.game.strings["credits"], SCREEN_WIDTH / 2, SCREEN_HEIGHT - 16, 13, (11, 85, 114), 'freesansbold.ttf', text.ALIGN_CENTER)
Exemple #12
0
	def draw(self):
		# draw backdrop
		self.game.screen.blit(self.imgBackground, (0, 0))

		# draw sprites
		for bub in self.game.bubbleSprites: bub.draw()
		for pop in self.bubblePopSprites: pop.draw()

		# draw player aim
		if self.game.player.speed == 0 and not self.game.gameCompleted and self.game.player.scaleCountIn == -1:
			for n in range(2,8):
				sin = math.sin( util.getAngle( self.game.player.rect.centerx , self.game.player.rect.centery , self.game.mouseX , self.game.mouseY ) )
				cos = math.cos( util.getAngle( self.game.player.rect.centerx , self.game.player.rect.centery , self.game.mouseX , self.game.mouseY ) )
				y = math.ceil( self.game.player.rect.centery + cos*(n*10 + 15) - 4 )
				x = math.ceil( self.game.player.rect.centerx + sin*(n*10 + 15) - 3 )
				self.game.screen.blit(self.imgPlayerAim, (x, y))

		# draw sidebar
		text.drawText(self.game.screen, str(self.game.gameGoal),  98, 155, 20, COLOR_SIDEBAR_TEXT , 'freesansbold.ttf', text.ALIGN_RIGHT)
		text.drawText(self.game.screen, self.game.gameOperator,  98, 217, 26, COLOR_SIDEBAR_TEXT, 'freesansbold.ttf' , text.ALIGN_RIGHT)
		text.drawText(self.game.screen, str(self.game.gameShots),  98, 283, 20, COLOR_SIDEBAR_TEXT, 'freesansbold.ttf' , text.ALIGN_RIGHT)
		self.game.screen.blit(self.imgPowerBar, (18, 322), self.rectPower)

		# draw sidebar text (drawing each text twice gives a nice bold look)
		for n in range(2): text.drawText(self.game.screen, self.game.strings["goal"], 16, 128, 11, COLOR_SIDEBAR_LABEL, 'freesansbold.ttf', text.ALIGN_LEFT)
		for n in range(2): text.drawText(self.game.screen, self.game.strings["operator"], 15, 192, 11, COLOR_SIDEBAR_LABEL, 'freesansbold.ttf', text.ALIGN_LEFT)
		for n in range(2): text.drawText(self.game.screen, self.game.strings["shots_left"], 16, 256, 11 , COLOR_SIDEBAR_LABEL, 'freesansbold.ttf', text.ALIGN_LEFT)
		for n in range(2): text.drawText(self.game.screen, self.game.strings["power"], 16, 320, 11, COLOR_SIDEBAR_LABEL, 'freesansbold.ttf', text.ALIGN_LEFT)

		# draw game completed overlay window
		if self.game.gameCompleted and self.game.player.speed < 2:
			if self.game.gameShots == 0 and self.game.bubblesLeft > 1:
				self.game.screen.blit(self.imgGameOver, (self.game.rectPlayfield.x + (self.game.rectPlayfield.height/2) -(self.imgGameOver.get_rect().width/2) , self.game.rectPlayfield.y + (self.game.rectPlayfield.height/2) - (self.imgGameOver.get_rect().height/2) ), self.gameCompletedRect)
			else:
				self.game.screen.blit(self.imgGameCompleted, (self.game.rectPlayfield.x + (self.game.rectPlayfield.height/2) -(self.imgGameCompleted.get_rect().width/2) , self.game.rectPlayfield.y + (self.game.rectPlayfield.height/2) - (self.imgGameCompleted.get_rect().height/2) ), self.gameCompletedRect)
Exemple #13
0
import fonts
import text
from mine import *

mc = Minecraft()
pos = mc.player.getTilePos()
forward = text.angleToTextDirection(mc.player.getRotation())

foreground = block.BEDROCK
background = block.AIR

text.drawText(mc, fonts.FONTS['bigfoot'], pos + forward, forward,
              Vec3(0, 1, 0), "EMIR", foreground, background)
# text.drawText(mc, fonts.FONTS['8x8'], pos + forward, forward, Vec3(0, 1, 0), "CEM", foreground, background)
def hide():
    mc.setBlocks(left, bottom, plane, left+WIDTH-1, bottom+HEIGHT-1, plane, GLASS)
    text.drawText(mc, FONTS['nicefontbold'], 
                    Vec3(left+WIDTH//2,bottom+5,plane), 
                    Vec3(1,0,0), Vec3(0,1,0), 
                    "P", SEA_LANTERN, align=text.ALIGN_CENTER)
Exemple #15
0
	def draw(self):
		# draw backdrop
		self.game.screen.blit(self.imgHelpBG, (0, 0))

		# draw headers
		text.drawText(self.game.screen, self.game.strings["help_header_1"], SCREEN_WIDTH / 2, 32, 28, COLOR_HELP_HEADER, 'freesansbold.ttf', text.ALIGN_CENTER)
		text.drawText(self.game.screen, self.game.strings["help_header_2"], SCREEN_WIDTH / 2, 64, 14, COLOR_HELP_HEADER, 'freesansbold.ttf', text.ALIGN_CENTER)

		# draw the help texts
		y = 200
		text.drawText(self.game.screen, self.game.strings["help_ball"]  , 120, y   , 15, COLOR_HELP_TEXT, 'freesansbold.ttf', text.ALIGN_CENTER)
		text.drawText(self.game.screen, self.game.strings["help_aim_1"] , 390, y   , 15, COLOR_HELP_TEXT, 'freesansbold.ttf', text.ALIGN_CENTER)
		text.drawText(self.game.screen, self.game.strings["help_aim_2"] , 390, y+20, 15, COLOR_HELP_TEXT, 'freesansbold.ttf', text.ALIGN_CENTER)
		text.drawText(self.game.screen, self.game.strings["help_aim_3"] , 390, y+40, 15, COLOR_HELP_TEXT, 'freesansbold.ttf', text.ALIGN_CENTER)
		text.drawText(self.game.screen, self.game.strings["help_bump_1"], 650, y   , 15, COLOR_HELP_TEXT, 'freesansbold.ttf', text.ALIGN_CENTER)
		text.drawText(self.game.screen, self.game.strings["help_bump_2"], 650, y+20, 15, COLOR_HELP_TEXT, 'freesansbold.ttf', text.ALIGN_CENTER)
		x, y = 400, 350
		text.drawText(self.game.screen, self.game.strings["help_main_1"], x, y      , 15, COLOR_HELP_TEXT, 'freesansbold.ttf', text.ALIGN_LEFT)
		text.drawText(self.game.screen, self.game.strings["help_main_2"], x, y + 20 , 15, COLOR_HELP_TEXT, 'freesansbold.ttf', text.ALIGN_LEFT)
		text.drawText(self.game.screen, self.game.strings["help_main_3"], x, y + 60 , 15, COLOR_HELP_TEXT, 'freesansbold.ttf', text.ALIGN_LEFT)
		text.drawText(self.game.screen, self.game.strings["help_main_4"], x, y + 80 , 15, COLOR_HELP_TEXT, 'freesansbold.ttf', text.ALIGN_LEFT)
		text.drawText(self.game.screen, self.game.strings["help_main_5"], x, y + 120, 15, COLOR_HELP_TEXT, 'freesansbold.ttf', text.ALIGN_LEFT)
		text.drawText(self.game.screen, self.game.strings["help_main_6"], x, y + 140, 15, COLOR_HELP_TEXT, 'freesansbold.ttf', text.ALIGN_LEFT)
		text.drawText(self.game.screen, self.game.strings["help_main_7"], x, y + 180, 15, COLOR_HELP_TEXT, 'freesansbold.ttf', text.ALIGN_LEFT)
		text.drawText(self.game.screen, self.game.strings["help_main_8"], x, y + 200, 15, COLOR_HELP_TEXT, 'freesansbold.ttf', text.ALIGN_LEFT)