Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import pygame as py
- import math as m
- from random import randint as rn
- py.font.init()
- font = py.font.Font("slkscre.ttf",16)
- bigfont = py.font.Font("slkscre.ttf",32)
- def dis(x,y,x2,y2):
- return m.sqrt((x-x2)**2+(y-y2)**2)
- def upload(imag, sx, sy):
- i = py.image.load(imag+".png").convert()
- i = py.transform.scale(i,(sx,sy))
- i.set_colorkey((110.0, 184.0, 168.0))
- return i
- def rotation(angle, image, screen, xyset, size):
- x, y = xyset
- avv = py.transform.rotate(image, -angle / m.pi * 180+90)
- difx = int(abs(avv.get_width()-size)/2)
- dify = int(abs(avv.get_height()-size)/2)
- screen.blit(avv, (x-difx+sx, y-dify+sy))
- particles =[]
- def createP(gx,gy,num,color,speed,size,special_param):
- for i in range(num):
- if special_param == "default":
- ag = rn(0,640)*0.01
- speedo = rn(speed[0],speed[1])*0.1
- sizeo = rn(size[0],size[1])*0.1
- p = [gx,gy,m.cos(ag)*speedo,m.sin(ag)*speedo,sizeo,color]
- else:
- vx_add,vy_add, gradient_1, gradient_2,gravity = special_param
- ag = rn(0,640)*0.01
- speedo = rn(speed[0],speed[1])*0.1
- sizeo = rn(size[0],size[1])*0.1
- p = [gx,gy,m.cos(ag)*speedo+vx_add,m.sin(ag)*speedo+vy_add,sizeo,[gradient_1,gradient_2,0,gravity]]
- particles.append(p)
- screen = py.display.set_mode((800,800))
- global absId
- absId = 0
- class Card():
- def __init__(self,img,cost):
- global absId
- self.id = absId
- self.img = img
- self.cost = cost
- self.bigimg = py.transform.scale(self.img,(192,192))
- absId += 1
- global AgList
- AgList = [-m.pi*0.075,-m.pi*0.05,-m.pi*0.025,0,
- m.pi*0.025,m.pi*0.05,m.pi*0.075,m.pi*0.125]
- global yOffsetList
- yOffsetList= [30,20,10,0,10,20,30,50]
- global mox
- global moy
- mox, moy = 0,0
- global sx
- global sy
- sx, sy = 0,0
- global bullets
- bullets = []
- global runo
- runo = 0
- global win
- win = 0
- class Player():
- def __init__(self,x,y):
- self.x = x
- self.y = y
- self.vx = 0
- self.vy = 0
- self.health = 100
- self.hand = []
- self.shield = 0
- self.orbsOwned = 5
- def draw(self):
- py.draw.rect(screen,(255,255,255),(self.x-7+sx,self.y-7+sy,14,14))
- def drawCards(self):
- isLookingAtCard = 0
- for card in self.hand:
- indexx = self.hand.index(card)
- #py.draw.ellipse(screen,(255,255,255),(230+indexx*60-50+64,650+yOffsetList[indexx]-50+64,100,100),2)
- if dis(200+indexx*60+64,580+yOffsetList[indexx]+64,mox,moy)<50 and isLookingAtCard == 0:
- isLookingAtCard = card
- else:
- rotation(m.pi/2+AgList[indexx],card.img,screen,(200+indexx*60,580+yOffsetList[indexx]),128)
- for card in self.hand:
- indexx = self.hand.index(card)
- if dis(200+indexx*60+64,580+yOffsetList[indexx]+64,mox,moy)<50 and card == isLookingAtCard:
- screen.blit(card.bigimg,(200+indexx*60+sx,550+yOffsetList[indexx]+sy))
- txt = font.render("Cost: " + str(card.cost),True,(255,255,255))
- screen.blit(txt,(200+indexx*60+sx+60,550+yOffsetList[indexx]+sy-20))
- return card
- if isLookingAtCard == 0:
- return 0
- def move(self):
- self.x += self.vx
- self.y += self.vy
- if abs(self.x-400)>400 and abs(self.vx)/self.vx*abs(self.x-400)/(self.x-400) > 0:
- self.x-=self.vx
- if abs(self.y-250)>250 and abs(self.vy)/self.vy*abs(self.y-250)/(self.y-250) > 0:
- self.y-=self.vy
- def checkKeys(self,e,booll):
- key = e.key
- if booll:
- if key == py.K_a:
- self.vx = -2
- if key == py.K_d:
- self.vx = 2
- if key == py.K_w:
- self.vy = -2
- if key == py.K_s:
- self.vy = 2
- else:
- if key == py.K_a or key == py.K_d:
- self.vx = 0
- if key == py.K_w or key == py.K_s:
- self.vy = 0
- class Boss():
- def __init__(self,img):
- self.x = 400
- self. y = 250
- self.pattern = 0
- self.internalClock = 0
- self.img = img
- self.size = self.img.get_width()
- self.health = 1000
- def draw(self):
- screen.blit(self.img,(self.x-self.size/2+sx,self.y-self.size/2+sy))
- py.draw.rect(screen,(255,255,255),(self.x-100,self.y-100,self.health/5,15))
- py.draw.rect(screen,(255,255,255),(self.x-110,self.y-110,200+20,15+20),5)
- def attack(self):
- self.internalClock += 1
- if self.internalClock > 500:
- if self.pattern == 0 and self.internalClock%8 == 0:
- for i in range(12):
- b = [self.x,self.y,m.cos(i/6*m.pi+m.pi*self.internalClock/600)*4,m.sin(i/6*m.pi+m.pi*self.internalClock/600)*4]
- bullets.append(b)
- if self.pattern == 1 and self.internalClock%8 == 0:
- for i in range(12):
- b = [self.x,self.y,m.cos(i/6*m.pi-m.pi*self.internalClock/600)*4,m.sin(i/6*m.pi-m.pi*self.internalClock/600)*4]
- bullets.append(b)
- if self.pattern == 2 and self.internalClock%2 == 0:
- ag = rn(0,640)*0.01
- b = [self.x,self.y,m.cos(ag)*2,m.sin(ag)*2]
- bullets.append(b)
- if self.internalClock > 600:
- self.internalClock = 0
- self.pattern = rn(0,2)
- def GameLoop():
- global mox
- global moy
- global sx
- global sy
- global bullets
- global runo
- global win
- def DrawACard(player):
- if len(player.hand)<8 and player.orbsOwned>0:
- player.orbsOwned -= 1
- player.hand.append(deck[0])
- deck.remove(deck[0])
- return 1
- else:
- return 0
- def doCardEffect(card):
- p1.orbsOwned -= card.cost
- if card.img == laserimg:
- nodes = []
- for i in range(int(dis(p1.x,p1.y,boss1.x,boss1.y)/50)):
- nodes.append([rn(-80,80)*0.01,rn(8,40)+i*30])
- lasers.append([40,nodes])
- if card.img == shieldimg:
- if p1.shield+30>70:
- p1.shield = 70
- else:
- p1.shield+=15
- createP(p1.x,p1.y,30,(255,255,255),[5,15],[200,320],"default")
- if card.img == swordcardimg:
- for i in range(12):
- disto = dis(p1.x,p1.y,boss1.x,boss1.y)+rn(-20,20)
- x = boss1.x+m.cos(rn(0,640))*disto
- y = boss1.y+m.sin(rn(0,640))*disto
- ag = m.atan2(y-boss1.y,x-boss1.x)+m.pi
- setOffTimer = rn(2,60)
- sword = [x,y,setOffTimer,ag]
- swords.append(sword)
- if card.img == rocket:
- ag = m.atan2(p1.y-boss1.y,p1.x-boss1.x)+m.pi
- for i in range(2):
- ro = [p1.x+m.cos(ag+m.pi/2-m.pi*i)*30,p1.y+m.cos(ag+m.pi/2-m.pi*i)*30,m.cos(ag)*5,m.sin(ag)*5,50+100*i,ag]
- rockets.append(ro)
- p1 = Player(200,400)
- deckimg = upload("CBHCardsBack",128,128)
- laserimg = upload("CBHlaser",128,128)
- shieldimg = upload("CBHshield",128,128)
- swordcardimg = upload("CBHsword",128,128)
- rocket = upload("CBHrocket",128,128)
- cardSets = [[laserimg,3],[shieldimg,2],[swordcardimg,5],[rocket,4]]
- p1.hand=[]
- deck = []
- for i in range(80):
- img, cost = cardSets[rn(0,len(cardSets)-1)]
- actualCard = Card(img,cost)
- if len(deck)>3:
- if not (actualCard == deck[i-1] and actualCard == deck[i-2]):
- deck.append(actualCard)
- else:
- deck.append(actualCard)
- print(len(deck))
- cardImLookingAt = p1.drawCards()
- bullets = []
- boss1 = Boss(upload("CBHBoss0",128,128))
- lasers = []
- sx,sy = 0,0
- shake = [0,0]
- youCanDraw = 1
- for i in range(7):
- DrawACard(p1)
- orbs = []
- drawTimer = 300
- orbimg = upload("CBHOrbs",32,32)
- vialimg = upload("CBHVial",256,256)
- vialimg2 = upload("CBHVialBitFilled",256,256)
- p1.orbsOwned = 10
- swords = []
- swordimg = upload("CBHindividualsword",64,64)
- automaticOrb = 0
- rockets = []
- rocketimg = upload("CBHrocketimg",96,96)
- cl = py.time.Clock()
- run = 1
- while run:
- screen.fill((0,0,0))
- mox, moy = py.mouse.get_pos()
- if shake[1]:
- shake[1]-=1
- sx,sy = rn(-10,10)*shake[0],rn(-4,4)*shake[0]
- else:
- sx,sy = 0,0
- #Bars
- py.draw.rect(screen,(255,255,255),(20,20,p1.health*3,15))
- py.draw.rect(screen,(255,255,255),(10,10,300+20,15+20),5)
- if p1.health>50:
- txt = font.render(str(p1.health)+ "/100",True,(0,0,0))
- screen.blit(txt,(30,27-txt.get_height()/2))
- else:
- txt = font.render(str(p1.health)+ "/100",True,(255,255,255))
- screen.blit(txt,(310-txt.get_width(),27-txt.get_height()/2))
- if p1.health<0:
- run = 0
- py.draw.rect(screen,(255,255,255),(20,70,p1.shield*3,15))
- py.draw.rect(screen,(255,255,255),(10,60,210+20,15+20),5)
- if p1.shield>35:
- txt = font.render(str(p1.shield)+ "/70",True,(0,0,0))
- screen.blit(txt,(30,77-txt.get_height()/2))
- else:
- txt = font.render(str(p1.shield)+ "/70",True,(255,255,255))
- screen.blit(txt,(220-txt.get_width(),77-txt.get_height()/2))
- if p1.shield<0:
- p1.shield = 0
- #Orbs and vial
- if drawTimer>0:
- drawTimer -= 1
- elif len(orbs)<10:
- orbs.append([rn(100,500),rn(100,400)])
- drawTimer = 150
- if p1.orbsOwned>0:
- youCanDraw = 1
- else:
- youCanDraw = 0
- if p1.orbsOwned>23:
- p1.orbsOwned = 23
- if p1.orbsOwned>0:
- screen.blit(vialimg2,(600,530))
- else:
- screen.blit(vialimg,(600,530))
- if automaticOrb<10 and p1.orbsOwned>0:
- automaticOrb += 0.01
- else:
- automaticOrb = 0
- p1.orbsOwned += 1
- if boss1.health>0:
- py.draw.rect(screen,(255,255,255),(695,760-(p1.orbsOwned*10+automaticOrb),60,(p1.orbsOwned*10+automaticOrb)))
- #Event handling
- for e in py.event.get():
- if e.type == py.QUIT:
- run =0
- runo = 0
- if e.type == py.KEYDOWN:
- p1.checkKeys(e,1)
- if e.key == py.K_SPACE and boss1.health<0:
- run = 0
- win = 1
- if e.type == py.KEYUP:
- p1.checkKeys(e,0)
- if e.type == py.MOUSEBUTTONDOWN:
- if e.button == 1 and boss1.health>0:
- if youCanDraw and dis(30+64,630+64,mox,moy)<50:
- DrawACard(p1)
- if cardImLookingAt != 0:
- if p1.orbsOwned>= cardImLookingAt.cost:
- p1.hand.remove(cardImLookingAt)
- doCardEffect(cardImLookingAt)
- screen.blit(py.transform.scale(cardImLookingAt.img,(256,256)),(400-128+sx,400-128+sy))
- py.display.update()
- py.time.wait(450)
- #Bullets
- for b in bullets:
- py.draw.circle(screen,(255,255,255),(b[0]+sx,b[1]+sy),6)
- b[0] += b[2]
- b[1] += b[3]
- if abs(b[0]-400)>400 or abs(b[1]-250)>250 or b[1]>500:
- bullets.remove(b)
- if abs(b[0]-p1.x)<7 and abs(b[1]-p1.y)<7 and b in bullets:
- if p1.shield:
- p1.shield-=6
- else:
- p1.health -= 6
- bullets.remove(b)
- shake = [1.2,60]
- #Swords
- for sw in swords:
- rotation(sw[3],swordimg,screen,(sw[0]-32,sw[1]-32),64)
- sw[2]-=1
- if sw[2]<0:
- sw[0]+=m.cos(sw[3])*8
- sw[1]+=m.sin(sw[3])*8
- if abs(sw[0]-boss1.x)<50 and abs(sw[1]-boss1.y)<50:
- createP(sw[0],sw[1],10,(255,255,255),[2,15],[40,400],"default")
- boss1.health -= 15
- swords.remove(sw)
- #Lasers
- for laser in lasers:
- nodes = laser[1]
- createP(boss1.x,boss1.y,2,(255,255,255),[2,25],[int(laser[0]*5),int(laser[0]*5)+50],"default")
- Ag = m.atan2(p1.y-boss1.y,p1.x-boss1.x)+m.pi
- for i in nodes:
- if i == nodes[0]:
- py.draw.line(screen,(255,255,255),(p1.x+sx,p1.y+sy),(p1.x+m.cos(Ag+i[0])*i[1],p1.y+m.sin(Ag+i[0])*i[1]),int(laser[0]))
- else:
- o = nodes[nodes.index(i)-1]
- py.draw.line(screen,(255,255,255),(p1.x+m.cos(Ag+o[0])*o[1],p1.y+m.sin(Ag+o[0])*o[1]),(p1.x+m.cos(Ag+i[0])*i[1],p1.y+m.sin(Ag+i[0])*i[1]),int(laser[0]))
- if i == nodes[len(nodes)-1]:
- py.draw.line(screen,(255,255,255),(boss1.x,boss1.y),(p1.x+m.cos(Ag+i[0])*i[1],p1.y+m.sin(Ag+i[0])*i[1]),int(laser[0]))
- if int(laser[0]%4)== 0:
- nodesnew = []
- for i in range(int(dis(p1.x,p1.y,boss1.x,boss1.y)/50)):
- nodesnew.append([rn(-80,80)*0.01,rn(8,40)+i*30])
- laser[1]=nodesnew
- laser[0]-=0.2
- boss1.health -= 0.4
- if laser[0]<10:
- lasers.remove(laser)
- #Particles
- for p in particles:
- py.draw.circle(screen,(255,255,255),(p[0]+sx,p[1]+sy),p[4])
- p[0]+=p[2]
- p[1]+=p[3]
- p[4]-=0.4
- if p[4]<3:
- particles.remove(p)
- #Rockets
- for ro in rockets:
- rotation(ro[5]+m.pi,rocketimg,screen,(ro[0]-48,ro[1]-48),96)
- createP(ro[0]-ro[2]*10,ro[1]-ro[3]*10,1,(255,255,255),[2,10],[40,200],[-ro[2],-ro[3],(255,255,255),(255,255,255),0])
- ro[4]-=1
- if ro[4]<0:
- ro[0]+=ro[2]
- ro[1]+=ro[3]
- if abs(ro[0]-boss1.x)<50 and abs(ro[1]-boss1.y)<50:
- createP(ro[0],ro[1],60,(255,255,255),[2,25],[40,500],"default")
- boss1.health -= 55
- rockets.remove(ro)
- #Orbs
- if boss1.health<0:
- orbs = []
- p1.orbsOwned = 0
- for orb in orbs:
- screen.blit(orbimg,(orb[0]-16,orb[1]-16))
- if abs(orb[0]-p1.x)<10 and abs(orb[1]-p1.y)<10:
- orbs.remove(orb)
- p1.orbsOwned += 1
- ag = m.atan2(p1.y-orb[1],p1.x-orb[0])
- dist = dis(orb[0],orb[1],p1.x,p1.y)+0.01
- orb[0] += m.cos(ag)/((dist/20)**2)
- orb[1] += m.sin(ag)/((dist/20)**2)
- #Boss
- if boss1.health<0:
- p1.hand = []
- txt = font.render("Press Space to go back to menu",True,(255,255,255))
- screen.blit(txt,(400-txt.get_width()/2,250-txt.get_height()/2))
- else:
- boss1.draw()
- boss1.attack()
- #Drawing deck
- for i in range(3):
- screen.blit(deckimg,(30-i*5+sx,630-i*5+sy))
- #Player
- p1.draw()
- p1.move()
- cardImLookingAt = p1.drawCards()
- cl.tick(150)
- py.display.update()
- def MainMenu():
- global runo
- global win
- letter = upload("CBHLetter",256,256)
- string1 = list("Our village has been haunted by The Sad Potato for yearsnow, it destroys our crops and kills us."+
- " Many have tried fighting it before but it's useless, only the chosen one can do it. Go on then chosen one, save the village.")
- if win:
- string1 = list("You have done it !!! We are free at last.")
- actualString1 = ""
- actualString2 = ""
- actualString3 = ""
- actualString4 = ""
- letterOpen = 0
- frame = 0
- cl = py.time.Clock()
- runo = 1
- while runo:
- screen.fill((0,0,0))
- mox, moy = py.mouse.get_pos()
- for e in py.event.get():
- if e.type == py.QUIT:
- runo = 0
- if e.type == py.MOUSEBUTTONDOWN:
- if e.button == 1:
- if abs(mox-600)<100 and abs(moy-400)<50:
- GameLoop()
- string1 = []
- if abs(mox-228)<128 and abs(moy-428)<128:
- letterOpen = 1
- frame+= 1
- if frame>20000000:
- frame = 0
- if letterOpen and frame%8 == 0 and string1 != []:
- if font.render(actualString3,True,(255,255,255)).get_width()>670 :
- actualString4 = actualString4 + string1[0]
- elif font.render(actualString2,True,(255,255,255)).get_width()>670:
- actualString3 = actualString3 + string1[0]
- elif font.render(actualString1,True,(255,255,255)).get_width()>670:
- actualString2 = actualString2 + string1[0]
- else:
- actualString1 = actualString1 + string1[0]
- del string1[0]
- if win and string1 == []:
- actualString1 = ""
- actualString2 = ""
- actualString3 = ""
- actualString4 = ""
- win = 0
- string1 = list("You have done it !!! We are free at last.")
- if letterOpen:
- txt = font.render(actualString4,True,(255,255,255))
- screen.blit(txt,(20,120))
- txt = font.render(actualString3,True,(255,255,255))
- screen.blit(txt,(12,100))
- txt = font.render(actualString2,True,(255,255,255))
- screen.blit(txt,(20,80))
- txt = font.render(actualString1,True,(255,255,255))
- screen.blit(txt,(20,60))
- screen.blit(letter,(100,300))
- py.draw.rect(screen,(255,255,255),(500,350,200,100))
- txt = bigfont.render("Play",True,(0,0,0))
- screen.blit(txt,(600-txt.get_width()/2,400-txt.get_height()/2))
- cl.tick(150)
- py.display.update()
- MainMenu()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement