Example #1
0
    def __init__(self, name, w, h, ww, wh, topology='wrapped'):

        #initializes world and window geometry
        self.WINDOW_WIDTH = ww
        self.WINDOW_HEIGHT = wh
        self.bounds = Bounds(-w / 2, -h / 2, w / 2, h / 2)
        self.topology = topology

        self.agents = []

        self.root = Tk()
        self.root.title(name)

        Frame.__init__(self, self.root)

        self.bind_all('<KeyPress>', self.keypress)
        self.bind_all('<KeyRelease>', self.keyrelease)

        #makes background canvas
        self.canvas = Canvas(self,
                             width=self.WINDOW_WIDTH,
                             height=self.WINDOW_HEIGHT,
                             bg='purple')

        self.grid()
        self.canvas.grid()

        #sets the top left corner of the display window to the actual (0,0). Was having
        #some weird issues with the edges of the world before, like the window was
        #at (3,3) instead or something weird like that.
        self.canvas.xview_moveto(0.0)
        self.canvas.yview_moveto(0.0)
Example #2
0
    def __init__(self,
                 name,
                 w,
                 h,
                 ww,
                 wh,
                 topology='wrapped',
                 console_lines=0):

        # Register the world coordinate and graphics parameters.
        self.WINDOW_WIDTH = ww
        self.WINDOW_HEIGHT = wh
        self.bounds = Bounds(-w / 2, -h / 2, w / 2, h / 2)
        self.topology = topology

        # Populate the world with creatures
        self.agents = []
        self.GAME_OVER = False
        self.PAUSE_GAME = False

        # Initialize the graphics window.
        self.root = Tk()
        self.root.title(name)
        Frame.__init__(self, self.root)
        self.canvas = Canvas(self.root,
                             width=self.WINDOW_WIDTH,
                             height=self.WINDOW_HEIGHT)

        # Handle mouse pointer motion and keypress events.
        self.mouse_position = Point2D(0.0, 0.0)
        self.mouse_down = False
        self.bind_all('<Motion>', self.handle_mouse_motion)
        self.canvas.bind('<Button-1>', self.handle_mouse_press)
        self.canvas.bind('<ButtonRelease-1>', self.handle_mouse_release)
        self.bind_all('<Key>', self.handle_keypress)

        self.canvas.pack()
        if console_lines > 0:
            self.text = Text(self.root,
                             height=console_lines,
                             bg="#000000",
                             fg="#A0F090",
                             width=115)
            self.text.pack()
        else:
            self.text = None
        self.pack()
Example #3
0
    def __init__(
        self,
        name,
        w,
        h,
        ww,
        wh,
        topology='wrapped',
        console_lines=0,
        port=10000,
        num_cns=1,
        FPS=60
    ):  #need to add options so running Main lets you choose your port.

        #stuff I need (from Frame) but don't want.  Remove?

        # Register the world coordinate and graphics parameters.
        self.WINDOW_WIDTH = ww
        self.WINDOW_HEIGHT = wh
        self.bounds = Bounds(-w / 2, -h / 2, w / 2, h / 2)
        self.topology = topology

        #        self.num_frames = 0

        # actual host:
        self.connections = [
        ]  #for now, this will be a pointer to the Client object.  I will need to change this when I go multiplayer.
        self.agents = [
        ]  #storing agents in a dictionary, rather than in a list, because it makes it easier to think about how to construct the command string.
        self.ships = []  #how does this work with closing connections?
        self.available_IDs = all_IDs()

        self.number_of_asteroids = 0
        self.number_of_shrapnel = 0

        self.before_start_ticks = self.DELAY_START
        self.started = False
        self.FPS = FPS

        self.command_string = ""

        self.level = 3  #deal with this later
        self.score = 0

        self.GAME_OVER = False  #should I include a way for the host to terminate the game, kicking out all the clients?

        #network stuff:
        IP = socket.gethostbyname(socket.gethostname())
        self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        server_address = (
            IP, port
        )  #does this need to go later?  Can I just make this work with localhost, and still have others connect to it?
        print('starting up on {} port {}'.format(*server_address))
        self.sock.bind(server_address)
        self.sock.listen(
            num_cns)  #should I be printing the ip address near here?
        connections_formed = 0
        while connections_formed < num_cns:  #Do I need to close each connection after each pass, and re-open it later?
            print("broadcasting on", self.sock.getsockname()[0])
            print("Waiting for a connection.  Currently connected:",
                  connections_formed, "out of", num_cns)
            connection, client_address = self.sock.accept()
            print("Connection from", client_address, "\n")
            self.add_connection((connection, client_address))
            connections_formed += 1
        self.address = server_address

        if len(self.ships) > 1:
            center = Point2D(w / 2, h / 2)
