Example #1
0
    def __init__(self, width, height):
        super().__init__(width, height)
        dishtxt = TextAsset(text="Radar Dish",
                            width=200,
                            align='center',
                            style='10px Arial',
                            fill=black)
        signaltxt = TextAsset(text="Signal (moving)",
                              width=200,
                              align='center',
                              style='10px Arial',
                              fill=red)
        #suntxt = TextAsset(text="Random Sun", width = 200, align = 'center', style = '10px Arial', fill=black)
        #planetxt = TextAsset(text="Plane (will idealy move)", width = 200, align = 'center', style = '10px Arial', fill=black)
        Sprite(RectangleAsset(1000, 500, thinlinesb, skyblue), (0, 0))
        dish((100, 450))
        Sprite(dishtxt, (45, 450))
        signal((100, 450))
        Sprite(signaltxt, (75, 375))
        plane((cpx, cpy))
        #plane1((cpx,cpy))
        #plane((900,72))
        #Sprite(planetxt,(865,25))
        if rainny == 1:
            for x in range(0, 31):
                rain((random.randrange(400, 800), random.randrange(0, 500)))
        if snowy == 1:
            for x in range(0, 31):
                snow((random.randrange(400, 800), random.randrange(0, 500)))
        if foggy == 1:
            fog((200, 0))

        Sprite(LineAsset(1000, 1, thinline), (0, 500))
        Sprite(CircleAsset(20, thinlinesun, sun), (200, 100))
Example #2
0
 def __init__(self, width, height):
     super().__init__(width, height)
     black = Color(0, 1)
     yellow = Color(0xffeb3b, 1.0)
     white = Color(0xfafafa, 1.0)
     liner = LineStyle(1, white)
     line = LineStyle(1, black)
     self.play = False
     self.ComicSans = True
     bg_asset = RectangleAsset(width, height, line, black)
     bg = Sprite(bg_asset, (0, 0))
     text = TextAsset("Press ENTER To Start",
                      style='40pt Comic Sans MS',
                      fill=Color(0xffeb3b, 1),
                      width=700)
     self.prompt = Sprite(text, (50, 250))
     TEXT = TextAsset("Game Over",
                      style='40pt Comic Sans Ms',
                      fill=Color(0xffeb3b, 1),
                      width=700)
     self.Prompt = Sprite(TEXT, (350, 350))
     self.prompt.visible = True
     self.Prompt.visible = False
     self.count = 0
     self.lost = False
     Kong.listenKeyEvent("keydown", "enter", self.playing)
Example #3
0
    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()
Example #4
0
 def __init__(self):
     super().__init__()
     grid = RectangleAsset(60,60,gridline,white)
     x = 0 
     y = 0 
     for d in range(13):
         for e in range(20):
             Sprite(grid, (x,y))
             x = x + 60
         x = 0
         Sprite(grid,(x,y))
         y = y + 60
     super().__init__()
     self.listenKeyEvent("keydown", "b", self.cBlock)
     self.listenKeyEvent("keydown", "p", self.cUser)
     self.listenKeyEvent("keydown", "s", self.cSpring)
     self.listenKeyEvent("keydown", "f", self.cPlat)
     self.listenKeyEvent("keydown", "left arrow", self.Keys)
     self.listenKeyEvent("keydown", "right arrow", self.Keys)
     self.listenKeyEvent("keydown", "up arrow", self.Keys)
     self.listenKeyEvent("keyup", "left arrow", self.stopKeys)
     self.listenKeyEvent("keyup", "right arrow", self.stopKeys)
     self.listenKeyEvent("keyup", "up arrow", self.stopKeys)
     self.listenMouseEvent("mousemove", self.Mouse)
     self.q = []
     self.w = []
     self.g = None
     self.pos = (0,0)
Example #5
0
 def __init__(self):
     super().__init__()
     black = Color(0, 1)
     noline = LineStyle(0, black)
     bg_asset = RectangleAsset(self.width, self.height, noline, black)
     bg = Sprite(bg_asset, (0,0))
     for i in range (1,10):
         white=Color(0xbbbb00,1)
         starline=LineStyle(2,white)
         star_asset =RectangleAsset(10, 10, starline, white)
         star = Sprite(star_asset, ((random.randint(0,1000)),(random.randint(0,500))))
     self.spaceship=SpaceShip((100,100))
     asteroid((random.randint(400,800),random.randint(0,200)), self.spaceship)
     asteroid((random.randint(400,800),random.randint(0,200)), self.spaceship)
     asteroid((random.randint(400,800),random.randint(0,200)), self.spaceship)
     asteroid((random.randint(400,800),random.randint(0,200)), self.spaceship)
     asteroid((random.randint(400,800),random.randint(0,200)), self.spaceship)
     asteroid((random.randint(400,800),random.randint(0,200)), self.spaceship)
     asteroid((random.randint(400,800),random.randint(0,200)), self.spaceship)
     asteroid((random.randint(400,800),random.randint(0,200)), self.spaceship)
     asteroid((random.randint(0,400),random.randint(0,200)), self.spaceship)
     asteroid((random.randint(0,400),random.randint(0,200)), self.spaceship)
     asteroid((random.randint(0,400),random.randint(0,200)), self.spaceship)
     asteroid((random.randint(0,400),random.randint(0,200)), self.spaceship)
     asteroid((random.randint(0,400),random.randint(0,200)), self.spaceship)
     asteroid((random.randint(0,400),random.randint(0,200)), self.spaceship)
     asteroid((random.randint(0,400),random.randint(0,200)), self.spaceship)
     asteroid((random.randint(0,400),random.randint(0,200)), self.spaceship)
Example #6
0
    def __init__(self):
        Screen.registerturtle(self)
        self.currentcolor = self.black
        self.currentthinline = self.thinlineblack
        width = Screen.width
        height = Screen.height
        screencenter = (width / 2, height / 2
                        )  #finds a tuple for the center of the screen
        #self.newturtle(self.currentcolor, self.currentthinline)
        startturtle = PolygonAsset([(5, 5), (20, 13), (5, 21), (10, 13),
                                    (5, 5)], self.currentthinline,
                                   self.currentcolor)
        self.turtle = Sprite(startturtle, screencenter)
        self.rotationgoal = None
        self.forwardgoal = None
        self.bkgoal = None

        self.vr = 0
        self.turtle.fxcenter = 1
        self.turtle.fycenter = 1 / 2

        self.vx = 0
        self.vy = 0

        self.commandlist = []
        self.currentcmd = None

        self.distance = 0

        self.combinedhead = 0

        self.fdx = width / 2
        self.fdy = height / 2
Example #7
0
    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)
Example #8
0
 def endgame(self):
     if self.gallows.hangingphase == 6:
         self.wordsprite.destroy()
         wordasset = TextAsset(finishedword, style='60px Helvetica',align='center',width=1000,fill=red)
         self.wordsprite = Sprite(wordasset,(500,525))
         self.wordsprite.fxcenter = 0.5
         Hangman.unlistenMouseEvent('mousemove', myapp.mousemove)
         Hangman.unlistenMouseEvent('mousedown', myapp.mousedown)
 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
Example #10
0
def display():
    for x in range(1,mapsize):
        for y in range(1,mapsize):
            if coord[(x,y)] == 0:
                Sprite(deadcell,(x*10,y*10))
            elif coord[(x,y)] == 1:
                Sprite(newcell,(x*10,y*10))
            elif coord[(x,y)] == 2:
                Sprite(oldcell,(x*10,y*10))
Example #11
0
    def __init__(self, asset, *args, **kwargs):
        """
        Required inputs
        
        * **asset** a ggame asset
        * **args** the list of required positional and nonpositional arguments,
          as named in the posinputsdef and nonposinputsdef lists
        * **kwargs** all other optional keyword arguments:
          positioning - logical (default) or physical, size, width, color, style
          movable
        
        """

        MathApp._addVisual(self)
        #Sprite.__init__(self, asset, args[0])
        _MathDynamic.__init__(self)
        self._movable = False
        self._selectable = False
        self._strokable = False
        self.selected = False
        self.mouseisdown = False
        #
        self.positioning = kwargs.get('positioning', 'logical')
        # positional inputs
        self.PI = namedtuple('PI', self.posinputsdef)
        # nonpositional inputs
        self.NPI = namedtuple('NPI', self.nonposinputsdef)
        # standard inputs (not positional)
        standardargs = ['size', 'width', 'color', 'style']
        self.SI = namedtuple('SI', standardargs)
        # correct number of args?
        if len(args) != len(self.posinputsdef) + len(self.nonposinputsdef):
            raise TypeError("Incorrect number of parameters provided")
        self.args = args
        # generated named tuple of functions from positional inputs
        self.posinputs = self.PI(*[self.Eval(p)
                                   for p in args][:len(self.posinputsdef)])
        self._getPhysicalInputs()
        # first positional argument must be a sprite position!
        Sprite.__init__(self, asset, self.pposinputs[0])
        # generated named tuple of functions from nonpositional inputs
        if len(self.nonposinputsdef) > 0:
            self.nposinputs = self.NPI(
                *[self.Eval(p)
                  for p in args][(-1 * len(self.nonposinputsdef)):])
        else:
            self.nposinputs = []
        self.stdinputs = self.SI(
            self.Eval(kwargs.get('size', self.defaultsize)),
            self.Eval(kwargs.get('width', self.defaultwidth)),
            self.Eval(kwargs.get('color', self.defaultcolor)),
            self.Eval(kwargs.get('style', self.defaultstyle)))
        self.sposinputs = self.PI(*[0] * len(self.posinputs))
        self.spposinputs = self.PI(*self.pposinputs)
        self.snposinputs = self.NPI(*[0] * len(self.nposinputs))
        self.sstdinputs = self.SI(*[0] * len(self.stdinputs))
Example #12
0
    def __init__(self, width, height):
        super().__init__(width, height)
        time.time()
        black = Color(1, 1)
        line = LineStyle(2, black)
        self.peanuts = 0
        Score = str(self.peanuts)
        grass = Color(0x229954, 1)
        hedge = Color(0x145A32, 1)
        stone = Color(0xB2BABB, 1)
        road = Color(0x515A5A, 1)
        roof = Color(0x5F6A6A, 1)
        Grass = RectangleAsset(1279, 939, line, grass)
        Hedge = RectangleAsset(25, 700, line, hedge)
        Hedge2 = RectangleAsset(25, 340, line, hedge)
        Hedge3 = RectangleAsset(25, 290, line, hedge)
        Hedge4 = RectangleAsset(485, 25, line, hedge)
        Stone = RectangleAsset(20, 50, line, stone)
        Road = RectangleAsset(60, 940, line, road)
        Roof = RectangleAsset(30, 400, line, roof)
        Roof2 = RectangleAsset(30, 300, line, roof)
        self.score = TextAsset("Score:" + Score + "",
                               style="40pt Comic Sans MS",
                               fill=Color(0xD2B4DE, 1),
                               width=200)
        self.waituntil = time.time() + 1
        X = random.randrange(100) + 1280
        X2 = random.randrange(100) + 1380
        Y = random.randrange(940)
        Sprite(Grass, (0, 0))
        Sprite(Roof2, (200, 0))
        Sprite(Roof2, (200, 600))
        Sprite(RectangleAsset(-400, 30, line, roof), (0, 0))
        Sprite(CircleAsset(45, line, roof), (215, 40))
        Sprite(CircleAsset(25, line, roof), (215, 40))
        Sprite(CircleAsset(45, line, roof), (215, 900))
        Sprite(CircleAsset(25, line, roof), (215, 900))

        People((X2, 300))
        People((X, 320))
        People((X2, 340))
        People((X, 360))
        People((X2, 380))
        People((X, 400))
        People((X2, 420))
        People((X, 440))
        People((X2, 460))
        People((X, 480))
        People((X2, 500))
        People((X, 520))
        People((X2, 540))
        People((X, 560))
        People((X2, 580))
        self.prompt = Sprite(self.score, (10, 10))

        Bingo((640, 300), self)
