Ejemplo n.º 1
0
class Game:
    def __init__(self):
        self.network = Network()
        self.map = Map(self)
        self.window = Window(self)
        self.main_loop_running = False

    def run(self):
        if self.network.check_file_data():
            MapScreen(self.window, self.map).open_()
        self.main_loop_running = True
        while self.main_loop_running:
            self.window.iteration()
            self.network.iteration()

    def stop(self):
        self.main_loop_running = False
Ejemplo n.º 2
0
def main():
    world = load_world(WORLD_FILE)

    window = Window(world=world,
                    width=800,
                    height=600,
                    caption='PythonCraft',
                    resizable=True)
    setup()
    pyglet.app.run()
Ejemplo n.º 3
0
def main(world_size):
    width, height = (world_size, ) * 2
    world = convert_heightmap(generate_heightmap(7487670, width, height),
                              width, height)
    window = Window(world=world,
                    width=800,
                    height=600,
                    caption='PythonCraft',
                    resizable=True)
    setup()
    pyglet.app.run()
Ejemplo n.º 4
0
    def decode(cls, obj_file: str) -> 'Scene':
        from scene import Scene
        # Returns a Scene with the window and objects found
        vertices = []
        objs: List[GraphicObject] = []
        window = None

        current_name = ''
        filled = False

        for line in obj_file.splitlines():
            cmd, *args = line.split(' ')

            if cmd == 'v':
                vertices.append(Vec2(float(args[0]), float(args[1])))
            elif cmd == 'o':
                current_name = ' '.join(args)
            elif cmd == 'usemtl':
                if args[0] == 'filled':
                    filled = True
            elif cmd == 'p':
                objs.append(
                    Point(pos=vertices[int(args[0]) - 1], name=current_name))
            elif cmd == 'l':
                if len(args) == 2:
                    objs.append(
                        Line(start=vertices[int(args[0]) - 1],
                             end=vertices[int(args[1]) - 1],
                             name=current_name))
                elif args[0] == args[-1]:
                    objs.append(
                        Polygon(
                            vertices=[vertices[int(i) - 1] for i in args[:-1]],
                            name=current_name,
                            filled=filled))
                    filled = False
                else:
                    objs.append(
                        Curve(
                            vertices=[vertices[int(i) - 1] for i in args],
                            name=current_name,
                        ))
            elif cmd == 'w':
                window = Window(min=vertices[int(args[0]) - 1],
                                max=vertices[int(args[1]) - 1])

        return Scene(objs=objs, window=window)
Ejemplo n.º 5
0
    def on_resize(self, widget: Gtk.Widget, allocation: Gdk.Rectangle):
        if self.scene.window is None:
            w, h = allocation.width, allocation.height
            self.old_size = allocation
            self.scene.window = Window(Vec2(-w / 2, -h / 2),
                                       Vec2(w / 2, h / 2))

        w_proportion = allocation.width / self.old_size.width
        h_proportion = allocation.height / self.old_size.height

        self.scene.window.max = Vec2(self.scene.window.max.x * w_proportion,
                                     self.scene.window.max.y * h_proportion)
        self.scene.window.min = Vec2(self.scene.window.min.x * w_proportion,
                                     self.scene.window.min.y * h_proportion)
        self.old_size = allocation

        self.scene.update_ndc()
Ejemplo n.º 6
0
 def __init__(self):
     self.network = Network()
     self.map = Map(self)
     self.window = Window(self)
     self.main_loop_running = False
