Exemple #1
0
	def __init__(self, width=1200, height=675):

		pg.init()
		pg.mixer.init()
		self.width = width
		self.height = height
		self.screen = pg.display.set_mode((self.width, self.height))
		pg.display.set_caption("Tanks")
		pg.display.update() 
		self.background = u.loadImage("myBackground.png")[0]#pg.Surface(self.screen.get_size()).convert()
		self.screen.blit(self.background, (0, 0))
		self.wall = u.loadImage("myWall.png")
		self.screen.blit(self.wall[0],(600,375))
		self.tank1 = tank.Tank(10, u.GROUND, "myTank.png", "myShootyThing45.png",1)
		self.screen.blit(self.tank1.image, (100, 577))
		self.screen.blit(self.tank1.shootyThingImage, (0, 0))
		self.tank2 = tank.Tank(-10, u.GROUND, "myTank2.png", "myShootyThing2_45.png",2)
		self.screen.blit(self.tank2.image, (1100, 577))
		self.screen.blit(self.tank2.shootyThingImage, (0, 0))
		self.spritegroup = pg.sprite.Group()
		self.smallfont = pg.font.SysFont("comicsansms",25)
		self.medfont = pg.font.SysFont("comicsansms",50)
		self.largefont = pg.font.SysFont("comicsansms",80)
		self.music = u.loadMusic("IntroMusic.mp3")		
		#self.icon = pg.image.load('myTank.png')
		pg.sprite.RenderPlain()
		pg.display.flip()
		#pg.display.set_icon(self.icon)#best size is 32*32
		self.clock = pg.time.Clock()
		self.buttong = pg.draw.rect(self.screen,u.GREEN,(100,500,100,50))
		self.buttony = pg.draw.rect(self.screen,u.YELLOW,(300,500,100,50))
		self.buttonr = pg.draw.rect(self.screen,u.RED,(500,500,100,50))
Exemple #2
0
	def angle(self, direction, the_angle):      
		if direction == pg.K_UP:
			the_angle += 1
			for i in u.ANGLE_DICTIONARY_2.keys():
				diff = the_angle - i
				if i == the_angle or (diff <= 4 and diff > 0):
					self.shootyThingImage = u.loadImage(u.ANGLE_DICTIONARY_2.get(i))
			return the_angle
		if direction == pg.K_w:
			the_angle += 1
			for i in u.ANGLE_DICTIONARY.keys():
				diff = the_angle - i
				if i == the_angle or (diff <= 4 and diff > 0):
					self.shootyThingImage = u.loadImage(u.ANGLE_DICTIONARY.get(i))
			return the_angle
		if direction == pg.K_DOWN:
			the_angle += 1
			for i in u.ANGLE_DICTIONARY_2.keys():
				diff = the_angle - i
				if i == the_angle or (diff <= 4 and diff > 0):
					self.shootyThingImage = u.loadImage(u.ANGLE_DICTIONARY_2.get(i))
			return the_angle
		if direction == pg.K_s:
			the_angle += 1
			for i in u.ANGLE_DICTIONARY.keys():
				diff = the_angle - i
				if i == the_angle or (diff <= 4 and diff > 0):
					self.shootyThingImage = u.loadImage(u.ANGLE_DICTIONARY.get(i))
			return the_angle
		return the_angle
Exemple #3
0
 def __init__(self, surface, target, lifeTimer = -1):
     actor.Actor.__init__(self)
     
     self.surface = surface
     self.surfaceRect = self.surface.get_rect()
     self.mounted = False
     self.target = target
     self.image = None
     self.balloonPointerDown = utility.loadImage("balloonPointerDown")
     self.balloonPointerUp = utility.loadImage("balloonPointerUp")
     self.balloonPointerDirection = "Down"
     self.rect = None
     self.velocity = vector.vector2d.zero
     self.bounds = [0,0,SCREEN_WIDTH,SCREEN_HEIGHT]
     self.boundStyle = BOUND_STYLE_CUSTOM
     self.offSet = vector.vector2d.zero
     
     self.lifeTimer = lifeTimer
     
     try:
         self.position = target.position + self.offSet
         self.mounted = True
     except:#This would cause an error, position isn't defined any where
         self.position = position + self.offSet
     
     self.createBubble()
     self.update()
Exemple #4
0
    def __init__(self, width=1200, height=675):

        pg.init()
        pg.mixer.init()
        self.width = width
        self.height = height
        self.screen = pg.display.set_mode((self.width, self.height))
        pg.display.set_caption("Tanks")
        pg.display.update()
        self.background = u.loadImage("myBackground.png")[
            0]  #pg.Surface(self.screen.get_size()).convert()
        self.screen.blit(self.background, (0, 0))
        self.wall = u.loadImage("theBarrierReal.jpg")[0]
        self.screen.blit(self.wall, (600, 0))
        self.tank1 = tank.Tank(10, u.GROUND, "myTank.png",
                               "myShootyThing45.png", 1, 1)
        self.screen.blit(self.tank1.image, (100, 577))
        self.screen.blit(self.tank1.shootyThingImage, (0, 0))
        #self.tank2 = tank.Tank(-10, u.GROUND, "myTank2.py", "myShootyThing2_45.png",2, 1)
        self.tank2 = tank.Tank(-10, u.GROUND, "trumpsan.png",
                               "myShootyThing2_45.png", 2, 3)
        self.screen.blit(self.tank2.image, (1100, 577))
        #self.screen.blit(self.tank2.shootyThingImage, (0, 0))
        self.spritegroup = pg.sprite.Group()
        self.smallfont = pg.font.SysFont("japan", 25)
        self.medfont = pg.font.SysFont("japan", 50)
        self.largefont = pg.font.SysFont("electron", 80)
        #self.music = u.loadMusic("IntroMusic.mp3")
        self.music = u.loadMusic("RealGameMusic.mp3")
        pg.sprite.RenderPlain()
        pg.display.flip()
        self.clock = pg.time.Clock()
        self.buttong = pg.draw.rect(self.screen, u.GREEN, (100, 500, 100, 50))
        self.buttony = pg.draw.rect(self.screen, u.YELLOW, (300, 500, 100, 50))
        self.buttonr = pg.draw.rect(self.screen, u.RED, (500, 500, 100, 50))
    def __init__(self):
        self.gameStillOver = True

        largefont = pygame.font.SysFont("comicsansms", 50)
        self.gameOverText = largefont.render("GAME OVER", True, BLACK)

        self.quitImageRect = (utility.loadImage("quit.png", 420, 250))[1]
        self.quitImage = (utility.loadImage("quit.png", 420, 250))[0]

        self.restartImageRect = (utility.loadImage("restart.png", 320, 250))[1]
        self.restartImage = (utility.loadImage("restart.png", 320, 250))[0]
Exemple #6
0
	def __init__(self, x, y, tankImg, shootyThingImg,tankNum):
		self.image, self.rect = u.loadImage(tankImg)
		self.shootyThingImage, self.shootyThingRect = u.loadImage(shootyThingImg)
		if tankNum == 1:		
			self.rect.x = 100
			self.shootyThingRect.x = self.rect.x + 175
		elif tankNum == 2:
			self.rect.x = 971
			self.shootyThingRect.x = self.rect.x + 175
		
		self.rect.y = u.GROUND
		self.shootyThingRect.y = u.GROUND + 60
		pg.sprite.Sprite.__init__(self)
		self.tankSpeed = 2
		self.health = 50
Exemple #7
0
 def loadSpriteFromXML(self, xmlpath, spriteName):
     #Set default variables
     imgDict = {}
     defaultState = False
     collisionRect = pygame.rect.Rect(0,0,0,0)
     #Load and parse XML
     document = minidom.parse(xmlpath)
     baseDir = document.documentElement.getAttribute('filedirectory')
     spriteNode = xpath.Evaluate('sprite[@name="'+spriteName+'"]',document.documentElement)
     if not spriteNode:
         return TypeError, 'No such sprite name in document.'
     spriteNode = spriteNode[0]
     spriteDir = spriteNode.getAttribute('filedirectory')
     collisionRect.width = int(spriteNode.getAttribute('rectwidth'))
     collisionRect.height = int(spriteNode.getAttribute('rectheight'))
     for stateNode in xpath.Evaluate('state',spriteNode):
         stateNodeName = stateNode.getAttribute('name')
         imgDict[stateNodeName] = []
         if xpath.Evaluate('@default',stateNode):
             defaultState = stateNodeName
         for imageNode in xpath.Evaluate('image',stateNode):
             iDict = {}
             iDict['img'] = utility.loadImage(imageNode.getAttribute('filename'),[baseDir,spriteDir],-1)
             iDict['frames'] = int(imageNode.getAttribute('frames'))
             iDict['offset'] = (int(imageNode.getAttribute('offsetx')),int(imageNode.getAttribute('offsety')))
             imgDict[stateNodeName].append(iDict)
     return (imgDict, defaultState, collisionRect)
