Ejemplo n.º 1
0
	def __init__(self, location):
		pygame.sprite.Sprite.__init__(self)	
		self.bomb = load_image("Images\TNT-unlit.png")
		self.bomb_loop = []
		for i in range(1,6):
			self.bomb_loop.append(load_image("Images/TNT-frames/TNT-" + str(10000 + i)[1:] + ".png"))
			
		self.no_image = pygame.Surface((1,1), pygame.SRCALPHA, 32)
		self.no_image.fill(0)
		self.image = self.bomb
		self.frame_ID = 0
		
		self.rect = self.image.get_rect()
		self.rect.center = location
		self.start_location = location
		
		self.carried = False
		self.interacting_timer = 0
		self.player = ""
		self.boom_time = 1500
		self.boom_sfx = Play_Music("//sfx//bomb-explode.ogg", -1)
		self.hiss_sfx = Play_Music("//sfx//hiss-fuse.ogg", -1)
		
		self.y_speed = 0
		self.x_speed = 0
		self.jumping = False
		
		self.type = "bomb"
		self.active = False
		
		self.live = False
		self.countdown = 0
		
		self.frame_ID = 0
Ejemplo n.º 2
0
	def __init__(self, ID):
		pygame.sprite.Sprite.__init__(self)		
		
		self.image = load_image("Images" + "\Players\\" + str(ID) + "\Idle/idle-0001.png")
		self.rect = self.image.get_rect()
		self.rect.center = (400.0, 500.0)
		
		self.reset = False
		
		self.hit_image = load_image("Images" + "\Players\\" + str(ID) + "/hit.png")
		self.hit_rect = self.hit_image.get_rect()
		self.hit_rect.center = self.rect.center
		
		self.land_rect = self.hit_image.get_rect()
		if ID != 2:
			self.land_image = load_image("Images\\Players\\1\\player_land.png")
			self.land_rect = self.land_image.get_rect()
			self.land_rect.center = self.rect.center
			
		self.x_direction = 0
		self.prev_x = 0
		self.speed = 10 + (5 * (ID - 1))
		
		self.jumping = False
		self.y_speed = 0
		self.landed = False
		self.dropping = 10
		
		self.facing = 1
		self.animation_type = "idle"
		self.frame_ID = 0

		self.player_ID = 1
		self.ID = ID
		self.dead = False
		self.type = "player"
		
		self.interacting = False
		self.bomb = False
		
		self.health = 10
		
		self.idle = []
		self.run = []
		
		self.idle_counter = 0
		
		self.run_sfx = Play_Music("//sfx//" + str(self.ID) + "-run.ogg", -1)
		self.jump_sfx = Play_Music("//sfx//" + str(self.ID) + "-jump.ogg", -1)
		
		self.pre_buffer()
Ejemplo n.º 3
0
	def __init__(self, location, map):
		pygame.sprite.Sprite.__init__(self)		
		self.image = load_image("Images/block.png")
		self.block_image = self.image
		
		self.explode_img = []
		for i in range(1,15):
			self.explode_img.append(load_image("Images/expload/boulder-explosion-" + str(10000 + i)[1:] + ".png"))
		self.rect = self.image.get_rect()
		self.rect.center = location
		self.start_location = location
		self.respawn = False
		
		self.roll = []
		self.x_direction = 0
		
		for i in range(1, 32):
			self.roll.append(load_image("Images/roll/roll-" + str(10000 + i)[1:] + ".png"))
		
		self.loc = self.rect
		self.map = 0#map
			
		self.type = "block"
		
		self.jumping = False
		self.y_speed = 0
		self.speed = 0
		
		self.angle = 0
		
		self.active = False
		self.dead = False
		self.dead_count = 0
		self.boom_timer = 0
		
		self.health = 450.0
		self.show_health = False
		self.health_image = pygame.Surface((169, 45), pygame.SRCALPHA, 32)
		self.health_background = load_image("Images/healthbar-background.png")
		self.health_foreground = load_image("Images/healthbar-bar.png")
		
		
		self.roll_sfx = Play_Music("//sfx//boulder-rolling.ogg", -1)
		self.boom_sfx = Play_Music("//sfx//rock-crumble.ogg", -1)
Ejemplo n.º 4
0
	def __init__(self, location, type, gate, trigger, gates):
		pygame.sprite.Sprite.__init__(self)	

		for item in gates:
			if item.ID == gate:
				self.gate = item
				break;
		
		self.trigger_ID = trigger
		self.activated = False
		self.activation_delay = 0
		
		self.type = "button"
		self.float = False
		self.float_hit = 0
		
		self.button_type = type
		
		self.plugged = []
		self.unplugged = []
		self.frame_ID = 0
		self.img_type = "unplugged"
		
		self.prebuffer()
		
		
		if type == 2:
			self.geyser = Play_Music("//sfx//geyser-flow.ogg", -1)
			self.geyser.play()
			self.plugged_sfx = Play_Music("//sfx//plugged-geyser.ogg", -1)
		else:
			self.switch_sfx = Play_Music("//sfx//switch.ogg", -1)
		
		if type != 2:
			self.image = load_image("Images\\button" + str(type) + ".png")

		else:
			self.image = self.unplugged[0]
		
		self.rect = self.image.get_rect()
		self.rect.center = location
Ejemplo n.º 5
0
	def __init__(self, location):
		pygame.sprite.Sprite.__init__(self)	
		self.image = load_image("Images/miner2-run/miner2-running0001.png")
		self.rect = self.image.get_rect()
		self.rect.center = location
		self.rect[2] += 15
		
		self.start_location = location
		
		self.run = []
		self.stand = []
		self.jump = []
		self.frame_ID = 0
		
		self.running = False
		self.active = False
		self.boulder = []
		self.destruction_timer = 0
		
		self.speed = 8
		self.x_direction = 0
		self.facing = -1
		
		self.y_speed = 0
		self.jumping = False
		
		self.pick_sfx = Play_Music("//sfx//robots-picking-at-rocks.ogg", -1)
		self.walk_sfx = Play_Music("//sfx//robot-walk.ogg", -1)
		self.boom_sfx = Play_Music("//sfx//boulder-explode.ogg", -1)

		self.walking = False
		self.picking = False
		
		
		self.type = "robot"
		
		self.pre_buffer()
Ejemplo n.º 6
0
def main():
	pygame.init()
	pygame.mouse.set_visible(False)
	music = Play_Music("/menu.ogg", -1)
	music.play()
	music.set_volume(0.4)
	frame_ID = 0
	running = True
	window_surface = pygame.display.set_mode((1336,768),  pygame.FULLSCREEN)
	menu = [load_image("Menus//menu-art1.png"), load_image("Menus//menu-art2.png")]
	
	while running == True:
		window_surface.blit(menu[int(frame_ID / 80)], (0,0))
		pygame.display.flip()
		frame_ID += 1
		if frame_ID >= 160:
			frame_ID = 0
		for event in pygame.event.get():
			if event.type == KEYDOWN:
				if event.key == K_RETURN:
					running = False
				if event.key == K_F12:
					pygame.event.post(pygame.event.Event(QUIT))
					
			if event.type == QUIT: 
				pygame.quit()

				
					
					
	pygame.mixer.quit()
	cutscene(window_surface, "Cutscenes/Cutscene1.avi")		
	run_game(window_surface)
	cutscene(window_surface, "Cutscenes/Cutscene2.avi")
	tbc()
	main()
Ejemplo n.º 7
0
	def __init__(self, location, ID):
		pygame.sprite.Sprite.__init__(self)	
		if ID != 0 and ID != 4:
			self.gate = load_image("Images\\gate.png")
			self.base = load_image("Images\\gate-portal.png")
		
			self.image = pygame.Surface((135,430), pygame.SRCALPHA, 32)
			self.image.blit(self.gate, (35,0))
			self.image.blit(self.base, (0, 390))
			
		elif ID == 0:
			self.gate = load_image("Images\\lift.png")
			self.base = load_image("Images\\lift-wall.png")
			self.gate_sfx = Play_Music("\\sfx\\crane-lifting.ogg", -1)
			self.image = pygame.Surface((319, 550), pygame.SRCALPHA, 32)
			self.image.blit(self.gate, (40,0))
			self.image.blit(self.base, (0,330))
			location[1] -= 70
		else:
			self.image = pygame.Surface((250,750), pygame.SRCALPHA, 32)
			self.image.blit(load_image("Images\\crumbly-wall.png"), (0,0))
			self.boom = []
			for i in range(1, 25):
				self.boom.append(load_image("Images\\crumble-wall\\cumble-wall-" + str(10000 + i)[1:] + ".png"))
		
		self.rect = self.image.get_rect()
		self.rect.center = location
		
		self.gate_timer = -1
		self.ID = ID
		self.activation_confirmation = 0
		self.transition_counter = 0
		self.type = "gate"
		
		self.open = False
		
		self.animating = 0
		self.frame_ID = 0
Ejemplo n.º 8
0
	def __init__(self, location, width, ID):
		pygame.sprite.Sprite.__init__(self)	
		
		self.image = load_image("Images\\pipe.png")
		self.rect = self.image.get_rect()
		
		self.water = pygame.Surface((1350 * width, 450), pygame.SRCALPHA, 32)
		water_image =  load_image("Images\\maps\\water\\WATER-0001.png")
		self.water_rect = self.water.get_rect()
		self.rect.center = location
		self.water_rect[0] = self.rect[0] - 500
		
		self.plank = load_image("Images\\plank.png")
		self.plank_rect = self.plank.get_rect()
		
		for i in range(0, width):
			self.water.blit(water_image, (1350 * i, 0))
			
		self.type = "water"
		self.ID = ID
			
		self.on = False
		self.water_height = 0
		
		self.frame_ID = 17
		self.water_ID = 0
		
		self.start = []
		self.flow = []
		self.stop = []
		self.pipe = load_image("Images\\pipe.png")
		self.water_animation = []
		self.blit_rect = []
		
		self.water_pouring = Play_Music("//sfx//water-flow.ogg", -1)
		
		self.prebuffer()
Ejemplo n.º 9
0
class Robot(pygame.sprite.Sprite):
		
	def __init__(self, location):
		pygame.sprite.Sprite.__init__(self)	
		self.image = load_image("Images/miner2-run/miner2-running0001.png")
		self.rect = self.image.get_rect()
		self.rect.center = location
		self.rect[2] += 15
		
		self.start_location = location
		
		self.run = []
		self.stand = []
		self.jump = []
		self.frame_ID = 0
		
		self.running = False
		self.active = False
		self.boulder = []
		self.destruction_timer = 0
		
		self.speed = 8
		self.x_direction = 0
		self.facing = -1
		
		self.y_speed = 0
		self.jumping = False
		
		self.pick_sfx = Play_Music("//sfx//robots-picking-at-rocks.ogg", -1)
		self.walk_sfx = Play_Music("//sfx//robot-walk.ogg", -1)
		self.boom_sfx = Play_Music("//sfx//boulder-explode.ogg", -1)

		self.walking = False
		self.picking = False
		
		
		self.type = "robot"
		
		self.pre_buffer()
		
	def pre_buffer(self):
		for i in range(1,13):
			self.run.append(load_image("Images/miner2-run/miner2-running" + str(10000 + i)[1:] + ".png"))
		for i in range(1,13):
			self.stand.append(load_image("Images/miner2/miner2" + str(10000 + i)[1:] + ".png"))
		for i in range(1,13):
			self.jump.append(load_image("Images/miner/miner-" + str(10000 + i)[1:] + ".png"))
		
	def update(self, map_location, map, players):
	
		if self.active == True:
					
			if self.boulder.rect.colliderect(self.rect) and self.rect[0] - self.boulder.rect[0] < 100 and self.boulder.rect[0] - self.rect[0] < 100	:
				self.walk_sfx.stop()
				self.walking = False
				if self.picking == False:
					self.pick_sfx.play()
					self.picking = True
				self.x_direction = 0
				if self.rect[0] < self.boulder.rect[0]:
					self.facing = -1
					self.image = pygame.transform.flip(self.stand[self.frame_ID], 1, 0)
				else:
					self.facing = 1
					self.image = self.stand[self.frame_ID]
					
				self.destruction_timer += 1
				self.boulder.health -= 1
				self.boulder.show_health = True
				if self.destruction_timer > 450:
					self.boulder.health = 450
					self.boulder.show_health = False
					self.boom_sfx.play_once()
					self.boulder.dead = True
					self.boulder.respawn = True
					self.active = False
					self.boulder = []
					self.destruction_timer = 0
					self.pick_sfx.stop()
					
				if self.frame_ID > 10:
					self.frame_ID = 0
			else:
				if self.walking == False:
					self.walk_sfx.play()
					self.walking = True
				self.pick_sfx.stop()
				self.picking = False
				if self.rect[0] < self.boulder.rect[0]:
					self.x_direction = 1
					self.facing = 1
					self.image = pygame.transform.flip(self.run[self.frame_ID], 1, 0)
				else:
					self.x_direction = -1
					self.facing = -1
					self.image = self.run[self.frame_ID]
					
				if self.frame_ID > 10:
					self.frame_ID = 0
					
				self.rect[0] += self.x_direction * self.speed
		else:
			if abs(self.rect[0] - self.start_location[0]) > 100:
				if self.walking == False:
					self.walk_sfx.play()
					self.walking = True
				self.pick_sfx.stop()
				self.picking = False
				if self.rect[0] < self.start_location[0]:
					self.x_direction = 1
					self.facing = 1
					self.image = pygame.transform.flip(self.run[self.frame_ID], 1, 0)
				else:
					self.x_direction = -1
					self.facing = -1
					self.image = self.run[self.frame_ID]
					
				if self.frame_ID > 10:
					self.frame_ID = 0
					
				self.rect[0] += self.x_direction * self.speed
			else:
				self.image = self.jump[self.frame_ID]
				self.walk_sfx.stop()
				if self.frame_ID > 10:
					self.frame_ID = 0
				
		if map.ground_collision(self, [0,422]) == False:
			self.y_speed += 1
			self.rect[1] += self.y_speed
		else:
			self.y_speed = 0
			
		self.frame_ID += 1
		
		test_rect = [self.rect[0] + map_location[0], self.rect[1] + map_location[1] - 832, self.rect[2], self.rect[3]]
		
		for player in players:
			if player.player_ID == player.ID:
				self.walk_sfx.locate(test_rect[0] - player.rect[0], test_rect[1] - player.rect[1])
				self.pick_sfx.locate(test_rect[0] - player.rect[0], test_rect[1] - player.rect[1])
				self.boom_sfx.locate(test_rect[0] - player.rect[0], test_rect[1] - player.rect[1])

	def test_landed(self, player, offset):
		return(False)