Ejemplo n.º 7
0
    def do_rotate(self):
        """
        Check if the current_shape can be rotated and
        rotate if it can.
        """
        
        if self.current_shape.can_move(self.board, 0, 1) and self.current_shape.can_rotate(self.board):
                self.current_shape.rotate(self.board)
    
    def key_pressed(self, event):
        """
        When a key is pressed,
        if users presses keys: "Left", "Right" or "Down", the current_shape will move in the appropriate direction
        if user presses the space bar "space", the shape will move down until it can no longer move and is added to the board
        if the user presses the "Up" arrow key, the shape rotates.
        """
        key = event.keysym
        if key == "Down" or key == "Right" or key == "Left":
            self.do_move(key)
        if key == "Up":
            self.do_rotate()
        if key == "space":
            while self.current_shape.can_move(self.board, 0, 1):
                self.do_move(key)
            self.board.add_shape(self.current_shape)

win = Window("Tetris")
game = Tetris(win)
win.mainloop()
Ejemplo n.º 8
0
from ptpython.repl import embed
import settings

import asyncio

loop = asyncio.get_event_loop()

from graphics import Window, draw_frame
d = Window(width=800, height=600, caption='pyBoxelEngine', resizable=True)

##An example
counter = [0]


async def print_counter():
    """
    Coroutine that prints counters and saves it in a global variable.
    """
    while True:
        print('Counter: %i' % counter[0])
        counter[0] += 1
        await asyncio.sleep(3)


##The interactive shell
@asyncio.coroutine
def interactive_shell():
    """
    Coroutine that starts a Python REPL from which we can access the global
    counter variable.
    """
        while self.running:
            start = time.time()
            self.port.read_csv_for_bar(self.temp, self.nbars)
            self.buffer.push(self.temp[:])
            print("Aquisition time:", time.time() - start)
            if (time.time() - last_update_time) > arduino_update_time:
                continue
            else:
                time.sleep(arduino_update_time - (time.time() - last_update_time))

    def stop(self):
        self.running = False


window = Window()


#-------------create the barplot and label it----------------
barplot = BarPlot(Point(-0.9, 0.4, 0), 0.5, 0.5, 8, 1023)

x_labels = []
x_labels.append(UI_Label("sensor.png", 0.1, 0.1))
x_labels[0].move(-0.95, 0.3)
for i in range(8):
    x_labels.append(UI_Label(f"{i}.png", 0.08, 0.08))
    if i == 0:
        x_labels[-1].move(-0.9 + 0.06, 0.3)
    elif i >= 4:
        x_labels[-1].move(-0.9 + 0.06 * (i + 1) + 0.01 * (i - 3), 0.3)
    else:
Ejemplo n.º 10
0
Archivo: main.py Proyecto: tombroc/TX52
if __name__ == '__main__':
	
	# Possible state of a drone
	drone_out          = 0;	# Drone on his spot but damage so a fly is impossible 
	drone_backprogress = 1;	# Drone is coming back of his mission
	drone_ready        = 2;	# Drone on his spot and operational
	drone_flying       = 3;	# Drone in mission flying through the target
	drone_back         = 4;	# Drone back of a mission ready for inspection
	drone_destroyed    = 5;	# Drone destroyed during a mission
	drone_detected     = 6;	# Drone ennemi dedetected
	
	p                  = 30
	
	utils              = Utils(thread_list);
	
	Win                = Window(utils, thread_list);

	utils.canvas       = Win.get_canvas();
	utils.label_list   = Win.get_label_list();
	utils.win          = Win;
	
	radar = Radar(utils, thread_list, Win.get_canvas(), Win.get_label_list(), Win.get_repare_b());
	thread_list.append(radar);
	print ("---- Drones 1 to "+str(g.NUMBER_DRONE)+" initialization ----");
	for i in range(g.NUMBER_DRONE):
		print ("Drone : "+ str(i+1));
		X = ((Win.get_width_zone() - g.NUMBER_DRONE * p) / 2 + p * i + p/2) * g.DIMENSION_COEFFICIENT;
		Y = Win.get_origine_Y() - 20 * g.DIMENSION_COEFFICIENT;
		Z = 0;
		drone = Drone(utils, Win.get_canvas(), i, X, Y, Z, thread_list, Win.get_label_list()[i]);
		thread_list.append(drone);