Example #4
0
    def __init__(self,
                 name,
                 w,
                 h,
                 ww,
                 wh,
                 topology='wrapped',
                 console_lines=0):
        # download jim if jim is not there to set the wallpaper on game over if JIM_MODE env var is not set to anything
        if os.path.isfile('fix-james-d.jpg') == False:
            request.urlretrieve(
                'https://www.reed.edu/dean_of_faculty/faculty_profiles/profiles/photos/fix-james-d.jpg',
                'fix-james-d.jpg')
        self.wallpaperSet = False

        self.paused = False
        self.gameOver = False

        # Register the world coordinate and graphics parameters.
        self.WIDTH = w
        self.HEIGHT = h
        self.WINDOW_WIDTH = ww
        self.WINDOW_HEIGHT = wh
        self.bounds = Bounds(-w / 2, -h / 2, w / 2, h / 2)
        self.topology = topology

        # Populate the world with creatures
        self.agents = []
        self.display = 'test'
        self.GAME_OVER = False

        # Populate the background with the walls for pacman
        self.prevWalls = None
        self.walls = []

        # Initialize the graphics window.
        self.root = Tk()
        self.root.title(name)
        # grab window focus after game starts
        self.root.after(500, lambda: self.root.grab_set_global())
        Frame.__init__(self, self.root)
        self.canvas = Canvas(self.root,
                             width=self.WINDOW_WIDTH,
                             height=self.WINDOW_HEIGHT)

        # Handle mouse pointer motion and keypress events.
        self.mouse_position = Point2D(0.0, 0.0)
        self.mouse_down = False
        self.bind_all('<Motion>', self.handle_mouse_motion)
        self.canvas.bind('<Button-1>', self.handle_mouse_press)
        self.canvas.bind('<ButtonRelease-1>', self.handle_mouse_release)
        self.bind_all('<Key>', self.handle_keypress)

        self.canvas.pack()
        if console_lines > 0:
            self.text = Text(self.root,
                             height=console_lines,
                             bg="#000000",
                             fg="#A0F090",
                             width=115)
            self.text.pack()
        else:
            self.text = None
        self.pack()

        # keep track of multiplayer
        self.otherPlayers = []
        self.socketID = []
    def __init__(self,
                 name,
                 w,
                 h,
                 ww,
                 wh,
                 topology='wrapped',
                 console_lines=0,
                 FPS=60):

        # Register the world coordinate and graphics parameters.
        self.WINDOW_WIDTH = ww
        self.WINDOW_HEIGHT = wh
        self.bounds = Bounds(-w / 2, -h / 2, w / 2, h / 2)
        self.topology = topology

        # Populate the world with creatures
        self.agents = {}
        self.GAME_OVER = False

        # Initialize the graphics window.
        self.root = Tk()
        self.root.title(name)
        Frame.__init__(self, self.root)
        self.root.config(cursor='none')  #mouse hiding test
        self.canvas = Canvas(self.root,
                             width=self.WINDOW_WIDTH,
                             height=self.WINDOW_HEIGHT)

        # Handle mouse pointer motion and keypress events.
        self.mouse_position = Point2D(0.0, 0.0)
        self.mouse_down = False
        self.bind_all('<Motion>', self.handle_mouse_motion)
        self.canvas.bind('<Button-1>', self.handle_left_mouse_press)
        self.canvas.bind('<ButtonRelease-1>', self.handle_left_mouse_release)
        self.canvas.bind('<Button-3>', self.handle_right_mouse_press)
        self.canvas.bind('<ButtonRelease-3>', self.handle_right_mouse_release)
        self.bind_all('<KeyPress>', self.handle_keypress)
        self.bind_all('<KeyRelease>', self.handle_keyrelease)

        #my stuff:
        #        self.ship_ID = None #change this later
        #should this report_strings info instead be in Ship?
        self.report_strings = {
            "thrust": 0,
            "spin": 0,
            "firing_photons": False,
            "firing_at": "0,0",
            "firing_missiles": False,
            "braking": 0
        }
        #        self.create_dict = {"MovingBody": PlayAsteroids.MovingBody, "Shootable": PlayAsteroids.Shootable,
        #                            "Asteroid": PlayAsteroids.Asteroid, "ParentAsteroid": PlayAsteroids.ParentAsteroid,
        #                            "Ember": PlayAsteroids.Ember, "ShrapnelAsteroid": PlayAsteroids.ShrapnelAsteroid,
        #                            "SmallAsteroid": PlayAsteroids.SmallAsteroid, "MediumAsteroid": PlayAsteroids.MediumAsteroid,
        #                            "LargeAsteroid": PlayAsteroids.LargeAsteroid, "Photon": PlayAsteroids.Photon,
        #                            "Ship": PlayAsteroids.Ship}
        if not MOUSEMODE:
            self.report_strings['firing_at'] = "mouseoff"
        self.draw_string = ""
        self.target_angle_1 = 45
        self.target_angle_2 = 135

        self.canvas.pack()
        if console_lines > 0:
            self.text = Text(self.root,
                             height=console_lines,
                             bg="#000000",
                             fg="#A0F090",
                             width=115)
            self.text.pack()
        else:
            self.text = None
        self.pack()

        # Create a TCP/IP socket
        self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)