Esempio n. 1
0
    def test_fancycontrols(self):
        self.imgbutton = InputImageButton("ggimages/button-round.png",
                                          self.pressbutton, (0, 0),
                                          frame=Frame(0, 0, 100, 100),
                                          qty=2)
        self.imgbutton.scale = 0.5
        self.ii = ImageIndicator("ggimages/red-led-off-on.png", (300, 500),
                                 self.imgbutton,
                                 positioning="physical",
                                 frame=Frame(0, 0, 600, 600),
                                 qty=2)
        self.ii.scale = 0.1
        self.glassbutton = GlassButton(None, (0, -0.5))
        self.toggle = MetalToggle(0, (0, -1))
        self.Li = LEDIndicator((300, 450),
                               self.glassbutton,
                               positioning="physical")
        self.Lit = LEDIndicator((300, 480),
                                self.toggle,
                                positioning="physical")

        ma = MathApp()
        ma.run()

        self.imgbutton.destroy()
        self.ii.destroy()
        self.glassbutton.destroy()
        self.toggle.destroy()
        self.Li.destroy()
        self.Lit.destroy()
class ObstacleS(Sprite):

    asset = ImageAsset("images/platformer_sprites_base.png",
                       Frame(0, 192, 64, 64), 8, 'horizontal')
    """asset.append("images/platformer_sprites_base -left.png",
        Frame(0, 192, 64, 64), 8, 'horizontal')"""
    asset.append("images/platformer_sprites_base.png", Frame(0, 64, 64, 64), 8,
                 'horizontal')
    """asset.append("images/platformer_sprites_base -left.png",
        Frame(0, 64, 64, 64), 8, 'horizontal')"""
    def __init__(self, position):
        super().__init__(ObstacleS.asset, position)
        self.animateosr = 8
        "self.animateosl = 8"

    def step(self):
        global Game
        self.left = Game.Pal.left
        self.right = Game.Pal.right
        self.x -= Game.Pal.tv - 8
        """if self.left == True:
            #self.x += Game.Pal.tv - 4 + Game.Pal.tv - 4
            self.setImage(self.animateosl)
            self.animateosl -= 0.2
            if self.animateosl >= 15:
                self.animateosl = 8"""
        self.setImage(self.animateosr)
        self.animateosr += 0.2
        if self.animateosr >= 16:
            self.animateosr = 8
Esempio n. 3
0
 def test_frame(self):
     f1 = Frame(10, 20, 30, 40)
     self.assertEqual(f1.x, 10)
     self.assertEqual(f1.y, 20)
     self.assertEqual(f1.w, 30)
     self.assertEqual(f1.h, 40)
     self.assertEqual(f1.center, (25, 40))
     f1.center = (15, 30)
     self.assertEqual(f1.x, 0)
     self.assertEqual(f1.y, 10)
     self.assertEqual(f1.w, 30)
     self.assertEqual(f1.h, 40)
     self.assertEqual(f1.center, (15, 30))
Esempio n. 4
0
 def test_frame(self):
   f1 = Frame(10, 20, 30, 40)
   self.assertEqual(f1.x, 10)
   self.assertEqual(f1.y, 20)
   self.assertEqual(f1.w, 30)
   self.assertEqual(f1.h, 40)
   self.assertEqual(f1.center, (25, 40))
   f1.center = (15,30)
   self.assertEqual(f1.x, 0)
   self.assertEqual(f1.y, 10)
   self.assertEqual(f1.w, 30)
   self.assertEqual(f1.h, 40)
   self.assertEqual(f1.center, (15, 30))
Esempio n. 5
0
class Blast(Sprite):
    asset = ImageAsset("images/player1.png", Frame(134,30,18,30), 1, 'vertical')
    collisionasset = CircleAsset(5)
    
    def __init__(self, app):
        super().__init__(Blast.asset,  (0,0))
        self.visible = False
        self.firing = False
        self.time = 0
        self.vy = 0
        self.vx = 0
        self.vr = 0
        
    def shoot(self, position, velocity, time):
        self.position = position
        self.vx = 0
        self.vy = -8
        self.time = time
        self.visible = True
        self.firing = True
        
    def step(self):
        self.x += self.vx
        self.y += self.vy
        self.rotation += self.vr
Esempio n. 6
0
 def __init__(self, arg):
     super().__init__(arg)
     self.image = ImageAsset("bunny.png")
     self.rocket = ImageAsset("ggimages/rocket.png")
     self.multiimage = ImageAsset("bunny.png", Frame(2, 2, 10, 14), 3,
                                  'horizontal', 2)
     color = 0x001122
     alpha = 0.5
     self.c = Color(color, alpha)
     pixels = 9
     self.l = LineStyle(pixels, color)
     self.rect = RectangleAsset(10, 20, LineStyle(3, Color(0x112233, 0.5)),
                                Color(0x223344, 0.6))
     self.circ = CircleAsset(30, LineStyle(3, Color(0x112233, 0.5)),
                             Color(0x223344, 0.6))
     self.ellipse = EllipseAsset(40, 50, LineStyle(4, Color(0x113355, 0.6)),
                                 Color(0x224466, 0.7))
     self.line = LineAsset(60, 70, LineStyle(5, Color(0x224466, 0.7)))
     self.poly = PolygonAsset([(10, 10), (20, 10), (15, 15), (10, 10)],
                              LineStyle(6, Color(0x665544, 0.9)),
                              Color(0x664422, 1.0))
     self.text = TextAsset("sample text",
                           style="20px Arial",
                           width=200,
                           fill=Color(0x123456, 1.0),
                           align='center')
Esempio n. 7
0
class Asteroid(Sprite):
    asset = ImageAsset("images/Asteroid2_spritesht.png",
                       Frame(256, 0, 128, 128), 8, 'vertical')

    def __init__(self, im_num, position):
        super().__init__(Asteroid.asset, position)
        self.setImage(im_num)
Esempio n. 8
0
class Shooter(Sprite):
    asset = ImageAsset("images/player1.png", 
        Frame(119,90,50,50), 1, 'vertical')
        
    
    def __init__(self, position):
        super().__init__(Shooter.asset, position)
        self.vx = 0
        self.vy = 0
        self.vr = 0
        self.rotation = 0
        self.fxcenter = .31
        SpaceShooter.listenKeyEvent("keydown", "a", self.LOn)
        SpaceShooter.listenKeyEvent("keyup", "a", self.LOff)
        SpaceShooter.listenKeyEvent("keydown", "d", self.ROn)
        SpaceShooter.listenKeyEvent("keyup", "d", self.ROff)
        

    def step(self):
        self.x += self.vx
        self.y += self.vy
        self.rotation += self.vr
    def LOn(self, event):
        self.vx = -5
    def LOff(self, event):
        self.vx = 0
    def ROn(self, event):
        self.vx = 5
    def ROff(self, event):
        self.vx = 0
Esempio n. 9
0
    def test_controls(self):
        self.imgbutton = InputImageButton("ggimages/button-round.png",
                                          self.pressbutton, (0, 0),
                                          frame=Frame(0, 0, 100, 100),
                                          qty=2)
        self.imgbutton.scale = 0.5
        self.vslider1 = Slider((100, 150),
                               0,
                               250,
                               125,
                               positioning='physical',
                               steps=10)
        self.label = Label(self.labelcoords,
                           self.buttonstatus,
                           size=15,
                           positioning="physical",
                           color=self.labelcolor)
        self.button = InputButton(self.pressbutton,
                                  self.buttoncoords,
                                  "Press Me",
                                  size=15,
                                  positioning="physical")
        self.numinput = InputNumeric((300, 275), 3.14, positioning="physical")

        ma = MathApp()
        ma.run()

        self.vslider1.destroy()
        self.label.destroy()
        self.button.destroy()
        self.numinput.destroy()
        self.imgbutton.destroy()
Esempio n. 10
0
 def __init__(self, x, y, app):
     w = 10
     h = 4
     asset = ImageAsset("20150207151848!Trampoline-2 copy 4.png",
                        Frame(17, 62, 161, 66))
     super().__init__(asset, x, y, app)
     self.scale = 0.5
Esempio n. 11
0
class SpaceShip(Sprite):
    """
    Animated space ship
    """
    asset = ImageAsset("images/four_spaceship_by_albertov_with_thrust.png",
                       Frame(227, 0, 292 - 227, 125), 4, 'vertical')

    def __init__(self, position):
        super().__init__(SpaceShip.asset, position)
        self.vx = 1
        self.vy = 1
        self.vr = 0.01
        self.thrust = 0
        self.thrustframe = 1
        SpaceGame.listenKeyEvent("keydown", "space", self.thrustOn)
        SpaceGame.listenKeyEvent("keyup", "space", self.thrustOff)
        self.fxcenter = self.fycenter = 0.5

    def step(self):
        self.x += self.vx
        self.y += self.vy
        self.rotation += self.vr
        if self.thrust == 1:
            self.setImage(self.thrustframe)
            self.thrustframe += 1
            if self.thrustframe == 4:
                self.thrustframe = 1
        else:
            self.setImage(0)

    def thrustOn(self, event):
        self.thrust = 1

    def thrustOff(self, event):
        self.thrust = 0
Esempio n. 12
0
class SpaceShip(Sprite):
    """
    Animated space ship
    """
    asset = ImageAsset("images/four_spaceship_by_albertov_with_thrust.png", Frame(227,0,65,125), 4, 'vertical')

    def __init__(self, position):
        super().__init__(SpaceShip.asset, position)
        self.vx = 0
        self.vy = 0
        self.vr = 0.00
        
        self.fxcenter = self.fycenter = 0.45

    def step(self):
        self.x += self.vx
        self.y += self.vy
        self.rotation += self.vr
        
        # manage thrust animation
        if self.thrust == 1:
            self.setImage(self.thrustframe)
            self.thrustframe += 1
            if self.thrustframe == 4:
                self.thrustframe = 1
        else:
            self.setImage(0)
Esempio n. 13
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
Esempio n. 14
0
 def __init__(self, position, rotation):
     asset = ImageAsset("download.png",
                        Frame(56.25, 56.25, 56.25 * 2, 56.25 * 2.1))
     super().__init__(asset, position)
     self.scale = .3
     self.fxcenter = .5
     self.fycenter = 0
     self.rotation = rotation
Esempio n. 15
0
 def test_multiimageasset(self):
     a = ImageAsset("bunny.png", Frame(2, 2, 10, 14), 3, "horizontal", 2)
     self.assertEqual(a.gfxlist[0].basewidth, 71)
     self.assertEqual(a.gfxlist[0].framerect.x, 2)
     self.assertEqual(a.gfxlist[0].framerect.height, 14)
     self.assertEqual(len(a.gfxlist), 3)
     self.assertEqual(a.gfxlist[1].framerect.x, 14)
     self.assertEqual(a.gfxlist[2].framerect.x, 26)
     a.destroy()
Esempio n. 16
0
class SpaceShip(Sprite):
    """
    Animated space ship
    """
    asset = ImageAsset("images/four_spaceship_by_albertov_with_thrust.png",
                       Frame(227, 0, 292 - 227, 125), 4, 'vertical')

    def __init__(self, position):
        super().__init__(SpaceShip.asset, position)
Esempio n. 17
0
class Bullet(GravitySprite):

    asset = ImageAsset("images/blast.png", Frame(0, 0, 8, 8), 8)
    pewasset = SoundAsset("sounds/pew1.mp3")

    def __init__(self, app, sun, sun2):
        super().__init__(Bullet.asset, (0, 0), (0, 0), sun, sun2)
        self.visible = False
        self.firing = False
        self.time = 0
        self.circularCollisionModel()
        self.pew = Sound(Bullet.pewasset)
        self.pew.volume = 10

    def shoot(self, position, velocity, time):
        self.position = position
        self.vx = velocity[0]
        self.vy = velocity[1]
        self.time = time
        self.visible = True
        self.firing = True
        self.pew.play()

    def step(self, T, dT):
        if self.time > 0:
            self.time = self.time - dT
            if self.visible:
                self.nextImage(True)
                super().step(T, dT)
                if self.collidingWith(self.sun):
                    self.visible = False
                if self.collidingWith(self.sun2):
                    self.visible = False
                    ExplosionSmall(self.position)
                ships = []
                ships = self.collidingWithSprites(Ship1)
                ships.extend(self.collidingWithSprites(Ship2))
                if len(ships):
                    if not self.firing and ships[0].visible:
                        ships[0].hitCount = ships[0].hitCount + 1
                        self.visible = False
                        ExplosionSmall(self.position)
                    if ships[0].hitCount >= 3:
                        ships[0].explode()
                        ships[0].hitCount = 0
                        self.visible = False

                    if ships[0].hitCount >= 2:
                        ships[0].shipThrust = int(ships[0].shipThrust) / 3

                elif self.firing:
                    self.firing = False

        else:
            if self.visible:
                self.visible = False
            self.time = 0