Example #13
0
 def __init__(self, width, height):
     super().__init__(width, height)
     black = Color(0, 1)
     noline = LineStyle(0, black)
     #bg_asset = RectangleAsset(width, height, noline, black)
     bg_asset = ImageAsset("images/starfield.jpg")
     bg=Sprite(bg_asset,(0,0))
     sun_asset = ImageAsset("images/sun.png")
     self.sun=Sprite(sun_asset, (200,200))
     SpaceShip((100,100), self)
Example #14
0
 def __init__(self, width, height):
     super().__init__(width, height)
     
     
     xaxis = RectangleAsset(1920,1, thinline, black)
     yaxis = RectangleAsset(1,1080, thinline, black)
     sprite1 = Sprite(xaxis, (0, 500))
     sprite2 = Sprite(yaxis, (840, 0))  #origin (840,500)
     
     Dot((0,0))
Example #15
0
 def test_spritecollision(self):
   s1 = Sprite(self.image, (51,52))
   s2 = Sprite(self.image, (51, 52))
   cl = s2.collidingWithSprites()
   self.assertEqual(len(cl), 1)
   self.assertEqual(s2.collidingWith(cl[0]), True)
   s2.x = 125
   self.assertEqual(s2.collidingWith(cl[0]), False)
   s1.destroy()
   s2.destroy()    
Example #16
0
def change(info):
    x = int(info.x/10)
    y = int(info.y/10)
    if x >= mapsize or y >= mapsize or x <= 0 or y <= 0:
        return
    elif coord[(x,y)] == 0:
        coord[(x,y)] = 1
        Sprite(newcell,(x*10,y*10))
    else:
        coord[(x,y)] = 0
        Sprite(deadcell,(x*10,y*10))
Example #17
0
def NewCellAt(coords):
    global screenoffset
    if not coords in livecells:
        try:
            newcell = deadcells.pop()
        except:
            newcell = (Sprite(redcircle, (0, 0)), Sprite(bluecircle, (0, 0)))
        livecells[coords] = newcell
        newcell[0].position = newcell[1].position = pfroml(
            (coords[0] + screenoffset[0], coords[1] + screenoffset[1]))
        newcell[0].visible = True
        newcell[1].visible = False
Example #18
0
 def test_sprite(self):
   s = Sprite(self.image, (51,52))
   self.assertEqual(s.x, 51)
   self.assertEqual(s.y, 52)
   self.assertEqual(s.width, 71)
   self.assertEqual(s.height, 100)
   self.assertEqual(s.position, (51,52))
   self.assertEqual(s.fxcenter, 0.0)
   s.x = 41
   self.assertEqual(s.x, 41)
   self.assertEqual(s.width, 71)
   s.destroy()
Example #19
0
 def test_sprite(self):
     s = Sprite(self.image, (51, 52))
     self.assertEqual(s.x, 51)
     self.assertEqual(s.y, 52)
     self.assertEqual(s.width, 71)
     self.assertEqual(s.height, 100)
     self.assertEqual(s.position, (51, 52))
     self.assertEqual(s.fxcenter, 0.0)
     s.x = 41
     self.assertEqual(s.x, 41)
     self.assertEqual(s.width, 71)
     s.destroy()
Example #20
0
def displayCells():
    x = 0
    y = 0
    for i in grid:
        for j in i:
            if j > 7:
                Sprite(circles[6], (x, y))
            elif j > 0:
                Sprite(circles[j - 1], (x, y))
            x += 10
        x = 0
        y += 10
Example #21
0
 def step(self):
     if self.statechange != 0 or self.life != 0:
         self.state += (self.statechange + self.life)
         self.statechange = 0
         self.life = 0
         if self.state > 0:
             LiveCell = RectangleAsset(98, 98, nl, black)
             Sprite(LiveCell, (self.x, self.y))
             self.state = 1
         else:
             self.state = 0
             DeadCell = RectangleAsset(98, 98, nl, white)
             Sprite(DeadCell, (self.x, self.y))
Example #22
0
 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)