Ejemplo n.º 10
0
class Bomb(pygame.sprite.Sprite):
		
	def __init__(self, location):
		pygame.sprite.Sprite.__init__(self)	
		self.bomb = load_image("Images\TNT-unlit.png")
		self.bomb_loop = []
		for i in range(1,6):
			self.bomb_loop.append(load_image("Images/TNT-frames/TNT-" + str(10000 + i)[1:] + ".png"))
			
		self.no_image = pygame.Surface((1,1), pygame.SRCALPHA, 32)
		self.no_image.fill(0)
		self.image = self.bomb
		self.frame_ID = 0
		
		self.rect = self.image.get_rect()
		self.rect.center = location
		self.start_location = location
		
		self.carried = False
		self.interacting_timer = 0
		self.player = ""
		self.boom_time = 1500
		self.boom_sfx = Play_Music("//sfx//bomb-explode.ogg", -1)
		self.hiss_sfx = Play_Music("//sfx//hiss-fuse.ogg", -1)
		
		self.y_speed = 0
		self.x_speed = 0
		self.jumping = False
		
		self.type = "bomb"
		self.active = False
		
		self.live = False
		self.countdown = 0
		
		self.frame_ID = 0
		
	def update(self, player_list, map, map_location, objects):
	
		active = 0
		for object in objects:
			if object.type == "bomb" and object.active == True:
				active += 1
				
		if active == 1 and self.active == True:
			active = 0
			
		if map.ground_collision(self, [0,532]) == False and self.carried == False:
			self.y_speed += 2
			self.rect[1] += self.y_speed
		else:
			self.x_speed = 0
			self.y_speed = 0
			
		test_rect = [self.rect[0] + map_location[0], self.rect[1] + map_location[1] - 832, self.rect[2], self.rect[3]]
			
		for player in player_list:
			if player.ID == 2 and player.dropping == True and player.player_ID == player.ID:	
				if self.carried == False:
					if player.hit_rect.colliderect(test_rect) and active == 0:
						self.carried = True
						self.player = player
						self.active = True
						player.bomb = True
						player.frame_ID = 1
						player.animation_type = "pickup"
						player.dead = 1
						self.interacting_timer = 0
						if self.countdown <= 1:
							self.countdown = 1
				elif self.interacting_timer > 30 and player.ID == 2 and self.active == True:
					self.carried = False
					self.active = False
					self.player.bomb = False
					self.x_speed = (player.speed * player.x_direction)
					self.frame_ID = 0
					self.image = self.bomb_loop[self.frame_ID]
					
			elif player.dead != 0 and player.ID == 2 and player.animation_type != "pickup" and self.active == True:
				self.carried = False
				self.active = False
				self.player.bomb = False
				self.x_speed = (player.speed * player.x_direction)
				self.frame_ID = 0
				self.image = self.bomb_loop[self.frame_ID]
				
			
			if player.animation_type == "pickup" and player.frame_ID == 15:
				self.image = self.no_image
			
		if self.countdown >= self.boom_time:
			if self.countdown == self.boom_time:
				self.boom_sfx.play_once()
			if self.carried == True and self.player.dead == 0:
				self.player.dead = 1
				self.player.animation_type = "boom"
				self.live = True
				self.player.bomb = False
				self.player.frame_ID = 1
				self.rect[1] -= 100
				self.rect[0] -= 100
			elif self.frame_ID == 1:
				self.rect[1] -= 75
				self.rect[0] -= 75
				
			self.frame_ID += 1
			self.image = load_image("Images/TNT-explosion-frames/TNT-explosion-" + str(10000 + self.frame_ID)[1:] + ".png")
			size = self.image.get_rect()
			self.rect[2] = size[2]
			self.rect[3] = size[3]
			
			for item in objects:
					if item.type == "gate" and item.ID == 4 and item.transition_counter != 500:
						if abs(self.rect[0] - item.rect[0]) < 200:
							item.trigger(10)
			
			if self.frame_ID >= 9:
				self.live = False
				self.image = self.bomb
				self.rect[0] = self.start_location[0]
				self.rect[1] = self.start_location[1]
				self.countdown = 0
				self.carried = False
				self.active = False
				self.frame_ID = 1			
		else:
			if self.frame_ID > 4:
				self.frame_ID = 0
				
		if self.carried == True and self.image == self.no_image:
			self.rect = [self.player.rect[0] - map_location[0], self.player.rect[1] - map_location[1]  + 887, self.rect[2], self.rect[3]]
			if self.player.facing == 1:
				self.rect[0] += 175
				
		self.interacting_timer += 1
		if self.countdown != 0:
			self.countdown += 1
			if self.carried == False and self.countdown < self.boom_time:
				self.image = self.bomb_loop[self.frame_ID]
		if self.countdown == 2:
			self.hiss_sfx.play_once()
		self.rect[0] += self.x_speed
		
		self.frame_ID += 1
		
		
	def test_landed(self, player, offset):
		return(False)
Ejemplo n.º 11
0
class Gate(pygame.sprite.Sprite):
		
	def __init__(self, location, ID):
		pygame.sprite.Sprite.__init__(self)	
		if ID != 0 and ID != 4:
			self.gate = load_image("Images\\gate.png")
			self.base = load_image("Images\\gate-portal.png")
		
			self.image = pygame.Surface((135,430), pygame.SRCALPHA, 32)
			self.image.blit(self.gate, (35,0))
			self.image.blit(self.base, (0, 390))
			
		elif ID == 0:
			self.gate = load_image("Images\\lift.png")
			self.base = load_image("Images\\lift-wall.png")
			self.gate_sfx = Play_Music("\\sfx\\crane-lifting.ogg", -1)
			self.image = pygame.Surface((319, 550), pygame.SRCALPHA, 32)
			self.image.blit(self.gate, (40,0))
			self.image.blit(self.base, (0,330))
			location[1] -= 70
		else:
			self.image = pygame.Surface((250,750), pygame.SRCALPHA, 32)
			self.image.blit(load_image("Images\\crumbly-wall.png"), (0,0))
			self.boom = []
			for i in range(1, 25):
				self.boom.append(load_image("Images\\crumble-wall\\cumble-wall-" + str(10000 + i)[1:] + ".png"))
		
		self.rect = self.image.get_rect()
		self.rect.center = location
		
		self.gate_timer = -1
		self.ID = ID
		self.activation_confirmation = 0
		self.transition_counter = 0
		self.type = "gate"
		
		self.open = False
		
		self.animating = 0
		self.frame_ID = 0
		
	def update(self, players, map_location):

		if self.activation_confirmation == 10 and (self.transition_counter > 300 or self.ID == 0):
			self.open = True
		else:
			self.open = False
			test_rect = [self.rect[0] + map_location[0], self.rect[1] + map_location[1] - 832, self.rect[2], self.rect[3]]
			for player in players:
				if player.hit_rect.colliderect(test_rect):
					if player.hit_rect[0] < test_rect[0]:
						player.rect[0] -= player.speed
					else:
						player.rect[0] += player.speed
						
		if self.ID == 0:
			for player in players:
				if player.player_ID == player.ID:
					test_rect = [self.rect[0] + map_location[0], self.rect[1] + map_location[1] - 832, self.rect[2], self.rect[3]]
					self.gate_sfx.locate(test_rect[0] - player.rect[0], test_rect[1] - player.rect[1] / 2)
						
		if self.animating == 1:
			self.open_gate()
		elif self.animating == -1:
			self.close_gate()
	
					
	def trigger(self, trigger_code):
		print trigger_code
		if trigger_code == 10:
			self.activation_confirmation = 10
			self.gate_timer = 99999
			self.animating = 1
			self.transition_counter = 0
			if self.ID == 0:
				self.gate_sfx.play_once()
		elif trigger_code > 0:
			self.activation_confirmation += trigger_code
			print self.activation_confirmation
			if self.activation_confirmation >= 10:
				self.activation_confirmation = 10
				self.gate_timer = 99999
				self.animating = 1
				self.transition_counter = 0
		else:
			self.activation_confirmation += trigger_code
			print self.activation_confirmation
			if self.activation_confirmation < 10:
				self.gate_timer = 0
				if self.activation_confirmation - trigger_code == 10 or trigger_code == -10:
					self.animating = -1
				self.transition_counter = 0
				
			elif self.activation_confirmation == 10:
				self.activation_confirmation = 10
				self.gate_timer = 99999
				self.animating = 1
				self.transition_counter = 0

				
	def open_gate(self):
		if self.ID != 0 and self.ID != 4:
			self.image = pygame.Surface((135,430), pygame.SRCALPHA, 32)
			self.image.blit(self.gate, (35, self.transition_counter))
			self.image.blit(self.base, (0, 390))
			self.transition_counter += 10
			
			if self.transition_counter > 400:
				self.animating = 0
		elif self.ID != 4:
			self.image = pygame.Surface((319, 550), pygame.SRCALPHA, 32)
			self.image.blit(self.gate, (40,0))
			self.image.blit(self.base, (0,330 - self.transition_counter))
			self.transition_counter += 3.25
			if self.transition_counter > 330:
				self.animating = 0
		else:
			self.image.fill(0)
			self.image = pygame.Surface((250, 750), pygame.SRCALPHA, 32)
			self.transition_counter = 500
			self.image.blit(self.boom[self.frame_ID], (10,0))
			self.frame_ID += 1
			if self.frame_ID > 23:
				self.animating = 0
				self.frame_ID = 0
				
	def close_gate(self):
		if self.ID != 0:
			print "Closing"
			self.image = pygame.Surface((135,430), pygame.SRCALPHA, 32)
			self.image.blit(self.gate, (35, 400 - self.transition_counter))
			self.image.blit(self.base, (0, 390))
			self.transition_counter += 10
			
			if self.transition_counter > 400:
				self.animating = 0
				
		elif self.ID != 4:
			
			self.image = pygame.Surface((319, 550), pygame.SRCALPHA, 32)
			self.image.blit(self.gate, (40,0))
			self.image.blit(self.base, (0,self.transition_counter))
			self.transition_counter += 10
			
			if self.transition_counter > 330:
				self.animating = 0	
		else:
			self.animating = 0
	def test_landed(self, player, offset):
		return(False)
