Exemple #1
0
 def diff_search(self, d):
     v1 = util.Vector(self.vector.get_vector())
     v1.request()
     print("diff from:" + self.vector.get_vector(d))
     for i in range(24):
         self.vector.update_digits1(i, d)
         v2 = util.Vector(self.vector.get_vector())
         v2.request()
         print(v1.diff(v2).strip("[]").replace(",", "\t"))
         v1 = v2
Exemple #2
0
 def __init__(self, gun, position, dir, texture):
     particle.Particle.__init__(self, position, texture)
     self.gun = gun
     self.dir = dir
     self.velocity = util.Vector(self.dir * self.gun.speed, 0)
     self.texture = pygame.transform.scale(
         texture, (int(math.sqrt(self.gun.speed) * 5), 1))
Exemple #3
0
 def dump_search(self, d):
     print("dump in:" + self.vector.get_vector(d))
     for i in range(24):
         self.vector.update_digits1(i, d)
         v2 = util.Vector(self.vector.get_vector())
         v2.request()
         print(str(v2.dump()).strip("[]").replace(",", "\t"))
Exemple #4
0
 def __init__(self, num, loop, initial_vector=None):
     super(Worker, self).__init__()
     self.num = num
     self.loop = loop
     self.vector = util.Vector(initial_vector)
     self.score = 0
     self.code = ""
     self.queue = queue.Queue()
Exemple #5
0
    def get_polygon(self):
        #        float cosa = (float)Math.cos((double)ang), sina = (float)Math.sin((double)ang);
        #
        #  Vector2D A = new Vector2D(S.x * cosa - S.y * sina, S.x * sina + S.y * cosa);
        #  Vector2D B = new Vector2D(-S.x * cosa - S.y * sina, -S.x * sina + S.y * cosa);
        # center point
        C = util.Vector(self.x, self.y)

        rad = math.radians(self.rotation)

        cosa = math.cos(rad)
        sina = math.sin(rad)

        h = self.height * self.scale / 2
        w = self.width * self.scale / 2

        # offset
        A = util.Vector(w * cosa - h * sina, w * sina + h * cosa)
        # y offset
        B = util.Vector(-w * cosa - h * sina, -w * sina + h * cosa)

        #  polygon.moveTo(C.x + A.x, C.y + A.y);
        #  polygon.lineTo(C.x + B.x, C.y + B.y);
        #  polygon.lineTo(C.x - A.x, C.y - A.y);
        #  polygon.lineTo(C.x - B.x, C.y - B.y);

        upper_left = util.Vector(C.x + A.x, C.y + A.y)
        upper_right = util.Vector(C.x + B.x, C.y + B.y)
        lower_right = util.Vector(C.x - A.x, C.y - A.y)
        lower_left = util.Vector(C.x - B.x, C.y - B.y)

        return util.Polygon([upper_left, upper_right, lower_right, lower_left])
Exemple #6
0
def net_update(data):
    if data["op"] == common.OP_ENTITY_MOVE:
        if not is_host:
            ent = entity.entity_from_id(data["eid"])
            if ent is None:
                print("added net player 0")
                entity.add_net_entity(data["eid"], Player("arnold", (data["x"], data["y"])))
            else:
                print("updated player")
                ent.rect.topleft = data["x"], data["y"]
    elif data["op"] == common.OP_ENTITY_VEL:
        if not is_host:
            entity.entity_from_id(data["eid"]).velocity = util.Vector(data["vx"], data["vy"])
Exemple #7
0
 def __init__(self, width, height):
     self._screen = util.Vector([width, height])
     
     self.is_perspective = True
     
     self._position = util.Z.copy()
     self._focus = util.ORIGIN.copy()
     
     self._r = util.X.copy()
     self._u = util.Y.copy()
     self._f = util.Z.copy()
     
     self.fov = 60
     self.z_near, self.z_far = 0, 200
     
     self._x_min, self._x_max = -10, 10
     self._y_min, self._y_max = -10, 10
     
     self._projection = util.IDEN4.copy()
     self._view = util.IDEN4.copy()
