示例#1
0
def drawChooseTutorial(win):
    drawMenuLayout(win)
    font1 = pygame.font.SysFont('comicsansms', 30)
    text = font1.render('Do you want to do the tutorial?', 1, white)
    win.blit(text, (230, 170))

    global yesbutton
    global nobutton
    global backbutton
    yesbutton = t.button(win, 'Yes', 270, 280, 150, 50, yellow, black, yellow)
    nobutton = t.button(win, 'No', 470, 280, 150, 50, yellow, black, yellow)
    backbutton = t.button(win, 'Back', 470, 470, 150, 50, yellow, black,
                          yellow)

    pygame.display.update()
示例#2
0
def drawquit(win):
    drawMenuLayout(win)
    font1 = pygame.font.SysFont('comicsansms', 30)
    text = font1.render('Are you sure you want to quit?', 1, white)
    win.blit(text, (250, 150))

    font2 = pygame.font.SysFont('comicsansms', 30)
    text = font1.render('Your highscore will be saved!', 1, white)
    win.blit(text, (250, 200))

    global yesbutton
    global nobutton
    yesbutton = t.button(win, 'Yes', 250, 280, 150, 50, yellow, black, yellow)
    nobutton = t.button(win, 'No', 450, 280, 150, 50, yellow, black, yellow)

    pygame.display.update()
示例#3
0
def drawCredits2(win):
    drawMenuLayout(win)
    crefont = pygame.font.SysFont('comicsansms', 30)
    text = crefont.render('Credits:', 1, white)
    win.blit(text, (250, 130))

    cfont = pygame.font.SysFont('comicsansms', 20)
    text = cfont.render('Alien pictures, ingame sounds: Tech with Tims', 1,
                        white)
    win.blit(text, (250, 170))
    text = cfont.render('pygame tutorial (I highy recommend checking', 1,
                        white)
    win.blit(text, (250, 200))
    text = cfont.render('him out he makes awesome tutorials/videos).', 1,
                        white)
    win.blit(text, (250, 230))
    text = cfont.render('If you find any bugs or have suggestions or', 1,
                        white)
    win.blit(text, (250, 290))
    text = cfont.render('ideas feel free to contact me (GitHub:', 1, white)
    win.blit(text, (250, 320))
    text = cfont.render('@ph3nix-cpu or just use the comment section', 1,
                        white)
    win.blit(text, (250, 350))
    text = cfont.render('on pygame.org.', 1, white)
    win.blit(text, (250, 380))
    text = cfont.render('Thank you for playing, I hope you enjoy it!', 1,
                        white)
    win.blit(text, (250, 425))

    global backbutton
    backbutton = t.button(win, 'Back', 470, 470, 150, 50, yellow, black,
                          yellow)

    pygame.display.update()
示例#4
0
def drawCredits(win):
    drawMenuLayout(win)
    crefont = pygame.font.SysFont('comicsansms', 30)
    text = crefont.render('Credits:', 1, white)
    win.blit(text, (250, 130))
    cfont = pygame.font.SysFont('comicsansms', 20)
    text = cfont.render('Menu music: "Epic" from Bensound.com', 1, white)
    win.blit(text, (250, 170))
    text = cfont.render('Game music: "Evolution" from Bensound.com', 1, white)
    win.blit(text, (250, 200))
    text = cfont.render('Space picture: "Milchstraße" by Felix', 1, white)
    win.blit(text, (250, 230))
    text = cfont.render('Mittermeier on pixabay.com', 1, white)
    win.blit(text, (250, 260))
    text = cfont.render('Version: 1.0.0', 1, white)
    win.blit(text, (250, 320))
    text = cfont.render('made with IDLE 3.8.3 and pygame 1.9.6', 1, white)
    win.blit(text, (250, 350))
    text = cfont.render('.exe-version converted with cx_Freeze 6.1', 1, white)
    win.blit(text, (250, 380))
    global nextbutton
    nextbutton = t.button(win, 'Next', 470, 470, 150, 50, yellow, black,
                          yellow)

    pygame.display.update()
示例#5
0
def redrawMenuWindow(win):
    drawMenuLayout(win)

    global button1
    global button2
    global button3
    global button4
    global button5
    button1 = t.button(win, 'Play!', 470, 150, 150, 50, yellow, black, yellow)
    button2 = t.button(win, 'Settings', 470, 220, 150, 50, yellow, black,
                       yellow)
    button3 = t.button(win, 'Score', 470, 290, 150, 50, yellow, black, yellow)
    button4 = t.button(win, 'Credits', 470, 360, 150, 50, yellow, black,
                       yellow)
    button5 = t.button(win, 'Quit', 470, 430, 150, 50, yellow, black, yellow)

    pygame.display.update()
示例#6
0
def pause(win):
    global timee
    for event in pygame.event.get():
        if event.type==pygame.QUIT:
            ptime=calculateTime()
            if int(ptime[1])<10:
                timee=ptime[0]+':0'+ptime[1]
            else:
                timee=ptime[0]+':'+ptime[1]
            return 0
    
    pygame.draw.rect(win,yellow,(150,115,400,320))
    pygame.draw.rect(win,black,(160,125,380,300))

    paufont=pygame.font.SysFont('comicsansms',50)
    text=paufont.render('Paused',1,yellow)
    win.blit(text,(350-round(text.get_width()/2),120))

    notefont=pygame.font.SysFont('comicsansms',15)
    text=notefont.render('NOTE: if you quit, you can go back to the current',1,yellow)
    win.blit(text,(170,320))
    text=notefont.render('save by just starting the game via the main menu.',1,yellow)
    win.blit(text,(170,340))
    text=notefont.render('If you close the whole game with an unfinished save,',1,yellow)
    win.blit(text,(170,360))
    text=notefont.render('it will be saved regularly but you wont be able to',1,yellow)
    win.blit(text,(170,380))
    text=notefont.render('finish it.',1,yellow)
    win.blit(text,(170,400))

    resumebutton=t.button(win,'Resume',250,200,200,50,yellow,black,yellow)
    if resumebutton:
        return 1

    quitbutton=t.button(win,'Quit',250,260,200,50,yellow,black,yellow)
    if quitbutton:
        ptime=calculateTime()
        if int(ptime[1])<10:
            timee=ptime[0]+':0'+ptime[1]
        else:
            timee=ptime[0]+':'+ptime[1]
        return 0

    pygame.display.update()
示例#7
0
def drawSettings(win):
    drawMenuLayout(win)
    global backbutton
    backbutton = t.button(win, 'Back', 470, 470, 150, 50, yellow, black,
                          yellow)

    font1 = pygame.font.SysFont('comicsansms', 20)
    text = font1.render('Music:', 1, white)
    win.blit(text, (300, 140))
    text = font1.render('Sounds:', 1, white)
    win.blit(text, (290, 300))
    global mushelp
    global soundhelp
    musicchoose.draw(win)

    if musicchoose.get_tof() and mushelp:
        mushelp = False
        pygame.mixer.music.play(-1)
    elif not (musicchoose.get_tof()):
        pygame.mixer.music.stop()
        mushelp = True

    if musicchoose.tof:

        text = font1.render('Volume:', 1, white)
        win.blit(text, (round(370 + 290 / 2 - text.get_width() / 2), 180))
        musicbar.draw(win)
        pygame.mixer.music.set_volume(musicbar.get_Volume())

    soundchoose.draw(win)
    if soundchoose.get_tof() and soundhelp:
        soundhelp = False
        laser.play()
    elif not (soundchoose.get_tof()):
        soundhelp = True

    if soundchoose.tof:
        text = font1.render('Volume:', 1, white)
        win.blit(text, (round(370 + 290 / 2 - text.get_width() / 2), 340))
        soundbar.draw(win)
        laser.set_volume(soundbar.get_Volume())
        if soundbar.soundplay:
            laser.play()
            soundbar.soundplay = False

    pygame.display.update()
示例#8
0
def drawscorewin(win):
    drawMenuLayout(win)
    global backbutton
    backbutton = t.button(win, 'Back', 470, 470, 150, 50, yellow, black,
                          yellow)

    try:
        scorearray = s.read()

        datefont = pygame.font.SysFont('comicsansms', 30)
        text = datefont.render('Best save with this game file:', 1, white)
        win.blit(text, (250, 130))
        text = datefont.render('Date: ' + scorearray[0], 1, white)
        win.blit(text, (250, 210))
        text = datefont.render('Reached Level: ' + str(scorearray[1]), 1,
                               white)
        win.blit(text, (250, 250))
        text = datefont.render('Aliens killed: ' + scorearray[2], 1, white)
        win.blit(text, (250, 290))
        text = datefont.render('Spaceships destroyed: ' + scorearray[3], 1,
                               white)
        win.blit(text, (250, 330))
        text = datefont.render('Survived time: ' + scorearray[4], 1, white)
        win.blit(text, (250, 370))

    except:
        datefont = pygame.font.SysFont('comicsansms', 20)
        text = datefont.render('You haven´t played a game with this game', 1,
                               white)
        win.blit(text, (250, 130))
        text = datefont.render('file so far.', 1, white)
        win.blit(text, (250, 160))
        text = datefont.render(
            "Just begin your first game by clicking 'Play!'", 1, white)
        win.blit(text, (250, 220))
        text = datefont.render(
            "on the main menu. You can do the tutorial first", 1, white)
        win.blit(text, (250, 250))
        text = datefont.render("if you want to.", 1, white)
        win.blit(text, (250, 280))
        text = datefont.render("Good luck! You´re gonna need it :P", 1, white)
        win.blit(text, (250, 330))

    pygame.display.update()
