def render(self):
     self.update()
     p1x=self.x+self.radius*math.cos(math.radians(self.angle))
     p1y=self.y+(-1)*self.radius*math.sin(math.radians(self.angle))
     p2x=(self.x-5)+self.radius*math.cos(math.radians(self.angle))
     p2y=(self.y-5)+(-1)*self.radius*math.sin(math.radians(self.angle))
     #print(p1x,p1y)
     pscreen.circle(p1x,p1y,self.radius,self.color,0)
     pscreen.circle(p2x,p2y,5,(0,0,0),0)
def drawS():#draws stars
    star_list=[]
    numStars=100
    #random color for stars
    randR=random.randint(0,255)
    randG=random.randint(0,255)
    randB=random.randint(0,255)
    randC=(randR,randG,randB)
    #add stars to list for background
    for i in range(0,numStars):
        star_list.append((random.randint(0,799),random.randint(0,599)))
     #randomize and draw random star locations
    for i in range(0,len(star_list)-1):
        (starX,starY)=star_list[i]
        pscreen.circle(starX,starY,random.randint(1,2),randC,0)
Esempio n. 3
0
 def draw(self):
     self.update()
     p1x = self.x + self.radius * math.cos(math.radians(self.angle + 18))
     p1y = self.y + (-1) * self.radius * math.sin(
         math.radians(self.angle + 18))
     p2x = self.x + self.radius * math.cos(math.radians(self.angle + 90))
     p2y = self.y - self.radius * math.sin(math.radians(self.angle + 90))
     p3x = self.x + self.radius * math.cos(math.radians(self.angle + 162))
     p3y = self.y - self.radius * math.sin(math.radians(self.angle + 162))
     p4x = self.x + self.radius * math.cos(math.radians(self.angle + 234))
     p4y = self.y - self.radius * math.sin(math.radians(self.angle + 234))
     p5x = self.x + self.radius * math.cos(math.radians(self.angle + 308))
     p5y = self.y - self.radius * math.sin(math.radians(self.angle + 308))
     pscreen.line(p1x, p1y, p3x, p3y, self.color, 1)
     pscreen.line(p1x, p1y, p4x, p4y, self.color, 1)
     pscreen.line(p2x, p2y, p4x, p4y, self.color, 1)
     pscreen.line(p2x, p2y, p5x, p5y, self.color, 1)
     pscreen.line(p3x, p3y, p5x, p5y, self.color, 1)
     pscreen.circle(self.x, self.y, self.radius, self.color, 1)
 def draw_Ship(self):
     Ship.move(self)
     if self.shield==True:
         pscreen.circle(self.x,self.y,25,(132,112,255),1)
     p1x=self.x+25*math.cos(math.radians(self.angle))
     p1y=self.y-25*math.sin(math.radians(self.angle))
     p2x=self.x+15*math.cos(math.radians(self.angle+120))
     p2y=self.y-15*math.sin(math.radians(self.angle+120))
     p3x=self.x+5*math.cos(math.radians(self.angle+180))
     p3y=self.y-5*math.sin(math.radians(self.angle+180))
     p4x=self.x+15*math.cos(math.radians(self.angle-120))
     p4y=self.y-15*math.sin(math.radians(self.angle-120))
     pscreen.triangle(p1x,p1y,p2x,p2y,p3x,p3y,(72,61,139),0)
     pscreen.triangle(p1x,p1y,p3x,p3y,p4x,p4y,(0,191,255),0)
     #draw flame behind ship when thrusting
     if self.thrust==True:
         for i in range(0,5):
             flame_length=random.randint(25,40)
             flame_spread=random.randint(-15,15)
             flame_x=self.x+flame_length*math.cos(math.radians(self.angle+180+flame_spread))
             flame_y=self.y-flame_length*math.sin(math.radians(self.angle+180+flame_spread))
             pscreen.line(self.x,self.y,flame_x,flame_y,(random.randint(150,200),random.randint(100,150),random.randint(150,175)),4)
def drawFace(x,y):
    #assigning values
    #Head
    pscreen.circle(x,y,25,aWhite,0)
    #mouth
    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)
    #eyes
    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)
Esempio n. 6
0
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"):
        #create a bullet
        bullet_list.append([0, 300 + random.randint(-150, 150)])
    #move bullets
    for bullet in bullet_list:
        bullet[0] += 1

    #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.remove(bullet)

    #render screen
    pscreen.fontWrite(0, 0, str(len(bullet_list)))
    pscreen.updateScreen()

