Ejemplo n.º 1
0
	def furball(self, mission, seed=0):
		globalvars.disable_menu = True #Disable the standard menu for now.
		rd.seed(seed) #Fix the seed for the random number generator.
		wipeOldScenario(); resetDust()
		globalvars.BGIMAGE = image_list['bggalaxies'].convert()
		#Make a few enemies near the player
		mindist = 200
		maxdist = 800
		#Make enemy units:
		points_to_win = 3 #Same as the number of enemies
		for _ in xrange(points_to_win):
			x,y = getCoordsNearLoc(globalvars.player.rect.center, mindist, maxdist, maxdist)
			enemy_ship = hudHelpers.getNewEnemy(x,y,'destroyer',2,2,2,2,2)
			hudHelpers.addNewEnemyToWorld(enemy_ship)
		#Make the score keeper:
		time_limit = 30 #time limit in seconds
		text = ['FURBALL COMPLETED']
		#Display timer and score count with the following:
		globalvars.score_keeper = displayUtilities.TimeLimitDisplay(text, \
			points_to_win=points_to_win, time_limit=time_limit, mission=mission)
		globalvars.intangibles_top.add(globalvars.score_keeper)
		#Draw the new background and flip the whole screen.
		globalvars.screen.blit(globalvars.BGIMAGE, (0,0))
		pygame.display.flip()
		#Display the intro to the mission
		globalvars.menu.setBasicTextPanel(['You have '+str(time_limit)+' seconds to defeat 3 enemies to win.'])
Ejemplo n.º 2
0
def resetDust(use_top=False):
	#Kill all the old dust.
	for d in globalvars.intangibles_bottom:
		if d.is_a == globalvars.DUST:
			d.kill()
	for d in globalvars.intangibles_top:
		if d.is_a == globalvars.DUST:
			d.kill()
	#Make 50 dust particles scattered around the player.
	for _ in range(50):
		x,y = getCoordsNearLoc(globalvars.player.rect.center, 50, 
				globalvars.WIDTH, globalvars.WIDTH)
		temp = objInstances.Dust(x=x, y=y, width=1, height=1,\
				 color=colors.white)
		if use_top:
			globalvars.intangibles_top.add(temp)
		else:
			globalvars.intangibles_bottom.add(temp)
Ejemplo n.º 3
0
	def asteroids(self, mission, seed=0):
		''' '''
		globalvars.disable_menu = True #Disable the standard menu for now.
		rd.seed(seed) #Fix the seed for the random number generator.
		wipeOldScenario(); resetDust(use_top=True)
		rocks = ['bigrock','medrock','smallrock','gold','silver']
		#Reset the player's location to 0,0 and his speed to zero
		globalvars.player.loc = (0.0, 0.0)
		globalvars.player.speed = 0.0
		globalvars.player.targetSpeed = 0.0
		#Define an arena 2000 pixels across for the player and all the asteroids
		#to bounce around inside
		globalvars.arena = 1000 #1000 pixel radius centered at zero, zero.
		#Make the background color blue so that we can draw a black circle 
		#to show where the arena is located.
		globalvars.BGCOLOR = colors.blue
		#Draw a black circle and put it in intangibles to show the limits 
		#of the arena
		temp = objInstances.FixedCircle(x=0, y=0, radius=globalvars.arena, color=colors.black)
		globalvars.intangibles_bottom.add(temp)
		#Make 10 rocks centered around, but not on the player
		for _ in range(10):
			#Select a rock type
			rock = rocks[rd.randint(0, len(rocks)-1)]
			#Get the coordinates of the rock
			mindist = 200
			maxdist = 800
			x,y = getCoordsNearLoc(globalvars.player.rect.center, mindist, maxdist, maxdist)
			#Make the rock
			temp = objInstances.Asteroid(x=x, y=y, image_name=rock)
			globalvars.tangibles.add(temp); globalvars.whiskerables.add(temp)
		time_limit = 30 #time limit in seconds
		points_to_win = 50
		text = ['ASTEROIDS COMPLETED']
		#Display timer and score count with the following:
		globalvars.score_keeper = displayUtilities.TimeLimitDisplay(text, \
			points_to_win=points_to_win, time_limit=time_limit, mission=mission)
		globalvars.intangibles_top.add(globalvars.score_keeper)
		#Draw the new background and flip the whole screen.
		globalvars.screen.fill(globalvars.BGCOLOR)
		pygame.display.flip()
		#Display the intro to the mission
		globalvars.menu.setBasicTextPanel(['You have '+str(time_limit)+' seconds to collect '+str(points_to_win)+' points.', 'Blow up asteroids and collect gems to earn points.'])