Exemple #8
0
class CarSpecimen:

	ACCEL_MAX = 5
	ACCEL_MIN = -5

	MAX_SPEED = 1	
	MAX_ANG_SPEED = 5

	_DISPLAY_HANDLER = None

	_GUIDES = [util.Vector(0,1), util.Vector(0,-1), util.Vector(1,1), util.Vector(1,-1), util.Vector(1,0)]
	# _GUIDES = [util.Vector(0,1)]

	@classmethod
	def set_display_handler(cls, handler):
		cls._DISPLAY_HANDLER = handler

	def __init__(self, x,y, orientation=0, speed=5, ang_speed=3, brain=None, name="Anon Car"):
		self.x = x
		self.y = y
		self.orientation = orientation		# in radians
		self.speed = speed
		self.ang_speed = ang_speed
		self._DISPLAY_HANDLER = self._DISPLAY_HANDLER()
		self._DISPLAY_HANDLER.initialize(self, x, y)
		self._ALIVE = True
		self.brain = brain
		self.name = name
		self.selected = False


	def select(self):
		self.selected = True

	def unselect(self):
		self.selected = False

	def act(self, inputs):
		# inputs
		if not self._ALIVE: return None

		out = self.brain.instruction(inputs)

		# print "{0}: Angle {1}, accel {2} - pos: ({3},{4})" .format(self.name, out[0], out[1], self.x, self.y)

		angle = out[0]
		accel = out[1]

		# TODO set controls on max angle and accel
		self.speed = min(self.speed + accel, self.MAX_SPEED)
		self.orientation += (angle * self.ang_speed)

		self.drive()


	def drive(self):
		self.x += math.cos(math.radians(self.orientation)) * self.speed
		self.y -= math.sin(math.radians(self.orientation)) * self.speed
		
	def turn(self, r):
		self.orientation += r*self.ang_speed

	def guides(self):
		return map(lambda l: l.normalize(1000).rotate(-self.orientation), self._GUIDES)

	def draw(self, params=None):
		self._DISPLAY_HANDLER.draw(params)

	def set_inputs(self, distances):
		self.distances = distances

	def kill(self):
		self._ALIVE = False
Exemple #9
0
 def translate(self, v = None, *, dx = 0, dy = 0, dz = 0):
     if v == None:
         v = util.Vector([dx, dy, dz], float)
     
     self._position += v
     self._focus += v
