Ejemplo n.º 1
0
    def __init__(self, name, location):
        self.leave = 0
        self.array = []
        self.npc = [Npc(), Npc(), Npc(), Npc()]
        self.name = name
        self.location = location
        self.roads = [
            Road("0 rd", [0, 0], 0),
            Road("1 rd", [0, 1], 0),
            Road("2 rd", [0, 2], 0),
            Road("3 rd", [0, 3], 0),
            Road("4 rd", [0, 4], 0),
            Road("5 rd", [1, 4], 0),
            Road("6 rd", [1, 3], 0),
            Road("7 rd", [-1, 3], 0),
            Road("8 rd", [-1, 1], 0),
            Road("9 rd", [1, 2], 0),
        ]

        self.roadp = [
            Road("0 rd", [0, 0], [0, 1]),
            Road("0 rd", [0, 0], [0, 2]),
            Road("0 rd", [0, 0], [0, 3]),
            Road("0 rd", [0, 0], [0, 4]),
            Road("1 rd", [0, 1], [0, 0]),
            Road("1 rd", [0, 1], [0, 2]),
            Road("1 rd", [0, 1], [0, 3]),
            Road("1 rd", [0, 1], [0, 4]),
            Road("1 rd", [0, 1], [-1, 1]),
            Road("2 rd", [0, 2], [0, 0]),
            Road("2 rd", [0, 2], [0, 1]),
            Road("2 rd", [0, 2], [0, 3]),
            Road("2 rd", [0, 2], [0, 4]),
            Road("2 rd", [0, 2], [1, 2]),
            Road("3 rd", [0, 3], [0, 0]),
            Road("3 rd", [0, 3], [0, 1]),
            Road("3 rd", [0, 3], [0, 2]),
            Road("3 rd", [0, 3], [0, 4]),
            Road("3 rd", [0, 3], [-1, 3]),
            Road("4 rd", [0, 4], [0, 0]),
            Road("4 rd", [0, 4], [0, 1]),
            Road("4 rd", [0, 4], [0, 2]),
            Road("4 rd", [0, 4], [0, 3]),
            Road("4 rd", [0, 4], [1, 4]),
            Road("5 rd", [1, 4], [0, 4]),
            Road("5 rd", [1, 4], [1, 3]),
            Road("6 rd", [1, 3], [1, 4]),
            Road("7 rd", [-1, 3], [0, 3]),
            Road("7 rd", [-1, 3], [-1, 1]),
            Road("8 rd", [-1, 1], [-1, 3]),
            Road("8 rd", [-1, 1], [0, 1]),
            Road("9 rd", [1, 2], [0, 2]),
        ]
Ejemplo n.º 2
0
 def __init__(self, player):
     self.player = player
     self.npcs = [Npc(1), Npc(2), Npc(3), Npc(4)]
     self.towns = [
         Town(self.npcs, "0", [0, 0]),
         Town(self.npcs, "1", [1, 1]),
         Town(self.npcs, "2", [2, 2]),
         Town(self.npcs, "3", [3, 3]),
         Town(self.npcs, "4", [4, 4]),
         Town(self.npcs, "5", [5, 5]),
         Town(self.npcs, "6", [6, 6]),
         Town(self.npcs, "7", [7, 7]),
         Town(self.npcs, "8", [8, 8])
     ]
Ejemplo n.º 3
0
	def __init__(self, engine):
		self.engine = engine
		self.render_text_block = engine.render_text_block
		self.width, self.height = engine.get_screensize()
		self.game_objects = []
		self.player = Player(self)
		self.npc = Npc(self)
		self.map = MapHandler(self, map_data.map_data)
		self.map.load_map("big_world")
Ejemplo n.º 4
0
    def __init__(self, maze_filename):
        """Initialize the game manager object.

        Arguments:

        maze_filename - name of human readable/writable text file containing
            the maze definition for use in single player mode
        """

        gs = GameState.singleton()
        self.gs = gs

        gs.nickname = input(
            "For multiplayer game, enter your nickname (default is single player):"
        )
        if gs.nickname:
            gs.multiplayer = True
            # TODO - should be assigned by MazeServer
            while True:
                new_color_text = input(
                    f"Choose a color code ({', '. join(list(gs.colors()))}) (default is w):"
                )
                if not new_color_text:
                    break
                if new_color_text in gs.colors():
                    gs.color = gs.colors()[new_color_text]
                    break
                print(
                    f"Unknown color code: '{new_color_text}''. Please try again."
                )
            print(f"Selected {gs.color}.")
            gs.connection = MazeClient('127.0.0.1', 8089)
            gs.connection.Loop()
            # server will send the maze data
            while not gs.maze:
                gs.connection.Loop()
        else:
            gs.maze = Maze(maze_filename)

        # loop through maze file and instanciate the specified objects

        for i in range(0, gs.maze.height):
            for j in range(0, gs.maze.width):
                ch = gs.maze.file_rows[i][j]
                if ch == 'P':
                    gs.player = Player((i, j))
                elif ch == 'N' and not gs.multiplayer:
                    Npc((i, j))
                elif ch == 'E' and not gs.multiplayer:
                    Exit(gs.maze, (i, j))

        # boiler plate pygame initialization (screen just black after this)

        gs.camera = Camera()