pscreen.unloadScreen
        bullet_recharge_time = time.time(
        ) + 0.1  #calculate time when gun is next ready
        #create a bullet
        bullet_list.append([0, 300 + random.randint(-15, 15)])

    #move bullets
    for bullet in bullet_list:
        bullet[0] += 1

    #render section
    pscreen.clearScreen((0, 0, 0))

    #draw bullets
    for bullet in bullet_list:
        (bulletx, bullety) = bullet
        pscreen.circle(bulletx, bullety, 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 collisions with circle
    bullets_to_remove = []
    for bullet in bullet_list:
        if distance(mx, my, bullet[0], bullet[1]) <= 30 + 5:
            #mark bullets to be removed
            bullets_to_remove.append(bullet)

    #remove marked bullets
    for bullet in bullets_to_remove:
Esempio n. 8
0
 def draw(self):
     pscreen.circle(self.x,self.y,self.radius,self.color,0)
Esempio n. 9
0
    if playerX > 799:
        playerX = 799
    if playerY < 0:
        playerY = 0
    if playerY > 599:
        playerY = 599
#bound enemy on screen
    if enemyX <= 0 or enemyX >= 799:
        enemyDx *= -1
    if enemyY <= 0 or enemyY >= 599:
        enemyDy *= -1
    if enemyX < 0:
        enemyX = 0
    if enemyX > 799:
        enemyX = 799
    if enemyY < 0:
        enemyY = 0
    if enemyY > 599:
        enemyY = 599
    #renderScreen
    pscreen.clearScreen((0, 0, 0))

    #drawPlayer
    pscreen.circle(int(playerX), int(playerY), 20, (255, 255, 0), 0)

    #refresh screen
    pscreen.updateScreen()

#unloadScreen
pscreen.unloadScreen()
# pscreen graphics assignment 4 by. Thomas Gilman

#imports for code
import pscreen
import math
import random
import time

#loading of the screen
pscreen.loadScreen()

#assigning values to white and black
#Face
pscreen.circle(200, 200, 50, (255, 255, 255), 1)
#Eyes
pscreen.ellipse(175, 185, 10, 5, (255, 255, 255),
                1)  #changed it from (140,175,20,10)
pscreen.ellipse(225, 185, 10, 5, (255, 255, 255), 1)
pscreen.circle(175, 185, 2, (255, 255, 255), 1)
pscreen.circle(225, 185, 2, (255, 255, 255), 1)
#smile
pscreen.line(175, 225, 225, 225, (255, 255, 255),
             1)  #changed it from (150,250,250,250)
pscreen.line(175, 225, 170, 230, (255, 255, 255),
             1)  #changed it from (150,250,130,260)
pscreen.line(225, 225, 230, 230, (255, 255, 255),
             1)  #changed it from (250,250,270,260)
#Nose
pscreen.line(190, 200, 200, 205, (255, 255, 255),
             1)  #changed it from (170,180,200,200)
pscreen.line(190, 200, 205, 190, (255, 255, 255),
        dY*=.9
        ballY=599

    #add a little bit of gravity
    dY+=.1
    #add jump force
    if ballJump==True:
        dY-=5
        ballJump=False

    #convert back to possible new angle and speed
    ballSpeed=(dX**2+dY**2)**.5
    ballAngle=math.degrees(math.atan2(-dY,dX))
    #add friction
    #ballSpeed*=.9999999999999999
    #speed limit
    if ballSpeed>20:
        ballSpeed=20
    

    #draw Screen
    pscreen.clearScreen((0,0,0))
    #draw ball
    pscreen.circle(int(ballX),int(ballY),20,(255,255,0),0)
    
    #render Screen
    pscreen.updateScreen()

pscreen.unloadScreen()

 def render(self):
     pscreen.circle(self.x,self.y,self.size,(255,135,0),0)
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
        pscreen.line(x-5,y+5,x+5,y+5,black)
        pscreen.line(x-5,y+5,x-7,y+7,black,0)
        pscreen.line(x+5,y+5,x+7,y+7,black,0)
    if randMood == "nuetral":#nuetral face
        pscreen.line(x-5,y+5,x+5,y+5,black)
    #eyes
    if randMood == "happy":
        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)
    if randMood == "nuetral":
        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)
    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)
