def gameOver():
    pscreen.fontSelect("Arial", 22)
    pscreen.fontWrite(350, 300, "Game Over")
    pscreen.fontWrite(250, 325, "Player1 Score:" + str(score))
    pscreen.fontWrite(410, 325, "Player2 Score:" + str(score2))
    if score > score2:
        pscreen.fontWrite(360, 375, "Player1 Wins!")
    elif score < score2:
        pscreen.fontWrite(360, 375, "Player2 Wins!")
    elif score == score2:
        pscreen.fontWrite(360, 375, "Tie!")
#Game loop test example code

#Initialization
import pscreen
import time

playerX = 400
playerY = 300

pscreen.loadScreen()
pscreen.fontSelect("Arial", 24)

#Game Loop
while True:
    #input
    if pscreen.keyIsPressed("q"):
        break
    if pscreen.keyIsPressed("a"):
        playerX -= 1
    if pscreen.keyIsPressed("d"):
        playerX += 1
    if pscreen.keyIsPressed("w"):
        playerY -= 1
    if pscreen.keyIsPressed("s"):
        playerY += 1
    #contain player on the screen
    if playerX < 0:
        playerX = 0
    if playerX > 799:
        playerX = 799
    if playerY < 0:
#score
Score=0
#make ship and asteroid entity
ship=Ship()
#asteroid list
asteroid_list=[]
for i in range(0,5):
    asteroid_list.append(Asteroid(x=random.randint(10,789),y=random.randint(10,589),speed=random.randint(1,5)/5,angle=random.randint(0,360)))
#bullet list
bullet_list=[]
bullet_recharge_time=1
shield_recharge_time=0
shiled_invincibility_time=2
#Load Screen
pscreen.loadScreen()
pscreen.fontSelect("Arial",18)
#Game loop
while True:
    if pscreen.keyIsPressed('escape'):
        break
    #clear Screen
    pscreen.clearScreen((0,0,0))
    #draw starField
    drawS()
    #shoot a bullet
    if pscreen.keyIsPressed('space') and time.time()>=bullet_recharge_time:
        bullet_recharge_time=time.time()+1*0.5
        #append bullet
        bullet_list.append(Bullet(ship.x+25,ship.y,ship.angle,2))
    for bullet in bullet_list:
        bullet.render()
Exemple #4
0
#Graphics list example

import random
import pscreen
import time


def distance(x1, y1, x2, y2):
    return ((x2 - x1)**2 + (y2 - y1)**2)**.05


pscreen.loadScreen()
pscreen.fontSelect()

bullet_list = []

while True:
    if pscreen.keyIsPressed("escape"):
        break

    pscreen.clearScreen((0, 0, 0))
    #check to see if we want to create a bullet
    if pscreen.keyIsPressed("space") and last_space_not_pressed == True:
        #set recharge time
        if last_space_not_pressed == True:
            #create a bullet
            bullet_list.append([0, 300 + random.randint(-150, 150)])
            last_space_not_pressed = False
    else:
        last_space_not_pressed = True
def gameTime():
    timeLeft = endTime - time.time()
    timeLeft = int(timeLeft * 10) / 10
    pscreen.fontSelect("Arial", 18)
    pscreen.fontWrite(700, 5, "Time Left:" + str(timeLeft))
    elif score < score2:
        pscreen.fontWrite(360, 375, "Player2 Wins!")
    elif score == score2:
        pscreen.fontWrite(360, 375, "Tie!")


#floating meteor obsticle
def meteor():
    #meteor object
    pscreen.circle(mX, mY, mR, (30, 26, 18), 0)


#load screen
pscreen.loadScreen()
#load font
pscreen.fontSelect('Arial', 16)
#load Time
startTime = time.time()
endTime = startTime + 60
#star list
star_list = []
#render stars
for i in range(0, 12):
    star_list.append(
        Star(x=random.randint(10, 789),
             y=random.randint(0, 589),
             rotation_speed=random.uniform(-1, 1)))
#Meteor specs
mX = random.randint(10, 789)  #x cord
mY = random.randint(10, 589)  #y cord
mR = 25  #radius
Exemple #7
0
def gameOver():
    pscreen.fontSelect("Arial", 50)
    pscreen.fontWrite(290, 300, "GAME OVER", black)
    pscreen.fontWrite(290, 360, "Score:" + str(s), black)
Exemple #8
0
def keepScore():
    pscreen.fontSelect("Arial", 25)
    pscreen.fontWrite(5, 570, "score is:" + str(s), black)
Exemple #9
0
def gameTime():
    timeLeft = endTime - time.time()
    timeLeft = int(timeLeft * 10) / 10
    pscreen.fontSelect("Arial", 20)
    pscreen.fontWrite(5, 5, "time:" + str(timeLeft), black)
Exemple #10
0
def gameOver():
    pscreen.fontSelect("Arial", 18)
    pscreen.fontWrite(310, 300, "GAME OVER")
    pscreen.fontWrite(300, 350, "Time Survived:" + str(sTime))
    pscreen.updateScreen()
    time.sleep(5)