Ejemplo n.º 5
0
class Game:
	def __init__(self, engine):
		self.engine = engine
		self.render_text_block = engine.render_text_block
		self.width, self.height = engine.get_screensize()
		self.game_objects = []
		self.player = Player(self)
		self.npc = Npc(self)
		self.map = MapHandler(self, map_data.map_data)
		self.map.load_map("big_world")
		#self.d = DialogBox(self, "This is just a test of the dialog box system!\nThis would be some cool stuff here if there was something cool to say\nHere's another line that should be pretty cool later on")

	def sort_gameobjects(self):
		self.game_objects = sorted(self.game_objects, key=lambda game_object: game_object.z, reverse=True)

	def add_game_object(self, obj):
		"""
		Adds a game object to the list of objects in the game
		These game objects need to have update and draw methods
		After inserting the object it sorts the list by z for drawing
		"""
		self.game_objects.append(obj)
		self.sort_gameobjects()

	def update(self, dt):
		for game_object in self.game_objects:
			game_object.update(dt)

	def draw(self, canvas):
		for game_object in self.game_objects:
			game_object.draw(canvas)
		#self.d.draw(canvas)

	def handle_event(self, event):
		key = event.key
		#if the key is a key that the player requests, send key to player
		if key in self.player.get_keys():
			self.player.handle_key(key, self.check_player_position)
		#else if the key is the letter m, open the menu
		elif key == pygame.K_m:
			self.engine.change_state("Menu")

	def is_valid_position(self, x, y, from_obj):
		if from_obj == "npc":
			map_test = self.map.is_position_ok(x, y)
			return map_test

	def c2_player_position(self, new_rect):
		#check if 
		# -- player is within the screen
		# -- player is in scroll area
		# -- -- don't let player move, move camera coords instead
		# -- temp, if hitting npc
		# -- check map
		can_go = new_rect
		if not self.check_if_onscreen(new_rect):
			can_go = False
		elif new_rect.colliderect(self.npc.get_rect()):
			can_go = False
		elif not self.map.is_position_ok(new_rect.x, new_rect.y):
			can_go = False
		if can_go:
			self.player.x = can_go.x
			self.player.y = can_go.y

	def check_player_position(self, new_rect):
		can_go = new_rect

		if not self.check_if_onscreen(new_rect):
			can_go = False
		elif new_rect.colliderect(self.npc.get_rect()):
			can_go = False
		elif not self.map.is_position_ok(new_rect.x, new_rect.y):
			can_go = False
		if can_go:
			on_pad = self.check_if_on_screenpad(can_go)
			if on_pad:
				self.map.move_camera(on_pad)
			
			self.player.x = can_go.x
			self.player.y = can_go.y

	def check_if_on_screenpad(self, rect):
		screenpad = self.map.get_screenpad()
		if rect.x < screenpad:
			return "left"
		elif rect.y < screenpad:
			return "up"
		elif rect.right > self.width - screenpad:
			return "right"
		elif rect.bottom > self.height - screenpad:
			return "down"
		return False

	def check_if_onscreen(self, rect):
		"""
		Checks if the rect is on the screen or not
		"""
		if rect.x < 0 or rect.y < 0:
			return False
		elif rect.right > self.width or rect.bottom > self.height:
			return False
		return True

	def get_player_info(self):
		info = self.player.attributes
		info["name"] = self.player.name
		return info

	def get_screensize(self):
		return self.engine.get_screensize()
