示例#1
0
def restart():
    global snakeman
    global SCORE
    global NEXT_ANIMATION
    global TICK_RATE
    global punkt
    global spielraster
    global restartCounter

    #kill sprites
    pgf.killSprite(snakeman.sprite)
    for body in snakeman.body:
        pgf.killSprite(body.sprite)
    pgf.killSprite(punkt.sprite)

    #setup start parameter
    spielraster = SPIELRASTER_START.copy()
    snakeman = Snakeman("Snake-Man", (SNAKEMAN_START_X, SNAKEMAN_START_Y))
    NEXT_ANIMATION = pgf.clock() + ANIMATION_REFRESH_RATE
    SCORE = -100
    TICK_RATE = START_RATE - ADD_TICK_RATE
    restartCounter = 0
    snakeman.addBody()
    snakeman.addBody()
    punkt = None
示例#2
0
def punktSetzen():
    global time_since_last_point
    while True:
        placeOn = rng.randrange(len(spielraster))
        if spielraster[placeOn] == 0:
            punkt = Punkt(i2xy(placeOn))
            spielraster[placeOn] = 1
            pgf.showSprite(punkt.sprite)
            time_since_last_point = pgf.clock()
            return punkt
示例#3
0
def run():
    global clear
    global nextAnimation

    while True:

        pgf.tick(FPS)  # 프레임 속도
        if pgf.keyPressed('right'): pacman.keyboardmemory = 0
        if pgf.keyPressed('left'): pacman.keyboardmemory = 1
        if pgf.keyPressed('up'): pacman.keyboardmemory = 2
        if pgf.keyPressed('down'): pacman.keyboardmemory = 3

        for Figure in Figures:
            if pgf.clock() > nextAnimation:
                Figure.animate()
            Figure.motinlogic()  # 모션 로직대로 행동
            Figure.move()  # 움직임
            if Figure.name != 'pacman':  # 고스트가 팩맨에게 부딪힐 때
                if Figure.i == pacman.i:
                    if Figure.mode == ('hunt'):  # 고스트가 hunt 상태라면
                        pacman.changemode('dead')  # 팩맨 사망
                        clear = True
                        break
                    if Figure.mode in ('frighten', 'blink'):  # 고스트가 도망가는 상태라면
                        Figure.changemode('dead')  # 고스트가 사망
                        writeScore(100)
            Figure.display()
        if clear == True:
            clear = False
            break

        if pgf.clock() > nextAnimation:
            nextAnimation += 100

        pgf.updateDisplay()

        if pgf.keyPressed('esc'):
            break
ghosts = [blinky, pinky, inky, clyde]


def dotsAufbauen():
    global dots
    dots = {}
    for i, zahl in enumerate(grid):
        if zahl == 1:
            x, y = i2xy(i)
            dots[i] = Dot(x, y, "dot.png")
        if zahl == 2:
            x, y = i2xy(i)
            dots[i] = Dot(x, y, "bit_dot.png")


nextFrame = pgf.clock()
game_status = "run"
dotsAufbauen()
while True:
    if pgf.clock() > nextFrame:
        nextFrame += 100
        for ghost in ghosts:
            ghost.changeAnimationFrame()
        pacman.changeAnimationFrame()

    fps = pgf.tick(120)

    if game_status == "run":
        if pgf.keyPressed("right"):
            pacman.dir_buffer = 0
        elif pgf.keyPressed("left"):
示例#5
0
#konstante paramter gegeben durch grafik und game größe
BREITE, HÖHE = 672, 744
RASTER = 24
ABSTAND_BODY = 50
SPALTEN, ZEILEN = BREITE // RASTER, HÖHE // RASTER

#konfigurations parameter
RICHTUNGEN = {0: (1, 0), 1: (-1, 0), 2: (0, -1), 3: (0, 1)}
STARTRICHTUNG = 0
SNAKEMAN_START_X = 336
SNAKEMAN_START_Y = 564

#ANIMATION time
ANIMATION_REFRESH_RATE = 100
NEXT_ANIMATION = pgf.clock() + ANIMATION_REFRESH_RATE

#Restart
WAIT_BEFORE_RESTART = 5000
restartCounter = 0

#SCORE
MIN_SCORE_POINT = 50
SCORE_FOR_POINT = 100
SCORE = -100
time_since_last_point = pgf.clock()

#TICK RATE
ADD_TICK_RATE = 10
START_RATE = 120
TICK_RATE = START_RATE - ADD_TICK_RATE
示例#6
0
    1: (-1, 0),
    2: (0, -1),
    3: (0, 1)
}  # 각 방향에 해당하는 좌표 변화 값
width, height = 672, 812
grid = 24
column = width // grid  # 맵 구조 열 개수
low = height // grid  # 맵 구조 행 개수

pgf.screenSize(width, height)
score = 0

main1 = pygame.image.load('Resource\Main_image1.png')
main2 = pygame.image.load('Resource\Main_image2.png')

nextAnimation = pgf.clock() + 100

clear = False


# 게임화면에 현재 점수를 표기하는 함수
def writeScore(count):
    global score
    pygame.draw.rect(pgf.screen, (0, 0, 0), [500, 760, 300, 100])
    score += count
    font = pygame.font.Font('Resource\\NanumGothic.ttf', 25)
    text = font.render('Score : ' + str(score), True, (255, 255, 255))
    pgf.screen.blit(text, (500, 760))


# 게임화면에 현재 세대 차수를 표기하는 함수