Esempio n. 14
0
def drawP():
    #body
    pscreen.circle(pX, pY, pR, aWhite, 0)
    #eyes
    pscreen.circle(int(pX) - 15, int(pY) - 12, pR - 20, white, 0)
    pscreen.circle(int(pX) + 15, int(pY) - 12, pR - 20, white, 0)
    #eye color
    pscreen.circle(int(pX) - 15, int(pY) - 12, pR - 25, nBlue, 0)
    pscreen.circle(int(pX) + 15, int(pY) - 12, pR - 25, nBlue, 0)
    #pupils
    pscreen.circle(int(pX) - 15, int(pY) - 12, pR - 27, black, 0)
    pscreen.circle(int(pX) + 15, int(pY) - 12, pR - 27, black, 0)
    #Mouth
    pscreen.line(int(pX) - 15, int(pY) + 15, (pX) + 15, pY + 15, black, 3)
    pscreen.line(int(pX) - 15, int(pY) + 15, (pX) - 20, pY + m, black, 3)
    pscreen.line(int(pX) + 15, int(pY) + 15, (pX) + 20, pY + m, black, 3)
    #Nose
    pscreen.circle(pX, pY, pR - 25, S, 0)
    pscreen.circle(pX, pY, pR - 27, dS, 0)
Esempio n. 15
0
def drawI(iX, iY):
    pscreen.circle(iX, iY, random.randint(30, 33), black, 0)
    pscreen.circle(iX, iY, iR, Gold, 0)
    pscreen.rectangle(iX - 25, iY - 25, iX + 25, iY + 25, black, 0)
    pscreen.circle(iX, iY, random.randint(15, 25), Gold, 0)
    pscreen.rectangle(iX - 12, iY - 12, iX + 12, iY + 12, pGoldr, 0)
    pscreen.circle(iX, iY, random.randint(8, 12), Gold, 0)
    pscreen.rectangle(iX - 6, iY - 6, iX + 6, iY + 6, black, 0)
    pscreen.circle(iX, iY, random.randint(4, 6), Gold, 0)
    pscreen.rectangle(iX - 3, iY - 3, iX + 3, iY + 3, pGoldr, 0)
    pscreen.circle(iX, iY, random.randint(1, 3), Gold, 0)
    pscreen.rectangle(iX - 1, iY - 1, iX + 1, iY + 1, black, 0)
    pscreen.circle(iX, iY, 1, Gold, 0)
Esempio n. 16
0
def drawObstacle():
    pscreen.circle(oX, oY, oR, black, 0)
    pscreen.circle(oX, oY, oR - 10, dS, 0)
Esempio n. 17
0
def drawBackground():
    pscreen.rectangle(0, 0, 799, 799, randC, 0)
    pscreen.circle(300, 300, 200, (178, 34, 34), 0)
    pscreen.circle(300, 300, 100, (178, 40, 40), 0)
# pscreen Test Program

import pscreen
import time
import random

pscreen.loadScreen()

pscreen.circle(200,200,100)
pscreen.circle(400,400,100,(0,0,255),5)
pscreen.circle(300,300,100,(0,0,254),0)

pscreen.line(200,200,400,400,(255,0,0),5)

i=0
while i<100:
    rand_x = random.randint(0,799)
    rand_y = random.randint(0,599)
    rand_radius = random.randint(20,100)
    rand_r = random.randint(0,255)
    rand_g = random.randint(0,255)
    rand_b = random.randint(0,255)
    pscreen.circle(rand_x,rand_y,rand_radius)
    i+=1
    

while pscreen.keyIsNotPressed("q"):
    pscreen.updateScreen()
time.sleep(5)

pscreen.unloadScreen()
Esempio n. 19
0
    #set recharge time
    #   bullet_recharge_time=time.time()+1

    #create a bullet
    #  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)))
Esempio n. 20
0
 def draw(self):
     pscreen.circle(self.x,self.y,self.radius,self.color,0)
     pscreen.circle(self.x-self.radius*0.35,self.y-self.radius*0.35,self.radius*0.2,(255,255,255),0)
     pscreen.loadScreen()
Esempio n. 21
0
    ship_y += resultant_dy

    #wrap ship on screen
    if ship_x < 0:
        ship_x = 799
    if ship_x > 799:
        ship_x = 0
    if ship_y < 0:
        ship_y = 599
    if ship_y > 599:
        ship_y = 0

    #clear screen
    pscreen.clearScreen((0, 0, 0))
    #draw target
    pscreen.circle(target_x + 100 * math.sin(math.radians(modulation_angle)),
                   target_y, 10, (255, 255, 255), 0)
    #draw pulsating planet
    pscreen.circle(
        400, 300, 100 + 10 * math.sin(math.radians(modulation_angle)), 150,
        240 + 50 * math.sin(math.radians(math.radians(modulation_angle)), 0),
        0)
    modulation_angle += 1
    #draw ship
    draw_Ship(ship_x, ship_y, ship_angle_facing, thrust_force)
    #UpdateScreen
    pscreen.updateScreen()

