Beispiel #1
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)
Beispiel #2
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)
Beispiel #3
0
 def playing(self, event):
     self.prompt.destroy()
     self.play = True
     if self.play == True:
         player((50, 640))
         Barrel((70, 145))
         black = Color(1, 0)
         Black = Color(0, 1)
         Red = Color(0xF44366, 1.0)
         noline = LineStyle(1000, Black)
         oline = LineStyle(0, Red)
         white = Color(0xfafafa, 1.0)
         yellow = Color(0xffca28, 1.0)
         liner = LineStyle(1, white)
         brown = Color(0x996633, 1.0)
         Blue = Color(0x558b24, 1.0)
         wall(RectangleAsset(700, 30, oline, Red), (0, 670))
         wall(RectangleAsset(550, 30, oline, Red), (0, 500))
         wall(RectangleAsset(550, 30, oline, Red), (150, 330))
         wall(RectangleAsset(600, 30, oline, Red), (0, 160))
         wall(RectangleAsset(100, 30, oline, Red), (100, 50))
         ladder(RectangleAsset(10, 170, oline, Blue), (550, 500))
         ladder(RectangleAsset(10, 170, oline, Blue), (140, 330))
         ladder(RectangleAsset(10, 170, oline, Blue), (600, 160))
         trophy(RectangleAsset(25, 25, liner, yellow), (100, 22))
Beispiel #4
0
    def test_geometry(self):
        self.ip = ImagePoint("bunny.png", (0, 0))
        self.ip.movable = True
        self.p1 = Point((0, 0), color=Color(0x008000, 1))
        self.p1.movable = True
        self.p2 = Point((0, -1))
        self.p3 = Point((1.2, 0))
        self.l1 = LineSegment(self.p2,
                              self.p3,
                              style=LineStyle(3, Color(0, 1)))
        self.l2 = LineSegment(self.p2,
                              self.p1,
                              style=LineStyle(3, Color(0, 1)))
        self.c2 = Circle((-1, -1), self.p1)

        ma = MathApp()
        ma.run()

        self.ip.destroy()
        self.p1.destroy()
        self.p2.destroy()
        self.p3.destroy()
        self.c2.destroy()
        self.l1.destroy()
        self.l2.destroy()
Beispiel #5
0
class Bullet(Sprite):
    
    red = Color(0xff0000, 1.0)
    noline = LineStyle(0, red)
    # Red bullets (boring)
    #asset = CircleAsset(5, noline, red)
    
    # How to get this frame working?
    asset = ImageAsset("images/blast.png", Frame(0,0,8,8), 8, 'horizontal')
    
    #asset = ImageAsset("images/four_spaceship_by_albertov_with_thrust.png", Frame(227,0,65,125), 4, 'vertical')
    
    def __init__(self, position, direction):
        super().__init__(Bullet.asset, [position[0] - 50 * math.sin(direction), position[1] - 50 * math.cos(direction)])
        self.vx = -5 * math.sin(direction)
        self.vy = -5 * math.cos(direction)
        self.vr = 0
        self.fxcenter = self.fycenter = 0.5
        self.bulletphase = 0
        
    def step(self):
        self.x += self.vx
        self.y += self.vy
        
        # manage bullet animation
        self.setImage(self.bulletphase%7)
        self.bulletphase += 1
Beispiel #6
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)
Beispiel #7
0
    def run(self, rocket=None):
        """
        Execute the Planet (and Rocket) simulation.

        Optional parameters:
        
        * **rocket** Reference to a Rocket object - sets the initial view
        """
        if rocket:
            viewalt = rocket.altitude
            viewanom = rocket.tanomaly
        else:
            viewalt = 0
            viewanom = pi / 2
        self.viewaltitude = self.kwargs.get('viewalt',
                                            viewalt)  # how high to look
        self.viewanomaly = self.kwargs.get('viewanom',
                                           viewanom)  # where to look
        self.viewanomalyd = self.kwargs.get('viewanomd',
                                            degrees(self.viewanomaly))
        self.planetcircle = Circle((0, 0),
                                   self.radius,
                                   style=LineStyle(1, Color(self.color, 1)),
                                   color=Color(self.color, 0.5))
        r = self.radius + self.viewaltitude
        self.viewPosition = (r * cos(self.viewanomaly),
                             r * sin(self.viewanomaly))
        super().run()
Beispiel #8
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)
Beispiel #9
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))
 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
Beispiel #11
0
class asteroid(Sprite):
    grey=Color(0xbebebe,1)
    asteroidline=LineStyle(2,grey)
    asteroid_asset =RectangleAsset(30, 30, asteroidline, grey)
    def __init__(self, position, spaceship):
        super().__init__(asteroid.asteroid_asset, position)
        self.vx = 0
        self.vy = 0
        self.thrust=1
        self.spaceship=spaceship
    def step(self):
        self.x += self.vx
        self.y += self.vy
        if self.thrust == 1 and self.visible==True:
            self.x += 0
            self.y += 1
            if self.y>600:
                print("you lose")
        if self.visible==False:
            pass
        if self.collidingWithSprites(bullet) and self.visible==True:
            self.visible=False
            ExplosionSmall(self.position)
            self.destroy()
            print("good job")
