for rainbow in rainbows:
        rainbow.draw()

def screenPositionUpdate(player):
    global screenPosition
    if player.centre[1] - screenPosition < 150:
        screenPosition = player.centre[1] - 150
    elif player.centre[1] - screenPosition > 600 - 150:
        screenPosition = player.centre[1] - (600 - 150)
        if screenPosition > 0:
            screenPosition = 0

def update(dt):
    global screenPosition
    if keyboard.left:
        player.left()
    elif keyboard.right:
        player.right()
    if keyboard.up:
        player.jump()
    player.update(surfaceLines)
    screenPositionUpdate(player)
    for rainbow in rainbows:
        rainbow.update()

def on_key_down(key):
    if key == keys.SPACE:
        player.shootRainbow()

pgzrun.go()
예제 #2
0
            y_sat = random.randint(SCOREBOX_HEIGHT, HEIGHT - satellite.height)
            satellite.topright = (x_sat, y_sat)
            score += -5
            sounds.explosion.play()
        if debris.colliderect(laser) == 1:
            lasers.remove(laser)
            x_deb = random.randint(-500, -50)
            y_deb = random.randint(SCOREBOX_HEIGHT, HEIGHT - debris.height)
            debris.topright = (x_deb, y_deb)
            score += 5
            sounds.explosion.play()


# activating lasers


def makeLaserActive():
    global player
    player.laserActive = 1


def fireLasers(laser):
    if player.laserActive == 1:
        player.laserActive = 0
        clock.schedule(makeLaserActive, 0.2)
        sounds.laserfire02.play()  #play sound effect
        lasers.append(laser)


pgzrun.go()  #runs the game
예제 #3
0
def draw():
    screen.fill("white")
    screen.blit("itachi", (300, 145))

    pgzrun.go()
예제 #4
0
    speedy = random.randint(1, 5)  # 小球y方向的速度
    r = random.randint(5, 50)  # 小球的半径
    colorR = random.randint(10, 225)
    colorG = random.randint(10, 255)
    colorB = random.randint(10, 255)
    # 存储小球所有信息的列表
    ball = [x, y, speedx, speedy, r, colorR, colorG, colorB]
    balls.append(ball)  # 把第i号小球的信息添加到balls中


def draw():  # 绘制模块,每帧重复执行
    screen.fill("white")
    for ball in balls:  # 绘制所有的球
        screen.draw.filled_circle((ball[0], ball[1]), ball[4],
                                  (ball[5], ball[6], ball[7]))


def update():  # 更新模块,每帧重复运行
    for ball in balls:
        ball[0] = ball[0] + ball[2]  # 利用x方向速度更新x坐标
        ball[1] = ball[1] + ball[3]  # 利用y方向速度更新y坐标
        # 当小球碰到左右边界时,x方向速度反向
        if ball[0] >= WIDTH - ball[4] or ball[0] <= ball[4]:
            ball[2] = -ball[2]
        # 当小球碰到上下边界时,y方向速度反向
        if ball[1] >= HEIGHT - ball[4] or ball[1] <= ball[4]:
            ball[3] = -ball[3]


pgzrun.go()  # 开始执行游戏
예제 #5
0
WIDTH = 500
#Screen height in pixels
HEIGHT = 500
#Circle X and Y positions
circle_posx = 250
circle_posy = 100

#offset
speed = 1


#function that draws
def draw():
    #screen is your window
    #screen.fill(colorname)
    screen.fill('black')

    #screen.draw.circle((posx,posy),radius,color)
    screen.draw.circle((circle_posx, circle_posy), 50, 'white')


#function called 60 times per second
def update():
    #scope
    global circle_posy  #do not edit this line
    #change in circle_posy
    circle_posy = circle_posy + speed


pgzrun.go()  # Do not edit this line
예제 #6
0
import pgzrun  #do not remove and leave as first line of code
from flappy_func import *

WIDTH = 400
HEIGHT = 708
start_position = (WIDTH / 5, HEIGHT / 3)
#global frame,speed,is_down,started_game,ground,pipes,score,highscore,game_over
pgzrun.go()  #do not remove and leave as last line of code
예제 #7
0
            sounds.explosion.play()
        if debris.colliderect(laser) == 1:
            lasers.remove(laser)
            x_deb = random.randint(-500, -50)
            y_deb = random.randint(SCOREBOX_HEIGHT, HEIGHT - debris.height)
            debris.topright = (x_deb, y_deb)
            score += 10
            sounds.explosion.play()


# activating lasers (template code)____________________________________________________________________________________________


def makeLaserActive(
):  # when called, this function will make lasers active again
    global player
    player.laserActive = 1


def fireLasers(laser):
    if player.laserActive == 1:  # active status is used to prevent continuous shoot when holding space key
        player.laserActive = 0
        clock.schedule(
            makeLaserActive, 0.2
        )  # schedule an event (function, time afterwhich event will occur)
        sounds.laserfire02.play()  # play sound effect
        lasers.append(laser)  # add laser to lasers list