Esempio n. 18
0
class SpaceShip(Sprite):
    asset = ImageAsset("images/four_spaceship_by_albertov_with_thrust.png",
                       Frame(227, 0, 65, 125), 4, 'vertical')

    def __init__(self, position):
        super().__init__(SpaceShip.asset, position)
        self.vx = 1
        self.vy = 1
        self.vr = 0.01
        self.thrust = 0
        self.thrustframe = 1
        SpaceGame.listenKeyEvent("keydown", "space", self.thrustOn)
        SpaceGame.listenKeyEvent("keyup", "space", self.thrustOff)
        SpaceGame.listenKeyEvent("keydown", "left arrow", self.leftRotate)
        SpaceGame.listenKeyEvent("keydown", "right arrow", self.rightRotate)
        SpaceGame.listenKeyEvent("keydown", "A", self.left)
        SpaceGame.listenKeyEvent("keydown", "D", self.right)
        SpaceGame.listenKeyEvent("keydown", "W", self.up)
        SpaceGame.listenKeyEvent("keydown", "S", self.down)
        self.fxcenter = self.fycenter = 0.5

    def step(self):
        self.x += self.vx
        self.y += self.vy
        self.rotation += self.vr
        if self.thrust == 1:
            self.setImage(self.thrustframe)
            self.thrustframe += 1
            if self.thrustframe == 4:
                self.thrustframe = 1
        else:
            self.setImage(0)

    def thrustOn(self, event):
        self.thrust = 1

    def thrustOff(self, event):
        self.thrust = 0

    def rightRotate(self, event):
        self.vr -= 0.01

    def leftRotate(self, event):
        self.vr += 0.01

    def left(self, event):
        self.vx -= 0.5

    def right(self, event):
        self.vx += 0.5

    def up(self, event):
        self.vy -= 0.5

    def down(self, event):
        self.vy += 0.5
Esempio n. 19
0
class plane(Sprite):
    asset = ImageAsset("images/four_spaceship_by_albertov_with_thrust.png",
                       Frame(227, 0, 292 - 227, 125), 1, 'vertical')

    #asset = ImageAsset("https://github.com/averywallis/Radar/blob/master/images/plane.png")
    def __init__(self, position):
        super().__init__(plane.asset, position)
        self.rotation = math.pi / 2
        self.fxcenter = 0.5
        self.fycenter = 0.5
Esempio n. 20
0
 def __init__(self, initindex, *args, **kwargs):
     """
     Required Inputs
     
     * **initindex** index to initial toggle state
     * **pos** position of toggle
     """
     kwargs.setdefault('frame', Frame(0, 0, 110, 150))
     super().__init__("toggle-up-down.png", [True, False], initindex, *args,
                      **kwargs)
     self.scale = 0.4
Esempio n. 21
0
class Sun(Sprite):

    width = 80
    height = 76
    asset = ImageAsset("images/sun.png", Frame(0, 0, width, height))

    def __init__(self, position):
        super().__init__(Sun.asset, position, CircleAsset(32))
        self.mass = 30 * 1000
        self.fxcenter = 0.5
        self.fycenter = 0.5
Esempio n. 22
0
 def __init__(self, callback, *args, **kwargs):
     """
     Required Inputs
     
     * **callback** reference of a function to execute, passing this button object
     * **pos** position of point
     """
     kwargs.setdefault('frame', Frame(0, 0, 100, 100))
     kwargs.setdefault('qty', 2)
     super().__init__("button-round.png", callback, *args, **kwargs)
     self.scale = 0.3
Esempio n. 23
0
    def __init__(self, *args, **kwargs):
        """
        Required Inputs
        
        * **pos** position of point
        * **value** state of the indicator (True/False or integer)

        """
        kwargs.setdefault('frame', Frame(0, 0, 600, 600))
        kwargs.setdefault('qty', 2)
        super().__init__("red-led-off-on.png", *args, **kwargs)
        self.scale = 0.05
Esempio n. 24
0
class ExplosionSmall(Sprite):
    ExplosionSmall_asset = ImageAsset("images/explosion1.png", 
    Frame(0,0,128,128), 10)
    def __init__(self, position):
        super().__init__(ExplosionSmall.ExplosionSmall_asset, position)
        self.fxcenter = self.fycenter = 0.5
        self.image=0
    def step(self):    
        self.setImage(self.image)
        self.image = self.image + 1
        if self.image == 20:
            self.destroy()
