def step(self): self.vy *= 0.99 self.vx *= 0.99 self.y += self.vy self.x += self.vx if sqrt((self.vy**2)+(self.vx**2)) < 1: self.vy = 0 self.vx = 0 collidinglisthole = self.collidingWith(holesprite) if collidinglisthole: xcoorballhole = self.x ycoorballhole = self.y vectorxhole = xcoorballhole-805 vectoryhole = ycoorballhole-110 unitvectorxhole = vectorxhole/(sqrt((vectoryhole**2)+(vectorxhole**2))) unitvectoryhole = vectoryhole/(sqrt((vectoryhole**2)+(vectorxhole**2))) self.x = self.x + (-.5*unitvectorxhole) self.y = self.y + (-.5*unitvectoryhole) self.vx = 0 self.vy = 0 scoreboard = TextAsset("Score: "+str(len(scorecounter)), style="bold 15pt Arial", width=250) Sprite(scoreboard, (760, 82)) collidinglistwater = self.collidingWith(watersprite) if collidinglistwater: self.vy *= 0.9 self.vx *= 0.9 self.y += self.vy self.x += self.vx if sqrt((self.vy**2)+(self.vx**2)) < 1.5: self.vy = 0 self.vx = 0 collidinglistwall1 = self.collidingWith(wall1sprite) if collidinglistwall1: self.vx = self.vx*-1 collidinglistwall2 = self.collidingWith(wall2sprite) if collidinglistwall2: self.vx = self.vx*-1 collidinglistwall4 = self.collidingWith(wall4sprite) if collidinglistwall4: self.vy = self.vy*-1 collidinglistwall5 = self.collidingWith(wall5sprite) if collidinglistwall5: self.vy = self.vy*-1 collidinglistwall6 = self.collidingWith(wall6sprite) if collidinglistwall6: self.vx = self.vx*-1 collidinglistwall7 = self.collidingWith(wall7sprite) if collidinglistwall7: self.vx = self.vx*-1 collidinglistwall11 = self.collidingWith(wall11sprite) if collidinglistwall11: self.vy = self.vy*-1 collidinglistwall12 = self.collidingWith(wall12sprite) if collidinglistwall12: self.vx = self.vx*-1 collidinglistwall13 = self.collidingWith(wall13sprite) if collidinglistwall13: self.vy = self.vy*-1 collidinglistwall14 = self.collidingWith(wall14sprite) if collidinglistwall14: self.vx = self.vx*-1 collidinglistwall15 = self.collidingWith(wall15sprite) if collidinglistwall15: self.vy = self.vy*-1 collidinglistwall16 = self.collidingWith(wall16sprite) if collidinglistwall16: self.vx = self.vx*-1 collidinglistwall17 = self.collidingWith(wall17sprite) if collidinglistwall17: self.vy = self.vy*-1
(MountWidth / 2) - OffSide, SkyHeight - MountHeight), (SkyWidth - MountWidth - OffSide, SkyHeight), (SkyWidth - OffSide, SkyHeight)], ThinLine, MountCol) Snow = PolygonAsset([(SnowWidth / 2, 0), (0, SnowHeight), (SnowWidth, SnowHeight)], ThinLine, White) Cloud1 = EllipseAsset(CloudWidth, CloudHeight, ThinLine, White) Cloud2 = EllipseAsset(CloudWidth / 2, CloudHeight, ThinLine, White) Cloud3 = EllipseAsset(CloudWidth * 0.75, CloudHeight * 1.5, ThinLine, White) BirdBody = PolygonAsset([(0, 0), (SkyWidth / 20, SkyHeight / 30), (0, SkyHeight / 15)], ThinLine, BirdCol) BirdHead = CircleAsset(SkyHeight / 30, ThinLine, BirdCol) BirdBeak = PolygonAsset([(0, 0), (SkyWidth / 100, SkyHeight / 150), (0, SkyHeight / 75)], ThinLine, Orange) BirdEye = CircleAsset(SkyHeight / 250, ThinLine, Black) Sprite(Back) Sprite(Ground, (0, SkyHeight)) Sprite(Sun, (SkyWidth - 3 * OffSide, SkyHeight - MountHeight)) Sprite(Mount) Sprite(Snow, (SkyWidth - (MountWidth / 2) - (SnowWidth / 2) - OffSide, SkyHeight - MountHeight)) Sprite(Cloud1, (CloudWidth * 1.25, CloudHeight * 2)) Sprite(Cloud2, (CloudWidth * 2.5, CloudHeight * 4)) Sprite(Cloud3, (CloudWidth * 3.75, CloudHeight * 2)) Sprite(BirdBody, (SkyWidth / 3, SkyHeight / 3)) Sprite(BirdBeak, (SkyWidth / 3 + SkyWidth / 20 + SkyWidth / 100, SkyHeight / 3 + SkyHeight / 30 - SkyHeight / 150)) Sprite(BirdHead, (SkyWidth / 3 + SkyWidth / 20, SkyHeight / 3 + SkyHeight / 30)) Sprite(BirdEye, (SkyWidth / 3 + SkyWidth / 19, SkyHeight / 3 + SkyHeight / 30))
#define colors and sprites for i in range(1): black = Color(0x000000, 1.0) green = Color(0x00ff00, 1.0) white = Color(0xFFFFFF, 1.0) blue = Color(0x5D5DFF, 1.0) red = Color(0xff0000, 1.0) noline = LineStyle(0, black) wallplace = RectangleAsset(35, 35, noline, black) bungosprite = RectangleAsset(17, 33, noline, green) jumpy = RectangleAsset(18, 3, noline, blue) bottomof = RectangleAsset(1015, 1, noline, black) sideof = RectangleAsset(1, 700, noline, black) Sprite(bottomof, (0, 0)) Sprite(bottomof, (0, 699)) Sprite(sideof, (0, 0)) Sprite(sideof, (1014, 0)) class Wall(Sprite): def __init__(self, position): super().__init__(wallplace, position) class Jumpy(Sprite): def __init__(self, position): super().__init__(jumpy, position) self.vertvel = 20 class Bungo(Sprite): def __init__(self, position):
from ggame import App, Color, LineStyle, Sprite from ggame import RectangleAsset, CircleAsset, EllipseAsset, PolygonAsset # Three primary colors with no transparency (alpha = 1.0) red = Color(0xff0000, 1.0) green = Color(0x00ff00, 1.0) blue = Color(0x0000ff, 1.0) black = Color(0x000000, 1.0) # Define a line style that is a thin (1 pixel) wide black line thinline = LineStyle(1, black) # A graphics asset that represents a rectangle rectangle = RectangleAsset(50, 20, thinline, blue) # Now display a rectangle Sprite(rectangle) Sprite(rectangle, (200, 50)) myapp = App() myapp.run()
green = Color(0x00ff00, 1.0) black = Color(0x000000, 1.0) cyan = Color(0x00EEEE, 1.0) purple = Color(0x9A32CD, 1.0) thickline = LineStyle(5, black) thinline = LineStyle(1, black) line = LineStyle(3, black) rectangle = RectangleAsset(500, 500, line, blue) circle = CircleAsset(100, thickline, purple) circle2 = CircleAsset(50, thinline, green) ellipse = EllipseAsset(40, 80, line, cyan) ellipse2 = EllipseAsset(80, 40, line, cyan) polygon = PolygonAsset([(50, 200), (50, 100), (150, 200), (150, 100)], thinline, red) Sprite(rectangle) Sprite(circle, (150, 150)) Sprite(circle2, (204, 202)) Sprite(ellipse, (210, 50)) Sprite(ellipse, (210, 300)) Sprite(ellipse2, (50, 215)) Sprite(ellipse2, (300, 215)) Sprite(polygon, (203, 200)) # add your code here /\ /\ /\ myapp = App() myapp.run()
red = Color(0xff0000, 1.0) mouthred = Color(0xff0000, 0.25) thinline = LineStyle(1, black) mouthline = LineStyle(4, red) face = EllipseAsset(136, 160, thinline, peach) pupil = CircleAsset(10, thinline, brown) mouth = CircleAsset(20, mouthline, mouthred) eyebrow = RectangleAsset(30, 2, thinline, brown) nose = PolygonAsset([(0, 0), (25, 25), (-25, 25), (0, 0)], thinline, peach) nosebridge = PolygonAsset([(0, 0), (0, 45)], thinline, black) hatbrim = RectangleAsset(250, 25, thinline, brown) hat = PolygonAsset([(0, 0), (60, -60), (120, -60), (180, 0), (0, 0)], thinline, brown) Sprite(face, (160, 160)) Sprite(pupil, (220, 260)) Sprite(pupil, (350, 260)) Sprite(mouth, (280, 400)) Sprite(eyebrow, (220, 230)) Sprite(eyebrow, (340, 230)) Sprite(nose, (272, 310)) Sprite(nosebridge, (273, 290)) Sprite(nosebridge, (323, 290)) Sprite(hatbrim, (170, 150)) Sprite(hat, (205, 90)) # add your code here /\ /\ /\ myapp = App() myapp.run()
blau = Color(0x0000ff, 1.0) schwartz = Color(0x000000, 1.0) orange = Color(0xffa500, 1.0) gelb = Color(0xffff00, 0.7) porklein = LineStyle (1, schwartz) brick = RectangleAsset(190, 68, porklein, rot) #brick face = EllipseAsset(68,76, porklein, gelb) #face hair = EllipseAsset(65, 20, porklein, orange) eyes = CircleAsset(10, porklein, schwartz) #eyes mouth = CircleAsset(13, porklein, rot) haircurl = PolygonAsset([(7,1), (5, 1), (60, 1)], porklein, schwartz) Sprite(brick, (100, 265)) Sprite(brick, (290, 265)) Sprite(brick, (480, 265)) Sprite(brick, (670, 265)) Sprite(brick, (90,333)) Sprite(brick, (280, 333)) Sprite(brick, (470, 333)) Sprite(brick, (660, 333)) Sprite(face, (180, 190)) #Sprite(hair, (175, 126)) Sprite(eyes, (170, 170)) Sprite(eyes, (210, 170)) Sprite(mouth, (190, 210)) Sprite(haircurl, (150, 126))
eye1 = CircleAsset(15, thinline, firebrick1) eye2 = CircleAsset(15, thinline, firebrick1) shoulder1 = CircleAsset(20, thinline, grey) shoulder2 = CircleAsset(20, thinline, grey) arm1 = RectangleAsset(100, 40, thinline, grey) arm2 = RectangleAsset(100, 40, thinline, grey) antenna = EllipseAsset(5, 40, thinline, purple) mouth = EllipseAsset(30, 8, thinline, gold) lip = RectangleAsset(59, 1, thinline, black) wave1 = CircleAsset(10, thinner, fade1) wave2 = CircleAsset(25, thinner, fade2) wave3 = CircleAsset(42, thinner, fade3) emblem = CircleAsset(37, thinline) design = PolygonAsset([(0, 0), (20, 50), (40, 0)], thinline, violet) Sprite(antenna, (485, 65)) Sprite(head, (432, 100)) Sprite(neck, (470, 200)) Sprite(body, (400, 228)) Sprite(leg1, (400, 428)) Sprite(leg2, (555, 428)) Sprite(eye1, (440, 115)) Sprite(eye2, (510, 115)) Sprite(arm1, (600, 228)) Sprite(arm2, (300, 228)) Sprite(shoulder1, (580, 228)) Sprite(shoulder2, (380, 228)) Sprite(mouth, (460, 165)) Sprite(lip, (460, 173)) Sprite(wave1, (480, 60)) Sprite(wave2, (465, 43))
blkline = LineStyle(1, black) noline = LineStyle(0, white) coolline = LineStyle(1, grey) blueline = LineStyle(2, blue) redline = LineStyle(1, red) greenline = LineStyle(1, green) gridline = LineStyle(1, grey) grid=RectangleAsset(30,30,gridline,white) LK = 'left key' RK = 'right key' UK = 'up key' DK = 'down key' Mainrect = RectangleAsset(15, 50, thinline, green) Boxrect = RectangleAsset(75, 20, thinline, black) Springrect = RectangleAsset(10, 5, thinline, blue) Main = Sprite(Mainrect, (15, 50)) Boxes = Sprite(Boxrect, (75, 20)) Springs = Sprite(Springrect, (10, 5)) for a in Main: def input: if input == 'p': #Spawn a Main Player for m in Main: def move(Main, key): if key == LK: #Move sprite to the left if key == RK: #Move sprite to the right if key == UK: #Move sprite up if key == DK:
myapp = App() red = Color(0xFF4040, 1.0) green = Color(0x00FF00, 1.0) blue = Color(0x1C86EE, 1.0) white = Color(0xF8F8FF, 1.0) black = Color(0x000000, 1.0) orange = Color(0xFF7D40, 1.0) thinline1 = LineStyle(1, black) thinline = LineStyle(1, blue) #values chosen by the user h = int(input('enter the h value of a parabola in the form y=(x-h)^2+k: ')) k = int(input('enter the k value of a parabola in the form y=(x-h)^2+k: ')) #this is the image used to represent the skier skier_asset = ImageAsset("images/Python Skiier.png", Frame(0,0,685,685)) skier = Sprite(skier_asset, (50, 160)) skier.fxcenter=.6 skier.fycenter=.7 skier.scale = 0.3 skier.rotation = .3 #Here I was able to center the vertex of the parabola xfunc = lambda t: 20*t+522 #Here I used -k vs +k to account for python moving down with regard to y values. yfunc = lambda t:-((t-h)**2)-k + 600 #Here I made the jump 60 units in length as this scale was appropriate for the python grid for t in range(-30, 30): Ypoints = yfunc(t) Xpoints = xfunc(t) #Here the actual circles are plotted which together form a parabola shape simmilar to ski jump point = CircleAsset(8, thinline, white) Sprite(point, (Xpoints, Ypoints))
from ggame import App, Color, LineStyle, Sprite from ggame import CircleAsset red = Color(0xff0000, 1.0) green = Color(0x00ff00, 1.0) blue = Color(0x0000ff, 1.0) black = Color(0x000000, 1.0) thinline = LineStyle(1, black) mycircle = CircleAsset(5, thinline, blue) mycircle2 = CircleAsset(2, thinline, red) xcoordinates = range(100, 600, 10) ycoordinates = range(50, 550, 5) # Generate a list of sprites that form a line! sprites = [Sprite(mycircle, (x, x * 0.5 + 100)) for x in xcoordinates] sprites = [Sprite(mycircle2, (x + 200, x)) for x in ycoordinates] myapp = App() myapp.run()
red = Color(0xff0000, 1.0) green = Color(0x00ff00, 1.0) blue = Color(0x0000ff, 1.0) black = Color(0x000000, 1.0) purple = Color(0x7D26CD, 1.0) thinline = LineStyle(1, black) mycircle = CircleAsset(5, thinline, blue) myredcircle = CircleAsset(5, thinline, red) mypurplecircle = CircleAsset(5, thinline, purple) xcoordinates = range(0, 360, 10) # Generate a list of sprites that form a line! sprites = [ Sprite(mycircle, (x, (100 + 100 * math.sin(math.radians(x))))) for x in xcoordinates ] sprites = [ Sprite(myredcircle, (x, (100 + 100 * math.cos(math.radians(x))))) for x in xcoordinates ] sprites = [ Sprite(mypurplecircle, (100 + 100 * math.cos(math.radians(x)), (400 + 100 * math.sin(math.radians(x))))) for x in xcoordinates ] # add your code here /\ /\ /\ myapp = App() myapp.run()
green = Color(0x00ff00, 1.0) blue = Color(0x0000ff, 1.0) black = Color(0x000000, 1.0) purple = Color(0x9B30ff, 1.0) thinline = LineStyle(1, black) mycircle = CircleAsset(10, thinline, blue) mycircle1 = CircleAsset(10, thinline, red) mycircle2 = CircleAsset(10, thinline, purple) xcoordinates = range(0, 360, 10) xcoordinates1 = range(0, 360, 10) xcoordinates2 = range(100, 700, 10) # Generate a list of sprites that form a line! sprites = [ Sprite(mycircle, (x, 100 + 100 * sin(radians(x)) + 20)) for x in xcoordinates ] sprites = [ Sprite(mycircle1, (x, 100 + 100 * cos(radians(x)) + 100)) for x in xcoordinates1 ] sprites = [ Sprite( mycircle2, (100 + 100 * cos(radians(x)) + 200, 100 + 100 * sin(radians(x)) + 400)) for x in xcoordinates2 ] myapp = App() myapp.run()
from ggame import App, Color, LineStyle, Sprite from ggame import CircleAsset red = Color(0xff0000, 1.0) green = Color(0x00ff00, 1.0) blue = Color(0x0000ff, 1.0) black = Color(0x000000, 1.0) thinline = LineStyle(1, black) mycircle = CircleAsset(5, thinline, blue) mycircle2 = CircleAsset(5, thinline, red) # xcoordinates = range(100, 600, 10) # Generate a list of sprites that form a line! sprites = [Sprite(mycircle, (x, x * 0.5 + 100)) for x in range(100, 600, 10)] sprites2 = [Sprite(mycircle2, (x, x * 2 - 50)) for x in range(100, 600, 10)] myapp = App() myapp.run()
from ggame import App, Color, LineStyle, Sprite, RectangleAsset, CircleAsset, EllipseAsset, PolygonAsset # add your code here \/ \/ \/ from ggame import App, Color, LineStyle, Sprite, RectangleAsset, CircleAsset, EllipseAsset, PolygonAsset # add your code here \/ \/ \/ red = Color(0xff0000, 1.0) green = Color(0x00ff00, 1.0) blue = Color(0x0000ff, 1.0) black = Color(0x000000, 1.0) yellow = Color(0xFDF200, 1.0) darkgreen= Color(0x00A61B,1.0) line = LineStyle(2, black) lineyellow = LineStyle(2, yellow) sky = RectangleAsset(2000,2000,line,blue) Sprite(sky, (-50,-50)) triangle = PolygonAsset([(0,0),(300,-400),(600,0)], line, green) Sprite(triangle, (100, 50)) longtriangle = PolygonAsset([(0,0),(400,-350),(800,0)], line, green) Sprite(longtriangle, (250, 100)) bigtriangle = PolygonAsset([(0,0),(275,-300),(750,0)], line, green) Sprite(bigtriangle, (250, 150)) hugetriangle= bigtriangle = PolygonAsset([(0,0),(500,-500),(900,0)], line, green) Sprite(hugetriangle, (450, -50)) bigtriangle = PolygonAsset([(0,0),(275,-300),(750,0)], line, green) Sprite(bigtriangle, (-150, 150)) sun = CircleAsset(75,line,yellow) Sprite(sun, (150,0)) hill = EllipseAsset(1200,250,line,darkgreen) Sprite(hill, (-500,400)) eye = CircleAsset(10,line,black)
from ggame import App from ggame import App, Color, LineStyle, Sprite from ggame import RectangleAsset, CircleAsset, EllipseAsset, PolygonAsset # Three primary colors with no transparency (alpha = 1.0) blue = Color(808080, 1.0) green = Color(53868, 1.0) # Define a line style that is a thin (1 pixel) wide black line thinline = LineStyle(4, blue) # A graphics asset that represents a rectangle ellipse = EllipseAsset(80, 40, thinline, green) # Now display a rectangle Sprite(ellipse) myapp = App() myapp.run()
""" from math import sin, cos, radians from ggame import App, Color, LineStyle, Sprite, RectangleAsset, CircleAsset, EllipseAsset, PolygonAsset red = Color(0xff0000, 1.0) blue = Color(0x0000ff, 1.0) purple = Color(0x800080, 1.0) black = Color(0x000000, 1.0) line = LineStyle(1, black) pircle = CircleAsset(5, line, purple) bircle = CircleAsset(5, line, blue) rircle = CircleAsset(5, line, red) xcoordinates = range(0, 370, 10) bircles = [ Sprite(bircle, (x, (100 + 100 * sin(radians(x))))) for x in xcoordinates ] rircles = [ Sprite(rircle, (x, (100 + 100 * cos(radians(x))))) for x in xcoordinates ] pircles = [ Sprite(pircle, (100 + 100 * cos(radians(x)), (400 + 100 * sin(radians(x))))) for x in xcoordinates ] myapp = App() myapp.run()
width=30 #imports graphics, gets color, sets dimensions of squares dictionary={} #creates an aptly named dictionary thinline=LineStyle(1, black) livingcell=RectangleAsset(30,30,line,celestegreen) zombiecell=RectangleAsset(30,30,line,red) #creates squares class cell(Sprite): def __init__(self, asset, position): super().__init__(asset, position) self.visible=False self.sca=0 for x in range(0,height): for y in range(0,width): Sprite(zombiecell,(x*height,y*width)) dictionary[(x,y)]=cell(livingcell,(x*height,y*width)) class ConwayGame(App): def __init__(self): ConwayGame.listenKeyEvent("keydown", "space",self.spaceclick) SCREEN_WIDTH=960 SCREEN_HEIGHT=720 self.moving = False super().__init__(SCREEN_WIDTH, SCREEN_HEIGHT) ConwayGame.listenMouseEvent("click",self.create) #creates the screen def create(self, event): self.cx=int(event.x/30) self.cy=int(event.y/30) #identifies mouse location dictionary[(self.cx, self.cy)].visible=not dictionary[(self.cx, self.cy)].visible
https://github.com/HHS-IntroProgramming/Standards-and-Syllabus/wiki/Programmed-Graphics for general information on using list comprehensions to generate graphics. http://brythonserver.github.io/ggame/ for detailed information on ggame. """ from ggame import App, Color, LineStyle, Sprite from ggame import CircleAsset from math import sin, cos, radians purple = Color(0xd98cd9, 1.0) red = Color(0xff6666, 1.0) blue = Color(0x80dfff, 1.0) black = Color(0x000000, 0.5) line = LineStyle(0.5, black) sincircle = CircleAsset(5, line, blue) coscircle = CircleAsset(5, line, red) circle = CircleAsset(5, line, purple) rads = range(0, 360, 10) sines = [Sprite(sincircle, (x, 100 + 100 * sin(radians(x)))) for x in rads] cosines = [Sprite(coscircle, (x, 100 + 100 * cos(radians(x)))) for x in rads] circles = [ Sprite(circle, (100 + 100 * cos(radians(x)), 400 + 100 * sin(radians(x)))) for x in rads ] myapp = App() myapp.run()
from ggame import App, Color, LineStyle, Sprite from ggame import CircleAsset red = Color(0xff0000, 1.0) green = Color(0x00ff00, 1.0) blue = Color(0x0000ff, 1.0) black = Color(0x000000, 1.0) thinline = LineStyle(1, black) mycircle = CircleAsset(5, thinline, blue) xcoordinates = range(100, 600, 10) myredcircle = CircleAsset(5, thinline, red) # Generate a list of sprites that form a line! sprites = [Sprite(mycircle, (x, x * -0.7 + 454)) for x in xcoordinates] redsprites = [Sprite(myredcircle, (x, x * 1.1 - 50)) for x in xcoordinates] myapp = App() myapp.run()
nocol=Color(0x000000, 0.0) brown=Color(0xA65711, 1.0) noline=LineStyle(0, nocol) darline=LineStyle(2, dargreen) palline=LineStyle(1, palyellow) Base=RectangleAsset(1500, 1000, noline, palyellow) Hill1=EllipseAsset(300, 150, noline, dargreen) Hill2=EllipseAsset(200, 75, noline, dargreen) Hill3=EllipseAsset (550, 200, darline, palgreen) Cloud_s=CircleAsset(57, noline, cloudy) Cloud_l=CircleAsset(189, noline, cloudy) House=PolygonAsset([(0,25), (15,10), (30,25), (26,25), (26,30), (40,30), (40, 55), (4,55), (4,25)], noline, brown) Sprite(Base) Sprite(Hill1, (80, 400)) Sprite(Hill1, (750, 480)) Sprite(Hill2, (-50, 400)) Sprite(Hill3, (-100,440)) Sprite(Cloud_l, (70,-175)) Sprite(Cloud_l, (900, -88)) Sprite(Cloud_l, (750, -190)) Sprite(Cloud_s, (35, 80)) Sprite(Cloud_s, (300, 50)) Sprite(Cloud_s, (359, 30)) Sprite(Cloud_s, (600, 120)) Sprite(Cloud_s, (807, 10)) Sprite(Cloud_s, (10, 101)) Sprite(Cloud_s, (150, 111)) Sprite(House, (670,430))
from ggame import App, RectangleAsset, LineStyle, Color, Sprite from random import randint SCREEN_WIDTH = 800 SCREEN_HEIGHT = 600 dir = 7 dirs = 1 dirss = 1 blue = Color(0x87cefa, 1) purple = Color(0x7b68ee, 1) pink = Color(0xff69b4, 1) line = LineStyle(0, blue) black = Color(0, 1) bg_asset = RectangleAsset(SCREEN_WIDTH, SCREEN_HEIGHT, line, black) bg = Sprite(bg_asset, (0, 0)) pi = 3.14159 go = True lineasset = RectangleAsset(1, 100, line, blue) circle = [ Sprite(lineasset, (400, 100)), Sprite(lineasset, (400, 100)), Sprite(lineasset, (400, 100)), Sprite(lineasset, (400, 100)), Sprite(lineasset, (400, 100)), Sprite(lineasset, (400, 100)), Sprite(lineasset, (400, 100)), Sprite(lineasset, (400, 100)), Sprite(lineasset, (400, 100)), Sprite(lineasset, (400, 100)), Sprite(lineasset, (400, 100)), Sprite(lineasset, (400, 100)),
def __init__(self): self.mazeArray = [] self.ghostArray = [] self.cellStack = [] self.visitedCells = 1 self.score = 0 self.mazeDict = {} self.currentCell = 0 self.bubbleArray = random.sample(range(1, cTotalCells - 1), 1) self.trophyArray = [] aCellWallH = LineAsset(cCellSize, 0, thinline) aCellWallV = LineAsset(0, cCellSize, thinline) bg_asset = RectangleAsset(cWidth * cCellSize, cHeight * cCellSize, thinline, white) self.bg = Sprite(bg_asset, (0, 0)) self.footer = Sprite( TextAsset(text='Maze Runner. Level - ' + str(cLeveli), width=250, align='center', style='20px Arial', fill=blue), ((cWidth * cCellSize - 200) / 2, cHeight * cCellSize + 20)) self.gOver = TextAsset(text='Game Over!', width=140, align='center', style='20px Arial', fill=red) #----------borrowed, heavily reworked---------------------- for y in range(cHeight): for x in range(cWidth): self.mazeDict['H:' + str(x) + ':' + str(y)] = Sprite( aCellWallH, (x * cCellSize, y * cCellSize)) for x in range(cWidth): self.mazeArray.append(0) if (y == 0): for yi in range(cHeight): self.mazeDict['V:' + str(x) + ':' + str(yi)] = Sprite( aCellWallV, (x * cCellSize, yi * cCellSize)) while (self.visitedCells < cTotalCells): x = int(self.currentCell % cWidth) y = int(self.currentCell / cWidth) neighbors = [] for i in range(4): nx = x + compass[i][0] ny = y + compass[i][1] if ((nx >= 0) and (ny >= 0) and (nx < cWidth) and (ny < cHeight)): if (self.mazeArray[(ny * cWidth + nx)] & 0x000F) == 0: nidx = ny * cWidth + nx neighbors.append((nidx, 1 << i)) if len(neighbors) > 0: idx = random.randint(0, len(neighbors) - 1) nidx, direction = neighbors[idx] dx = x * cCellSize dy = y * cCellSize if direction & 1: self.mazeArray[nidx] |= (4) self.mazeDict['V:' + str(x) + ':' + str(y)].destroy() del self.mazeDict['V:' + str(x) + ':' + str(y)] elif direction & 2: self.mazeArray[nidx] |= (8) self.mazeDict['H:' + str(x) + ':' + str(y + 1)].destroy() del self.mazeDict['H:' + str(x) + ':' + str(y + 1)] elif direction & 4: self.mazeArray[nidx] |= (1) self.mazeDict['V:' + str(x + 1) + ':' + str(y)].destroy() del self.mazeDict['V:' + str(x + 1) + ':' + str(y)] elif direction & 8: self.mazeArray[nidx] |= (2) self.mazeDict['H:' + str(x) + ':' + str(y)].destroy() del self.mazeDict['H:' + str(x) + ':' + str(y)] self.mazeArray[self.currentCell] |= direction self.cellStack.append(self.currentCell) self.currentCell = nidx self.visitedCells = self.visitedCells + 1 else: self.currentCell = self.cellStack.pop() #-------------------------------- for i in range(cLeveli): self.ghostArray.append( Ghost(self.getMazeArray(), self.getCellStack())) for tCell in self.bubbleArray: self.trophyArray.append(Trophy(tCell))
http://brythonserver.github.io/ggame/ for detailed information on ggame. """ from math import sin, cos, radians from ggame import App, Color, LineStyle, Sprite, RectangleAsset, CircleAsset, EllipseAsset, PolygonAsset blue = Color(0x07608f, 1.0) purple = Color(0x993299, 1.0) red = Color(0xf41844, 1.0) bline = LineStyle(1, blue) pline = LineStyle(1, purple) rline = LineStyle(1, red) xcoords = range(0, 360, 10) bcircle = CircleAsset(4, bline, blue) rcircle = CircleAsset(4, rline, red) pcircle = CircleAsset(4, pline, purple) sine_sprites = [ Sprite(bcircle, (x, 100 + 100 * sin(radians(x)))) for x in xcoords ] cos_sprites = [ Sprite(rcircle, (x, 100 + 100 * cos(radians(x)))) for x in xcoords ] purple_sprites = [ Sprite(pcircle, (100 + 100 * cos(radians(x)), 400 + 100 * sin(radians(x)))) for x in xcoords ] myapp = App() myapp.run()
from ggame import App, RectangleAsset, ImageAsset, SoundAsset from ggame import LineStyle, Color, Sprite, Sound myapp = App() # define colors and line style green = Color(0x00ff00, 1) black = Color(0, 1) noline = LineStyle(0, black) # a rectangle asset and sprite to use as background bg_asset = RectangleAsset(myapp.width, myapp.height, noline, green) bg = Sprite(bg_asset, (0, 0)) # A ball! This is already in the ggame-tutorials repository ball_asset = ImageAsset("images/orb-150545_640.png") ball = Sprite(ball_asset, (0, 0)) # Original image is too big. Scale it to 1/10 its original size ball.scale = 0.1 # custom attributes ball.direction = 1 ball.go = True # reverse - change the ball direction def reverse(b): b.direction *= -1 # Set up function for handling screen refresh def step(): if ball.go:
#colors red = Color(0xff0000, 1.0) green = Color(0x00ff00, 1.0) blue = Color(0x0000ff, 1.0) black = Color(0x000000, 1.0) purple = Color(0x9932CC, 1.0) #Spritebases thinline = LineStyle(1, black) blueCircle = CircleAsset(5, thinline, blue) redCircle = CircleAsset(5, thinline, red) purpleCircle = CircleAsset(5, thinline, purple) xcoordinates = range(0, 370, 10) #line generators blues = [ Sprite(blueCircle, (x, 100 + 100 * sin(radians(x)))) for x in xcoordinates ] reds = [ Sprite(redCircle, (x, 100 + 100 * cos(radians(x)))) for x in xcoordinates ] purples = [ Sprite(purpleCircle, (100 + 100 * cos(radians(x)), 400 + 100 * sin(radians(x)))) for x in xcoordinates ] myapp = App() myapp.run()
from ggame import App myapp = App() myapp.run() from ggame import App, Color, LineStyle, Sprite from ggame import RectangleAsset, CircleAsset, EllipseAsset, PolygonAsset # Three primary colors with no transparency (aplpha = 1.0) red = Color(0xff0000, 1.0) green = Color(0x00ff00, 1.0) blue = Color(0x0000ff, 1.0) black = Color(0x000000, 1.0) # Define a line style that is a thin (1 pixel) wide black line thinline = LineStyle(1, black) # A graphics asset that represents a rectangle rectangle = RectangleAsset(50, 20, thinline, blue) #Now display a rectangle Sprite(rectangle)
http://brythonserver.github.io/ggame/ for detailed information on ggame. """ from ggame import App, Color, LineStyle, Sprite, RectangleAsset, CircleAsset, EllipseAsset, PolygonAsset # add your code here \/ \/ \/ red = Color(0xff0000, .7) green = Color(0x00ff00, .7) blue = Color(0x0000ff, .7) black = Color(0x000000, 1) #the window itself thinline = LineStyle(1, black) rect = RectangleAsset(400,5, thinline, black) Sprite(rect, (20,40)) thinline = LineStyle(1, black) rect = RectangleAsset(400,5, thinline, black) Sprite(rect, (20,300)) thinline = LineStyle(1, black) rect = RectangleAsset(5,265, thinline, black) Sprite(rect, (20,40)) thinline = LineStyle(1, black) rect = RectangleAsset(5,265, thinline, black) Sprite(rect, (415,40)) thinline = LineStyle(1, black) rect = RectangleAsset(5,265, thinline, black)
def __init__(self, width, height): super().__init__(width, height) suhan = ImageAsset("images/starfield.jpg") quiter = Sprite(suhan, (0, 0)) #jjeeeefffffff quiter1 = Sprite(suhan, (512, 512)) quiter2 = Sprite(suhan, (0, 512)) quiter3 = Sprite(suhan, (512, 0)) quiter4 = Sprite(suhan, (1024, 512)) quiter5 = Sprite(suhan, (1024, 0)) quiter6 = Sprite(suhan, (0, 1024)) quiter10 = Sprite(suhan, (512, 2014)) quiter11 = Sprite(suhan, (1024, 1024)) quiter12 = Sprite(suhan, (512, 1024)) quiter13 = Sprite(suhan, (1024, 512)) Sun((700, 430)) Sun((500, 600)) Sun((500, 250)) Sun((900, 600)) Sun((900, 250)) Sun((700, 760)) Sun((700, 100)) #SCREEN_WIDTH = 1400 #SCREEN_HEIGHT = 860 Ship((400, 430)) Sip((1000, 430))
black = Color(0x000000, 1.0) slategrey = Color(0x8B8878, 1.0) white = Color(0xffffff, 1.0) brown = Color(0xCD661D, 1.0) khaki = Color(0xF0E68C, 1.0) darkgreen = Color(0x006400, 1.0) watercolor = Color(0x1874CD, 1.0) thinline = LineStyle(2, black) brownline = LineStyle(2, brown) blueline = LineStyle(2, blue) greenline = LineStyle(2, darkgreen) waterline = LineStyle(2, watercolor) treegreenline = LineStyle(2, treegreen) background = RectangleAsset(1200, 1000, thinline, treegreen) Sprite(background, (0, 0)) floor1 = RectangleAsset(100, 200, greenline, darkgreen) Sprite(floor1, (80, 200)) floor2 = PolygonAsset([(60, 200), (180, 100), (370, 100), (137, 200)], greenline, darkgreen) Sprite(floor2, (90, 100)) floor3 = RectangleAsset(95, 346, greenline, darkgreen) Sprite(floor3, (300, 100)) floorpatch = RectangleAsset(10, 10, greenline, darkgreen) Sprite(floorpatch, (290, 140)) floor4 = EllipseAsset(80, 40, greenline, darkgreen) Sprite(floor4, (50, 360)) floor6 = RectangleAsset(620, 75, greenline, darkgreen) Sprite(floor6, (300, 380)) floor7 = RectangleAsset(200, 300, greenline, darkgreen) Sprite(floor7, (722, 80))