playerY += 1 #contain player on the screen if playerX < 0: playerX = 0 if playerX > 799: playerX = 799 if playerY < 0: playerY = 0 if playerY > 599: playerY = 599 #render objects / draw stuff #clear the screen pscreen.clearScreen((0, 0, 0)) #draw a circle pscreen.circle(playerX, playerY, 20, (255, 255, 0), 0) #head outline pscreen.circle(playerX - 6, playerY - 6, 3) #left eye (our left) pscreen.circle(playerX - 6, playerY - 6, 2, (0, 255, 255), 0) #left pupil pscreen.circle(playerX + 6, playerY - 6, 3) #right eye (our right) pscreen.circle(playerX + 6, playerY - 6, 2, (0, 255, 255), 0) #right pupil pscreen.line(playerX - 8, playerY + 8, playerX + 8, playerY + 8, (255, 0, 255)) #mouth pscreen.fontWrite( 0, 0, "Game Loop Example", (255, 255, 255)) #display text in upper left hand corner (our left) pscreen.updateScreen() #Clean-up pscreen.unloadScreen()
ship.shield=False shield_recharge_time=time.time()+2 #draw ship ship.draw_Ship() #draw Asteroid for asteroid in asteroid_list: asteroid.render() #break from loop if energy reaches 0 if ship.energy==0: break if asteroid_list==[]: break #display time gameTime() #display energy left pscreen.fontWrite(0,579,"Shield Energy Left:"+str(ship.energy)) #display Score pscreen.fontWrite(100,0,"Score:"+str(Score)) #update Screen pscreen.updateScreen() #Unload screen if ship.energy==0: pscreen.fontWrite(375,300,"Game Over",(255,140,0)) pscreen.fontWrite(385,325,"Score:"+str(Score),(255,140,0)) pscreen.updateScreen() time.sleep(5) else: pscreen.fontWrite(375,300,"Thanks for Play!",(255,140,0)) pscreen.fontWrite(395,325,"Score:"+str(Score),(255,140,0)) pscreen.updateScreen() time.sleep(5)
def gameTime(): sTime=time.time()-startTime sTime=int(sTime*10)/10 pscreen.fontWrite(0,0,'Time:'+str(sTime))
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!")
# bullet_list.append([0,300+random.randint(-150,150)]) #move bullets for bullet in bullet_list: bullet[0] += 1 mx = pscreen.mouseGetX() my = pscreen.mouseGetY() #draw bullets for bullet in bullet_list: (bx, by) = bullet pscreen.circle(bx, by, 5, (255, 0, 0), 0) #check for bullets that have left the screen for bullet in bullet_list: if bullet[0] > 799: bullet_list.remove(bullet) #check for bullet collision with circle for bullet in bullet_list: if distance(mx, my, bullet[0], bullet[1]) <= 30 + 5: bullet_list.remove(bullet) pscreen.circle(mx, my, 30, (0, 0, 255), 0) #render screen pscreen.fontWrite(0, 0, str(len(bullet_list))) pscreen.updateScreen() pscreen.unloadScreen
#distance between ship 2 and meteor if distance(ship2_x, ship2_y, mX, mY) < 50: mDx *= -1 mDy *= -1 ship2_speed *= -1 score2 *= 0 #end game timeLeft = endTime - time.time() if timeLeft <= 0: break #draw Target draw_target(tx, ty, tradius, tcolor) #draw Meteor meteor() #draw player 1 draw_ship(ship_x, ship_y, ship_angle_facing, thrust_force) #draw player 2 draw_ship2(ship2_x, ship2_y, ship2_angle_facing, thrust2_force) #show Score pscreen.fontWrite(0, 0, "Player1 Score" + str(score)) pscreen.fontWrite(150, 0, "Player2 Score:" + str(score2)) #show Time gameTime() #update Screen in loop pscreen.updateScreen() gameOver() pscreen.updateScreen() time.sleep(5) #Unload Screen pscreen.unloadScreen()
def gameTime(): timeLeft = endTime - time.time() timeLeft = int(timeLeft * 10) / 10 pscreen.fontSelect("Arial", 18) pscreen.fontWrite(700, 5, "Time Left:" + str(timeLeft))
def gameOver(): pscreen.fontSelect("Arial", 50) pscreen.fontWrite(290, 300, "GAME OVER", black) pscreen.fontWrite(290, 360, "Score:" + str(s), black)
#chest body pscreen.rectangle(x-60,y-20,x-30,y,brown,0) #line between chest lid and chest body pscreen.line(x-50,y-20,x-40,y-20,black,0) #chest lock pscreen.rectangle(x-47,y-23,x-42,y-14,yellow,0) #Program 1 game loop while True: drawFace(400,400) drawTreasure(300,200) drawTreasure(600,200) drawTreasure(700,400) drawBorderBox() pscreen.fontWrite(0,0,"press:Escape to exit program 1.",(255,255,255)) #update Screen pscreen.updateScreen() if pscreen.keyIsPressed("escape"): break #second drawFace for program 2 def drawFace2(x,y,randColor,randMood): #Head pscreen.circle(x,y,25,randColor,0) #mouth if randMood == "happy":#happy face pscreen.line(x-5,y+5,x+5,y+5,black) pscreen.line(x-5,y+5,x-7,y+2,black,0) pscreen.line(x+5,y+5,x+7,y+2,black,0) if randMood == "mad":#mad face
def keepScore(): pscreen.fontSelect("Arial", 25) pscreen.fontWrite(5, 570, "score is:" + str(s), black)
def gameTime(): timeLeft = endTime - time.time() timeLeft = int(timeLeft * 10) / 10 pscreen.fontSelect("Arial", 20) pscreen.fontWrite(5, 5, "time:" + str(timeLeft), black)
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)
A_list.remove(Asteroid) pop -= random.randint(50, 200) #Collision between Asteroid and Bullet for Asteroid in A_list: (Ax, Ay) = Asteroid for bullet in Bullet_list: (bulletX, bulletY) = bullet if distance(Ax, Ay, bulletX, bulletY) < 25: A_list.remove(Asteroid) Bullet_list.remove(bullet) #Time sTime = time.time() - startTime sTime = int(sTime * 10) / 10 #End game if Population is wiped out if pop <= 0: break #display number of bullets pscreen.fontWrite(0, 0, 'Bullets:' + str(len(Bullet_list))) #display number of Asteroids pscreen.fontWrite(100, 0, 'Asteroids:' + str(len(A_list))) #display population number pscreen.fontWrite(0, 550, 'Population:' + str(pop)) #display time pscreen.fontWrite(150, 550, "Survival Time:" + str(sTime)) #updateScreen pscreen.updateScreen() gameOver() #unloadScreen pscreen.unloadScreen()
pscreen.rectangle(200, 565, 210, 575, (0, 0, 0), 0) #black color pscreen.rectangle(200, 575, 210, 585, (255, 255, 255), 0) #white color pscreen.rectangle(210, 565, 220, 575, (255, 0, 0), 0) #Red color pscreen.rectangle(210, 575, 220, 585, (0, 255, 0), 0) #Green color pscreen.rectangle(220, 565, 230, 575, (0, 0, 255), 0) #Blue color pscreen.rectangle(220, 575, 230, 585, (255, 255, 0), 0) #Red, and Green color pscreen.rectangle(230, 565, 240, 575, (255, 0, 255), 0) #Red,and Blue color pscreen.rectangle(230, 575, 240, 585, (0, 255, 255), 0) #Blue,and Green color #exit button pscreen.rectangle(70, 547, 15, 580, (255, 255, 255), 0) #box under exit button pscreen.fontWrite( 25, 550, "Exit", (255, 0, 255)) #should display Exit in the bottom left corner #Exit button loop break if pscreen.mouseGetButtonL() and 15 < x < 70 and 547 < y < 580: break #objects that change brush size, and shape if pscreen.mouseGetButtonL() and 75 < x < 85 and 565 < y < 575: brush_radius = 5 isCircle = True if pscreen.mouseGetButtonL() and 100 < x < 120 and 565 < y < 575: brush_radius = 10 isCircle = True if pscreen.mouseGetButtonL() and 130 < x < 170 and 565 < y < 575: brush_radius = 20 isCircle = True if pscreen.mouseGetButtonL() and 180 < x < 190 and 565 < y < 575: