コード例 #1
0
ファイル: Game.py プロジェクト: maggie199x/expert-dollop
    def initialize_objects(self):
        log.info("initialize_objects()")
        args = {"GAME": self}
        objects = json.load(open("GameObjects.json"))
        for location in objects["locations"]:
            z = objects["locations"][location].copy()
            z.update(args)
            self.locations[location] = Location(**z)
            self.allObj[location] = self.locations[location]
        for barrier in objects["barriers"]:
            z = objects["barriers"][barrier].copy()
            z.update(args)
            self.barriers[barrier] = Barrier(**z)
            self.allObj[barrier] = self.barriers[barrier]
        for item in objects["items"]:
            z = objects["items"][item].copy()
            z.update(args)
            self.items[item] = Item(**z)
            self.allObj[item] = self.items[item]
        z = objects["player"]["player"]
        z.update(args)
        self.player = Player(**z)

        self.assemble_barriers()
        self.assemble_inventories(self.items)
        return True
コード例 #2
0
    def __init__(self, wavelength=6):
        global IMAGE_SIZE
        IMAGE_SIZE = (700, 300)

        self.im_size = np.array((700, 300))

        self.canvas = Canvas(*self.im_size)

        self.im_domain = self.canvas.getDomain()

        self.wall_pos = 20
        self.wall_width = 4

        self.slit_width = 6

        self.slit_sep = 100

        # self.slit_pos_top = (self.wall_pos, (self.im_size[1] / 2) - (self.slit_sep / 2))
        # self.slit_pos_mid = (self.wall_pos, (self.im_size[1] / 2))
        # self.slit_pos_bot = (self.wall_pos, (self.im_size[1] / 2) + (self.slit_sep / 2))

        self.num_sources = 10

        self.low_threshold = 0
        self.high_threshold = 1

        self.wavelength = wavelength

        self.amplitude = 1

        self.image_domain = Domain(0, 0, *self.im_size)

        self.incoming_domain, self.interference_domain = self.image_domain.split_vertical(
            self.wall_pos)

        self.plane_wave = PlaneWave(self.wavelength, self.amplitude,
                                    self.incoming_domain, np.array([1.0, 0.0]))

        self.barrier = Barrier(
            Domain(self.wall_pos, 0, self.wall_pos + self.wall_width,
                   IMAGE_SIZE[1]))
        self.barrier.setSlits(2, self.slit_width, self.slit_sep,
                              self.interference_domain)

        self.wave_drawer = GenericWaveDrawer()
