Text Size
Text Size
Exit Full Screen
Python Mini
Show
Source Code
View Source Code in Full Screen
Open in New Tab
from processing import * from random import randint from math import cos, sin, radians, atan2 cooldown = 1 holup = 0 settings = { 'fuse':100,#fuse time 'look':0,#color 'fused':1,#will it explode on a timer? 'gravity':0,#1 = nograv??? no sense 'bounce':.9,#how bouncy 'bounceTop':0,#does it bounce off the top of the screen? 'stick':0,#sticks to walls? 'cluster':0,#explosions make more bombs? 'drops':0,#can it be thrown or dropped? 'explosiontype':0,#shape of explosion } colors = [(120,),(0,120,0),(255,),(255,120,0),(255,0,0),(120,120,255),(0,),(0,0,240),(50,50,100),(150,0,150)] #list to change to add the new feature: #class Bomb #reload script #keyboard.keys #new color #add to settings #add to custombombmaker #clusterbomb code supersecret = { 'cool':30, 'textonbomb':0, } class Bomb: instance = [] def __init__(self,x,y,vx,vy,d,fuse=100,look=0,thrown=0,fused=1,bounce=.9,bounceTop=0,stick=0,cluster=0,gravity=0,drops=0,explosiontype=0,explosiondata=16): self.x = x self.y = y self.vx = vx self.vy = vy self.d = d#diameter self.fuse = fuse self.look = look self.thrown = thrown #configurations of bomb self.fused = fused self.gravity = gravity self.bounceTop = bounceTop self.stick = stick self.cluster = cluster self.bounce = bounce self.drops = drops self.explosiontype = explosiontype self.explosiondata = explosiondata Bomb.instance.append(self) def checkExploded(self): if self.fuse < 0: Bomb.instance.remove(self) if self.explosiontype == 0: for i in range(16): Debris(self.x,self.y,0,0,20,TAU/16*i,5,255,randint(0,255)) elif self.explosiontype == 1 and self.explosiondata > 0: Debris(self.x,self.y,0,0,20,TAU/4,5,255,randint(0,255)) Debris(self.x,self.y,0,0,20,TAU/2,5,255,randint(0,255)) Debris(self.x,self.y,0,0,20,TAU*3/4,5,255,randint(0,255)) Debris(self.x,self.y,0,0,20,TAU,5,255,randint(0,255)) Bomb(self.x,self.y,0,0,0,10,self.look,1,1,1,0,0,0,1,0,1,self.explosiondata-4) elif self.explosiontype == 2 and self.explosiondata > 0: Debris(self.x,self.y,0,0,20,TAU/16*self.explosiondata,5,255,randint(0,255)) Bomb(self.x,self.y,0,0,0,2,self.look,1,1,1,0,0,0,1,0,2,self.explosiondata-1) elif self.explosiontype == 3: for i in range(16): Debris(self.x,self.y,self.vx/2,self.vy/2,20,atan2(self.vy,self.vx)+radians(randint(-40,40)),5,255,randint(0,255)) elif self.explosiontype == 4: if self.explosiondata == 16: for i in [1,2,3]: Bomb(self.x,self.y,3*i,0,self.d*.7,25,self.look,1,1,1,0,0,0,1,0,4,3) Bomb(self.x,self.y,0,3*i,self.d*.7,25,self.look,1,1,1,0,0,0,1,0,4,2) Bomb(self.x,self.y,-3*i,0,self.d*.7,25,self.look,1,1,1,0,0,0,1,0,4,1) Bomb(self.x,self.y,0,-3*i,self.d*.7,25,self.look,1,1,1,0,0,0,1,0,4,0) else: Debris(self.x,self.y,0,0,20,TAU/4*self.explosiondata,5,255,randint(0,255)) Debris(self.x,self.y,0,0,20,TAU/4*self.explosiondata+(PI),5,255,randint(0,255)) if self.cluster > 0: if self.gravity == 1: Bomb(self.x,self.y,5,5,self.d*.7,50,self.look,1,self.fused,self.bounce,self.bounceTop,self.stick,self.cluster-1,self.gravity,self.drops,self.explosiontype) Bomb(self.x,self.y,5,-5,self.d*.7,50,self.look,1,self.fused,self.bounce,self.bounceTop,self.stick,self.cluster-1,self.gravity,self.drops,self.explosiontype) Bomb(self.x,self.y,-5,-5,self.d*.7,50,self.look,1,self.fused,self.bounce,self.bounceTop,self.stick,self.cluster-1,self.gravity,self.drops,self.explosiontype) Bomb(self.x,self.y,-5,5,self.d*.7,50,self.look,1,self.fused,self.bounce,self.bounceTop,self.stick,self.cluster-1,self.gravity,self.drops,self.explosiontype) else: Bomb(self.x,self.y,2,5,self.d*.7,50,self.look,1,self.fused,self.bounce,self.bounceTop,self.stick,self.cluster-1,self.gravity,self.drops,self.explosiontype) Bomb(self.x,self.y,1,-10,self.d*.7,50,self.look,1,self.fused,self.bounce,self.bounceTop,self.stick,self.cluster-1,self.gravity,self.drops,self.explosiontype) Bomb(self.x,self.y,-1,-10,self.d*.7,50,self.look,1,self.fused,self.bounce,self.bounceTop,self.stick,self.cluster-1,self.gravity,self.drops,self.explosiontype) Bomb(self.x,self.y,-2,5,self.d*.7,50,self.look,1,self.fused,self.bounce,self.bounceTop,self.stick,self.cluster-1,self.gravity,self.drops,self.explosiontype) class Debris: instance = [] def __init__(self,x,y,vx,vy,d=20,di=0,v=0,r=255,g=120): #position and moving self.x = x self.y = y self.vx = vx self.vy = vy self.d = d#diameter #alternate moving self.di = di#direction self.v = v #coloring self.r = r self.g = g Debris.instance.append(self) def checkOOB(self): if self.x > 550 or self.x < -50 or self.y > 550 or self.y < -50: Debris.instance.remove(self) def delHolding(): global cooldown for i in Bomb.instance: if i.thrown == 0: Bomb.instance.remove(i) cooldown = 1 def setup(): size(500,500) background(120,120,240) def mouseReleased(): global cooldown for i in Bomb.instance: if i.thrown == 0: i.thrown = 1 if i.drops == 0: i.vx = mouse.x - mouse.px i.vy = mouse.y - mouse.py cooldown = supersecret['cool'] def keyPressed(): global cooldown, settings, holup, progress, a if holup == 0: if keyboard.key == '1': settings = {'fuse':100,'look':0,'fused':1,'bounce':.9,'bounceTop':0,'stick':0,'cluster':0,'gravity':0,'drops':0,'explosiontype':0,} delHolding() if keyboard.key == '2': settings = {'fuse':100,'look':1,'fused':0,'bounce':.9,'bounceTop':0,'stick':0,'cluster':0,'gravity':0,'drops':0,'explosiontype':0,} delHolding() if keyboard.key == '3': settings = {'fuse':150,'look':2,'fused':1,'bounce':1,'bounceTop':1,'stick':0,'cluster':0,'gravity':1,'drops':0,'explosiontype':0,} delHolding() if keyboard.key == '4': settings = {'fuse':100,'look':3,'fused':1,'bounce':.9,'bounceTop':0,'stick':0,'cluster':1,'gravity':0,'drops':0,'explosiontype':0,} delHolding() if keyboard.key == '5': settings = {'fuse':100,'look':4,'fused':1,'bounce':.9,'bounceTop':0,'stick':0,'cluster':2,'gravity':0,'drops':0,'explosiontype':0,} delHolding() if keyboard.key == '6': settings = {'fuse':100,'look':5,'fused':0,'bounce':.9,'bounceTop':1,'stick':1,'cluster':0,'gravity':0,'drops':0,'explosiontype':0,} delHolding() if keyboard.key == '7': settings = {'fuse':100,'look':6,'fused':1,'bounce':0,'bounceTop':1,'stick':0,'cluster':0,'gravity':1,'drops':1,'explosiontype':1,} delHolding() if keyboard.key == '8': settings = {'fuse':100,'look':7,'fused':1,'bounce':.9,'bounceTop':0,'stick':0,'cluster':0,'gravity':0,'drops':0,'explosiontype':2,} delHolding() if keyboard.key == '9': settings = {'fuse':100,'look':8,'fused':1,'bounce':.9,'bounceTop':0,'stick':0,'cluster':0,'gravity':0,'drops':0,'explosiontype':4,} delHolding() if keyboard.key == '0': settings = {'fuse':100,'look':9,'fused':1,'bounce':.2,'bounceTop':0,'stick':0,'cluster':0,'gravity':0,'drops':0,'explosiontype':0,} delHolding() if keyboard.key == ' ': for i in Bomb.instance: if i.fused == 0 and i.thrown == 1: i.fuse = -1 if keyboard.key == 'c': holup = 1 a = 0 progress = 0 if holup == 1: if keyboard.keyCode == 32: progress += 1 if progress == 1: settings['fused'] = a if progress == 2: settings['fuse'] = a*10 if progress == 3: settings['look'] = a if progress == 4: settings['bounce'] = float(a)/10 if progress == 5: settings['gravity'] = a if progress == 6: settings['bounceTop'] = a if progress == 7: settings['stick'] = a if progress == 8: settings['cluster'] = a if progress == 9: settings['drops'] = a if progress == 10: settings['explosiontype'] = a holup = 0 delHolding() if progress == 101: supersecret['textonbomb'] = a if progress == 102: supersecret['cool'] = a holup = 0 a = 0 if progress == 3: a = 9 elif progress == 1 and settings['fused'] == 1: a = 10 elif progress == 101: a = 30 if keyboard.keyCode == UP: a += 1 if keyboard.keyCode == DOWN: a -= 1 if keyboard.key == 'm': progress = 100 def draw(): global cooldown, holup, progress, a background(120,120,240) if holup == 0: cooldown -= 1 if cooldown == 0: Bomb(mouse.x,mouse.y,0,0,30,settings['fuse'],settings['look'],0,settings['fused'],settings['bounce'],settings['bounceTop'],settings['stick'],settings['cluster'],settings['gravity'],settings['drops'],settings['explosiontype'],16) for i in Bomb.instance: i.x += i.vx i.y += i.vy if i.thrown == 1: if i.fused == 1: i.fuse -= 1 if i.gravity != 1: i.vy += 0.5 if i.y + i.d/2> 500: i.vy = abs(i.vy) * -1*i.bounce i.y = 500 - i.d/2 if i.stick == 1: i.gravity = 1 i.vx = 0;i.vy = 0 if i.x + i.d/2 > 500: i.vx = abs(i.vx) * -1*i.bounce i.x = 500 - i.d/2 if i.stick == 1: i.gravity = 1 i.vx = 0;i.vy = 0 if i.x - i.d/2 < 0: i.vx = abs(i.vx) * i.bounce i.x = i.d/2 if i.stick == 1: i.gravity = 1 i.vx = 0;i.vy = 0 if i.bounceTop == 1: if i.y - i.d/2 < 0: i.vy = abs(i.vy) * i.bounce + 1 i.y = i.d/2 if i.stick == 1: i.gravity = 1 i.vx = 0;i.vy = 0 i.checkExploded() if i.thrown == 0: i.x = mouse.x i.y = mouse.y fill(*colors[i.look]) #colorsssss!!!!!!!! ellipse(i.x,i.y,i.d,i.d) fill(0) textAlign(CENTER,CENTER) if supersecret['textonbomb'] == 1: if i.fused == 1: text(i.fuse,i.x,i.y) else: text("Spc",i.x,i.y) for i in Debris.instance: if i.v != '-' and i.di != '-': i.vx += cos(i.di)*i.v i.vy += sin(i.di)*i.v i.v = 0 i.di = 0 i.x += i.vx i.y += i.vy fill(i.r,i.g,0) ellipse(i.x,i.y,i.d,i.d) i.checkOOB() fill(0) textSize(12) text('Press numbers 0-9 for more bombs, or press c to create a custom bomb',200,10) if holup == 1: fill(0) textSize(25) text(a,250,250) text('Space to confirm',250,350) if progress == 0: text('Will the bomb explode on a timer?',250,120) if a > 1: a = 1 if a < 0: a = 0 if progress == 1 and settings['fused'] == 0: progress += 1 settings['fuse'] = 1 if progress == 1: text('What is the fuse length?',250,120) if progress == 2: text('What is the color?',250,120) if a > 7: a = 7 if a < 0: a = 0 if progress == 3: text('What is the bounciness? (9=default)',250,120) if progress == 4: text('no gravity (1) or gravity (0)?',250,120) if a > 1: a = 1 if a < 0: a = 0 if progress == 5: text('Will it collide with the celing?',250,120) if a > 1: a = 1 if a < 0: a = 0 if progress == 6: text('Will it stick to walls?',250,120) if a > 1: a = 1 if a < 0: a = 0 if progress == 7: text('cluster?',250,120) if a < 0: a = 0 if progress == 8: text('Will the bomb be dropped?',250,120) if a > 1: a = 1 if a < 0: a = 0 if progress == 9: text('Explosion type?',250,120) if a > 4: a = 4 if a < 0: a = 0 if progress == 100: text('textonbomb?',250,120) if a > 1: a = 1 if a < 0: a = 0 if progress == 101: text('cooldown?',250,120) if a < 1: a = 1 run()
bomberAdvance.py
( around 348 lines python code )
Published By:
luyfru
Published on
2023-09-21T19:19:28Z
Python Mini
- an
OYOclass
application,
own your own class today
.
Run
Result
×
Error message shows here