Ejemplo n.º 4
0
def populateSpace(
    objects=None,
    width=1000,
    height=1000,
    center=(0, 0),
    seed=0.0,
    ship_tech=0,
    engine_tech=0,
    weapon_tech=0,
    missile_tech=0,
    mine_tech=0,
    fuel_depots=None,
    planets=None,
):
    """This is the first draft of a method to randomly populate space with objects.
	This is currently called by the racing minigame.
	Pre: objects is a dictionary containing natural numbers specifying how
	many of each of a variety of objects should be placed in the space.
	width is a nat specifying the width of the rectangle of space to be populated.
	height is a nat specifying the height.
	center is where the center of the rectangle should be positioned.
	Post: """
    # print 'TESTING populate '+str(width)+'x'+str(height)+' space centered at '+str(center)
    # Test variables START
    TESTING = False  # True #Turn on and off testing.
    area_covered = 0
    num_removed = 0
    # Test variables END

    rd.seed(seed)  # Fix the seed for the random number generator.

    # Populate space in a semi narrow corridor between the player and the finish line
    course_length = width / 2  # actually half length because getCoordsNearLoc doubles it
    course_height = height / 2  # actually half height because getCoordsNearLoc doubles it

    physical_objs = []

    # Make one NPC just headed for a warp point.
    x, y = geometry.getCoordsNearLoc(center, 0, course_length, course_height)
    # Generate a pirate ship with the node's level of tech
    temp = getNewEnemy(x, y, "destroyer", ship_tech, engine_tech, weapon_tech, missile_tech, mine_tech)
    temp.team = globalvars.team_manager.default_neutral_team
    temp.state = ship.GOTHRUWARP_STATE
    physical_objs.append(temp)

    for _ in xrange(objects["capital_ship"]):
        x, y = geometry.getCoordsNearLoc(center, 0, course_length, course_height)
        enemy_ship = getNewCapitalShip(x, y)
        physical_objs.append(enemy_ship)

    for _ in xrange(objects["enemy"]):
        x, y = geometry.getCoordsNearLoc(center, 0, course_length, course_height)
        # Generate a pirate ship with the node's level of tech
        temp = getNewEnemy(x, y, "destroyer", ship_tech, engine_tech, weapon_tech, missile_tech, mine_tech)
        physical_objs.append(temp)

    for _ in xrange(objects["crystal"]):
        x, y = geometry.getCoordsNearLoc(center, 0, course_length, course_height)
        physical_objs.append(objInstances.Gem(x=x, y=y, speed_min=0.0, speed_max=0.0))

    for _ in xrange(objects["large_asteroid"]):
        x, y = geometry.getCoordsNearLoc(center, 0, course_length, course_height)
        physical_objs.append(objInstances.Asteroid(x=x, y=y, speed_min=0.0, speed_max=0.0, image_name="bigrock"))

    for _ in xrange(objects["medium_asteroid"]):
        x, y = geometry.getCoordsNearLoc(center, 0, course_length, course_height)
        physical_objs.append(objInstances.Asteroid(x=x, y=y, speed_min=0.0, speed_max=0.0, image_name="medrock"))

    for _ in xrange(objects["small_asteroid"]):
        x, y = geometry.getCoordsNearLoc(center, 0, course_length, course_height)
        physical_objs.append(objInstances.Asteroid(x=x, y=y, speed_min=0.0, speed_max=0.0, image_name="smallrock"))

    for _ in xrange(objects["gold_metal"]):
        x, y = geometry.getCoordsNearLoc(center, 0, course_length, course_height)
        physical_objs.append(objInstances.Asteroid(x=x, y=y, speed_min=0.0, speed_max=0.0, image_name="gold"))

    for _ in xrange(objects["silver_metal"]):
        x, y = geometry.getCoordsNearLoc(center, 0, course_length, course_height)
        physical_objs.append(objInstances.Asteroid(x=x, y=y, speed_min=0.0, speed_max=0.0, image_name="silver"))

    for _ in xrange(objects["health"]):
        x, y = geometry.getCoordsNearLoc(center, 0, course_length, course_height)
        physical_objs.append(objInstances.HealthKit(x, y))

    if not fuel_depots is None:
        for f in fuel_depots:
            physical_objs.append(f)

    if not planets is None:
        for p in planets:
            physical_objs.append(p)

            # Prevent collisions.
    nudgeApart(physical_objs)

    # Put everything in tangibles and whiskerables unless they collide with any tangibles.
    toreturn = pygame.sprite.Group()
    for p in physical_objs:
        temp = pygame.sprite.spritecollideany(p, globalvars.tangibles)
        # print temp
        if temp is None:
            if TESTING:
                area_covered += math.pi * p.collisionradius ** 2
            # Set the ship's health bar. This must be done right
            # before adding any ship to tangibles
            # It cannot be done earlier in this method because a ship
            # might collide with an object and not be added, but setHealthBar
            # puts the health bar in intangibles so the health bar ends up
            # floating in space with no one to ever remove it.
            if p.is_a == globalvars.SHIP or p.is_a == globalvars.CAPITALSHIP:
                addNewEnemyToWorld(p, add_to_team=p.team)
            else:
                globalvars.tangibles.add(p)
                globalvars.whiskerables.add(p)
            toreturn.add(p)
        else:
            if TESTING:
                num_removed += 1

            # Print testing feedback
    if TESTING:
        print "Area covered: " + str(area_covered)
        temp = course_length * 2 * course_height * 2
        print "compared to the total area " + str(temp)
        print "fraction of area covered " + str(area_covered / temp)
        print "Objects removed: " + str(num_removed)
        print "from a total of " + str(sum(objects)) + " objects."
        print "Fraction of objects removed: " + str(float(num_removed) / float(sum(objects)))
    return toreturn
Ejemplo n.º 5
0
	def update(self):
		self.countdown -= 1
		globalvars.player.destination = self.player_destination
		if self.countdown < 0:
			#reset countdown
			self.countdown = globalvars.FPS*5
			#Transition to next phase
			if self.phase == 0:
				#Puts in dust and gives player ship motion.
				resetDust()
				globalvars.player.theta = 0.0
				globalvars.player.speed = 10.0
				globalvars.player.targetSpeed = 10.0
				self.phase += 1
			elif self.phase == 1:
				#puts in rocks at fixed places.
				numbers = dict()
				numbers['enemy'] = 0
				numbers['crystal'] = 5
				numbers['large_asteroid'] = 20
				numbers['medium_asteroid'] = 30
				numbers['small_asteroid'] = 40
				numbers['gold_metal'] = 5
				numbers['silver_metal'] = 6
				numbers['health'] = 7
				numbers['capital_ship'] = 0
				#Populate space in a semi narrow corridor between the player and the finish line
				course_length = 8000 #pixels
				course_height = 1000 #pixels
				#Midway between player and destination
				midway = (course_length/2, 0)
				hudHelpers.populateSpace(objects=numbers,\
					width=course_length, \
					height=course_height,\
					center=globalvars.player.rect.center,\
					seed=0)
				self.phase += 1
			elif self.phase == 2:
				#puts in ships at fixed places.
				#puts in rocks at fixed places.
				numbers = dict()
				numbers['enemy'] = 10
				numbers['crystal'] = 0
				numbers['large_asteroid'] = 0
				numbers['medium_asteroid'] = 0
				numbers['small_asteroid'] = 0
				numbers['gold_metal'] = 0
				numbers['silver_metal'] = 0
				numbers['health'] = 0
				numbers['capital_ship'] = 1
				#Populate space in a semi narrow corridor between the player and the finish line
				course_length = 8000 #pixels
				course_height = 1000 #pixels
				#Midway between player and destination
				midway = (course_length/2, 0)
				hudHelpers.populateSpace(objects=numbers,\
					width=course_length, \
					height=course_height,\
					center=globalvars.player.rect.center,\
					seed=0)
				self.phase += 1
			elif self.phase == 3:
				#clears all sprite groups again.
				wipeOldScenario()
				#Add self back in
				globalvars.intangibles_bottom.add(self)
				#Draw the new background and flip the whole screen.
				globalvars.screen.fill(globalvars.BGCOLOR)
				pygame.display.flip()
				resetDust()
				#5 seconds of lots of explosions everywhere.
				self.phase += 1
			elif self.phase == 4:
				#prints graphical data straight to file.
				if sys.platform != 'darwin': #This is not working on my mac for some reason
					import matplotlib.pyplot as plt
					plt.plot(globalvars.dirty_rect_size)
					plt.xlabel('Frames')
					plt.ylabel('Number of dirty rects')
					plt.savefig('profiling/dirty_rect_size.jpeg') #plt.show()
					plt.clf()
					plt.plot(globalvars.time_lapses, 'ro')
					plt.xlabel('Frames')
					plt.ylabel('Tick length')
					plt.savefig('profiling/tick_lengths.jpeg') #plt.show()
					plt.clf()
				exit()
		if self.phase == 4:
			x,y = getCoordsNearLoc(globalvars.player.rect.center, 50, 
				globalvars.WIDTH, globalvars.WIDTH)
			globalvars.intangibles_top.add(objInstances.Explosion(x=x,y=y))