pgzrun.go()  # function that runs our game loop
예제 #8
0
    #putting lasers on screen
    for laser in lasers:
        laser.draw()

    #instructions
    ins = "Touch rocks and cars. Shoot broken satellites and cars."
    ins_2 = "Don't shoot good satelites. Don't touch good or bad satellites."
    screen.draw.text(ins, topleft=(400, 5), fontsize=20, color="yellow")
    screen.draw.text(ins_2, topleft=(400, 20), fontsize=20, color="yellow")

    #game over
    if (score < 0):
        show_game_over = "GAME OVER"
        screen.draw.text(show_game_over, center=(WIDTH/2,HEIGHT/2), fontsize=100, color="red", ocolor='white', owidth=0.5)

    #game win
    if (score >= 150):
        win = "YOU WIN!"
        screen.draw.text(win, center=(WIDTH/2,HEIGHT/2), fontsize=100, color="orange", ocolor='white', owidth=0.5)

    #timer
    timer = "Time: " + str(elp_time)
    screen.draw.text(timer, topleft=(875,42), fontsize=45, color="orange")
        
    #showing score on screen
    show_score = "Score: " + str(score)
    screen.draw.text(show_score, topleft=(880,15), fontsize=35, color="white")

pgzrun.go() #runs game loop

#Procedure: game_status_three
def game_status_three():
    """
    After entering a side room, this procedure determines what the cadet will
    encounter by random choice (Health Boost, TACs, CGR) then takes appropriate
    actions. For now, we are just drawing a message on the screen.
    """
    global sideRoom, room_choice
    if sideRoom:
        room_choice = random.choices(
            ['Health', 'TAC', 'CGR'],
            [0.5, 0.25, 0.25])  #Change probability based off game_level
        sideRoom = False
    if room_choice == ["CGR"]:
        screen.draw.text("CGR! Press Enter to return", (100, 300),
                         color="white",
                         fontsize=32)
    if room_choice == ["TAC"]:
        screen.draw.text("TAC! Press Enter to return", (100, 300),
                         color="white",
                         fontsize=32)
    if room_choice == ["Health"]:
        screen.draw.text("Health Boost! Press Enter to return", (100, 300),
                         color="white",
                         fontsize=32)


pgzrun.go()  #Run the game with this command. We are using Spyder
예제 #10
0
        # z pliku p3_walk09
        elif klatka == 8:
            gracz.image = 'p3_walk09'

        # jeśli klatka jest równa 9
        # zmień kostium gracza na ten
        # z pliku p3_walk10
        elif klatka == 9:
            gracz.image = 'p3_walk10'

        # jeśli klatka jest równa 10
        # zmień kostium gracza na ten
        # z pliku p3_walk11
        elif klatka == 10:
            gracz.image = 'p3_walk11'

    klatka += 1  # zwiększ wartość
    # zmiennej klatka o 1
    klatka %= 11  # obliczamy resztę z dzielenia
    # zmiennej klatka przez 11
    # wynik takiej operacji to liczba większa bądź
    # równa zero oraz mniejsza od 11


clock.schedule_interval(odmierzaj_czas, 0.1)
# wywołujemey funkcję odmierzaj_czas() co 0.1 sekundy
clock.schedule_interval(zmiania_trudnosci, 20)
# wywołujemy funkcję zmiana_trudnosci() co 20 sekundy
pgzrun.go()  # linia ta jest konieczna
# aby okno nie zostało zamknięte
예제 #11
0
import pgzrun

alien = Actor('alien.png')
alien.pos = 100, 56

WIDTH = 500
HEIGHT = alien.height + 20


def draw():
    screen.clear()  #pycharm  каже про помилку, але код працює!
    alien.draw()


pgzrun.go()  # Must be last line
예제 #12
0
        block.value = 2
    blocks.append(block)


def update():
    for block in blocks:
        block.pos = block.position[0] * 100, block.position[1] * 100
    update_positions()


def update_positions():
    for block in blocks:
        positions.clear()
        positions.append(block.position)


def move_left():
    for i in range(4):
        for block in blocks:
            for position in positions:
                if block.position[0] - 1 == position[0]:
                    continue
            if block.position[0] != 1:
                block.position[0] -= 1


add_block()
add_block()

pg.go()
예제 #13
0
        # # if ball.right >= WIDTH:
        #     ball.direction = -ball.dx, ball.dy

        # elif ball.left <= 0:
        #     ball.direction = ball.dx, -ball.dy

        ball.direction = ball.dx, ball.dy
        ball.speed = game.speed
        # ball.move_ip(ball.speed * 3, ball.speed * 3)
        ball.move_ip(ball.dx, ball.dy)

    if ball.colliderect(PADDLE1) or ball.colliderect(PADDLE2):
        print('COLLISION')
        ball.dx = -ball.dx
    
    if ball.top <= 0 or ball.bottom >= HEIGHT:
        ball.dy = -ball.dy




def draw():
    screen.clear()
    screen.draw.filled_rect(ball, WHITE)
    screen.draw.filled_rect(PADDLE1, BLUE)
    screen.draw.filled_rect(PADDLE2, RED)   



pgz.go()
예제 #14
0
import pgzrun  #must be include in every pygame


def draw(
):  #called everytime an event occurs (when another pygame method such as update(), on_mouse_up(), etc is used)
    pass


def update():  #runs 60 times per second
    pass


def on_mouse_down(pos):
    print("mouse clicked (down)")


def on_mouse_up(pos):
    print("mouse unclicked (up)")


pgzrun.go()  #must be include in every pygame