def __init__(self): super().__init__() black = Color(0, 1) noline = LineStyle(0, black) back_asset = ImageAsset("images/e36d28c490fe26653e50fbd17025f3ef.jpg") back = Sprite(back_asset, (0,0)) back.scale=1.4 self.text=Sprite(TextAsset("Game Over", width=700, align='center',style='70px Arial', fill=Color(0xff2222,1)), (300,350)) self.text.visible= False SpaceShip((40,100)) Asteroid((400,400)) Asteroid((50,30)) Asteroid((800,300)) moon_asset=ImageAsset("images/super-moon.png") moon= Sprite(moon_asset, (300, 200)) moon.scale=0.2
def __init__(self): super().__init__() # Background black = Color(0, 1) noline = LineStyle(0, black) #bg_asset = RectangleAsset(self.width, self.height, noline, black) #bg = Sprite(bg_asset, (0,0)) starfield_asset = ImageAsset("images/starfield.jpg") starfield_sprite = Sprite(starfield_asset, (0, 0)) # Scale the sprite according to size of screen if self.width > self.height: starfield_sprite.scale = self.width / starfield_sprite.width else: starfield_sprite.scale = self.height / starfield_sprite.height #sun_asset = ImageAsset("images/sun.png") #sun_sprite = Sprite(sun_asset, (self.width / 2, self.height / 2)) # Start Player1 in center of screen self.player1 = PlayerShip((self.width / 2, self.height / 2)) # Start enemy ship @ random location on screen self.safex = 0 self.safey = 0 self.safeRespawn() # Sets difficulty level of enemy ship (frequency of which it makes movements) self.challenge = 100 EnemyShip((self.safex, self.safey), self.challenge)
def test_scaledcirclecollision(self): s1 = Sprite(self.circ, (100, 80)) s2 = Sprite(self.rect, (161, 100)) c = s1.collidingWith(s2) self.assertFalse(c, msg="circle not colliding with rect") s1.x = 101 c = s1.collidingWith(s2) self.assertTrue(c, msg="circle colliding with rect") s1.x = 170 c = s1.collidingWith(s2) self.assertTrue(c, msg="circle colliding with rect on right side") s1.x = 172 c = s1.collidingWith(s2) self.assertFalse(c, msg="circle not colliding with rect on right side") # Now scale at 2x s1.scale = 2 s1.x = 40 c = s1.collidingWith(s2) self.assertFalse(c, msg="2x scaled circle not colliding with rect") s1.x = 41 c = s1.collidingWith(s2) self.assertTrue(c, msg="2x scaled circle colliding with rect") s1.x = 170 c = s1.collidingWith(s2) self.assertTrue( c, msg="2x scaled circle colliding with rect on right side") s1.x = 172 c = s1.collidingWith(s2) self.assertFalse( c, msg="2x scaled circle not colliding with rect on right side") s1.destroy() s2.destroy()
def __init__(self): super().__init__() self.gameover = False rectangle = RectangleAsset(1000, 1000, thinline, blue) rectangle1 = RectangleAsset(1000, 1000, thinline, white) Sprite(rectangle, (0, 0)) Sprite(rectangle1, (0, 350)) #initial positions Background((0, 0)) Background((512, 0)) Background((1024, 0)) House1((300, 350)) House2((900, 350)) Grinch((1000, 335)) Grinch((100, 335)) Grinch((1500, 335)) self.p1 = Present1((350, 50)) self.Hlist = Heartlist() #sleigh sleigh_asset = ImageAsset("images/santa_sleigh_PNG72.png") sleigh = Sprite(sleigh_asset, (350, 50)) sleigh.scale = 0.3 #music jingle_asset = SoundAsset("sounds/Santa Claus Is Coming To Town.mp3") jingle = Sound(jingle_asset) jingle.volume = 8 jingle.play()
def __init__(self): super().__init__() bg_asset = ImageAsset("images/starfield.jpg") bg = Sprite(bg_asset, (0, 0)) bg.scale = 2 self.rocketship = rocket((500, 30)) self.sun = sun((500, 250)) self.exploding = False
def __init__(self): super().__init__() # Background black = Color(0, 1) noline = LineStyle(0, black) #bg_asset = RectangleAsset(self.width, self.height, noline, black) #bg = Sprite(bg_asset, (0,0)) starfield_asset = ImageAsset("images/starfield.jpg") starfield_sprite = Sprite(starfield_asset, (0,0)) # Scale the sprite according to size of screen if self.width > self.height: starfield_sprite.scale = self.width / starfield_sprite.width else: starfield_sprite.scale = self.height / starfield_sprite.height sun_asset = ImageAsset("images/sun.png") sun_sprite = Sprite(sun_asset, (self.width / 2, self.height / 2)) player1 = Player((100,100))
def __init__(self, position): ball_asset = ImageAsset("images/orb-150545_640.png") #pull from repository ball = Sprite(ball_asset, (0, 400)) ball.scale = 0.07 # custom attributes ball.direction = 1 ball.go = True # Sounds pew1_asset = SoundAsset("sounds/pew1.mp3") pew1 = Sound(pew1_asset) pop_asset = SoundAsset("sounds/reappear.mp3") pop = Sound(pop_asset) super().__init__(ball_asset, position)
def __init__(self): super().__init__() bg_asset = ImageAsset("images/istockphoto-114445289-612x612.jpg") bg = Sprite(bg_asset, (-100, -115)) bg.scale = 2 self.ball = Ball((515, 265)) self.paddle1 = Paddle1((97, 265)) self.paddle2 = Paddle2((935, 265)) self.borderleft = Borderleft((0, 265)) self.borderright = Borderright((1100, 265)) self.bordertop = Bordertop((515, 60)) self.borderbottom = Borderbottom((515, 470))
def __init__(self, width, height): super().__init__(width, height) black = Color(0, 1) noline = LineStyle(0, black) bg_asset = ImageAsset("images/kSQdCxM.jpg") bg = Sprite(bg_asset, (0, 0)) bg.scale = 0.6 SpaceShip((125, 100)) #SpaceShip((225,200)) #SpaceShip((25,200)) SpaceShip((175, 150)) SpaceShip((75, 150)) Asteroid(1, (200, 400)) for a in range(8): x = random() x = x * 1400 + 100 y = random() y = y * 800 + 100 pos = (x, y) Asteroid(a, pos)
def __init__(self): super().__init__() bg_asset = ImageAsset("images/tenniscourt1.jpg") bg = Sprite(bg_asset, (-100, -115)) bg.scale = 2 self.ball = Ball((515, 265)) self.paddle1 = Paddle1((97, 265)) self.paddle2 = Paddle2((935, 265)) self.borderleft = Borderleft((80, 265)) self.borderright = Borderright((952, 265)) self.bordertop = Bordertop((515, 60)) self.borderbottom = Borderbottom((515, 470)) self.disap = False
green = Color(0x00ff00, 1) black = Color(0, 1) noline = LineStyle(0, black) bg_asset = RectangleAsset(SCREEN_WIDTH, SCREEN_HEIGHT, noline, green) bg = Sprite(bg_asset, (0,0)) # Sounds pew1_asset = SoundAsset("sounds/pew1.mp3") pew1 = Sound(pew1_asset) pop_asset = SoundAsset("sounds/reappear.mp3") pop = Sound(pop_asset) # 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 ball.y = 200 # custom attributes ball.dir = 1 ball.go = True # Sounds pew1_asset = SoundAsset("sounds/pew1.mp3") pew1 = Sound(pew1_asset) pop_asset = SoundAsset("sounds/reappear.mp3") pop = Sound(pop_asset) def reverse(b): b.dir *= -1 pop.play()
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 brectangle = RectangleAsset(50, 20, thinline, blue) rrectangle = RectangleAsset(50, 20, thinline, red) bellipse = EllipseAsset(500,250,thinline, blue) rpolygon = PolygonAsset([(50,0),(950,0),(1000,50),(1000,450), (950,500),(50,500),(0,450),(0,50),(50,0)],thinline, redtransparent) # Now display a rectangle Sprite(brectangle,(100,100)) Sprite(rrectangle,(110,110)) Sprite(bellipse,(500,250)) polySprite = Sprite(rpolygon,(0,0)) count = 0; while count < 10: polySprite.scale = random.random() time.sleep(1) count = count + 1 myapp = App() myapp.run()
def map(file,scale): picture=ImageAsset("images/" + file) picture_sprite=Sprite(picture, (0,0)) picture_sprite.scale = scale myapp = App() myapp.run()
from ggame import App, RectangleAsset, ImageAsset, SoundAsset from ggame import LineStyle, Color, Sprite, Sound rectangle dimensions:1728 862 # A ball! This is already in the ggame-tutorials repository ball_asset = ImageAsset("images/orb-150545_640.png") ball = Sprite(ball_asset, (0, 0)) ball.fxcenter = 0.7 ball.fycenter = 0.6 # Original image is too big. Scale it to 1/10 its original size ball.scale = 0.05 #Handle the mouse movement def mouseMove(event): ball.x = event.x ball.y = event.y myapp = App() myapp.listenMouseEvent('mousemove', mouseMove) myapp.run()
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)) print(' ') #What is going on here? #for t in range(-10000,56):
See: 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 \/ \/ \/ # 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 rectSprite = Sprite(rectangle) rectSprite.scale = 10.0 # add your code here /\ /\ /\ myapp = App() myapp.run()
green = Color(0x00FF00, 1) brown = Color(0x966F33, 1) black = Color(0, 1) noline = LineStyle(0, black) bg_asset = RectangleAsset(SCREEN_WIDTH, SCREEN_HEIGHT, noline, brown) cover_asset = RectangleAsset(600, 440, noline, green) bg = Sprite(bg_asset, (0, 0)) cover = Sprite(cover_asset, (20, 20)) # A ball! This is already in the ggame-tutorials repository ball_asset = ImageAsset("images/orb-150545_640.png") beach_asset = ImageAsset("images/beach-ball-575425_640.png") ball = Sprite(ball_asset, (0, 0)) beach = Sprite(beach_asset, (40, 40)) # Original image is too big. Scale it to 1/10 its original size ball.scale = 0.1 # custom attributes ball.dir = 1 ball.go = True beach.scale = 0.1 beach.dir = 2 beach.go = True def reverse(b): b.dir *= -1 pop.play() # Set up function for handling screen refresh def step():
noline = LineStyle(0, black) space_asset = ImageAsset("images/starfield.jpg", ) space_asset2 = ImageAsset("images/starfield.jpg", ) space = Sprite(space_asset, (0, 0)) space2 = Sprite(space_asset, (512, 0)) space3 = Sprite(space_asset, (1024, 0)) space4 = Sprite(space_asset, (0, 512)) space5 = Sprite(space_asset, (512, 512)) space6 = Sprite(space_asset, (1024, 512)) spaceship_asset = ImageAsset( "images/four_spaceship_by_albertov_with_thrust.png", Frame(227, 0, 292 - 227, 125), 4, 'vertical') asteroid_asset = ImageAsset("images/asteroid_for_program.png", ) asteroid1 = Sprite(asteroid_asset, (300, 300)) asteroid2 = Sprite(asteroid_asset, (1120, 300)) asteroid1.scale = .5 asteroid1.xmov = 10 asteroid1.ymov = 10 asteroid2.scale = .5 asteroid2.x2mov = -10 asteroid2.y2mov = -10 spaceship = Sprite(spaceship_asset, (740, 405)) spaceship.fxcenter = spaceship.fycenter = 0.5 # Movement spaceship.dir = 3 spaceship.bob = 3 spaceship.go = False spaceship.ygo = False spaceship.thrust = 0 spaceship.thrustframe = 1
green = Color(0x00ff00, 1) black = Color(0, 1) noline = LineStyle(0, black) bg_asset = RectangleAsset(SCREEN_WIDTH, SCREEN_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.dir = 1 ball.go = True #Sounds pew1_asset = SoundAsset("sounds/pew1.mp3") pew1 = Sound(pew1_asset) pop_asset = SoundAsset("sounds/reappear.mp3") pop = Sound(pop_asset) def reverse(b): b.dir *= -1 # Set up function for handling screen refresh
circle = CircleAsset(100, thinlineblue, cornflowerblue) smalltriangle = PolygonAsset([(725, 600), (775, 600), (750, 600 + 25 * sqrt(3))], thinlineblack, black) whiteeye = CircleAsset(32, thinlinewhite, white) pupil = CircleAsset(12, thinlineblack, black) whisker = RectangleAsset(100, 7, thinlineblack, black) cheese = RectangleAsset(180, 70, thinlinegold, gold) cheesetop = PolygonAsset([(650, 245), (830, 245), (780, 205), (650, 245)], thinlinegolder, golder) cheesehole = EllipseAsset(17, 10, thinlinegolder, golder) alsocheesehole = EllipseAsset(9, 6, thinlinegolder, golder) alsoalsocheesehole = EllipseAsset(11, 8, thinlinegolder, golder) #print #head s = Sprite(triangle, (120, 120)) s.scale = 0.8 #ears Sprite(circle, (60, 45)) Sprite(circle, (380, 45)) #nose Sprite(smalltriangle, (294.5, 420)) #eyes Sprite(whiteeye, (225, 200)) Sprite(whiteeye, (350, 200)) Sprite(pupil, (255, 220)) Sprite(pupil, (380, 220)) #whiskers w = Sprite(whisker, (370, 330)) w.rotation = .3 W = Sprite(whisker, (370, 335)) W.rotation = 0
def __init__(self): super().__init__() Aasset = ImageAsset("images/Member_A.png", Frame(0, 0, 127, 115), 8, 'horizontal') Basset = ImageAsset("images/Member_B.png", Frame(0, 0, 127, 115), 8, 'horizontal') Casset = ImageAsset("images/Member_C.png", Frame(0, 0, 127, 115), 8, 'horizontal') Dasset = ImageAsset("images/Member_D.png", Frame(0, 0, 127, 115), 8, 'horizontal') #Cover images is 812 wide and 191*4 down) rock = ImageAsset('images/Cover.png', Frame(0, 0, 203, 191), 3, 'vertical') pillar = ImageAsset('images/Cover.png', Frame(203, 0, 203, 191), 3, 'vertical') box = ImageAsset('images/Cover.png', Frame(406, 0, 203, 191), 3, 'vertical') etc = ImageAsset('images/Cover.png', Frame(609, 0, 203, 191), 3, 'vertical') self.state = 'none' self.labels = [] instructions = [ 'These are the instructions. Press enter to continue.', 'If, at any point, you want to skip the instructions, type "s" then press enter.', 'This game allows you to control three characters and use them to defeat enemies in various levels.', 'To control the characters, click any location on the map. They will go to that location.', 'If they are busy (hiding, shooting at any enemy, etc.) then they will not respond.', 'If you want them to respond even while they are busy, use your "control keys".', 'There is a different control key for each character. The first uses the control key "a", the second uses "b", and the third uses "c".', 'To use the control key, merely hold it down. While you are holding it, the character will ignore nearby enemies and focus only on your instructions.', 'When you release the key, they will resume paying attention to enemies nearby.', 'Have fun! Press enter to select your level.' ] for a in instructions: if input(a) == 's': break select = 0 while select == 0: stage = input('''Select your level. Enter t for tutorial 1 for level 1 2 for level 2 or 3 for level 3 ''') if stage == 't': select = 1 m = ImageAsset("images/map_base.jpg") am = Sprite(m) am.scale = 1.2 c = Cover((100, 100), 2, etc) c1 = Cover((500, 200), 0, rock) b = Enemy((0, 0)) e = Enemy((300, 300)) coor_a = (500, 0) coor_b = (500, 200) coor_c = (500, 400) elif stage == '1': select = 1 m = ImageAsset("images/map_base2.jpg") am = Sprite(m) am.scale = 1.2 c = Cover((100, 290), 2, etc) c1 = Cover((700, 360), 1, rock) c2 = Cover((304, 390), 0, rock) c3 = Cover((500, 30), 2, rock) e = Enemy((800, 0)) e1 = Enemy((782, 15)) e2 = Enemy((802, 30)) coor_a = (0, 0) coor_b = (0, 10) coor_c = (0, 21) elif stage == '2': select = 1 m = ImageAsset("images/map_base3.jpg") am = Sprite(m) am.scale = 1.1 c = Cover((10, 100), 0, pillar) c1 = Cover((120, 105), 1, pillar) c2 = Cover((600, 50), 0, pillar) c3 = Cover((800, 300), 2, box) coor_a = (500, 0) coor_b = (550, 0) coor_c = (450, 50) e = Enemy((800, 0)) e1 = Enemy((10, 250)) e2 = Enemy((400, 300)) e3 = Enemy((800, 400)) e3.hp = 40 e3.scale = 0.58 elif stage == '3': select = 1 m = ImageAsset("images/map_base4.jpg") am = Sprite(m) am.scale = 1.1 c = Cover((10, 0), 0, etc) c1 = Cover((550, 300), 1, rock) c2 = Cover((480, 320), 1, etc) c2.scale = 0.47 e1 = Enemy((400, 50)) e2 = Enemy((500, 50)) e = Enemy((450, 20)) e.hp = 250 e.scale = 0.8 coor_a = (0, 251) coor_b = (400, 252) coor_c = (800, 253) else: print("Sorry, didn't understand. Try again.") self.akey = 'False' self.bkey = 'False' self.ckey = 'False' select = 0 while select == 0: char = input('''Select a type for the first position: a is generally balanced b is slow but powerful c is quick with light damage d has high damage and low hp ''') if char == 'a': Member(10, 1.5, 1, 1, 190, coor_a, Aasset, 'a') select = 1 elif char == 'b': Member(18, 0.5, 2.5, 1, 185, coor_a, Basset, 'a') select = 1 elif char == 'c': Member(7, 2, 0.3, 1, 180, coor_a, Casset, 'a') select = 1 elif char == 'd': Member(33, 1.1, 0.8, 1, 50, coor_a, Dasset, 'a') select = 1 else: print("Sorry, I don't understand.") while select == 1: char = input('''Select a type for the second position: (see desc above) ''') if char == 'a': Member(10, 1.5, 1, 1, 190, coor_b, Aasset, 'b') select = 2 elif char == 'b': Member(18, 0.5, 2.5, 1, 185, coor_b, Basset, 'b') select = 2 elif char == 'c': Member(7, 2, 0.3, 1, 180, coor_b, Casset, 'b') select = 2 elif char == 'd': Member(33, 1.1, 0.8, 1, 50, coor_b, Dasset, 'b') select = 2 else: print("Sorry, I don't understand.") while select == 2: char = input('''Select a type for the third (and final) position: (see desc. above) ''') if char == 'a': a = Member(10, 1.5, 1, 1, 190, coor_c, Aasset, 'c') select = 0 elif char == 'b': a = Member(18, 0.5, 2.5, 1, 185, coor_c, Basset, 'c') select = 0 elif char == 'c': a = Member(7, 2, 0.3, 1, 180, coor_c, Casset, 'c') select = 0 elif char == 'd': Member(33, 1.1, 0.8, 1, 50, coor_c, Dasset, 'c') select = 0 else: print("Sorry, I don't understand.") #Aasset attributes are as follows: (11,1.5,0.7,1,200) #Basset attributes are as follows: (20,0.5,2.5,1,170) #Casset attributes are as folloes: (7,2,0,3,1,180) for x in self.getSpritesbyClass(Member): pic = TextAsset(str(x.hp), style='bold 16px Times', fill=Color(0x070E68, 0.9)) pict = Sprite(pic, (x.x + 33, x.y + 80)) self.labels.append([pict, x, x.hp, 'M']) for x in self.getSpritesbyClass(Enemy): pic = TextAsset(str(x.hp), style='bold 16px Helvetica', fill=Color(0x8C2727, 0.9)) pict = Sprite(pic, (x.x + 33, x.y + 80)) self.labels.append([pict, x, x.hp, 'E']) Game.listenKeyEvent('keydown', 'a', self.a_down) Game.listenKeyEvent('keyup', 'a', self.a_up) Game.listenKeyEvent('keydown', 'b', self.b_down) Game.listenKeyEvent('keyup', 'b', self.b_up) Game.listenKeyEvent('keydown', 'c', self.c_down) Game.listenKeyEvent('keyup', 'c', self.c_up)
align='center', style='200px Arial', width=1300) background4 = Sprite(background_asset4, (200, 0)) background5 = Sprite(background_asset5, (600, 600)) background6 = Sprite(background_asset6, (200, 0)) background_asset1 = RectangleAsset(1220, 650, edge, blue) background_asset2 = ImageAsset("images/Green.png", ) background_asset3 = RectangleAsset(1420, 810, edge, black) background1 = Sprite(background_asset1, (70, 30)) background2 = Sprite(background_asset2, (0, 0)) background3 = Sprite(background_asset3, (0, 0)) castle_asset = ImageAsset("images/castleyeah.png", ) factory_asset = ImageAsset("images/Factory.png", ) factory = Sprite(factory_asset, (100, 100)) factory.scale = .25 potato_asset = ImageAsset("images/door.jpg", ) castle = Sprite(castle_asset, (850, 200)) castle.scale = .1 castle.fxcenter = castle.fycenter = 0.5 class FactoryFloor(Sprite): factoryflr = floor_asset = ImageAsset("images/stonefloor.jpg", ) def __init__(self, position): super().__init__(FactoryFloor.factoryflr, position) self.scale = .15 self.fxcenter = self.fycenter = 0.5