Ejemplo n.º 6
0
	def __init__(self, myid, x, y):
		''' '''
		self.id = myid
		self.x = x
		self.y = y
		self.loc = (x,y)
		#list of id,location pairs this node is connected to
		self.connections = []

		#Parameters for the faction (if any) that owns this node:
		self.owner = -1 #Id of the faction that owns this node.
		self.flag = ''
		#The following arrays determine how many items of the given tech level 
		#are produced at this node per turn.
		#For example, if self.ship_production[4] = 2 then 2 class 4 ships will be produced.
		self.ship_production = [0 for _ in range(len(ship.ship_class_names))]
		self.engine_production = [0 for _ in range(len(ship.engine.engine_class_names))]
		self.weapon_production = [0 for _ in range(len(ship.weapon.weapon_class_names))]
		self.missile_production = [0 for _ in range(len(ship.missile.missile_class_names))]
		self.mine_production = [0 for _ in range(len(ship.mine.mine_class_names))]
		#How many of these tech items are at this node.
		#Production values are added into this array each turn.
		self.ship_tech = [0 for _ in range(len(ship.ship_class_names))]
		self.engine_tech = [0 for _ in range(len(ship.engine.engine_class_names))]
		self.weapon_tech = [0 for _ in range(len(ship.weapon.weapon_class_names))]
		self.missile_tech = [0 for _ in range(len(ship.missile.missile_class_names))]
		self.mine_tech = [0 for _ in range(len(ship.mine.mine_class_names))]

		#Parameters to distinguish nodes by parameterizing the infinite space generator.
		#Randomly initialize these for now:
		rd.seed(self.id)
		self.description = 'Unknown'
		self.piracy = rd.uniform(0.0, 4.0) #chance to generate pirate ships
		self.pirate_caps = rd.uniform(0.0, 1.2) #chance of generating pirate capital ships
		self.amt_debris = rd.uniform(3.0, 15.0) #chance of asteroids
		self.amt_wealth = rd.uniform(0.5, 3.0) #chance of gems, health, and rich asteroids
		#The class of pirate ships generated at this node.
		self.pirate_weapon_tech = rd.randint(0, len(ship.weapon.weapon_class_names) / 2)
		self.pirate_missile_tech = rd.randint(0, len(ship.missile.missile_class_names) / 2)
		self.pirate_mine_tech = rd.randint(0, len(ship.mine.mine_class_names) / 2)
		self.pirate_ship_tech = rd.randint(0, len(ship.ship_class_names) / 2)
		self.pirate_engine_tech = rd.randint(0, len(ship.engine.engine_class_names) / 2)

		#Nodes will store the references to the following objects at their location
		self.warps=[]
		self.planets=[]
		self.fuel_depots=[]

		#For now make 2 planets and 2 fuel stops at each node within a 4000 pixel radius of the node center
		num_to_make = 2
		mindist = 500
		radius = 4000
		for _ in range(num_to_make):
			x,y = getCoordsNearLoc(self.loc, mindist, radius, radius)
			self.planets.append(objInstances.Planet(x, y))
		for _ in range(num_to_make):
			x,y = getCoordsNearLoc(self.loc, mindist, radius, radius)
			self.fuel_depots.append(objInstances.GasStation(x, y))

		#Objects that can appear in space around this node
		self.obstacles = dict()
		self.obstacles['enemy'] = 0
		self.obstacles['crystal'] = 0
		self.obstacles['large_asteroid'] = 0
		self.obstacles['medium_asteroid'] = 0
		self.obstacles['small_asteroid'] = 0
		self.obstacles['gold_metal'] = 0
		self.obstacles['silver_metal'] = 0
		self.obstacles['health'] = 0
		self.obstacles['capital_ship'] = 0

		#Now initialize the values to be used to populate space based on the above values.
		self.initialize()