x = random.randint(0, 799) #random x cordinate y = random.randint(0, 799) #random y cordinate randR = random.randint(5, 255) #random Red value randG = random.randint(5, 255) #random Green value randB = random.randint(5, 255) #random Blue value c = (randR, randG, randB) #random colors #pressing c prints circles on the screen if pscreen.keyIsPressed("c"): pscreen.circle(x, y, 20, c) #pressing s prints squares on the screen if pscreen.keyIsPressed("s"): pscreen.rectangle(x, y, x - 20, y - 20, c) #pressing f prints faces with moods on the screen if pscreen.keyIsPressed("f"): #draws the defined face drawFace(x, y, randMood) #clear screen to a random color if pscreen.keyIsPressed("e"): pscreen.clearScreen(c) #random diamonds if pscreen.keyIsPressed("d"): pscreen.triangle(x, y, x - 6, y, x - 3, y - 10, c) pscreen.triangle(x, y, x - 6, y, x - 3, y + 10, c) if pscreen.keyIsPressed("escape"): break pscreen.updateScreen() #unloadScreen pscreen.unloadScreen()
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: 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.ellipse(x+5,y-10,4,4,white,0) pscreen.circle(x-5,y-10,2,blue,0) pscreen.circle(x+5,y-10,2,blue,0) if randMood == "mad": pscreen.line(x-10,y-18,x-5,y-15,black) pscreen.line(x+10,y-18,x+5,y-15,black) pscreen.ellipse(x-5,y-10,4,4,white,0) pscreen.ellipse(x+5,y-10,4,4,white,0) pscreen.circle(x-5,y-10,2,blue,0) pscreen.circle(x+5,y-10,2,blue,0) #nose pscreen.line(x-2,y+2,x,y-1,black,0) pscreen.line(x-2,y+2,x+1,y+1,black,0) #update screen 2 pscreen.clearScreen(black) pscreen.updateScreen() #Program 2 game loop while True: drawBorderBox() pscreen.fontWrite(0,0,"press:Q to exit program 2 after program.",(255,255,255)) while i<10: #program 2 random face values randMood2=m1[random.randint(0,len(m1)-1)] rand_x2=random.randint(25,700) rand_y2=random.randint(25,544) randR2=random.randint(5,250) randG2=random.randint(5,250) randB2=random.randint(5,250) randColor2=(randR2,randG2,randB2)
def clearScreen(): pscreen.clearScreen((0, 0, 0))
px=100 py=100 #player radius pr=20 #treasure position tx=400 ty=400 #treasure radius tr=20 #initialization pscreen.loadScreen() #game loop while True: pscreen.clearScreen() if pscreen.keyIsPressed("escape"): break if pscreen.keyIsPressed("a"): px-=1 if pscreen.keyIsPressed("d"): px+=1 if pscreen.keyIsPressed("w"): py-=1 if pscreen.keyIsPressed("s"): py+=1 #player pscreen.circle(px,py,pr,(0,255,0),0) #treasure pscreen.circle(tx,ty,tr,(255,255,0),0)