Exemple #8
0
 def __init__(self, image, minmax, conversationList, group = ()):
     self.__conversationList = conversationList
     #for collision detection, no longer necessary when Sean completes his new version
     self.type = 9
     #for use in the network manager
     self.radix = 0
     self.stop = 0
     self.wait = 0
     self.rest = 0
     self.talking = 0
     #begin common init function with player
     image = utility.loadImage(image)
     rect = image.get_rect()
     savePos = (rect.centerx,rect.bottom)
     rect.width = 50
     rect.height = 50
     rect.centerx = savePos[0]
     rect.bottom = savePos[1]
     state = 'default'
     min = minmax[0]
     max = minmax[1]
     xmax = 50*(-1*min[0]+max[0])
     ymax = 50*(-1*min[1]+max[1])
     rect.topleft = (random.randint(0,xmax), random.randint(0,ymax))
     imgdict = {state:[{'img':image,'frames':1,'offset':(0,0)}]}
     TopDownSprite.__init__(self, imgdict, rect, state, group)
Exemple #9
0
 def __init__(self, x, y, direction, bulletImg):
     pg.sprite.Sprite.__init__(self)
     self.bulletImage, self.rect = u.loadImage(bulletImg)
     self.rect.x = x + 75
     self.rect.y = y
     self.bulletXSpeed = 5 * direction
     self.bulletYSpeed = -5
     self.bulletMaxY = 0
Exemple #10
0
 def __init__(self, x, y, direction, bulletImg):
     pg.sprite.Sprite.__init__(self)
     self.bulletImage, self.rect = u.loadImage(bulletImg)
     self.vel = 50
     self.grav = 10
     self.rect.x = x + 75
     self.rect.y = y
     self.bulletXSpeed = 1.5 * direction
     self.bulletYSpeed = 3.5
     self.direct = 1
     self.YIncr = 1
Exemple #11
0
 def buildAnimation(self, sequenceID, frames):
     self.sequenceDict[sequenceID] = []
     if not self.currentSequence:
         self.currentSequence = sequenceID
     try:
         for frame in frames:
             try:
                 self.sequenceDict[sequenceID].append(self.frameDict[frame])
                 
             except:
                 self.frameDict[frame] = (utility.loadImage(frame))
                 self.sequenceDict[sequenceID].append(self.frameDict[frame])
     except:
         try:
             self.sequenceDict[sequenceID].append(self.frameDict[frames])
         except:
             self.frameDict[frames] = (utility.loadImage(frames))
             self.sequenceDict[sequenceID].append(self.frameDict[frames])
             
     self.image = self.sequenceDict[self.currentSequence][self.currentFrame]
     
Exemple #12
0
 def __init__(self, screen, background):
     self.screen = screen
     self.background = background
     self.result = None
     self.running = 0
     self.background.fill((255, 255, 255))
     self.welcome = utility.loadImage('welcome.bmp')
     self.choices = []
     #newgame must be first and quit must be last
     self.choices.append(utility.drawText('New Game', 50, (0,255,0), self.screen, (327,300)))
     self.choices.append(utility.drawText('Save Game', 50, (0,255,0), self.screen, (325,350)))
     self.choices.append(utility.drawText('Load Game', 50, (0,0,0), self.screen, (320,400)))
     self.choices.append(utility.drawText('Options', 50, (0,0,0), self.screen, (347,450)))
     self.choices.append(utility.drawText('Credits', 50, (0,0,0), self.screen, (354,500)))
     self.choices.append(utility.drawText('Quit', 50, (0,0,0), self.screen, (375,550)))
Exemple #13
0
def loadData():
    BossTut.music = utility.loadSound("bossMusic")
    BossTut.bulletSound = utility.loadSound("baakeHit")
    BossTut.hurtSound = utility.loadSound("hurtBoss")
    BossTut.howToKill = utility.loadImage("howToBoss1")
    BossTut.MasterAnimationList.buildAnimation("idle", ["boss1"])
    BossTut.MasterAnimationList.buildAnimation("hurt", ["boss1","boss1","boss1_1","boss1_1"])

    BaakeBoss.music = utility.loadSound("bossMusic")
    BaakeBoss.bulletSound = utility.loadSound("baakeHit")
    BaakeBoss.hurtSound = utility.loadSound("hurtBoss")
    BaakeBoss.howToKill = utility.loadImage("howToBoss1")
    BaakeBoss.MasterAnimationList.buildAnimation("idle", ["boss0"])
    BaakeBoss.MasterAnimationList.buildAnimation("hurt", ["boss0","boss0","boss0_1","boss0_1"])
    
    MoonoBoss.music = utility.loadSound("bossMusic")
    MoonoBoss.bulletSound = utility.loadSound("baakeHit")
    MoonoBoss.hurtSound = utility.loadSound("hurtBoss")
    MoonoBoss.shieldBreak = utility.loadSound("shieldBreak")
    MoonoBoss.shieldRestore = utility.loadSound("shieldRestore")
    MoonoBoss.howToKill = utility.loadImage("howToBoss3")
    MoonoBoss.MasterAnimationList.buildAnimation("idle", ["boss2idle_0","boss2idle_1","boss2idle_2","boss2idle_3","boss2idle_4","boss2idle_5","boss2idle_0","boss2idle_0","boss2idle_0","boss2idle_0","boss2idle_0","boss2idle_0","boss2idle_0","boss2idle_0","boss2idle_0","boss2idle_0","boss2idle_0","boss2idle_0","boss2idle_0","boss2idle_0","boss2idle_0","boss2idle_0","boss2idle_0","boss2idle_0","boss2idle_0","boss2idle_0","boss2idle_0","boss2idle_0","boss2idle_0","boss2idle_0","boss2idle_0","boss2idle_0","boss2idle_0","boss2idle_0","boss2idle_0","boss2idle_0","boss2idle_0","boss2idle_0","boss2idle_0","boss2idle_0","boss2idle_0","boss2idle_0","boss2idle_0","boss2idle_0","boss2idle_0","boss2idle_0","boss2idle_0","boss2idle_0","boss2idle_0","boss2idle_0","boss2idle_0","boss2idle_0","boss2idle_0","boss2idle_0","boss2idle_0","boss2idle_0","boss2idle_0","boss2idle_0","boss2idle_0","boss2idle_0","boss2idle_0","boss2idle_0","boss2idle_0","boss2idle_0","boss2idle_0","boss2idle_0"])
    MoonoBoss.MasterAnimationList.buildAnimation("vulnerable", ["boss2v"])
    MoonoBoss.MasterAnimationList.buildAnimation("hurt", ["boss2_1"])
Exemple #14
0
 def credits(self):
     credits = utility.loadImage('credits.bmp')
     self.screen.blit(credits, (0, 0))
     pygame.display.flip()
     keystates = {}
     while 1:
         for event in pygame.event.get():
             if event.type == pygame.locals.KEYDOWN:
                 keystates[event.key] = True
                 continue
             elif event.type == pygame.locals.KEYUP:
                 keystates[event.key] = False
                 continue
         if keystates.has_key(pygame.locals.K_RETURN) and keystates[pygame.locals.K_RETURN]:
             return
     return
Exemple #15
0
 def __init__(self, lead_x, lead_y):
     pygame.sprite.Sprite.__init__(self)
     self.image, self.rect = utility.loadImage("cactus.png", lead_x, lead_y,
                                               None)
     self.tooClose = False
 def __init__(self, lead_x, lead_y):
     pygame.sprite.Sprite.__init__(self)
     self.image, self.rect = utility.loadImage("cloud.png", lead_x, lead_y,
                                               None)
Exemple #17
0
from settings import *
from pygame.locals import *

pygame.init()

from utility import *

readSettings()

if settingList[SETTING_FULLSCREEN]:
    screen = utility.setFullscreen()
else:
    screen = utility.setFullscreen(False)
    
pygame.display.set_icon(utility.loadImage("icon"))
pygame.display.set_caption("Trouble In CloudLand v1.1")

screen.fill([0,0,0])
tempText = text.Text(FONT_PATH, 36, [255,255,255])
tempText.setText("Loading...")
tempText.position = vector.vector2d((SCREEN_WIDTH / 2) - (tempText.image.get_width() / 2), (SCREEN_HEIGHT / 2) - (tempText.image.get_height() / 2))
tempText.update()
tempText.draw(screen)
pygame.display.flip()

try:
    pygame.mixer.set_reserved(MUSIC_CHANNEL)
    pygame.mixer.Channel(MUSIC_CHANNEL).set_volume(1)
    
    pygame.mixer.set_reserved(PLAYER_CHANNEL)