Example #23
0
 def guessletter(self):
     global wordinprogress
     global word
     global displayedword
     global wordsprite
     global alreadyguessedstring
     global guessedasset
     global wordasset
     global hangingphase
     global gallows
     global guessedsprite
     global allletters
     displayedword = ''
     guessedletter = input('Please guess a letter!')
     guessedletter = guessedletter.lower()
     
     while alreadyguessed.count(guessedletter) > 0:
         guessedletter = input('You already guessed that letter! Try again:')
     
     while allsymbols.count(guessedletter) > 0:
         guessedletter = input("That's not a letter! Try again:")
     
     while len(guessedletter) > 1:
         guessedletter = input("Please only input one letter:")
     
     if word.count(guessedletter) > 0:
         for x in range(len(word)):
             if guessedletter == word[x]:
                 wordinprogress = wordinprogress[:x] + "{0}".format(guessedletter) + wordinprogress[x+1:]
         for x in range(len(wordinprogress)):
             displayedword = displayedword + "{0:<3}".format(wordinprogress[x])
         self.wordsprite.destroy()
         wordasset = TextAsset(displayedword, style='60px Helvetica',align='center',width=1000)
         self.wordsprite = Sprite(wordasset,(500,525))
         self.wordsprite.fxcenter = 0.5
         alreadyguessed.append(guessedletter)
         alreadyguessedstring = alreadyguessedstring + "{0:<3}".format(guessedletter)
     else:
         alreadyguessed.append(guessedletter)
         alreadyguessedstring = alreadyguessedstring + "{0:<3}".format(guessedletter)
         self.gallows.hangingphase += 1
         self.gallows.setImage(self.gallows.hangingphase)
         
     self.guessedsprite.destroy()
     guessedasset = TextAsset(alreadyguessedstring, style='20px Helvetica',align='center',width=100)
     self.guessedsprite = Sprite(guessedasset, (100,250))
     
     self.endgame()
     self.wongame()
Example #24
0
    def test_advancedspritecollision(self):
        class SpriteChild(Sprite):
            pass

        s1 = Sprite(self.image, (51, 52))
        s2 = Sprite(self.image, (61, 52))
        s3 = SpriteChild(self.image, (71, 52))
        cl = s1.collidingWithSprites(SpriteChild)
        self.assertEqual(len(cl), 1)
        self.assertIs(cl[0], s3)
        cl = s1.collidingWithSprites()
        self.assertEqual(len(cl), 2)
        s1.destroy()
        s2.destroy()
        s3.destroy()