#unloadScreen
pscreen.unloadScreen()

#3.)Modulating game parameters:
#moods
m = ["happy", "sad", "nuetral"]

#loop
while True:
    #values
    randMood = m[random.randint(0, len(m) - 1)]
    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)
Esempio n. 23
0
#imports for code
import pscreen
import math
import random
import time

#loading of the screen
pscreen.loadScreen()

while pscreen.keyIsNotPressed("q"):
    #assigning values to white and black
    #Face
    pscreen.circle(200, 200, 100, (255, 255, 255), 1)
else:
    pscreen.unloadScreen
Esempio n. 24
0
def Asteroid(Ax, Ay):
    pscreen.circle(Ax, Ay, 20, (112, 138, 144), 0)
def meteor():
    #meteor object
    pscreen.circle(mX, mY, mR, (30, 26, 18), 0)
Esempio n. 26
0
#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)

    #Check for collision
    #method 1:same location
    #if px==tx and py==ty:
       # pscreen.line(0,0,799,599,(255,0,0),10)
       # pscreen.line(0,599,799,0,(255,0,0),10)

    #method 2:bounding box overlap
    #if abs(tx-px)<=tr+pr and abs(ty-py)<=tr+pr:
        # pscreen.line(0,0,799,599,(255,0,0),10)
        # pscreen.line(0,599,799,0,(255,0,0),10)

    #method 3: distance check
        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()
def draw_target(x, y, radius, color):
    tx = random.randint(10, 789)
    ty = random.randint(10, 589)
    tradius = 100
    tcolor = (168, 178, 100)
    pscreen.circle(x, y, tradius, color, 0)
def drawFace(x, y, randMood):
    #face
    pscreen.circle(x, y, 20, c, 0)
    #whites of eyes
    pscreen.circle(x - 5, y - 5, 5, white, 0)
    pscreen.circle(x + 5, y - 5, 5, white, 0)
    #color of eyes
    pscreen.circle(x - 5, y - 5, 2, b, 0)
    pscreen.circle(x + 5, y - 5, 2, b, 0)
    #pupils
    pscreen.circle(x - 5, y - 5, 1, (0, 0, 0), 0)
    pscreen.circle(x + 5, y - 5, 1, (0, 0, 0), 0)
    #nose
    pscreen.line(x - 2, y, x + 3, y + 2, (0, 0, 0), 1)
    pscreen.line(x - 2, y, x + 3, y - 2, (0, 0, 0), 1)
    #Mouth
    if randMood == "happy":
        pscreen.line(x - 5, y + 5, x + 5, y + 5, black)
        pscreen.line(x - 5, y + 5, x - 7, y + 3, black)
        pscreen.line(x + 5, y + 5, x + 7, y + 3, black)
    elif randMood == "nuetral":
        pscreen.line(x - 5, y + 5, x + 5, y + 5, black)
    elif randMood == "sad":
        pscreen.line(x - 5, y + 5, x + 5, y + 5, black)
        pscreen.line(x - 5, y + 5, x - 7, y + 8, black)
        pscreen.line(x + 5, y + 5, x + 7, y + 8, black)
Esempio n. 30
0
star_list = []
numStars = 200

for i in range(0, numStars):
    star_list.append((random.randint(0, 799), random.randint(0, 599)))

while True:
    randR = random.randint(0, 255)
    randG = random.randint(0, 255)
    randB = random.randint(0, 255)
    randC = (randR, randG, randB)
    if pscreen.keyIsPressed("escape"):
        break
    if pscreen.keyIsPressed("a"):
        star_list.append((random.randint(0, 799), random.randint(0, 599)))
    if pscreen.keyIsPressed("c"):
        star_list = []

    #render
    pscreen.clearScreen((0, 0, 0))

    #drawStar
    for i in range(0, len(star_list) - 1):
        (starX, starY) = star_list[i]
        pscreen.circle(starX, starY, random.randint(1, 3), randC, 0)

    pscreen.updateScreen()

pscreen.unloadScreen()