Ejemplo n.º 6
0
 def __init__(self,render):
     self.threshold = 15
     self.render = render
     
     self.cp1anchorx = Constants.CP1X
     self.cp1anchory = Constants.CP1Y
     self.cp1anchorz = -1
     
     self.cp2anchorx = Constants.CP2X
     self.cp2anchory = Constants.CP2Y
     self.cp2anchorz = -1
     
     self.cp3anchorx = Constants.CP3X
     self.cp3anchory = Constants.CP3Y
     self.cp3anchorz = -1
     
     self.cp4anchorx = Constants.CP4X
     self.cp4anchory = Constants.CP4Y
     self.cp4anchorz = -1
     
     self.cp5anchorx = Constants.CP5X
     self.cp5anchory = Constants.CP5Y
     self.cp5anchorz = -1
     
     cp1team = 0
     cp2team = 0
     cp3team = 0
     cp4team = 1
     cp5team = 1
     
     
     self.npc10 = Npc(1,1,self.cp1anchorx+1, self.cp1anchory+1, self.cp1anchorz,render, cp1team)
     self.npc11 = Npc(1,2,self.cp1anchorx+2, self.cp1anchory+2, self.cp1anchorz,render, cp1team)
     self.npc12 = Npc(1,3,self.cp1anchorx-2, self.cp1anchory+2, self.cp1anchorz,render, cp1team)
     self.npc13 = Npc(1,4,self.cp1anchorx-2, self.cp1anchory-2, self.cp1anchorz,render, cp1team)
     self.npc14 = Npc(1,5,self.cp1anchorx+2, self.cp1anchory-2, self.cp1anchorz,render, cp1team)
     
     self.npc20 = Npc(2,6,self.cp2anchorx+1, self.cp2anchory+1, self.cp2anchorz,render, cp2team)
     self.npc21 = Npc(2,7,self.cp2anchorx+2, self.cp2anchory+2, self.cp2anchorz,render, cp2team)
     self.npc22 = Npc(2,8,self.cp2anchorx-2, self.cp2anchory+2, self.cp2anchorz,render, cp2team)
     self.npc23 = Npc(2,9,self.cp2anchorx-2, self.cp2anchory-2, self.cp2anchorz,render, cp2team)
     self.npc24 = Npc(2,10,self.cp2anchorx+2, self.cp2anchory-2, self.cp2anchorz,render, cp2team)
     
     self.npc30 = Npc(3,11,self.cp3anchorx+1, self.cp3anchory+1, self.cp3anchorz,render, cp3team)
     self.npc31 = Npc(3,12,self.cp3anchorx+2, self.cp3anchory+2, self.cp3anchorz,render, cp3team)
     self.npc32 = Npc(3,13,self.cp3anchorx-2, self.cp3anchory+2, self.cp3anchorz,render, cp3team)
     self.npc33 = Npc(3,14,self.cp3anchorx-2, self.cp3anchory-2, self.cp3anchorz,render, cp3team)
     self.npc34 = Npc(3,15,self.cp3anchorx+2, self.cp3anchory-2, self.cp3anchorz,render, cp3team)
     
     self.npc40 = Npc(4,16,self.cp4anchorx, self.cp4anchory, self.cp4anchorz,render, cp4team)
     self.npc41 = Npc(4,17,self.cp4anchorx+2, self.cp4anchory+2, self.cp4anchorz,render, cp4team)
     self.npc42 = Npc(4,18,self.cp4anchorx-2, self.cp4anchory+2, self.cp4anchorz,render, cp4team)
     self.npc43 = Npc(4,19,self.cp4anchorx-2, self.cp4anchory-2, self.cp4anchorz,render, cp4team)
     self.npc44 = Npc(4,20,self.cp4anchorx+2, self.cp4anchory-2, self.cp4anchorz,render, cp4team)
     
     self.npc50 = Npc(5,21,self.cp5anchorx+1, self.cp5anchory+1, self.cp5anchorz,render, cp5team)
     self.npc51 = Npc(5,22,self.cp5anchorx+2, self.cp5anchory+2, self.cp5anchorz,render, cp5team)
     self.npc52 = Npc(5,23,self.cp5anchorx-2, self.cp5anchory+2, self.cp5anchorz,render, cp5team)
     self.npc53 = Npc(5,24,self.cp5anchorx-2, self.cp5anchory-2, self.cp5anchorz,render, cp5team)
     self.npc54 = Npc(5,25,self.cp5anchorx+2, self.cp5anchory-2, self.cp5anchorz,render, cp5team)
     
     
     self.controlPoint1List = [self.npc10,self.npc11,self.npc12,self.npc13,self.npc14]
     self.controlPoint2List = [self.npc20,self.npc21,self.npc22,self.npc23,self.npc24]
     self.controlPoint3List = [self.npc30,self.npc31,self.npc32,self.npc33,self.npc34]
     self.controlPoint4List = [self.npc40,self.npc41,self.npc42,self.npc43,self.npc44]
     self.controlPoint5List = [self.npc50,self.npc51,self.npc52,self.npc53,self.npc54]
     
     self.controlPointList = [self.controlPoint1List,self.controlPoint2List,self.controlPoint3List,self.controlPoint4List,self.controlPoint5List]
     
     self.AIworld = AIWorld(self.render)
     self.setAI()
Ejemplo n.º 7
0
 def __init__(self, quest_x, quest_y, main_class):
     self.quest_x = quest_x
     self.quest_y = quest_y
     self.quest_npcs = [Npc("Farmer", self.quest_x, self.quest_y)]
     self.main_class = main_class