Ejemplo n.º 12
0
class Player(pygame.sprite.Sprite):

	def __init__(self, ID):
		pygame.sprite.Sprite.__init__(self)		
		
		self.image = load_image("Images" + "\Players\\" + str(ID) + "\Idle/idle-0001.png")
		self.rect = self.image.get_rect()
		self.rect.center = (400.0, 500.0)
		
		self.reset = False
		
		self.hit_image = load_image("Images" + "\Players\\" + str(ID) + "/hit.png")
		self.hit_rect = self.hit_image.get_rect()
		self.hit_rect.center = self.rect.center
		
		self.land_rect = self.hit_image.get_rect()
		if ID != 2:
			self.land_image = load_image("Images\\Players\\1\\player_land.png")
			self.land_rect = self.land_image.get_rect()
			self.land_rect.center = self.rect.center
			
		self.x_direction = 0
		self.prev_x = 0
		self.speed = 10 + (5 * (ID - 1))
		
		self.jumping = False
		self.y_speed = 0
		self.landed = False
		self.dropping = 10
		
		self.facing = 1
		self.animation_type = "idle"
		self.frame_ID = 0

		self.player_ID = 1
		self.ID = ID
		self.dead = False
		self.type = "player"
		
		self.interacting = False
		self.bomb = False
		
		self.health = 10
		
		self.idle = []
		self.run = []
		
		self.idle_counter = 0
		
		self.run_sfx = Play_Music("//sfx//" + str(self.ID) + "-run.ogg", -1)
		self.jump_sfx = Play_Music("//sfx//" + str(self.ID) + "-jump.ogg", -1)
		
		self.pre_buffer()
	
	def pre_buffer(self):
		if self.ID == 1:
			for i in range(1,109): 
				self.idle.append(load_image("Images/Players/1/Idle/idle-" + str(10000 + i)[1:] + ".png"))
			for i in range(1,17):
				self.run.append(load_image("Images/Players/1/Running/run-" + str(10000 + i)[1:] + ".png"))
		else:
			for i in range(1,101): 
				self.idle.append(load_image("Images/Players/2/Idle/idle-" + str(10000 + i)[1:] + ".png"))
			for i in range(1,17):
				self.run.append(load_image("Images/Players/2/Running/run-" + str(10000 + i)[1:] + ".png"))
		
	def update(self, current_ID, item_list, player_list, map, map_location):
		if self.dead != 1:
			if current_ID == self.ID:
				self.keyboard_controls()
			
			self.update_image()
			if self.ID == 1:
				self.land_rect.center = [self.rect[0] + 25, self.rect[1] + 25]
			if self.ID == 1:
				self.hit_rect.center = [self.rect[0] + 110, self.rect[1] + 140]
			else:
				self.hit_rect.center = [self.rect[0] + 125 + 25 * self.facing, self.rect[1] + 150]
			#self.image.blit(self.hit_image, (self.hit_rect[0] - self.rect[0], self.hit_rect[1] - self.rect[1]))
			self.run_collisions(item_list, player_list, map, map_location)
			if self.dropping < 10:
				self.dropping += 1
			self.idle_counter += 1
			
			if self.idle_counter > 9000:
				self.reset = True
		else:
			self.play_dead()
		
		if self.health <= 0:
			self.dead = 1
		
	def keyboard_controls(self):
		# Keyboard controls
		for event in pygame.event.get():
			# Quits the program
			if event.type == QUIT: 
				pygame.quit()
			
			# Key press handling
			if event.type == KEYDOWN:
				# If escape is pressed, close
				if event.key == K_F12:
					pygame.event.post(pygame.event.Event(QUIT))
					
				if event.key == K_F1:
					self.reset = True
				
				# X movement
				if self.jumping == False or self.jumping == True:
					if event.key == K_a or event.key == K_LEFT:
						self.x_direction = -1
						self.idle_counter = 0
						
					if event.key == K_d or event.key == K_RIGHT:
						self.x_direction = 1
						self.idle_counter = 0
						
				if event.key == K_1:
					self.player_ID = 1
					self.idle_counter = 0
				
				if event.key == K_2:
					self.player_ID = 2
					self.idle_counter = 0
				
				# Jumping
				if event.key == K_w or event.key == K_UP:
					if self.jumping == False or self.ID == 3:
						self.jumping = True
						self.jump_sfx.play_once()
						self.y_speed = 12
						if self.ID == 2:
							self.y_speed += 5
					
				# Enabling interaction
				if event.key == K_SPACE:
					self.interacting = True

				if event.key == K_s or event.key == K_DOWN:
					self.dropping = True
			
			# Key release hadling
			if event.type == KEYUP:
				# Refreshes the events
				pygame.event.pump()
				# Creates a list of pressed keys
				key_list = pygame.key.get_pressed()
				# If A is up
				if event.key == K_a or event.key == K_LEFT:
					# But D is down
					if key_list[pygame.K_d] == True or key_list[pygame.K_RIGHT] == True:
						# Swap directions
						self.x_direction = 1
					# But D is up
					else:
						# Stop moving
						self.x_direction = 0
				# Same for D
				if event.key == K_d or event.key == K_RIGHT:
					if key_list[pygame.K_a] == True or key_list[pygame.K_LEFT] == True:
						self.x_direction = -1
					else:
						self.x_direction = 0
						
			# Disabling interaction
				if event.key == K_SPACE:
					self.interacting = False
				
				if event.key == K_s or event.key == K_DOWN:
					self.dropping = False
						
	def update_image(self):

		if self.facing is not self.x_direction:
			# if they're swapping directions
			if self.x_direction is not 0:
				# Flip the way they're facing and refresh the image
				self.facing = self.x_direction
				self.animation_type = "run"
				if self.run_sfx.playing == False:
					self.run_sfx.play()
				self.image = self.run[0]
			else:
				# If they're stopping but havent already started the slow animation
				if self.prev_x is not 0:
					# play the slow animation
					self.animation_type = "slow"
					if self.bomb == False:
						self.image = change_image("slow", self.facing, str(self.ID))
					else:
						self.image = change_image("slow-TNT", self.facing, str(self.ID))
					# Dont want to change the direction they're facing or the stop image will flip
					if self.x_direction is not 0:
						self.facing = self.x_direction
					# Reset the counter
					self.frame_ID = 0
		
		#If the player starts moving from standing but doesnt change direction
		if self.x_direction is not self.prev_x and self.prev_x is 0:
			self.animation_type = "run"
			if self.run_sfx.playing == False:
				self.run_sfx.play()
			self.image = self.run[0]
			self.frame_ID = 0
		
		# if the player is slowing down
		if self.animation_type is "slow":
			if self.frame_ID >= 3:
				# Reset the animation to the standing player
				self.animation_type = "idle"
				self.image = self.idle[0]
				self.frame_ID = 0
			#else:
				# If it hasnt finished slowing, move slightly forwards
				#self.rect[0] += 2 * self.facing * self.speed / (self.frame_ID + 1)

		self.prev_x = self.x_direction
		
		if self.run_sfx.playing == True and self.animation_type != "run":
			self.run_sfx.stop()
		
		# Vertical stuff
		if self.jumping == True:
			self.y_speed -= GRAVITY
			# Going up
			if self.y_speed > 0:
				if self.animation_type == "jump" and self.frame_ID > 5 and self.animation_type != "tuck" and self.ID == 2:
					self.animation_type = "tuck"
					if self.bomb == False:
						self.image = change_image("tuck", self.facing, str(self.ID))
					else:
						self.image = change_image("tuck-TNT", self.facing, str(self.ID))
				elif self.animation_type != "tuck" and self.animation_type != "jump":
					self.animation_type = "jump"
					if self.bomb == False:
						self.image = change_image("jump", self.facing, str(self.ID))
					else:
						self.image = change_image("jump-TNT", self.facing, str(self.ID))
					self.frame_ID = 0
			# Going down
			else:
				if self.animation_type is not "jump2":
					self.animation_type = "jump2"
					self.frame_ID = 0
				if self.ID is not 2:
					self.image = change_image("jump2", self.facing, str(self.ID))
		
		if self.animation_type == "land":
			if self.frame_ID >= 1:
				if self.x_direction == 0:
					self.animation_type = "idle"
					self.image = self.run[0]
					self.frame_ID = 0
				else:
					self.animation_type = "run"
					if self.run_sfx.playing == False:
						self.run_sfx.play()
					if self.bomb == False:
						self.image = change_image("slow", self.facing, str(self.ID))
					else:
						self.image = change_image("slow-TNT", self.facing, str(self.ID))
				self.frame_ID = 0

		self.rect[1] -= self.y_speed
		
		# These animations override even jumping
		if self.animation_type == "sinking":
			self.x_direction = 0
			self.jumping = False
				
		# Play the animations
		self.frame_ID += 1
		if self.bomb == False:
			for case in switch(self.animation_type):
				if case("idle"):

					self.image = self.idle[self.frame_ID]
					if self.facing == 1:
						self.image = pygame.transform.flip(self.image, 1, 0)
					if self.frame_ID > 106 and self.ID == 1:
						self.frame_ID = 0
					if self.frame_ID > 98 and self.ID == 2:
						self.frame_ID = 0
					break;
				if case("run"):
					self.image = self.run[self.frame_ID]
					if self.facing == 1:
						self.image = pygame.transform.flip(self.image, 1, 0)
					if self.frame_ID > 14 and self.ID == 1:
						self.frame_ID = 0
					if self.frame_ID > 14 and self.ID == 2:
						self.frame_ID = 0
					break;
				if case("jump2") and self.ID == 2:
					self.image = change_image("Falling/flap-" + str(10000 + self.frame_ID)[1:], self.facing, str(self.ID))
					if self.frame_ID > 3:
						self.frame_ID = 0
					break;
				elif self.animation_type == "push" and self.ID == 1:
					self.image = change_image("boulder-push//boulder-push-" + str(10000 + self.frame_ID)[1:], self.facing, str(self.ID))
					if self.frame_ID > 14:
						self.frame_ID = 0
					break;
					
		else:
			if self.animation_type == "idle":
				self.image = change_image("idle-TNT/idle" + str(10000 + self.frame_ID)[1:], self.facing, str(self.ID))
				if self.frame_ID > 99 and self.ID == 2:
					self.frame_ID = 0
			elif self.animation_type == "run":
				self.image = change_image("running-TNT/running-TNT-" + str(10000 + self.frame_ID)[1:], self.facing, str(self.ID))
				if self.frame_ID > 15 and self.ID == 2:
					self.frame_ID = 0
			elif self.animation_type == "jump2":
				self.image = change_image("flap-wTNT/flapping-flash-TNT" + str(10000 + self.frame_ID)[1:], self.facing, str(self.ID))
				if self.frame_ID > 3:
					self.frame_ID = 0

	def run_collisions(self, item_list, player_list, map, map_location):
		# Have to define a new variable for some reason
		map_loc = [0,0]
		map_loc[0] = map_location[0]
		map_loc[1] = map_location[1] - 432
		
		# Reset for next loop
		self.landed = False 

		# Check if falling
		if self.jumping == True:
			# If hit ground
			if map[self.ID - 1].ground_collision(self, [map_location[0], map_location[1]]) == True:
				# Reset the player to their walking values
				self.jumping = False
				self.landed = True
				self.animation_type = "land"
				if self.y_speed <= HEALTH_DAMAGE:
						self.health -= 1
				self.y_speed = 0
				# Reset the image
				self.frame_ID = 0
				self.image = change_image("land", self.facing, str(self.ID))
				for object in item_list:
					if object.type == "button":
						object.float = False
		# Still need to check if they've walked off a ledge/down a slope
		elif map[self.ID - 1].ground_collision(self, map_location) == True:
				self.landed = True

		# Player on player collisions - NEEDS FIXING
		for player in player_list:
			# If player 2 is on top of player 1
			if self.ID == 2 and player.ID != 2 and self.hit_rect.colliderect(player.rect) and self.landed == False:
				# this if statement is horrible and ugly and doesnt work - fix ASAP
				if self.hit_rect[1] - 70 >= player.rect[1] and  self.hit_rect[0] * self.facing < player.hit_rect[0] + 30 and self.hit_rect[0] * self.facing > player.hit_rect[0] - 20 and self.y_speed <= 0 and abs(self.hit_rect[1] - player.hit_rect[1]) > 5:
					
					# Same as before just with the player
					self.landed = True
					self.rect[1] = player.rect[1] - 70
					self.jumping = False
					if self.y_speed <= HEALTH_DAMAGE:
						self.health -= 1
					self.y_speed = 0
					# Test for later - possible addition?
					# self.facing = player.facing
					
					self.animation_type = "idle"
					
					# Move velociryy along with the other dino
					self.rect[0] += player.speed * player.x_direction
					if player.animation_type == "slow":
						self.rect[0] += 2 * player.facing * player.speed / (player.frame_ID + 1)
					break
		
		# Check if the player is on top of an object
		for object in item_list:
			if object.test_landed(self, map_loc) == True:
				self.landed = True
		
		# If the player was on the ground and is now falling
		if self.landed == False and self.jumping == False:
			self.jumping = True
			# automatically jumps to the down fall image
			if self.animation_type != "jump2":
				self.animation_type = "jump2"
				self.frame_ID = 0
				if self.ID != 2:
					self.image = change_image("jump2", self.facing, str(self.ID))

	def play_dead(self):
		if self.animation_type == "sinking":
			if self.frame_ID < 15:
				self.frame_ID += 1
				self.image = change_image("Sinking/sinking-" + str(10000 + self.frame_ID)[1:], self.facing, str(self.ID))
			elif self.frame_ID < 30:
				self.image = change_image("Sinking/sinking-" + str(10000 + int(self.frame_ID / 2))[1:], self.facing, str(self.ID))
				self.frame_ID += 1
				#play sinking shit
			else:
				self.health -= 1
				self.dead = 2
				self.animation_type = "idle"
				self.facing = 1
				self.frame_ID = 0
		elif self.animation_type == "squashed":
			self.image = change_image("squished/squished-" + str(10000 + self.frame_ID)[1:], self.facing, str(self.ID))
			self.frame_ID += 1
			
			if self.frame_ID > 15:
				self.dead = 2
				self.animation_type = "idle"
				self.facing = 1
				self.frame_ID = 0	
				
		elif self.animation_type == "pickup":
				self.image = change_image("bomb-lift-frames/bomb-pick-up" + str(10000 + self.frame_ID)[1:], self.facing, str(self.ID))
				self.frame_ID += 1
				self.dropping = False
				self.x_direction = 0
				self.run_sfx.stop()
				if self.frame_ID > 22:
					self.animation_type = "idle"
					self.dead = 0
					self.frame_ID = 0
		elif self.animation_type == "boom":
			self.image = change_image("explosion-death/explosion-" + str(10000 + self.frame_ID)[1:], self.facing, str(self.ID))
			self.frame_ID += 1
			self.x_direction = 0
			if self.frame_ID > 72:
				self.dead = 2
				self.animation_type = "idle"
				self.facing = 1
				
				self.frame_ID = 0	