Beispiel #12
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))
Beispiel #13
0
 def __init__(self, width, height):
     super().__init__(width, height)
     black = Color(1, 0)
     Black = Color(0, 1)
     Blue = Color(0x0000ff, 1.0)
     noline = LineStyle(5, Black)
     Noline = LineStyle(0, Black)
     bg_asset = RectangleAsset(width, height, noline, black)
     Platformer.listenKeyEvent("keydown", "w", self.Wall)
     Platformer.listenKeyEvent("keydown", "p", self.Boxy)
     Platformer.listenKeyEvent("keydown", "s", self.Springo)
     Platformer.listenMouseEvent('mousemove', self.mousemove)
     self.Robbie = False
     bg = Sprite(bg_asset, (0, 0))
     self.x = 0
     self.y = 0
Beispiel #14
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)
Beispiel #15
0
 def test_rectangleasset(self):
     r = RectangleAsset(10, 20, LineStyle(3, Color(0x112233, 0.5)),
                        Color(0x223344, 0.6))
     self.assertEqual(r.gfx.visible, False)
     self.assertEqual(r.width, 10)
     self.assertEqual(r.height, 20)
     self.assertEqual(r.gfx.x, 0)
Beispiel #16
0
 def test_ellipseasset(self):
     e = EllipseAsset(40, 50, LineStyle(4, Color(0x113355, 0.6)),
                      Color(0x224466, 0.7))
     self.assertEqual(e.gfx.visible, False)
     self.assertEqual(e.gfx.ehw, 40)
     self.assertEqual(e.gfx.ehh, 50)
     self.assertEqual(e.gfx.x, 0)
Beispiel #17
0
 def __init__(self,x,y,w,h,COLOR,app):
     self.vx=0
     self.vy=0
     self.app=app
     self.stuck=False
     self.resting=False
     BOX=RectangleAsset(w,h,LineStyle(0, white),COLOR)
     super().__init__(BOX,(x, y)) 
Beispiel #18
0
 def __init__(self, x, y, w, h, color):
     snapfunc = lambda X : X - X % w
     super().__init__(
         RectangleAsset(w-1,h-1,LineStyle(0,Color(0x0000ff, 1.0)), color),
         (snapfunc(x), snapfunc(y)))
     collideswith = self.collidingWithSprites(type(self))
     if len(collideswith):
         collideswith[0].destroy()
Beispiel #19
0
 def __init__(self, x, y, w, h, color):
     grid = lambda X : X - X % w
     super().__init__(
         RectangleAsset(w-1, h-1, LineStyle(0,Color(0, 1.0)), color),(grid(x), grid(y)))
     #collisions
     collisioncontra =self.collidingWithSprites(type(self))
     if len(collisioncontra):
         collisioncontra[0].destroy()
 def __init__(self, x, y, color, app):
     super().__init__(
         EllipseAsset(12, 12, LineStyle(0, Color(0, 1.0)), color), (x, y))
     self.xdirection = 0
     self.ydirection = 0
     self.go = True
     self.pacisalive = True
     self.stopscore = False
Beispiel #21
0
class Wall(Sprite):
    # Create asset
    black = Color(0, 1)
    noline = LineStyle(0, black)
    rect = RectangleAsset(10, 10, noline, black)

    def __init__(self, position, asset):
        super().__init__(asset, position)
Beispiel #22
0
 def __init__(self, direction, x, y, app):
     w = 15
     h = 5
     self.direction = direction
     self.app = app
     super().__init__(RectangleAsset(w, h, 
         LineStyle(0, Color(0, 1.0)),
         Color(0x00ffff, 1.0)),
         (x-w//2, y-h//2))
Beispiel #23
0
 def __init__(self):
     super().__init__()
     # Background
     black = Color(0, 1)
     noline = LineStyle(0, black)
     bg_asset = ImageAsset("images/starfield.jpg")
     bg = Sprite(bg_asset, (0, 0))
     SpaceShip((100, 100))
     SpaceShip2((400, 400))
Beispiel #24
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))
     SpaceShip((100, 100))
     SpaceShip((150, 150))
     SpaceShip((200, 50))
Beispiel #25
0
 def test_polygonasset(self):
     p = PolygonAsset(
         [(10, 10), (20, 10), (15, 15), (10, 10)],
         LineStyle(6, Color(0x665544, 0.9)),
         Color(0x664422, 1.0),
     )
     self.assertEqual(len(p.gfx.jpath), 8)
     self.assertEqual(p.gfx.jpath[4], 15)
     self.assertEqual(p.gfx.visible, False)
Beispiel #26
0
 def test_linestyle(self):
     color = 0x001122
     alpha = 0.5
     c = Color(color, alpha)
     pixels = 9
     l = LineStyle(pixels, c)
     self.assertEqual(l.width, pixels)
     self.assertEqual(l.color.color, color)
     self.assertEqual(l.color.alpha, alpha)
Beispiel #27
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)
Beispiel #28
0
class Apple(Sprite):
    # Create asset
    black = Color(0, 1)
    noline = LineStyle(0, black)
    rect = RectangleAsset(15, 15, noline, black)

    #circ = CircleAsset(7.5, noline, black)

    def __init__(self, position):
        super().__init__(Apple.rect, position)
Beispiel #29
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)
Beispiel #30
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 = Sprite(bg_asset, (0,0))
     SpaceShip((100,200))
     SpaceShip((300,200))
     SpaceShip((200,200))
     SpaceShip((600, 450))