Exemple #10
0
 def test_util_generate_random_vector(self):
     v = util.Vector()
     self.assertEqual("XX-XX-XX-XX-XX-XX", v.get_vector())
    def start(self):
        while self.running:
            #update
            self.editApp.update(self.screen)

            if self.Li_Tile_select.value:
                self.cur_Tile = self.Li_Tile_select.value
            else:
                self.cur_Tile = 0

            self.layerVis = [
                self.Sw_layer1_vis.value, self.Sw_layer2_vis.value,
                self.Sw_layer3_vis.value
            ]

            #update linke Seite
            self.layerTable.clear()
            self.layerTable.td(self.Lb_Layer_Topic, 0, 0, collspan=2)
            self.layerTable.td(self.Lb_layer1, 0, 1)
            self.layerTable.td(self.Sw_layer1_vis, 1, 1)
            self.layerTable.td(self.Lb_layer2, 0, 2)
            self.layerTable.td(self.Sw_layer2_vis, 1, 2)
            self.layerTable.td(self.Lb_layer3, 0, 3)
            self.layerTable.td(self.Sw_layer3_vis, 1, 3)
            #---------

            #update rechte Seite (wg. TileBild
            self.tilesTable.clear()
            self.tilesTable.td(self.Lb_Tiles_Topic, 0, 0, colspan=2)
            self.tilesTable.td(self.Lb_curT_index, 0, 1)
            self.tilesTable.td(gui.Label(str(self.cur_Tile)), 1, 1)
            self.tilesTable.td(self.Lb_curT_name, 0, 2)
            self.tilesTable.td(gui.Label(self.tiles[self.cur_Tile][0]), 1, 2)
            self.tilesTable.td(self.Lb_curT_type, 0, 3)
            self.tilesTable.td(gui.Label(self.tiles[self.cur_Tile][1]), 1, 3)
            self.tilesTable.td(self.Lb_curT_image, 0, 4)
            self.tilesTable.td(
                gui.Image(
                    os.path.join(self.basepath, 'data', 'tiles',
                                 self.tiles[self.cur_Tile][2])), 1, 4)
            self.tilesTable.td(self.Lb_curT_access, 0, 5)
            self.tilesTable.td(gui.Label(self.tiles[self.cur_Tile][3]), 1, 5)
            self.tilesTable.td(self.Lb_curT_danger, 0, 6)
            self.tilesTable.td(gui.Label(self.tiles[self.cur_Tile][4]), 1, 6)
            self.tilesTable.td(self.Lb_Tiles, 0, 7)

            self.tilesTable.td(self.Li_Tile_select, 1, 7)
            #------

            #update oben
            self.topTable.clear()
            self.topTable.td(self.Lb_map_name, 0, 0)
            self.topTable.td(self.Inp_map_name, 1, 0)
            self.topTable.td(self.Lb_map_dimH, 0, 1)
            self.topTable.td(self.Inp_map_dimH, 1, 1)
            self.topTable.td(self.Lb_map_dimV, 0, 2)
            self.topTable.td(self.Bt_applyOpt, 0, 3)
            self.topTable.td(self.Bt_resetCam, 1, 3)
            self.topTable.td(self.Inp_map_dimV, 1, 2)
            self.topTable.td(self.Lb_map_bgMusic, 2, 0)
            self.topTable.td(self.Inp_map_bgMusic, 3, 0)
            self.topTable.td(self.Lb_map_entityFile, 2, 1)
            self.topTable.td(self.Inp_map_entityFile, 3, 1)
            self.topTable.td(self.Lb_map_nextLvl, 2, 2)
            self.topTable.td(self.Inp_map_nextLevel, 3, 2)
            self.topTable.td(self.Bt_newMap, 4, 0)
            self.topTable.td(self.Bt_loadMap, 4, 1)
            self.topTable.td(self.Bt_saveMap, 4, 2)
            #-----------

            #render
            if self.calcTopLayer() == 0:
                self.transpColor = (255, 0, 255)
            elif self.calcTopLayer() == 1:
                self.transpColor = (125, 255, 125)
            elif self.calcTopLayer() == 2:
                self.transpColor = (125, 125, 255)
            else:
                self.transpColor = (255, 255, 255)
            self.mapSurface.fill((0, 0, 0))
            self.renderMapBg()
            self.renderMap()
            self.screen.blit(self.mapSurface, (150, 150))
            self.screen.blit(self.layerMenuBG, (0, 0))
            self.screen.blit(self.tilesMenuBG, (950, 0))
            self.screen.blit(self.topMenuBG, (150, 0))
            self.editApp.paint(self.screen)

            for event in pygame.event.get():
                if event.type == pygame.QUIT:
                    self.running = False
                elif event.type == pygame.KEYDOWN:
                    if event.key == pygame.K_ESCAPE:
                        self.running = False
                elif event.type == pygame.MOUSEBUTTONDOWN:
                    #Linke Maustaste
                    if event.button == 1:
                        self.replaceTile(pygame.mouse.get_pos())
                    #Rechte Maustaste
                    elif event.button == 3:
                        self.rightMouseDown = True
                elif event.type == pygame.MOUSEBUTTONUP:
                    if event.button == 3:
                        self.rightMouseDown = False
                        self.camera += (mouseCoordsOnMap - self.firstKoord)
                        self.firstKoord = util.Vector(0, 0)
                elif event.type == pygame.MOUSEMOTION:
                    mouseCoords = util.Vector(pygame.mouse.get_pos()[0],
                                              pygame.mouse.get_pos()[1])
                    if self.rightMouseDown:
                        if mouseCoords[0] > 150 and mouseCoords[0] < 1080:
                            if mouseCoords[1] > 150 and mouseCoords[1] < 720:
                                mouseCoordsOnMap = mouseCoords + util.Vector(
                                    -150, -150)

                                if self.firstKoord == util.Vector(0, 0):
                                    self.firstKoord = mouseCoordsOnMap

                self.editApp.event(event)

            pygame.display.update()
 def BUTTONresetCam(self, arg):
     self.camera = util.Vector(0, 0)
    def __init__(self):
        self.basepath = os.path.join(os.path.dirname(__file__), "..")
        #map Vars
        self.name = ""
        self.dimensions = [0, 0]
        self.tiles = {}
        #background (wird manuell eingefuegt erstmal
        self.music = ""
        self.grid = []
        self.entityFile = "DUMMY"
        self.nextLevel = ""
        #END map Vars

        self.cur_Tile = 1
        self.camera = util.Vector(0, 0)

        self.rightMouseDown = False
        self.firstKoord = util.Vector(0, 0)

        self.screen = pygame.display.set_mode((1150, 630))

        self.mapSurface = pygame.Surface((800, 480))

        self.layerMenuBG = pygame.Surface((150, 630))
        self.layerMenuBG.fill((0, 200, 200))
        self.tilesMenuBG = pygame.Surface((200, 630))
        self.tilesMenuBG.fill((200, 200, 0))
        self.topMenuBG = pygame.Surface((800, 150))
        self.topMenuBG.fill((155, 0, 155))

        self.editApp = gui.App()
        self.editApp.connect(gui.QUIT, self.editApp.quit, None)

        self.Bt_applyOpt = gui.Button("Apply Options")
        self.Bt_applyOpt.connect(gui.CLICK, self.BUTTONapplyOpt, None)
        self.Bt_newMap = gui.Button("New Map")
        self.Bt_newMap.connect(gui.CLICK, self.BUTTONnewMap, None)
        self.Bt_loadMap = gui.Button("Load Map")
        self.Bt_loadMap.connect(gui.CLICK, self.BUTTONloadMap, None)
        self.Bt_saveMap = gui.Button("Save Map")
        self.Bt_saveMap.connect(gui.CLICK, self.BUTTONsaveMap, None)
        self.Bt_resetCam = gui.Button("reset Cam")
        self.Bt_resetCam.connect(gui.CLICK, self.BUTTONresetCam, None)

        self.Lb_Layer_Topic = gui.Label("Layer-Menu")
        self.Lb_layer1 = gui.Label("Layer 1 visible?: ")
        self.Lb_layer2 = gui.Label("Layer 2 visible?: ")
        self.Lb_layer3 = gui.Label("Layer 3 visible?: ")
        self.Lb_Tiles_Topic = gui.Label("Tiles-Menu")
        self.Lb_Tiles = gui.Label("Tiles: ")
        self.Lb_curT_index = gui.Label("Index: ")
        self.Lb_curT_name = gui.Label("Name: ")
        self.Lb_curT_type = gui.Label("Type: ")
        self.Lb_curT_image = gui.Label("Image: ")
        self.Lb_curT_access = gui.Label("Access.: ")
        self.Lb_curT_danger = gui.Label("Dangerous.: ")
        self.Lb_map_name = gui.Label("Map-Name: ")
        self.Lb_map_dimH = gui.Label("dimH: ")
        self.Lb_map_dimV = gui.Label("dimV: ")
        self.Lb_map_bgMusic = gui.Label("bgMusic: ")
        self.Lb_map_entityFile = gui.Label("entityFile: ")
        self.Lb_map_nextLvl = gui.Label("nextLvl: ")

        self.Inp_map_name = gui.Input(size=8)
        self.Inp_map_dimH = gui.Input(size=8)
        self.Inp_map_dimV = gui.Input(size=8)
        self.Inp_map_bgMusic = gui.Input(size=8)
        self.Inp_map_entityFile = gui.Input(size=8)
        self.Inp_map_nextLvl = gui.Input(size=8)

        self.Li_Tile_select = gui.List(width=100, height=300)
        for i in range(len(self.tiles)):
            self.Li_Tile_select.add(self.tiles[i][0], value=i)

        self.Sw_layer1_vis = gui.Switch(True)
        self.Sw_layer2_vis = gui.Switch(True)
        self.Sw_layer3_vis = gui.Switch(True)

        self.container = gui.Container(width=1150, height=630)

        self.layerTable = gui.Table(width=150, height=630, align=-1)
        self.tilesTable = gui.Table(width=200, height=630, align=1)
        self.topTable = gui.Table(width=30)

        self.container.add(self.layerTable, 0, 0)
        self.container.add(self.tilesTable, 950, 0)
        self.container.add(self.topTable, 150, 0)

        self.editApp.init(self.container, self.screen)
        self.running = True

        self.initNewMap()

        self.transpColor = ()  # layer1: (255,0,255)   layer2: (0,255,0)