示例#9
0
def redrawGameWindow(win):
    global powerups
    global battleship
    global alienkills
    global spaceshipkills
    global pausebutton
    global holdingpowerup
    global usepowerup
    global poweruploop
    
    win.blit(gamebg,(0,0))

    lvlfont=pygame.font.SysFont('comicsans',30)
    text=lvlfont.render('Level: '+str(level),1,white)
    win.blit(text,(350-round(text.get_width()/2),5))

    text=lvlfont.render('Powerups: ',1,white)
    win.blit(text,(5,25))

    for powerup in powerups:
        if powerup[1]==True:
            textp=lvlfont.render(powerup[0],1,white)
            win.blit(textp,(text.get_width()+5,25))
            holdingpowerup=True

    if holdingpowerup:
        usebutton=t.button(win,'Use',5+text.get_width()+textp.get_width()+20,25,45,20,yellow,black,yellow)
        if usebutton:
            holdingpowerup=False
            usepowerup=True

    if usepowerup:
        for powerup in powerups:
            if powerup[1]==True:
                powerup[1]=False
                powerup[2]=True

    for powerup in powerups:
        if powerup[2]:
            textp=lvlfont.render(powerup[0],1,white)
            win.blit(textp,(text.get_width()+5,25))
            poweruploop+=1
            if poweruploop==720:
                poweruploop=0
                powerup[2]=False
                usepowerup=False

    if not holdingpowerup and not usepowerup:
        textp=lvlfont.render('None',1,white)
        win.blit(textp,(text.get_width()+5,25))
        
    
    pausebutton=t.button(win,'Pause',625,10,65,30,yellow,black,yellow)
    
    keys=pygame.key.get_pressed()
    if pausebutton or keys[pygame.K_ESCAPE]:
        pause(win)

    for laser in lasers:
        laser.draw(win)

    for laser in enemylasers:
        laser.draw(win)

    for alien in aliens:
        if alien.health>0:
            alien.draw(win)
        else:
            aliens.pop(aliens.index(alien))
            alienkills+=1

    for v in enemyspaceships:
        if v.health>0:
            v.draw(win)
        else:
            enemyspaceships.pop()
            spaceshipkills+=1
            

    if battleship.visible:    
        battleship.draw(win)
    battleship.drawHealthBar(win)

    pygame.display.update()
示例#10
0
def gameover(win):
    global alienkills
    global spaceshipkills
    global totaltestseconds
    global level
    global aliens
    global lasers
    global enemylasers
    global timee
    pygame.mixer.music.stop()
    helplevel=level
    
    ptime=calculateTime()
    if int(ptime[1])<10:
        timee=ptime[0]+':0'+ptime[1]
    else:
        timee=ptime[0]+':'+ptime[1]
        
    generateLevel(win,1)
    print(str(helplevel))
    print(str(s.readlevel()))
    if helplevel>s.readlevel():
        s.save(helplevel,alienkills,spaceshipkills,timee,totaltestseconds)
        highscoreloop=True
        hslo=0
        ybutton=370
    elif helplevel==s.readlevel() and totaltestseconds>s.readseconds():
        s.save(helplevel,alienkills,spaceshipkills,timee,totaltestseconds)
        highscoreloop=True
        hslo=0
        ybutton=370
    else:
        highscoreloop=False
        ybutton=350
    
    f=True
    g=True
    h=True
    while f:
        try:
            aliens.pop()
        except:
            f=False
    while g:
        try:
            lasers.pop()
        except:
            g=False
    while h:
        try:
            enemylasers.pop()
        except:
            h=False
            
    gaov=True
    while gaov:
        clock.tick(30)
        for event in pygame.event.get():
            if event.type==pygame.QUIT:
                ptime=calculateTime()
                if int(ptime[1])<10:
                    timee=ptime[0]+':0'+ptime[1]
                else:
                    timee=ptime[0]+':'+ptime[1]
                return 0
        pygame.draw.rect(win,yellow,(50,75,600,400))
        pygame.draw.rect(win,black,(60,85,580,380))
        
        gameoverfont=pygame.font.SysFont('comicsansms',50)
        text=gameoverfont.render('Game Over!',1,yellow)
        win.blit(text,(350-round(text.get_width()/2),80))

        statfont=pygame.font.SysFont('comicsans',30)

        text=statfont.render('Level: '+str(helplevel),1,white)
        win.blit(text,(350-round(text.get_width()/2),160))
        
        text=statfont.render('Aliens killed: '+str(alienkills),1,white)
        win.blit(text,(350-round(text.get_width()/2),190))

        text=statfont.render('Enemy spaceships destroyed: '+str(spaceshipkills),1,white)
        win.blit(text,(350-round(text.get_width()/2),220))

        if highscoreloop:
            hslo+=1
            if hslo<15:
                highfont=pygame.font.SysFont('comicsansms',40)
                text=highfont.render('New Highscore!',1,yellow)
                win.blit(text,(350-round(text.get_width()/2),290))
            elif hslo==30:
                hslo=0
                
        text=statfont.render('Survived time: '+timee,1,white)
        win.blit(text,(350-round(text.get_width()/2),250))

        exbutton=t.button(win,'Main Menu',250,ybutton,200,50,yellow,black,yellow)
        if exbutton:
            return 1
        
        pygame.display.update()