Exemple #1
0
 def move(self, dt):
     #если игрок слишком далеко отошел от артефакта
     if not self.initPoint.inRectangle(
             self.focus - GVector(WIDTHSCREEN, HEIGHTSCREEN),
             self.focus + GVector(WIDTHSCREEN, HEIGHTSCREEN) * 2):
         #переместим за пределы видимости игрока
         self.relocate()
Exemple #2
0
    def run(self):
        pygame.init()
        self.screen = pygame.display.set_mode(
            (self.WIDTHSCREEN, self.HEIGHTSCREEN), pygame.FULLSCREEN, 32)
        self.running = True
        dt = 0
        #обрабатываем события
        while self.running:
            self.moveWorld(dt)
            #пересчитываем фокус
            px, py = self.player.initPoint.get()
            mx, my = pygame.mouse.get_pos()  #координаты мыши
            self.mousePoint = GVector(mx, my) + self.focus

            self.objectUnderPick = self.getObjectUnderPoint(self.mousePoint)
            if px < self.focus[0] + self.focusMargin:
                self.focus[0] = px - self.focusMargin
            if px > self.focus[0] + self.WIDTHSCREEN - self.focusMargin:
                self.focus[0] = px - self.WIDTHSCREEN + self.focusMargin
            if py < self.focus[1] + self.focusMargin:
                self.focus[1] = py - self.focusMargin
            if py > self.focus[1] + self.HEIGHTSCREEN - self.focusMargin:
                self.focus[1] = py - self.HEIGHTSCREEN + self.focusMargin

            self.drawWorld()  #<- пока тут, потом в поток занесу
            pressedKeys = pygame.key.get_pressed()
            #вперед
            if ((pressedKeys[K_UP] or pressedKeys[K_w])
                    and not (pressedKeys[K_DOWN] or pressedKeys[K_s])):
                self.player.goUp()
            #наэад
            elif ((pressedKeys[K_DOWN] or pressedKeys[K_s])
                  and not (pressedKeys[K_UP] or pressedKeys[K_w])):
                self.player.goDown()
            #направо
            if ((pressedKeys[K_RIGHT] or pressedKeys[K_d])
                    and not (pressedKeys[K_LEFT] or pressedKeys[K_a])):
                self.player.goRight()
            #налево
            if ((pressedKeys[K_LEFT] or pressedKeys[K_a])
                    and not (pressedKeys[K_RIGHT] or pressedKeys[K_d])):
                self.player.goLeft()
            #выход из игры
            if pressedKeys[K_BACKSPACE]:
                self.running = False
            for event in pygame.event.get():
                if event.type == QUIT:
                    #выходим по нажатию на крестик
                    self.running = False
                elif event.type == KEYDOWN:
                    #хватаем предмет
                    if (event.key == pickKey):
                        self.pickAction()
                    elif event.key == K_ESCAPE:
                        self.running = False

        #обработали---
            dt = (self.fpsClock.tick(FPS)) / 1000
        exit()
Exemple #3
0
 def __init__(self, x, y, w, h, focus):
     pygame.surface.Surface.__init__(self, (int(w), int(h)),
                                     flags=SRCALPHA,
                                     depth=32)
     RenderedObject.__init__(self, GVector(x, y), focus=focus)
     self.width = w
     self.height = h
     self.grassWidth = 20
     self.grassHeight = 20
     self.grassNum = 20
     self.genField()
Exemple #4
0
    def __init__(self, focus, inventoryName='grayball'):
        RenderedObject.__init__(self, GVector(), focus=focus)
        self.inventoryName = inventoryName
        if not inventoryName in artTypesTuple:
            self.inventoryName = 'grayball'
        PickableObject.__init__(self, self.inventoryName)
        self.color = artefactsTypes[self.inventoryName]['color']
        self.price = artefactsTypes[self.inventoryName]['price']
        self.radius = artefactSize

        self.deltaPulse = choice([-1, 1])
        self.pulse = 0
Exemple #5
0
    def __init__(self):
        displayInfo = pygame.display.Info()
        self.WIDTHSCREEN = displayInfo.current_w
        self.HEIGHTSCREEN = displayInfo.current_h

        #переменные фокуса
        self.focus = GVector()

        #зазор для фокуса
        self.focusMargin = int(self.HEIGHTSCREEN / 4)

        self.MAINCOLOR = hexToTuple('B6F788')
        self.fpsClock = pygame.time.Clock()
        self.player = Player(self.WIDTHSCREEN / 2, self.HEIGHTSCREEN / 2,
                             self.focus, self)
        #добавляем подложки
        self.pods = []
        for i in [-1, 0, 1]:
            for j in [0, -1, 1]:
                self.pods.append(
                    Pod(i * self.WIDTHSCREEN, j * self.HEIGHTSCREEN,
                        self.WIDTHSCREEN, self.HEIGHTSCREEN, self.focus))
        self.addArtefacts()

        # добавляем flying text
        self.flyingTexts = [
            FlyingText(self.focus) for _ in range(flyingTextCount)
        ]
        # self.flyingTexts =
        self.debugInfo = DebugInfo(self)
        # self.anotherStalkerS = self.initAnotherStalkersForTestAi()
        self.anotherStalkerS = self.initAnotherStalkersNormaly(
        )  #вернуть для нормальной игры
        self.objects = (self.pods, self.artefacts, self.anotherStalkerS,
                        [self.player], self.flyingTexts, [self.debugInfo])
        self.mousePoint = (0, 0
                           )  # кортеж с координатами мыши, чтобы несколько раз
        # не узнавать её координаты через функцию
        self.objectUnderPick = None
        self.run()
Exemple #6
0
    def __init__(self):
        self.WIDTHSCREEN = WIDTHSCREEN
        self.HEIGHTSCREEN = HEIGHTSCREEN

        #переменные фокуса
        self.focus = GVector()

        #зазор для фокуса
        self.focusMargin = int(self.HEIGHTSCREEN / 4)

        self.MAINCOLOR = hexToTuple('B6F788')
        self.fps = 60
        self.fpsClock = pygame.time.Clock()
        self.player = Player(self.WIDTHSCREEN / 2, self.HEIGHTSCREEN / 2,
                             self.focus)
        #добавляем подложки
        self.pods = []
        for i in [-1, 0, 1]:
            for j in [0, -1, 1]:
                self.pods.append(
                    Pod(i * self.WIDTHSCREEN, j * self.HEIGHTSCREEN,
                        self.WIDTHSCREEN, self.HEIGHTSCREEN, self.focus))
        self.objects = {'player': [self.player], 'pods': self.pods}
        self.run()
	def __init__(self, x, y, focus, artType='grayball'):
		RenderedObject.__init__(GVector(x, y))

		if not artType in artefactsType:
			artType ='grayball'