Esempio n. 25
0
class Cell(Sprite):
    """
    
    """
    asset = ImageAsset("greenandyellow.jpg", Frame(50, 50, cell_size,
                                                   cell_size), 1, 'horizontal')
    asset.append("greenandyellow.jpg", Frame(60, 60, cell_size, cell_size), 1,
                 'horizontal')

    def __init__(self, position):
        super().__init__(Cell.asset, position)
        self.setImage(0)

    def ageCell(self):
        self.setImage(1)

    def step(self):
        self.ageCell()

    def getPosition(self):
        return ((self.x, self.y))
Esempio n. 26
0
class Rocket(Sprite):
    rocketpic = ImageAsset("images/four_spaceship_by_albertov_with_thrust.png",
                           Frame(227, 0, 65, 125), 4, 'vertical')

    def __init__(self, position):
        super().__init__(Rocket.rocketpic, position)
        self.vx = 1
        self.vy = 1
        self.vr = 0.01
        self.thrust = 0
        self.thrustframe = 1
        self.center = (0.5, 0.5)

        SpaceShooter.listenKeyEvent("keydown", "right arrow",
                                    self.rightarrowKey)
        SpaceShooter.listenKeyEvent('keydown', "left arrow", self.leftarrowKey)
        SpaceShooter.listenKeyEvent('keydown', "up arrow", self.uparrowKey)
        SpaceShooter.listenKeyEvent('keydown', "down arrow", self.downarrowKey)

    def rightarrowKey(self, event):
        self.vx += .2
        '''print(ImageAsset("images/blast.png"))'''

    def leftarrowKey(self, event):
        self.vx += -.2

    def uparrowKey(self, event):
        self.vy += -.2

    def downarrowKey(self, event):
        self.vy += .2

    def step(self):
        self.x += self.vx
        self.y += self.vy
        self.rotation += self.vr
        collision = self.collidingWith

        if self.thrust == 5:
            self.setImage(self.thrustframe)
            self.thrustframe += 1
            if self.thrustframe == 4:
                self.thrustframe = 1
        else:
            self.setImage(0)

    def collidingWithSprites(sun, sclass=None):
        if sclass is None:
            slist = App.spritelist
        else:
            slist = App.getSpritesbyClass(sclass)
        return list(filter(self.collidingWith, slist))
Esempio n. 27
0
class explosionn(Sprite):
    asset = ImageAsset("images/explosion1.png", Frame(0, 0, 128, 128), 10)

    def __init__(self, position):
        super().__init__(explosionn.asset, position)
        self.image = 0
        self.center = (0.5, 0.5)

    def step(self):
        self.setImage(self.image // 2)
        self.image = self.image + 1
        if self.image == 20:
            self.destroy()
Esempio n. 28
0
class BigExplosion(Sprite):
    image = ImageAsset("images/explosion2.png", Frame(0, 0, 192, 195), 25)

    def __init__(self, position):
        super().__init__(BigExplosion.image, position)
        self.frame = 0
        self.fxcenter = 0.5
        self.fycenter = 0.5

    def step(self):
        self.frame += 1
        if self.frame == 50:
            self.destroy()
Esempio n. 29
0
class explosion(Sprite):
    asset = ImageAsset("images/explosion2.png", Frame(0,0,192-0,195), 25, 'horizontal')
    def __init__(self, position):
        super().__init__(explosion.asset, position)
        self.FrameNum=0
        self.speed=0.0
    def step(self):
        self.setImage(self.FrameNum)
        self.speed+=0.2
        self.FrameNum=int(self.speed)
        self.FrameNum += 1
        if self.FrameNum==25:
            self.destroy()
Esempio n. 30
0
class explosion(Sprite):
    asset = ImageAsset("images/explosion2.png", Frame(0, 0, 192 - 0, 195), 25,
                       'horizontal')

    def __init__(self, position):
        super().__init__(explosion.asset, position)
        self.explosion = 0
        self.explosionframe = 1

    def step(self):
        self.setImage(self.explosionframe)
        self.explosionframe += 1
        if self.explosionframe == 25:
            self.destroy()
Esempio n. 31
0
class ExplosionBig(Sprite):
    
    asset = ImageAsset("images/explosion2.png", Frame(0,0,4800/25,195), 25)
    
    def __init__(self, position):
        super().__init__(ExplosionBig.asset, position)
        self.image = 0
        self.center = (0.5, 0.5)
        
    def step(self):
        self.setImage(self.image//0.5)  # slow it down
        self.image = self.image + 1
        if self.image == 50:
            self.destroy()