Example #25
0
 def __init__(self, width, height):
     super().__init__(width, height)
     black = Color(0, 1)
     noline = LineStyle(0, black)
     bg_asset = ImageAsset("images/starfield.jpg")
     txt_asset= TextAsset(text="Press R to Reset", width=200, align='center',style='20px Arial', fill=Color(0xff2222,1))
     star0 = Sprite(bg_asset, (0,0))
     star1= Sprite(bg_asset, (512,0))
     star2= Sprite(bg_asset, (0,512))
     star3= Sprite(bg_asset, (512, 512))
     txt = Sprite(txt_asset, (0,0))
     Sunthing((500,360))
     
     SpaceShip((300,300))
     '''
Example #26
0
  def __init__(self):
      super().__init__()
      black = Color(0, 1)
      line = LineStyle(0, black)
      bg_asset = RectangleAsset(self.width, self.height, line, black)
      bg = Sprite(bg_asset, (0,0))
      self.shooter = Shooter((500,450))
      Enemy((40, 10))
      Enemy((130, 10))
      Enemy((220, 10))
      Enemy((310, 10))
      Enemy((400, 10))
      Enemy((490, 10))
      Enemy((580, 10))
      Enemy((670, 10))
      Enemy((760, 10))
      Enemy((850, 10))
      Enemy((940, 10))
      
      Enemy((40, 80))
      Enemy((130, 80))
      Enemy((220, 80))
      Enemy((310, 80))
      Enemy((400, 80))
      Enemy((490, 80))
      Enemy((580, 80))
      Enemy((670, 80))
      Enemy((760, 80))
      Enemy((850, 80))
      Enemy((940, 80))
 
      #self.blast = Blast(self)
      SpaceShooter.listenKeyEvent("keydown", "space", self.ShootOn)
Example #27
0
 def __init__(self, width, height):
     super().__init__(width, height)
     black = Color(0, 1)
     noline = LineStyle(0, black)
     bg_asset = RectangleAsset(SCREEN_WIDTH, SCREEN_HEIGHT, noline, black)
     bg = Sprite(bg_asset, (0, 0))
     SpaceShip((100, 100))
Example #28
0
def destination(place, file):
    thequestion=input("Welcome to {0}! You may: 1. Look around, 2. Attempt to Trade, 3. Stop to Rest, 4. See your health, 5. Review your items, 6. Go to the Store, 7. Continue on the hike".format(place))
    if thequestion is "1":
        picture=ImageAsset("images/" + file)
        picture_sprite=Sprite(picture, (0,0))
        myapp = App()
        myapp.run()
Example #29
0
 def __init__(self, *args, **kwargs):
     super().__init__(RectangleAsset(1, 1), *args, **kwargs)
     self._val = self.nposinputs.initial()
     self._steps = kwargs.get('steps', 50)
     self._step = (self.nposinputs.maxval() -
                   self.nposinputs.minval()) / self._steps
     self._leftctrl = kwargs.get('leftkey', None)
     self._rightctrl = kwargs.get('rightkey', None)
     self._centerctrl = kwargs.get('centerkey', None)
     self.selectable = True  # must be after super init!
     self.strokable = True  # this enables grabbing/slideing the thumb
     self.thumbcaptured = False
     self._thumbwidth = max(self.stdinputs.width() / 40, 1)
     self.thumb = Sprite(
         RectangleAsset(self._thumbwidth,
                        self.stdinputs.size() - 2,
                        LineStyle(1, self.stdinputs.color()),
                        self.stdinputs.color()), self.thumbXY())
     self._touchAsset()
     if self._leftctrl:
         MathApp.listenKeyEvent("keydown", self._leftctrl, self.moveLeft)
     if self._rightctrl:
         MathApp.listenKeyEvent("keydown", self._rightctrl, self.moveRight)
     if self._centerctrl:
         MathApp.listenKeyEvent("keydown", self._centerctrl,
                                self.moveCenter)
Example #30
0
 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))
Example #31
0
 def hit2(self):
     elapsed = time.time()
     if elapsed > self.end:
         print(self.dead)
         self.dead.destroy()
         global t
         t = 1
         if self.lives == 0:
             gameoverT = TextAsset("Final Score: {0}".format(score))
             Sprite(gameoverT, (myapp.width - 150, 40))
             if SCREEN_WIDTH1 / 1071 < SCREEN_HEIGHT / 571:
                 self.go = Sprite(gameover, (1, 1))
                 self.go.scale = SCREEN_WIDTH1 / 1071
             else:
                 self.go = Sprite(gameover, (1, 1))
                 self.go.scale = SCREEN_HEIGHT / 571
Example #32
0
 def __init__(self, width, height):
     super().__init__(width, height)
     for x in range(self.width // Stars.width + 1):
         for y in range(self.height // Stars.height + 1):
             Stars((x * Stars.width, y * Stars.height))
     self.sun = Sun((self.width / 2, self.height / 2))
     self.ship1 = Ship1(self, (self.width / 2 - 140, self.height / 2),
                        (0, -120), self.sun)
     self.ship2 = Ship2(self, (self.width / 2 + 140, self.height / 2),
                        (0, 120), self.sun)
     self.tsprites = {
         k: Sprite(
             TextAsset(text=v,
                       width=200,
                       align='center',
                       style='20px Arial',
                       fill=Color(0xff2222, 1)))
         for k, v in Spacewar.strings.items()
     }
     self.tsprites['winner'].visible = False
     self.tsprites['winner'].y = self.height / 2
     self.tsprites['tie'].visible = False
     self.tsprites['tie'].position = (self.width / 2 - 100,
                                      self.height / 2 + 50)
     self.tsprites['space'].position = (self.width / 2 - 100,
                                        self.height * 3 / 4)
     self.tsprites['left'].position = (self.width / 4 - 50, self.height / 2)
     self.tsprites['right'].position = (self.width * 3 / 4 - 50,
                                        self.height / 2)
     self.state = 'instructions'
     self.listenKeyEvent('keydown', 'space', self.space)
Example #33
0
  def test_advancedspritecollision(self):
    class SpriteChild(Sprite):
      pass

    s1 = Sprite(self.image, (51,52))
    s2 = Sprite(self.image, (61,52))
    s3 = SpriteChild(self.image, (71,52))
    cl = s1.collidingWithSprites(SpriteChild)
    self.assertEqual(len(cl), 1)
    self.assertIs(cl[0], s3)
    cl = s1.collidingWithSprites()
    self.assertEqual(len(cl), 2)
    s1.destroy()
    s2.destroy()
    s3.destroy()
Example #34
0
SCREEN_WIDTH = 640
SCREEN_HEIGHT = 480


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
Example #35
0
oshape = CircleAsset(30, oline, clear)
xshape = PolygonAsset([(5,5),(35,35),(65,5),(5,65),(35,35),(65,65)], xline, red)

Sprite(vline, (140, 40))
Sprite(vline, (240, 40))
Sprite(hline, (40, 140))
Sprite(hline, (40, 240))

osprites = [ ]
xsprites = [ ]
playeralive = [ ]
compalive = [ ]

for x in [95, 195, 295]:
    for y in [95, 195, 295]:
        so = Sprite(oshape, (x,y))
        so.visible = False
        osprites.append(so)

for x in [60, 160, 260]:
    for y in [60, 160, 260]:
        sx = Sprite(xshape, (x,y))
        sx.visible = False
        xsprites.append(sx)

choice = input("Would you like to be X's or O's? ")
player = 0

while player==0:
    if choice=="x":
        player = xsprites
Example #36
0
SCREEN_WIDTH = 640
SCREEN_HEIGHT = 480

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()
Example #37
0
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()
Example #38
0
SCREEN_HEIGHT = 480

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
Example #39
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
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()
Example #40
0
from ggame import LineStyle, Color, Sprite, Sound

white = Color(0xffffff, 1.0)
black = Color(0x000000, 1.0)
red = Color(0xff0000, 1.0)
noline = LineStyle(0, black)
line = LineStyle(.2, black)
list1 = []

square = RectangleAsset(20, 20, noline, red) 
screen = RectangleAsset(500,500, line, white)
Sprite(screen,(0,0))

for x in range(0,25):
    for y in range(0,25):
        s = Sprite(square, (20*x,20*y))
        s.visible = False
        list1.append(s)

class Conway(App):
    
    def __init__(self):
        super().__init__()
        self.listenMouseEvent( 'click', self.click)
        self.running = False
        self.listenKeyEvent("keydown", "space", self.spacebar)
        self.listenKeyEvent("keydown", "s", self.skey)
    
    def click(self, event):
        x = event.x
        y = event.y
Example #41
0
 def test_spritevariety(self):
   s1 = Sprite(self.multiimage)
   s2 = Sprite(self.rect)
   s3 = Sprite(self.circ)
   s4 = Sprite(self.ellipse)
   s5 = Sprite(self.line)
   s6 = Sprite(self.poly)
   s7 = Sprite(self.text)
   s1.destroy()
   s2.destroy()
   s3.destroy()
   s4.destroy()
   s5.destroy()
   s6.destroy()
   s7.destroy()
Example #42
0
lights = RectangleAsset(10, 30, noline, yellow)
windshield = RectangleAsset(30, 140, noline, translucent)
handle = RectangleAsset(20, 5, noline, white)

# Now display a rectangle

#Car one
Sprite(rectangle, (100, 200))
Sprite(circle, (475, 400))
Sprite(circle, (225, 400))
Sprite(cartriangle1, (100, 200))
Sprite(cartriangle2, (600, 200))
Sprite(window1, (330, 275))
Sprite(window1, (495, 275))
Sprite(lights, (100, 360))
s1 = Sprite(windshield, (237, 220))
s1.rotation = -0.9
Sprite(handle, (320, 325))
Sprite(handle, (485, 325))

#Car two
Sprite(rectangle2, (700, 200))
Sprite(circle, (1075, 400))
Sprite(circle, (825, 400))
Sprite(cartriangle1, (700, 200))
Sprite(cartriangle2, (1200, 200))
Sprite(window1, (930, 275))
Sprite(window1, (1095, 275))
Sprite(lights, (700, 360))
s2 = Sprite(windshield, (837, 220))
s2.rotation = -0.9
Example #43
0
from ggame import LineStyle, Color

SCREEN_WIDTH = 500
SCREEN_HEIGHT = 500

green = Color(0x00ff00, 1)
blue = Color(0x2EFEF7, 1)
black = Color(0, 1)
noline = LineStyle(0, black)
bg_asset = RectangleAsset(SCREEN_WIDTH, SCREEN_HEIGHT, noline, green)
bg = Sprite(bg_asset, (0,0))



ball_asset = ImageAsset("images/orb-150545_640.png")
ball = Sprite(ball_asset, (0, 0))

ball.scale = 0.07
ball.y = 200

ball.dir = 0.76
ball.go = True

def reverse(b):
    b.dir *= -0.76
    pop.play()

def step():
    if ball.go:
        ball.x += ball.dir
        if ball.x + ball.width > SCREEN_WIDTH or ball.x < 0:
Example #44
0
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()
Example #45
0
nlu = LineStyle(5 , blue)
thickline = LineStyle(5 , red)
thickline2 = LineStyle(5, orange)
circle = CircleAsset(10, noline, beige)


poly = PolygonAsset([(20,20), (30,40), (50,160), (20,100)], thickline, red)
portal1 = EllipseAsset(40, 10, nlu, white)
rectum = RectangleAsset(40, 60, thickline2, orange)
portal2 = EllipseAsset(40, 10, thickline2, white)
rectum2 = RectangleAsset(40, 30, thickline2, orange)
legs = RectangleAsset(5, 30, thickline2, orange)
#arm1 =
#arm2 = 

arm1 = Sprite(legs, (130, 480))
arm2 = Sprite(legs, (30, 480))
arm1.rotation=-1
arm2.rotation=1
#arm1.roation=.5

Sprite(circle, (80, 478)) 
Sprite(poly, (90, 530))
Sprite(portal1, (80, 150))
Sprite(portal2, (80, 550))
Sprite(rectum, (60, 490))
Sprite(rectum2, (60, 150))
Sprite(legs, (60, 180))
Sprite(legs, (95, 180))

Example #46
0
            gameend = True
            if wintext.visible == False:
                losetext.visible = True
        if wintext.visible == False:
            secondslist[secondssincestart].visible = True

#Win/Lose message
youwin = TextAsset("Congrats, you win!!")
youlose = TextAsset("Sorry, but you lose :(")
for s in secondslist:
    s.visible = False
for s in blocklist:
    s.visible = False
blocklist[0].visible = True

wintext = Sprite(youwin, (0, 0))
wintext.visible = False
losetext = Sprite(youlose, (0, 365))
losetext.visible = False
blockcount = 0

#Mouse clicks
def mouseClick(event):
    global blockcount
    if gameend == False:
        if blockcount >= len(blocklist):
            return
        if event.x >= blocklist[blockcount].x and event.y >= blocklist[blockcount].y and event.x <= blocklist[blockcount].x + 50 and event.y <= blocklist[blockcount].y + 50:
            if event.x >= rect11.x and event.y >= rect11.y and event.x <= rect11.x + 50 and event.y <= rect11.y + 50:
                wintext.visible = True
            #blocklist[blockcount].visible = False
Write and submit a program that implements the spacewar game:
https://github.com/HHS-IntroProgramming/Spacewar

"""
from ggame import App, RectangleAsset, ImageAsset, Sprite, LineStyle, Color, Frame
from math import sin, cos

SCREEN_WIDTH = 1423
SCREEN_HEIGHT = 788

asset1 = ImageAsset("images/starfield.jpg")
width = 512
height = 512
 
stars = Sprite(asset1)
stars1 = Sprite(asset1)
stars1.x = 512
stars1.y = 0
stars2 = Sprite(asset1)
stars2.x = 1024
stars2.y = 0
stars3 = Sprite(asset1)
stars3.x = 0
stars3.y = 512
stars4 = Sprite(asset1)
stars4.x = 512
stars4.y = 512
stars5 = Sprite(asset1)
stars5.x = 1024
stars5.y = 512