Ejemplo n.º 13
0
class Water(pygame.sprite.Sprite):
		
	def __init__(self, location, width, ID):
		pygame.sprite.Sprite.__init__(self)	
		
		self.image = load_image("Images\\pipe.png")
		self.rect = self.image.get_rect()
		
		self.water = pygame.Surface((1350 * width, 450), pygame.SRCALPHA, 32)
		water_image =  load_image("Images\\maps\\water\\WATER-0001.png")
		self.water_rect = self.water.get_rect()
		self.rect.center = location
		self.water_rect[0] = self.rect[0] - 500
		
		self.plank = load_image("Images\\plank.png")
		self.plank_rect = self.plank.get_rect()
		
		for i in range(0, width):
			self.water.blit(water_image, (1350 * i, 0))
			
		self.type = "water"
		self.ID = ID
			
		self.on = False
		self.water_height = 0
		
		self.frame_ID = 17
		self.water_ID = 0
		
		self.start = []
		self.flow = []
		self.stop = []
		self.pipe = load_image("Images\\pipe.png")
		self.water_animation = []
		self.blit_rect = []
		
		self.water_pouring = Play_Music("//sfx//water-flow.ogg", -1)
		
		self.prebuffer()
		
	def update(self, players, map_location):

		if self.on and self.water_height < 90:
			self.water_height += 2
		elif self.on == False and self.water_height > 0:
			self.water_height -= 2
		self.water_rect[1] = self.rect[1] + 50 - self.water_height
		
		if self.on and self.frame_ID < 16:
			self.image = self.start[self.frame_ID]
			
		if self.on == False and self.frame_ID < 16:
			self.image = self.stop[self.frame_ID]
			
		if self.on and self.frame_ID >= 16:
			self.image = self.flow[self.frame_ID - 16]
			
			if self.frame_ID >= 31:
				self.frame_ID = 16
				
		if self.on == False and self.frame_ID >= 16:
			self.image = self.pipe
			
		self.water = self.water_animation[int(self.water_ID)]
		
		if self.water_ID >= 22:
			self.water_ID = 0
		
		self.frame_ID += 1
		self.water_ID += 0.5
		
		self.blit_rect = [self.rect[0], 490 - self.water_height + self.rect[1], 321, 300]
		self.plank_rect = [self.rect[0] - 320, self.rect[1] + 490 - self.water_height, self.plank_rect[2], self.plank_rect[3]]
		
		test_rect = [self.plank_rect[0] + map_location[0] + self.rect[3] / 2, self.plank_rect[1] + map_location[1] - 832, self.plank_rect[2], self.plank_rect[3]]
		for player in players:
			if player.player_ID == player.ID:
				self.water_pouring.locate(test_rect[0] - player.rect[0], test_rect[1] - player.rect[1])
		
	def trigger(self, trigger_code):
		self.on = not self.on
		if self.frame_ID >= 16:
			self.frame_ID = 0
		
		if self.on:
			self.water_pouring.play()
		else:
			self.water_pouring.stop()
		
	def prebuffer(self):
		for i in range(1, 17):
			self.start.append(load_image("Images\\begin-flow\\start-flow-" + str(10000 + i)[1:] + ".png"))
		
		for i in range(1, 17):
			self.flow.append(load_image("Images\\flowing\\flowing-" + str(10000 + i)[1:] + ".png"))
		
		for i in range(1, 17):
			self.stop.append(load_image("Images\\stopping\\stopping-" + str(10000 + i)[1:] + ".png"))
		
		for i in range(1, 24):
			self.water_animation.append(load_image("Images\\Maps\\water\\water-" + str(10000 + i)[1:] + ".png"))
		
	def test_landed(self, player, offset):
		# Corrected rect for floating blocks
		collide_rect = [self.plank_rect[0] + offset[0], self.plank_rect[1] + offset[1] + 30, self.plank_rect[2], self.plank_rect[3] + 500]
		# Check the player is within the hitbox and is colliding with the block (first check is for air, second for ground)
		if (player.hit_rect.colliderect(collide_rect)):
			if player.y_speed < 0:
				player.rect[1] = self.rect[1] + 490 - self.water_height + offset[1] - 150 + 30
				player.jumping = False
				player.animation_type = "land"
				player.y_speed = 0
				player.frame_ID = 0	
				
			if player.rect[1] > self.rect[1] + 490 - self.water_height + offset[1] - 150 + 30 and player.jumping == False:
				player.rect[1] = self.rect[1] + 490 - self.water_height + offset[1] - 150 + 30
				
			if self.on and self.water_height > 0 and self.water_height < 90:
				player.rect[1] -= 2
			
			if not self.on and self.water_height != 0:
				player.rect[1] += 2
			
			return(True)
		else:
			return(False)
Ejemplo n.º 14
0
class Block(pygame.sprite.Sprite):
		
	def __init__(self, location, map):
		pygame.sprite.Sprite.__init__(self)		
		self.image = load_image("Images/block.png")
		self.block_image = self.image
		
		self.explode_img = []
		for i in range(1,15):
			self.explode_img.append(load_image("Images/expload/boulder-explosion-" + str(10000 + i)[1:] + ".png"))
		self.rect = self.image.get_rect()
		self.rect.center = location
		self.start_location = location
		self.respawn = False
		
		self.roll = []
		self.x_direction = 0
		
		for i in range(1, 32):
			self.roll.append(load_image("Images/roll/roll-" + str(10000 + i)[1:] + ".png"))
		
		self.loc = self.rect
		self.map = 0#map
			
		self.type = "block"
		
		self.jumping = False
		self.y_speed = 0
		self.speed = 0
		
		self.angle = 0
		
		self.active = False
		self.dead = False
		self.dead_count = 0
		self.boom_timer = 0
		
		self.health = 450.0
		self.show_health = False
		self.health_image = pygame.Surface((169, 45), pygame.SRCALPHA, 32)
		self.health_background = load_image("Images/healthbar-background.png")
		self.health_foreground = load_image("Images/healthbar-bar.png")
		
		
		self.roll_sfx = Play_Music("//sfx//boulder-rolling.ogg", -1)
		self.boom_sfx = Play_Music("//sfx//rock-crumble.ogg", -1)
		
	def update(self, player_list, map, map_location, objects, robots):
		#self.rect[1] -= map_location[2]
		if self.dead == False:
			if map[0].ground_collision(self, [0,422]) == False:
				self.y_speed += 1
				self.rect[1] += self.y_speed
			else:
				self.y_speed = 0
			moving = 0
			test_rect = [self.rect[0] + map_location[0], self.rect[1] + map_location[1] - 832, self.rect[2], self.rect[3]]
			
			active = 0
			for object in objects:
				if object.type == "block" and object.active == True:
					active += 1
					
			if active == 1 and self.active == True:
				active = 0
				
			for player in player_list:
				if player.ID == 1:
					if player.hit_rect.colliderect(test_rect):
						if player.interacting == True:
							if player.hit_rect[1] > test_rect[1] + 40 and active < 1:
								if player.animation_type != "push":
									self.roll_sfx.play()
									player.animation_type = "push"
									player.frame_ID = 0
								if player.x_direction == -1: 
									if test_rect[0] < player.hit_rect[0] - 100:
										self.speed = 10 * player.x_direction
										self.angle += 1
										self.active = True
								elif player.x_direction == 1:  
									if test_rect[0] > player.rect[0] + 100:
										self.speed = 10 * player.x_direction
										self.angle -= 1
										self.active = True
								ping = []
								for robot in robots:
									if robot.boulder == []:
										ping = robot
									elif robot.boulder == self:
										ping = []
										break;
										
								if ping != []:
									ping.boulder = self
									ping.active = True
									
						else:
							for object in objects:
								if object.type == "block":
									object.active = False
									object.roll_sfx.stop()
									
					else:
						self.speed = 0
						self.roll_sfx.stop()
				elif player.ID == 1:
					self.active = False
				if player.animation_type == "push" and active == 0 and self.active == False:
					if player.x_direction != 0:
						player.animation_type = "run"
					else:
						player.animation_type = "idle"
						
					player.frame_ID = 0
				
			if self.show_health == True:
				self.health_image.blit(self.health_background, (0,0))
				overlay = pygame.Surface((169, 45), pygame.SRCALPHA, 32)
				overlay.blit(self.health_foreground, (0,0))
				overlay.fill(0, (0, 0, ( 1- self.health / 450.0) * 169 ,45))
				print self.health / 450
				self.health_image.blit(overlay, (0,0))
				#self.image.blit(self.health_image, (0,0))

			if self.active == False:
				self.speed = 0
				
			if self.angle > 30:
				self.angle = 0
			if self.angle < 0:
				self.angle = 30
			
			self.image = self.roll[self.angle]
					
			self.rect[0] += self.speed
		else:
			self.explode(map_location, player_list)

		
	def spawner_update(self, map_location, map, players):
		if self.dead == True:
			self.rect[1] = 1950
			self.explode(map_location, players)
		elif self.rect[1] < 1950:
			self.y_speed += 1
			self.rect[1] += self.y_speed
			self.boom_timer += 1
		else:
			self.y_speed = 0
			self.dead = True
		
	def explode(self, map_location, players):
		if self.dead_count > 14:
			self.dead = False
			if self.respawn == False:
				self.rect[1] = -1000000
			else:
				self.rect.center = self.start_location
			self.image = self.block_image
			self.dead_count = 0
			self.boom_timer = 0
		elif self.dead_count == 1:
			self.show_health = False
			self.boom_sfx.play_once()
			self.image = self.explode_img[self.dead_count - 1]
			self.dead_count += 1
			test_rect = [self.rect[0] + map_location[0], self.rect[1] + map_location[1] - 832, self.rect[2], self.rect[3]]
			for player in players:
				if player.player_ID == player.ID:
					self.boom_sfx.locate(test_rect[0] - player.rect[0], test_rect[1] - player.rect[1])
		else:
			self.image = self.explode_img[self.dead_count - 1]
			self.dead_count += 1
		
	def test_landed(self, player, offset):
		return False
		## Corrected rect for floating blocks
		# collide_rect = [self.rect[0] + offset[0], self.rect[1] + offset[1], self.rect[2], self.rect[3]]
		##Check the player is within the hitbox and is colliding with the block (first check is for air, second for ground)
		# if player.rect[1] >= self.rect[1] - 100 + offset[1] and player.rect[1] < self.rect[1] - 50 + offset[1] and player.dropping == 10:
			# if (player.hit_rect.colliderect(collide_rect) or player.hit_rect.colliderect(self.rect)):
				# if player.y_speed < 0:
					# player.rect[1] = self.rect[1] - 100 + offset[1]
					# player.jumping = False
					# player.animation_type = "land"
					# player.y_speed = 0
					# player.frame_ID = 0	
				
				# return(True)
			# else:
				# return(False)
Ejemplo n.º 15
0
def run_game(window_surface):
	window_surface = pygame.display.set_mode((1336,768),  pygame.FULLSCREEN)
	music = Play_Music("/loading.ogg", -1)
	music.play()
	music.set_volume(0.2)	
	# Variables
	f = pygame.font.Font("arial.ttf", 16)
	black_colour = pygame.Color(0,0,0)

	foreground_X = 0.0
	foreground_Y = 0.0
	prev_y = 0.0
	sliding = False
	
	map_size = 5.55 # 0 = 1000px, etc
	map_file = [[0,500], [1500, 500], [2200, 350], [2600, 325], [4100, 325], [4700, 300], [5200, 350], [5800, 710], [6500, 760], [8000, 750], [10000, 750]]
	map_file_2 = [[0,1550], [1100, 1550], [2350, 1500], [2800, 1500], [3050, 1600], [3150, 1650], [4000, 1650], [4100, 1450], [5315, 1450], [6310, 900], [7000, 750], [10000, 750]]
	map_code = [6, [], [[8, [4100, 2010, 150, 300], [-1, 0]], [8, [200, 1075, 1000, 100], [0, 1]], [8, [100, 1000, 100, 1010], [-1,0]], [0, [1100, 1200], 0], [0, [1400, 1200], 0], [0, [1700, 1200], 0], [7, [1000, 800]], [7, [1200, 800]], [7, [1400, 800]], [2, [850, 930], 0], [2, [4600, 1800], 2], [2, [4900, 1800], 3], [5, [1850,1550]],[6, [3700,2050], 1, 1], [3, [2800, 750],2, 1, 10], [3, [920, 2000], 0, 0, 10], [2, [6900, 1050], 4], [3, [4000, 880], 1, 2, 10], [3, [4250, 880], 1, 3, 5], [3, [4500, 880], 1, 3, 5], [4, [700, 5000]]]]
	entity_file = []
	collision_map = Collision_map(map_file, entity_file, 1000)
	collision_map_2 = Collision_map(map_file_2, entity_file, 1000)
	hit_maps = [collision_map, collision_map_2]
	
	fpsclock = pygame.time.Clock()
	pygame.display.set_caption("Rawr")
	
	window_surface.blit(load_image("Menus//loading.png"), (0,0))
	pygame.display.flip()

	bg_image = load_image("Images/Maps/background.png")
	bg_image = pygame.transform.scale(bg_image, (1336,768))
	cave = load_image("Images/Maps/cave.png")
	cave_ground = load_image("Images/Maps/cave-ground.png")
	fence = load_image("Images/Maps/mining-layer.png")
	rocks = load_image("Images/Maps/rock-mound.png")
	grass = load_image("Images/Maps/grass.png")
	hut = load_image("Images/Maps/hut.png")
	tunnel = load_image("Images/Maps/tunnel.png")
	other_rocks = load_image("Images//Maps//boulder-pile-lift.png")
	tnt_box = load_image("Images//Maps//TNT-box.png")
	hanging_light = load_image("Images//hanging-lights1.png")
	spawner = load_image("Images//spawner.png")
	tile = []
	for i in range(1,5):
		tile.append(load_image("Images/Maps/ground/" + str(i) + ".png"))
	map = Map_Image(map_code)
	
	# Current player	
	player_ID = 1 
		
	# Set up sprites and objects
	plr = Player(1)	
	plr2 = Player(2)
	
	players = pygame.sprite.Group()
	players.add((plr, plr2))
	clouds = pygame.sprite.Group()
	for a in range(1,5):
		for i in range(1, 3):
				clouds.add((Cloud(i))) 
	
	current_player = plr 
	running = True
	music.stop()
	music2 = Play_Music("/test.ogg", -1)
	music2.play()
	music2.set_volume(0.2)

	while running == True:
		rect_change = 0
		for player in players:
			if player.dead == 1:
				current_player.player_ID = player.ID
			elif player.dead == 2:
				print foreground_X
				print player.rect[1]
				plr2.rect[0] += foreground_X
				print foreground_X
				player.dead = 0
				print plr.rect
				
		# If the player swapped characters
		if current_player.player_ID is not player_ID:
			old_y = foreground_Y
			# Assign new player ID
			player_ID = current_player.player_ID
			health = current_player.health
			# Reset the movement
			current_player.x_direction = 0
			# Sets the new controllable sprite
			if current_player.player_ID == 1:
				current_player = plr
			elif current_player.player_ID == 2:
				current_player = plr2
			# Tells the current player what ID is selected
			current_player.player_ID = player_ID
			# Slides
			sliding = True
			
			#button correction
			for item in map.dynamic_objects:
				if item.type == "button" and item.button_type != 0:
					item.activation_delay = 11
					item.float = True
		
		# If the player is further than the right cutoff but not at the end of the map
		if current_player.rect[0] > 500.0 and foreground_X > -1000.0 * map_size:
			# Cloud movement correction
			for cloud in clouds:
				cloud.rect[0] -= current_player.speed * 0.25
			# Move the foreground and all objects
			foreground_X -= (current_player.rect[0] - 500)
			# Move the players
			for dino in players:
				if dino is not current_player:
					dino.rect[0] -= (current_player.rect[0] - 500)
			# Stop the player from moving farther than 600 till you reach the end of the map
			current_player.rect[0] = 500.0
			
			# keeps the foreground in place
			if foreground_X <= -1000 * map_size:
				# Corrector for all the objects on the screen when sliding
				if sliding == True:
					for dino in players:
						dino.rect[0] -= foreground_X + 1000 * map_size
					
				# Holds the foreground in place
				foreground_X = -1000 * map_size
		
		# Same for the left hand side
		if (current_player.rect[0] < 500.0) and (foreground_X < 0):
			for cloud in clouds:
				cloud.rect[0] += current_player.speed * 0.25
				
			foreground_X += (500 - current_player.rect[0])
			for dino in players:
				if dino is not current_player:
					dino.rect[0] += (500 - current_player.rect[0])	
			current_player.rect[0] = 500
			
			if foreground_X >= 0:
				if sliding == True:
					for dino in players:
						dino.rect[0] -= foreground_X
					
				foreground_X = 0
		
		# stop player moving past boundaries
		if current_player.rect[0] >= 0:
			current_player.rect[0] += current_player.speed * current_player.x_direction
		
		if current_player.rect[0] < 0:
			current_player.rect[0] = 0
			
		# Y stuff	
		if current_player.rect[1] < 500:
			if sliding == False:
				# Move the foreground and all objects
				foreground_Y -= current_player.rect[1] - 500
				for player in players:#
					if player != current_player:
						player.rect[1] -= current_player.rect[1] - 500
						rect_change = current_player.rect[1] - 500
				# Stop the player from moving farther than 600 till you reach the end of the map
				
				current_player.rect[1] = 500
				
			else:
				foreground_Y = 500 + current_player.rect[1]
				for player in players:
					player.rect[1] -= old_y - foreground_Y
				sliding == False
					
		# and down
		if current_player.rect[1] >= 500 and foreground_Y > -1050:
			
			if sliding == False:
				# Move the foreground and all objects
				foreground_Y -= current_player.rect[1] - 500
				for player in players:
					if player != current_player:
						player.rect[1] -= current_player.rect[1] - 500
						
				# Stop the player from moving farther than 600 till you reach the end of the map
						
				current_player.rect[1] = 500
			
			
			else:
				if current_player.rect[1] >= 500:
					
					for player in players:
						player.rect[1] -= foreground_Y
					foreground_Y = 0
		
		if foreground_Y < -1050:
			for dino in players:
				dino.rect[1] -= foreground_Y + 1050
			foreground_Y = -1050
					
					
		if foreground_Y != prev_y and current_player.jumping == False:
			for item in map.dynamic_objects:
				if item.type == "button" and item.button_type != 0:
					item.float = True
					
		prev_y = foreground_Y
			
		# Update everything and refresh the screen
		sliding = False
		map_location = [foreground_X, 432 + foreground_Y, rect_change]
		map.update(players, hit_maps, map_location)
	
		players.update(player_ID, map.collision_objects, players, hit_maps, [foreground_X, foreground_Y])

		window_surface.blit(bg_image, (0,0))
		window_surface.blit(map.treeline, [foreground_X * 0.5,-150 + foreground_Y * 0.5])
		window_surface.blit(fence, [foreground_X * 0.8, 250 + foreground_Y * 0.8])
		window_surface.blit(rocks, (1030 + foreground_X,210 + foreground_Y))
		for i in range(0,4):
			window_surface.blit(tile[i], ((i * 1750) + foreground_X, foreground_Y + 375))
		window_surface.blit(map.water[0], [map.water[1][0] + foreground_X, map.water[1][1] + foreground_Y])
		window_surface.blit(cave_ground, [foreground_X, 900 + foreground_Y])
		window_surface.blit(tnt_box, [foreground_X + 350, foreground_Y + 1500])
		#for cloud in clouds:	
			#if current_player.rect[0] > ((foreground_X  + 1000) * 0.25) - 3000 and  current_player.rect[0] < ((foreground_X  + 1000) * 0.95) + 3000 : 
				#window_surface.blit(cloud.image, (cloud.rect[0] + foreground_X * 0.25 , 125 + foreground_Y * 0.))
			#cloud.update(foreground_X, map_size)
		window_surface.blit(map.foreground_dynamic,[0,0], (-1 * foreground_X, 432 - foreground_Y, 1336, 768))
		for player in players:
			if player.ID != player_ID:
				if player.ID == 1:
					window_surface.blit(player.image, player.rect)
				elif (player.ID == 2 and player.rect[0] > 20):
					window_surface.blit(player.image, player.rect)
	
		window_surface.blit(spawner, [1350 + foreground_X,1018 + foreground_Y])
		if current_player.ID == 1:
			window_surface.blit(current_player.image, current_player.rect)
		elif (current_player.ID == 2 and current_player.rect[0] > 20):
			window_surface.blit(current_player.image, current_player.rect)

		window_surface.blit(other_rocks, [600 + foreground_X, 600 + foreground_Y])
		window_surface.blit(hut, [foreground_X,foreground_Y + 150])
		window_surface.blit(other_rocks, [-200 + foreground_X, 600 + foreground_Y])
		window_surface.blit(tunnel, [foreground_X - 50, foreground_Y + 1060])
		window_surface.blit(hanging_light, [foreground_X + 550, foreground_Y + 1000])

		window_surface.blit(grass, [20 + foreground_X, 440+ foreground_Y])		
		window_surface.blit(cave, [-200 + foreground_X * 1.25,894 + foreground_Y])

		timer = fpsclock.get_fps()
		x = foreground_Y
		#text_surface2 = f.render(str(timer) + " " + str(x), 1, (255,0,0))
		#window_surface.blit(text_surface2,(0,0))

		#tracer = hit_maps[1].draw_map()
		#window_surface.blit(tracer, (foreground_X,foreground_Y))

		pygame.display.update()
		map.clear_screen(map_location)
		fpsclock.tick(30)
		
		if current_player.reset == True:
			pygame.mixer.quit()
			main()
		if current_player.rect[0] > 1336:
			pygame.mixer.quit()
			running = False