コード例 #3
0
 def init(self):
     pygame.mixer.music.load('music/snakeMusic.mp3')
     pygame.mixer.music.play(-1)
     self.bgColor = (255, 255, 255)
     self.gameOver = True
     # Snake
     Snake.init()
     self.snakeGroup = pygame.sprite.Group()
     self.snakeList = []
     # Snake movement
     self.counter = 0
     self.isMoveRight = True
     self.snakeLength = 4
     self.snakeSize = 14
     self.timer = 0
     # Border
     Border.init()
     self.blockGroup = pygame.sprite.Group()
     # Barrier
     Barrier.init()
     self.barrierGroup = pygame.sprite.Group()
     self.collideBarrier = (0, 0)
     self.points = 0
     # Food
     Food.init()
     # Block
     Block.init()
     # Initialize the snakeGroup
     for i in range(self.snakeLength):
         snake = Snake(self.width // 2,
                       self.height // 2 + self.snakeSize * i)
         self.snakeGroup.add(snake)
         self.snakeList.append(snake)
     # Initialize the foodGroup
     self.foodGroup = pygame.sprite.Group()
     # Initialize the borderGroup
     self.borderGroup = pygame.sprite.Group(
         Border(self.width // 2, self.height + 300, self.width,
                self.height))
     # GameOver Image
     self.GGImage = pygame.image.load('images/gameover.png').convert_alpha()
     self.GGImage = pygame.transform.scale(self.GGImage, (1920, 1080))
     self.GGrect = self.GGImage.get_rect()
コード例 #4
0
def launch_nodes(class_name):

    partition_nums_mutex.acquire()
    barrier = Barrier((len(worker_vm.partition_nums) + 1))
    partition_nums_mutex.release()
    for num in worker_vm.partition_nums:
        thread = Thread(target=worker_vm.superstep, args=(num,))
        thread.daemon = True
        thread.start()

    barrier.wait()

    peer_messages_mutex.acquire()
    if len(worker_vm.peer_messages) > 0 and len(worker_vm.peer_messages) < 100:
        worker_vm.send_message()
    peer_messages_mutex.release()

    nodes_mutex.acquire()
    next_messages_mutex.acquire()
    num_inactive_mutex.acquire()
    worker_vm.send_master_ack(("launch", (len(worker_vm.nodes) - num_inactive) + len(worker_vm.next_messages)))
    num_inactive_mutex.release()
    next_messages_mutex.release()
    nodes_mutex.release()
コード例 #5
0
ファイル: si.py プロジェクト: lazarchitect/Space-Invaders
screen.fill(backgroundColor)
# backgroundImage = pygame.transform.scale(pygame.image.load("space.jpg"), (x, y))
# screen.blit(backgroundImage, (0,0))

quitMsg = pygame.font.SysFont("couriernew",
                              24).render("Spacebar to shoot. Press q to quit",
                                         0, (128, 100, 100))
screen.blit(quitMsg, (10, 10))

#########################################################
ship = Ship(screen, x / 2, y - 120)
ship.move(screen, 0)

barriers = []
for i in range(5):
    tempVar = Barrier(screen, x * (5 + (20 * i)) / 100, y - 250)
    barriers.append(tempVar)
    screen.blit(tempVar.image, (tempVar.x, tempVar.y))

bullets = []
bulletWidth = int(screen.get_width() / 240)
bulletHeight = int(screen.get_height() / 27)
bulletClock = ticks()
bulletAvailable = True

enemybullets = []

aliens = []
alienMoveClock = ticks()
alienShotClock = ticks()
alienDirection = 1
コード例 #6
0
def create_barriers():
    Barrier = Group()
    for row in range(4):
        for column in range(9):
            barriers = Barrier(10, WHITE, row, column)
            barriers.rect.x = 50 + (200 * 4) + (column * barriers.width)
コード例 #7
0
    bullet.goto(3000, 3000)
    bullet.clear()
    del bullet
    bullet = None


def RandomAlienBomb():
    random_chance = random.randint(1, 12)
    if random_chance == 1:
        random_alien = random.choice(fleet.aliens)
        bomb.MakeBomb(position_x=random_alien.xcor(),
                      position_y=random_alien.ycor())


player = SpaceShip()
barrier1 = Barrier(-260, -220)
fleet = Fleet(-240, 160)
bomb = AlienBombManager()
bullet = None
scoreboard = Scoreboard()

# Initialise game
screen.update()
screen.listen()
screen.onkey(player.go_left, "a")
screen.onkey(player.go_right, "d")
screen.onkey(FireBullet, "space")
game_is_on = True
while game_is_on == True:
    sleep(0.0001)
    screen.update()
コード例 #8
0
 def __init__(self):
     self.barriers.append(Barrier(230, 100, 200, 50))
     self.barriers.append(Barrier(0, 100, 200, 50))
コード例 #9
0
class PILTest_interference():
    def __init__(self, wavelength=6):
        global IMAGE_SIZE
        IMAGE_SIZE = (700, 300)

        self.im_size = np.array((700, 300))

        self.canvas = Canvas(*self.im_size)

        self.im_domain = self.canvas.getDomain()

        self.wall_pos = 20
        self.wall_width = 4

        self.slit_width = 6

        self.slit_sep = 100

        # self.slit_pos_top = (self.wall_pos, (self.im_size[1] / 2) - (self.slit_sep / 2))
        # self.slit_pos_mid = (self.wall_pos, (self.im_size[1] / 2))
        # self.slit_pos_bot = (self.wall_pos, (self.im_size[1] / 2) + (self.slit_sep / 2))

        self.num_sources = 10

        self.low_threshold = 0
        self.high_threshold = 1

        self.wavelength = wavelength

        self.amplitude = 1

        self.image_domain = Domain(0, 0, *self.im_size)

        self.incoming_domain, self.interference_domain = self.image_domain.split_vertical(
            self.wall_pos)

        self.plane_wave = PlaneWave(self.wavelength, self.amplitude,
                                    self.incoming_domain, np.array([1.0, 0.0]))

        self.barrier = Barrier(
            Domain(self.wall_pos, 0, self.wall_pos + self.wall_width,
                   IMAGE_SIZE[1]))
        self.barrier.setSlits(2, self.slit_width, self.slit_sep,
                              self.interference_domain)

        self.wave_drawer = GenericWaveDrawer()
        # self.slit_1 = SlitSource(self.slit_pos_top, self.slit_width, self.num_sources, self.wavelength, self.amplitude/3, self.interference_domain)
        # self.slit_2 = SlitSource(self.slit_pos_mid, self.slit_width, self.num_sources, self.wavelength, self.amplitude/3, self.interference_domain)
        # self.slit_3 = SlitSource(self.slit_pos_bot, self.slit_width, self.num_sources, self.wavelength, self.amplitude/3, self.interference_domain)

    def draw_superficial_barrier(self, domain, data):
        self.canvas.drawData(np.full(domain.shape, 255), domain)

    def run(self):
        d_data = []

        self.wave_drawer.drawPlaneWaveData(self.plane_wave.get_wave_data(),
                                           self.incoming_domain, self.canvas)
        self.wave_drawer.drawPlaneWaveData(self.barrier.get_wave_data(),
                                           self.interference_domain,
                                           self.canvas)

        # self.draw_superficial_barrier(Domain(self.wall_pos-self.wall_width/2, 0, self.wall_pos + self.wall_width/2, self.slit_pos_top[1] - self.slit_width/2), self.canvas.getData())
        # self.draw_superficial_barrier(Domain(self.wall_pos-self.wall_width/2, self.slit_pos_top[1] + self.slit_width/2, self.wall_pos + self.wall_width/2, self.slit_pos_bot[1] - self.slit_width/2), self.canvas.getData())
        # self.draw_superficial_barrier(Domain(self.wall_pos-self.wall_width/2, self.slit_pos_bot[1] + self.slit_width/2, self.wall_pos + self.wall_width/2, self.im_size[1]), self.canvas.getData())

        im = self.canvas.getImage()
        if 1:
            im.save(f"test_interference_{self.wavelength}.png")
            im.show()
        return im
コード例 #10
0
    def timerFired(self, dt):
        if len(self.snakeList) == 0:
            self.gameOver = True
        if self.gameOver == False:
            # Time counter
            self.timer += 1
            # Update the group
            self.blockGroup.update(self.isKeyPressed, self.width, self.height)
            self.foodGroup.update(self.width, self.height)
            self.barrierGroup.update(self.width, self.height)
            # Create new elements on screen
            # Create blocks
            if self.timer % 100 == 0:
                #TODO: make sure doesnt go off screen, make sure it doesnt overlap with other blocks
                randList = randBinList(10)
                for i in range(len(randList)):
                    if randList[i] == 1:
                        randomX = i * 192
                        for j in range(random.randint(0, 10)):
                            self.blockGroup.add(Block(randomX, 0))

            # Create barriers
            if self.timer % 100 == 0:
                barrierX = random.randint(0, self.width)
                self.barrierGroup.add(Barrier(barrierX, 0))
                pygame.sprite.groupcollide(self.blockGroup, self.barrierGroup,
                                           True, False,
                                           pygame.sprite.collide_circle)
            # Create fruits
            if self.timer == 200:
                # # Barrier.init()
                #				for i in range(1):
                applex = random.randint(0, self.width)
                appley = random.randint(0, self.height // 4)
                self.foodGroup.add(Food(applex, 0))
                self.timer = 0


#				pygame.sprite.groupcollide(self.blockGroup, self.foodGroup,False,True,pygame.sprite.collide_circle)
#				pygame.sprite.groupcollide(self.barrierGroup, self.foodGroup,False,True,pygame.sprite.collide_circle)
#MARK: Snake Movement
            if self.counter >= len(self.snakeList):
                self.counter = 0
                if self.isMoveRight:
                    self.isMoveRight = False
                else:
                    self.isMoveRight = True
            else:
                if self.isMoveRight:
                    if self.counter == 0:
                        speed = 3
                        self.snakeList[self.counter].moveRight(
                            self.width, self.height, speed)
                        self.counter += 1
                    else:
                        speed = 3
                        self.snakeList[self.counter].moveRight(
                            self.width, self.height, speed)
                        self.counter += 1
                else:
                    if self.counter == 0:
                        speed = 3
                        self.snakeList[self.counter].moveLeft(
                            self.width, self.height, speed)
                        self.counter += 1
                    else:
                        speed = 3
                        self.snakeList[self.counter].moveLeft(
                            self.width, self.height, speed)
                        self.counter += 1
            if pygame.sprite.groupcollide(self.snakeGroup, self.blockGroup,
                                          False, True,
                                          pygame.sprite.collide_circle):
                self.snakeLength -= 1
                snakeHead = self.snakeList[0]
                self.snakeList = []
                self.snakeGroup = pygame.sprite.Group()
                for i in range(self.snakeLength):
                    snake = Snake(snakeHead.x,
                                  snakeHead.y + self.snakeSize * i)
                    self.snakeGroup.add(snake)
                    self.snakeList.append(snake)
            if pygame.sprite.groupcollide(self.snakeGroup, self.foodGroup,
                                          False, True,
                                          pygame.sprite.collide_circle):
                self.snakeLength += 1
                self.points += 1
                snakeHead = self.snakeList[0]
                snakeTail = self.snakeList[-1]
                snake = Snake(snakeTail.x, snakeTail.y + self.snakeSize)
                self.snakeList.append(snake)
                self.snakeGroup.add(snake)

            if pygame.sprite.groupcollide(self.barrierGroup, self.snakeGroup,
                                          False, False):
                sumCollideX = []
                for elem in pygame.sprite.groupcollide(self.barrierGroup,
                                                       self.snakeGroup, False,
                                                       False):
                    sumCollideX.append(elem.x)
                sumSnakeX = 0
                for snakeEle in self.snakeGroup:
                    sumSnakeX += snakeEle.x

                if sumSnakeX / float(len(self.snakeList)) > sum(
                        sumCollideX) / float(len(sumCollideX)):
                    self.collideBarrier = (1, 0)
                else:
                    self.collideBarrier = (0, 1)

            self.snakeGroup.update(self.isKeyPressed, self.width, self.height,
                                   self.collideBarrier)
            self.collideBarrier = (0, 0)