Ejemplo n.º 16
0
class Button(pygame.sprite.Sprite):
		
	def __init__(self, location, type, gate, trigger, gates):
		pygame.sprite.Sprite.__init__(self)	

		for item in gates:
			if item.ID == gate:
				self.gate = item
				break;
		
		self.trigger_ID = trigger
		self.activated = False
		self.activation_delay = 0
		
		self.type = "button"
		self.float = False
		self.float_hit = 0
		
		self.button_type = type
		
		self.plugged = []
		self.unplugged = []
		self.frame_ID = 0
		self.img_type = "unplugged"
		
		self.prebuffer()
		
		
		if type == 2:
			self.geyser = Play_Music("//sfx//geyser-flow.ogg", -1)
			self.geyser.play()
			self.plugged_sfx = Play_Music("//sfx//plugged-geyser.ogg", -1)
		else:
			self.switch_sfx = Play_Music("//sfx//switch.ogg", -1)
		
		if type != 2:
			self.image = load_image("Images\\button" + str(type) + ".png")

		else:
			self.image = self.unplugged[0]
		
		self.rect = self.image.get_rect()
		self.rect.center = location
		
	def update(self, players, objects, map_location):
		test_rect = [self.rect[0] + map_location[0], self.rect[1] + map_location[1] - 832, self.rect[2], self.rect[3]]
		# Standard wall button
		if self.button_type == 0:
			for player in players:
				if player.rect.colliderect(test_rect):
					if player.interacting == True:
						self.button_pressed()
		# Floor button					
		else:
			hit = False
			for player in players:
				if player.hit_rect.colliderect(test_rect) and player.rect[0] - test_rect[0] > -150 and player.rect[0] - test_rect[0] < 50 and self.button_type != 2:
					hit = True
					if self.activated == False:
						self.button_pressed()
			
			for object in objects:
				if object.type == "block":
					if object.rect.colliderect(self.rect) and object.rect[0] - self.rect[0] > -150 and object.rect[0] - self.rect[0] < 50:
						hit = True
						if self.activated == False:
							if self.button_type != 2:
								self.switch_sfx.play_once()
							else:
								self.geyser.stop()
								self.plugged_sfx.play()
							self.button_pressed()

			if hit == False and self.activated == True:
				self.float_hit += 1
				if self.float_hit > 20:
					if self.button_type == 2:
						self.plugged_sfx.stop()
						self.geyser.play()
					self.button_pressed()
					self.float_hit = 0
					self.float = False
		self.activation_delay += 1
		
		if self.button_type == 2:
			self.run_animation()
			for player in players:
				if player.player_ID == player.ID:
					self.geyser.locate(test_rect[0] - player.rect[0], test_rect[1] - player.rect[1])
					self.plugged_sfx.locate(test_rect[0] - player.rect[0], test_rect[1] - player.rect[1])
		
			
	def button_pressed(self):
		if self.activated == False and self.activation_delay > 10:
			self.gate.trigger(self.trigger_ID)
			self.activation_delay = 0
			if self.button_type != 2:
				self.switch_sfx.play_once()
				self.image = load_image("Images\\button" + str(self.button_type) + "-pressed.png")
			self.frame_ID = 0
			self.activated = True
		elif self.activated == True and self.activation_delay > 10:
			self.gate.trigger(self.trigger_ID * -1)
			if self.button_type != 2:
				#self.switch_sfx.play_once()
				self.image = load_image("Images\\button" + str(self.button_type) + ".png")
			self.frame_ID = 0
			self.activated = False
			self.activation_delay = 0
			
	def run_animation(self):
		if self.activated == True:
			self.image = self.plugged[self.frame_ID]
			self.frame_ID += 1
			if self.frame_ID > 7:
				self.frame_ID = 0
			
		else:
			self.float = False
			self.image = self.unplugged[self.frame_ID]
			self.frame_ID += 1
			if self.frame_ID > 9:
				self.frame_ID = 0
				
	def prebuffer(self):
		for i in range(1, 9):
			self.plugged.append(load_image("Images//plugged//plugged-" + str(10000 + i)[1:] + ".png"))
		for i in range(1, 11):
			self.unplugged.append(load_image("Images//unplugged//geyser-" + str(10000 + i)[1:] + ".png"))
			
	def test_landed(self, player, offset):
		return(False)