Example #1
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()
Example #2
0
 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)
Example #3
0
class Sun(Sprite):
    asset = ImageAsset("images/sun.png")
    width = 80
    height = 76

    def __init__(self, position):
        super().__init__(Sun.asset, position)
        self.fxcenter = 0.0
        self.fycenter = -1.0

    def step(self):
        if self.setImage(1):
            collides = self.collidingWithSprites(Rocket1)
        if self.setImage(2):
            collides = self.collidingWithSprites(Rocket2)

    def explode(self):
        self.visible = False
        ExplosionBig(self.position)
        self.waitspawn = 500
Example #4
0
class astroid(Sprite):
    asset = ImageAsset("images/asteroid1.png", 
    Frame(0,0,72,72), 4, 'vertical')
    
    def __init__(self, position, width, height):
        super().__init__(astroid.asset, position)    
        self.avx = 0
        self.widthscreen = width
        self.heightscreen = height
        self.avy = 0
        self.avr = 0.05
        self.circularCollisionModel()

        self.randomx = 0
        self.randomy = 0
        self.fxcenter = self.fycenter = 0.5
        self.randomxn = 0
        self.randomyn = 0
        
        self.randomx = zufaellig(0, 3)
        self.randomy = zufaellig(0, 3)
        self.randomxn = zufaellig(0,1)
        self.randomyn = zufaellig(0, 1)
        self.avx = (self.randomx*-1)*6
        self.avy = (self.randomy*-1)*6
        
    def step(self):
        # abfrage
        if self.x > self.widthscreen-30:
            self.avx = self.avx*-1
        elif self.x < 30:
            self.avx = self.avx*-1
        elif self.y < 30:
            self.avy = self.avy*-1
        elif self.y > self.heightscreen-30:
            self.avy = self.avy*-1
            
            
        self.rotation += self.avr
        self.x += self.avx
        self.y += self.avy
Example #5
0
class Present1(Sprite):

    p1_asset = ImageAsset("images/clipart42143.png")

    def __init__(self, position):
        super().__init__(Present1.p1_asset, position)
        self.scale = 0.1
        self.vy = 0
        self.a = 0
        SantaGame.listenMouseEvent("click", self.MouseClick)
        self.visible = True

    totalscore = 0

    def MouseClick(self, event):
        self.vy = 0
        self.a = 0.9

    def step(self):
        self.vy += self.a
        self.y += self.vy

        self.collision = self.collidingWithSprites(
            House1) or self.collidingWithSprites(House2)
        self.gcollision = self.collidingWithSprites(Grinch)

        if self.visible and (self.collision
                             or self.gcollision) or self.y > 800:
            self.x = 350
            self.y = 50
            self.vy = 0
            self.a = 0

        #s_asset=TextAsset(("Presents Delivered: {0}!! :)").format(totalscore), width=500, align='left',style='30px Arial', fill=Color(0xff2222,1))
        if self.visible and self.collision:
            self.totalscore += 1
            #print(self.totalscore)
            Score.scoreChange(self.totalscore)

        if self.visible and self.gcollision:
            myapp.Hlist.removeheart()
Example #6
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))
Example #7
0
    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
Example #8
0
class Enemy(Sprite):
    asset = ImageAsset("images/191-1916209_space-invaders-sprites.png", 
        Frame(140, 200,50,50), 1, 'vertical')
    collisionasset = CircleAsset(40)
    
    def __init__(self, position):
        super().__init__(Enemy.asset, position)
        self.vx = 0
        self.vy = f
        self.vr = 0
        self.rotation = 0
        self.thrust = 0
        
    def step(self):
        self.x += self.vx
        self.y += self.vy
        self.rotation += self.vr
        blast = self.collidingWithSprites(Blast)
        if blast:
            self.destroy()
            blast[0].destroy()
Example #9
0
class Bunny(Sprite):
    
    asset = ImageAsset("ggame/bunny.png")
    
    def __init__(self, position):
        super().__init__(Bunny.asset, position)
        # register mouse events
        self.app.listenMouseEvent(MouseEvent.mousedown, self.mousedown)
        self.app.listenMouseEvent(MouseEvent.mouseup, self.mouseup)
        self.app.listenMouseEvent(MouseEvent.mousemove, self.mousemove)
        self.dragging = False

    
    def step(self):
        """
        Every now and then a bunny hops...
        """
        if random() < 0.001:
            self.x += randint(-50,50)
            self.y += randint(-50,50)
        
    def mousedown(self, event):
        # capture any mouse down within 50 pixels
        self.deltax = event.x - (self.x + self.width//2) 
        self.deltay = event.y - (self.y + self.height//2)
        if abs(self.deltax) < 50 and abs(self.deltay) < 50:
            self.dragging = True
            # only drag one bunny at a time - consume the event
            event.consumed = True
            
    def mousemove(self, event):
        if self.dragging:
            self.x = event.x - self.deltax - self.width//2
            self.y = event.y - self.deltay - self.height//2
            event.consumed = True
            
    def mouseup(self, event):
        if self.dragging:
            self.dragging = False
            event.consumed = True
Example #10
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 = .5
        self.vy = 0
        self.vr = 0.00
        self.thrust = 0
        self.thrustframe = 1
        SpaceGame.listenKeyEvent("keydown", "space", self.thrustOn)
        SpaceGame.listenKeyEvent("keyup", "space", self.thrustOff)
        SpaceGame.listenKeyEvent("keyleaft" , "a" , self.rotationLEFT)
        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 rotationLEFT(self, event):
        self.rotation = slef.vr = 1
     
    def thrustOn(self, event):
        self.thrust = 1

    def thrustOff(self, event):
        self.thrust = 0
Example #11
0
class blast(Sprite):
    boom = ImageAsset("images/blast.png", Frame(0, 0, 8, 8), 4, 'horizontal')

    def __init__(self, position):
        super().__init__(blast.boom, position)
        #boom.scale = 3
        self.newx = 0
        self.newy = 0
        self.blastgo = 0
        self.blastframe = 1
        self.setframe = 0
        SpaceGame.listenKeyEvent("keydown", "enter", self.blastOn)
        self.fxcenter = self.fycenter = 0.5

    def step(self, w, h):
        self.setImage(self.blastframe)
        if self.blastgo == 1:
            if self.setframe == 40:
                self.blastgo = 0
                self.setframe = 0
                self.newx = randint(10, w)
                self.newy = randint(10, h)
                self.setImage(0)
                self.x = -10
                self.y = -10
            else:
                self.x = self.newx
                self.y = self.newy
                self.setImage(self.blastframe)
                self.blastframe += 1
                self.setframe += 1
                if self.blastframe == 7:
                    self.blastframe = 1

    def blastOn(self, event):
        self.blastgo = 1

    def blastOff(self, event):
        self.blastgo = 0
Example #12
0
    def __init__(self, url, *args, **kwargs):
        """
        Required Inputs
        
        * **url** location of image file consisting of two image sprite sheet
        * **pos** position of point
        * **value** state of the indicator (True/False or integer)

        Optional Inputs
        * **frame** sub-frame location of image within file
        * **qty** number of sub-frames, when used as sprite sheet
        * **direction** one of 'horizontal' (default) or 'vertical'
        * **margin** pixels between sub-frames if sprite sheet
        """
        kwargs.setdefault('frame', None)
        kwargs.setdefault('qty', 1)
        kwargs.setdefault('direction', 'horizontal')
        kwargs.setdefault('margin', 0)
        super().__init__(
            ImageAsset(url, kwargs['frame'], kwargs['qty'],
                       kwargs['direction'], kwargs['margin']), *args, **kwargs)
        self.center = (0, 0)
Example #13
0
class EnemyCopter(Sprite):
    ecopter = ImageAsset("images/fighter1.png")

    def __init__(self, position):
        super().__init__(EnemyCopter.ecopter, position)
        self.vx = 3
        self.scale = 0.5
        self.fxcenter = self.fycenter = 0.5
        Game.listenKeyEvent("keydown", "p", self.Restart)
        Game.listenKeyEvent("keydown", "u", self.Restart)

    def explode(self):
        self.visible = False
        Explosion(self.position)
        self.x = 100
        self.y = -2000

    def step(self):
        self.x += self.vx
        if self.x > 1200:
            self.x = 0
        planeCollision = self.collidingWithSprites(Plane)
        if len(planeCollision) > 0:
            self.explode()
        bombCollision = self.collidingWithSprites(Explosion)
        if len(bombCollision) > 0:
            self.visible = False
        explosionCollision = self.collidingWithSprites(GiantExplosion)
        if len(explosionCollision) > 0:
            self.visible = False
        nukeCollision = self.collidingWithSprites(NuclearExplosion)
        if len(nukeCollision) > 0:
            self.visible = False

    def Restart(self, event):
        self.visible = True
        self.x = -600
        self.y = 360
Example #14
0
class Blimp(Sprite):
    eblimp = ImageAsset("images/blimp1.png")

    def __init__(self, position):
        super().__init__(Blimp.eblimp, position)
        self.fxcenter = self.fycenter = 0.5
        self.scale = 0.15
        self.vx = -0.5
        Game.listenKeyEvent("keydown", "p", self.Restart)
        Game.listenKeyEvent("keydown", "u", self.Restart)

    def explode(self):
        self.visible = False
        Explosion(self.position)
        self.x = 100
        self.y = -1000

    def step(self):
        self.x += self.vx
        planeCollision = self.collidingWithSprites(Plane)
        if len(planeCollision) > 0:
            self.explode()
        bombCollision = self.collidingWithSprites(Explosion)
        if len(bombCollision) > 0:
            self.visible = False
        explosionCollision = self.collidingWithSprites(GiantExplosion)
        if len(explosionCollision) > 0:
            self.visible = False
        if self.x < 0:
            self.x = 1250
        nukeCollision = self.collidingWithSprites(NuclearExplosion)
        if len(nukeCollision) > 0:
            self.visible = False

    def Restart(self, event):
        self.visible = True
        self.x = 300
        self.y = 160
Example #15
0
class suasage(Sprite):
    """
    suasage
    """
    shumcks = ImageAsset("sausage-merguez.jpg")

    def __init__(self, position, invx, invy):
        super().__init__(suasage.shumcks, position)
        self.vx = invx
        self.vy = invy
        self.vr = 0

    def step(self):
        self.x += self.vx
        self.y += self.vy
        self.rotation += self.vr
        self.vr = .1
        if self.y >= 600 or self.y <= 0:
            self.vy = self.vy * -1

        if self.x >= 1200 or self.x <= 0:
            self.vx = self.vx * -1
        self.scale = 0.2
Example #16
0
class Snake(Sprite):
    asset = ImageAsset("images/sheet_snake_walk.png", Frame(0,40,64,24), 7, 'horizontal')
    asset.append("images/sheet_snake_hurt.png", Frame(0,40,64,24), 2, 'horizontal')
    def __init__(self,position):
        super().__init__(Snake.asset,position, CircleAsset(15))
        self.vx=-1
        self.thrustframe=1
        self.rightdetect=Collide(position,5,15,green)
        self.leftdetect=Collide(position,5,15,red)
        #self.bottomdetect=Collide(position,5,15,blue)
        self.fxcenter = self.fycenter = 0.5
    def step(self):
        self.x += self.vx
        self.rightdetect.x=self.x+10
        self.rightdetect.y=self.y
        self.leftdetect.x=self.x-10
        self.leftdetect.y=self.y
        leftdetect=self.leftdetect.collidingWithSprites(Spike)
        #rightdetect=self.rightdetect.collidingWithSprites(Spike)
        ros=(self.rightdetect.collidingWithSprites(Collide))
        #rightdetect.extend(ros)
        #if len(rightdetect):
        #self.thrustframe+=.25
        if len(leftdetect) or len(ros):
            if self.thrustframe<=7:
                self.thrustframe=8
            self.vx=0
            self.setImage(self.thrustframe)
        else: 
            if self.thrustframe>=7:
                self.thrustframe=1
        self.setImage(self.thrustframe)
        self.thrustframe+=.25
        if self.thrustframe>=9:
            Snake.destroy(self.rightdetect)
            Snake.destroy(self.leftdetect)
            Snake.destroy(self)
Example #17
0
class Bullet(Sprite):
    asset = ImageAsset("images/blast.png", Frame(0, 0, 8, 8), 8, 'horizontal')

    def __init__(self, position, direction):
        super().__init__(Bullet.asset, [
            position[0] - 50 * math.sin(direction),
            position[1] - 50 * math.cos(direction)
        ])
        self.vx = -2.5 * speed_limit * math.sin(direction)
        self.vy = -2.5 * speed_limit * math.cos(direction)
        self.vr = 0
        self.fxcenter = self.fycenter = 0.5
        self.bulletphase = 0
        self.collisions = []

    def collision(self):
        [
            self.collisions.append(x)
            for x in self.collidingWithSprites(PlayerShip)
        ]
        [
            self.collisions.append(x)
            for x in self.collidingWithSprites(EnemyShip)
        ]
        [self.collisions.append(x) for x in self.collidingWithSprites(Bullet)]
        if collisions:
            self.destroy()
            [Explosion((x.x, x.y)) for x in self.collisions]
            [x.destroy() for x in self.collisions]

    def step(self):
        self.x += self.vx
        self.y += self.vy

        # manage bullet animation
        self.setImage(self.bulletphase % 7)
        self.bulletphase += 1
Example #18
0
class Bullet(Sprite):
    bullet = ImageAsset("images/bullet.png")

    def __init__(self, position, plane_rotation):
        super().__init__(Bullet.bullet, position)
        self.scale = 0.02
        self.vx = 0
        self.vy = 0
        self.center = (0.5, 0.5)
        self.memes = plane_rotation
        self.rotation = self.memes
        self.count = 0

    def explode(self):
        self.visible = False
        Explosion(self.position)
        self.y = 1000000000000

    def step(self):
        angle = AOA(self.rotation)
        self.vx = (angle.anglex() * 15)
        self.vy = (angle.angley() * 15)
        self.x += self.vx
        self.y += self.vy
        BlimpCollision = self.collidingWithSprites(Blimp)
        if len(BlimpCollision) > 0:
            self.explode()
        EnemyPlaneCollision = self.collidingWithSprites(EnemyCopter)
        if len(EnemyPlaneCollision) > 0:
            self.explode()
        EnemyChopperCollision = self.collidingWithSprites(EnemyChopper)
        if len(EnemyChopperCollision) > 0:
            self.explode()
        TankCollision = self.collidingWithSprites(Tank)
        if len(TankCollision) > 0:
            self.visible = False
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.rotation = 4.712
        self.vr = 0.01
        self.thrust = 0
        self.thrustframe = 1
        SpaceGame.listenKeyEvent("keydown", "space", self.thrustOn)
        SpaceGame.listenKeyEvent("keydown", "w", self.wKey)
        SpaceGame.listenKeyEvent("keydown", "s", self.sKey)
        SpaceGame.listenKeyEvent("keydown", "d", self.dKey)
        SpaceGame.listenKeyEvent("keydown", "a", self.aKey)
        SpaceGame.listenKeyEvent("keyup", "space", self.thrustOff)
        SpaceGame.listenKeyEvent("keyup", "d", self.thrustOff)
        SpaceGame.listenKeyEvent("keydown", "up arrow", self.upKey)
        SpaceGame.listenKeyEvent("keydown", "down arrow", self.downKey)
        self.fxcenter = self.fycenter = 0.5

    def step(self):
        if self.thrust == 1:
            self.setImage(self.thrustframe)
            self.thrustframe += 1
            if self.thrustframe == 4:
                self.thrustframe = 1
        lit = self.collidingWithSprites(sun)
        if len(lit) > 0:
            self.visible = False
        #clist = self.collidingWithSprites(sun)
        #if clist:
        #    print("collision!")
        #   self.visible = False

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

    def wKey(self, event):
        self.y -= 10

    def sKey(self, event):
        self.y += 10

    def dKey(self, event):
        self.x += 15
        self.thrust = 1
        print("HUH?")

    def aKey(self, event):
        self.x -= 10

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

    def upKey(self, event):
        self.rotation += 3.14159265 / 2

    def downKey(self, event):
        self.rotation -= 3.14159265 / 2
Example #20
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)
Example #21
0
class Enemy(Sprite):
    asset = ImageAsset("images/enemy_wheels.png", Frame(0, 0, 158, 133), 7,
                       'horizontal')

    def __init__(self, position):
        super().__init__(Enemy.asset, position)
        self.hp = 190
        self.turn = 0
        self.f = 0
        self.targetx = self.x
        self.targety = self.y
        self.scale = 0.64
        self.v = 0
        self.enemy = "None"
        self.state = 'Seeking'
        self.damage = 10
        self.wait = 0
        self.m = 0
        self.c = 0
        #Member hitbox is as follows: Starts 25.5 to right of and 6 below spawn point. Stretches 29 wide and 50 tall

    def step(self):
        if self.state == 'Seeking':
            self.pick_target(250)
            if self.enemy == 'None':
                self.v = 1
                if self.wait == 0 or time.time() > self.wait:
                    self.wait = time.time() + 3
                    self.m = radians(random.randint(-360, 360))
                    self.state = 'Moving'
        elif self.state == 'Firing':
            self.pick_target(100)
            self.v = 0
            if self.enemy == 'None':
                self.state = 'Seeking'
            else:
                self.turn = atan(
                    (self.targety - self.y) / (self.targetx - self.x))
                if time.time() > self.wait and self.enemy.state != 'hidden':
                    Bullet(self.x, self.y, self.targetx, self.targety,
                           (self.damage + random.randint(-3, 3)), 'E')
                    self.wait = time.time() + 2
                if self.targetx < self.x:
                    self.f = 4
                else:
                    self.f = 2
        if self.v > 0:
            if cos(self.turn) >= 0:
                self.f += 1
                if self.f > 1:
                    self.f = 0
            elif cos(self.turn) < 0:
                if self.f == 5:
                    self.f = 6
                else:
                    self.f = 5
            if self.f == 2:
                self.f = 0
            if self.x != self.targetx:
                self.turn = atan(
                    (self.targety - self.y) / (self.targetx - self.x))
            if self.targetx < self.x:
                self.turn += radians(180)
            if self.state == 'Moving':
                self.turn = self.m
                if time.time() > self.wait:
                    self.state = 'Seeking'
            if self.x + (self.v * cos(
                    self.turn)) > myapp.width - 50 or self.x + (self.v * cos(
                        self.turn)) < -21 or self.y + (self.v * sin(
                            self.turn)) > myapp.height - 50 or self.y + (
                                self.v * sin(self.turn)) < -15:
                if self.c == 0:
                    self.turn += radians(180)
                    self.m += radians(180)
                    self.c = 1
            else:
                self.c = 0
            self.x += (self.v * cos(self.turn))
            self.y += (self.v * sin(self.turn))
            if self.x < self.targetx + 70 and self.x > self.targetx - 70 and self.y < self.targety + 70 and self.y > self.targety - 70 and self.state == 'Seeking':
                self.state = 'Firing'
                self.v = 0
                self.wait = time.time()
            elif self.x < self.targetx + 2 and self.x > self.targetx - 2 and self.y < self.targety + 2 and self.y > self.targety - 2 and self.state != 'Moving':
                self.v = 0
            elif self.x < self.targetx + 28 and self.x > self.targetx - 28 and self.y < self.targety + 28 and self.y > self.targety - 28:
                self.v = 3
            else:
                self.v += 0.1
                if self.v > 1.8:
                    self.v = 1.8
                elif self.v < 0:
                    self.v = 0
        if self.state == 'dead':
            self.f = 3
        self.setImage(self.f)

    def pick_target(self, d):
        self.enemy = "None"
        d2 = d**2
        for enemy in myapp.getSpritesbyClass(Member):
            y = enemy.y - self.y
            x = enemy.x - self.x
            d1 = x**2 + y**2
            if d1 < d2 and enemy.state != 'dead':
                self.enemy = enemy
                self.targetx = enemy.x + 5
                self.targety = enemy.y + 5
                d2 = d1
                self.v = 1

    def hit(self, dam):
        self.hp -= dam
        if self.hp <= 0:
            self.state = 'dead'
        if self.hp < 0:
            self.hp = 0
Example #22
0
for x in range(11):
    Sprite(line1, (x * 40, 0))
    Sprite(line2, (0, x * 40))

#Making user be able to click and fill a cell
cell_asset = RectangleAsset(40, 40, thinline, blue)


def mouseClick(event):
    x = floor(event.x / 40) * 40
    y = floor(event.y / 40) * 40
    if x < 400 and y < 400:
        Sprite(cell_asset, (x, y))


cell_asset = ImageAsset("Conway-life.png")
ball = sprite(ball_asset, (0, 0))
"""       
def mousedown(event):
    global cell
    x = int((event.x//40)*40)
    y = int((event.y//40)*40)
    if x < 400 and y < 400:
        Sprite(cell_asset,(x, y))
        
def mouseup(event):
    global cell
    x = int((event.x//40)*40)
    y = int((event.y//40)*40)
    if x < 400 and y < 400:
        Sprite(cell_asset,(x, y))
Example #23
0
 def __init__(self, position):
     background = ImageAsset("images/starfield.jpg")
     super().__init__(background, position)
     self.scale = 3
Example #24
0
 class SpaceShip(Sprite):
   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.rotation = 4.7
 
       self.vr = 0.01
 
       self.thrust = 0
 
       self.thrustframe = 1
 
       SpaceGame.listenKeyEvent("keydown", "space", self.thrustOn)
 
       SpaceGame.listenKeyEvent("keydown", "w", self.wKey)
 
       SpaceGame.listenKeyEvent("keydown", "s", self.sKey)
 
       SpaceGame.listenKeyEvent("keydown", "d", self.dKey)
 
       SpaceGame.listenKeyEvent("keydown", "a", self.aKey)
 
       SpaceGame.listenKeyEvent("keyup", "space", self.thrustOff)
 
       SpaceGame.listenKeyEvent("keyup", "d", self.thrustOff)
 
       SpaceGame.listenKeyEvent("keydown", "r", self.upKey)
 
       SpaceGame.listenKeyEvent("keydown", "q", self.downKey)
 
       self.fxcenter = self.fycenter = 0.7
 
 #other stuff and events that needs to work
   def step(self):
       if self.thrust == 1:
           self.setImage(self.thrustframe)
           self.thrustframe += 1
           if self.thrustframe == 4:
               self.thrustframe = 1
       lit = self.collidingWithSprites(sun)
       if len(lit) > 0:
           self.visible = True
   def thrustOn(self, event):
       self.thrust = 1
   def wKey(self,event):
       self.y-=10
   def sKey(self,event):
       self.y+=10
   def dKey(self,event):
       self.x+=15
       self.thrust = 1
   def aKey(self,event):
       self.x-=10
   def thrustOff(self, event):
       self.thrust = 0
   def upKey(self, event):
       self.rotation+=3/2
   def downKey(self, event):
       self.rotation-=3/2
class SpaceShip(Sprite):
    """
    Animated space ship
    """
    asset = ImageAsset(
        "images/28293b2fe5801e03f1f70ed61c8397f6_airplane-clipart-transparent-airplane-clipart-transparent-background_2400-1009.png"
    )

    def __init__(self, position):
        super().__init__(SpaceShip.asset, position)
        self.vx = 1
        self.vy = 1
        self.vr = 0.01
        self.scale = 0.1
        self.thrust = 0
        self.size = 1
        SpaceGame.listenKeyEvent("keydown", "space", self.thrustOn)
        SpaceGame.listenKeyEvent("keyup", "space", self.thrustOff)
        SpaceGame.listenKeyEvent("keydown", "left arrow", self.Rotate)
        SpaceGame.listenKeyEvent("keydown", "right arrow", self.RotateOpposite)
        SpaceGame.listenKeyEvent("keyup", "left arrow", self.Stop)
        SpaceGame.listenKeyEvent("keyup", "right arrow", self.Stop)
        SpaceGame.listenKeyEvent("keydown", "w", self.Up)
        SpaceGame.listenKeyEvent("keydown", "s", self.Down)
        SpaceGame.listenKeyEvent("keydown", "a", self.Left)
        SpaceGame.listenKeyEvent("keydown", "d", self.Right)
        SpaceGame.listenKeyEvent("keyup", "w", self.StopMovement)
        SpaceGame.listenKeyEvent("keyup", "a", self.StopMovement)
        SpaceGame.listenKeyEvent("keyup", "s", self.StopMovement)
        SpaceGame.listenKeyEvent("keyup", "d", self.StopMovement)
        SpaceGame.listenKeyEvent("keydown", "r", self.Respawn)

        self.fxcenter = self.fycenter = 0.5

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

    def Respawn(self, event):
        self.x = 1
        self.y = 1
        self.visible = True

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

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

    def Rotate(self, event):
        self.vr += 0.1

    def RotateOpposite(self, event):
        self.vr -= 0.1

    def Stop(self, event):
        self.vr = 0.0

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

    def Up(self, event):
        self.vy -= 0.5
        self.thrust = 1

    def Down(self, event):
        self.vy += 0.5
        self.thrust = 1

    def Left(self, event):
        self.vx -= 0.5
        self.thrust = 1

    def Right(self, event):
        self.vx += 0.5
        self.thrust = 1
 def __init__(self,position):
     bucketzombie_asset = ImageAsset("images/Buckethead_Zombie.png")
     self.vx = 0
     self.bhh = 20
     super().__init__(bucketzombie_asset, position)
     self.scale = 0.16
 def __init__(self,position):
     regularzombie_asset = ImageAsset("images/clipart844194.png")
     self.vx = 0
     self.rzh = 10
     super().__init__(regularzombie_asset, position)
     self.scale = 0.18
 def __init__(self,position):
     peashooter_asset = ImageAsset("images/clipart215049.png")
     self.rph = 4
     super().__init__(peashooter_asset, position)
     self.scale = 0.07
 def __init__(self,position):
     walnut_asset = ImageAsset("images/kisspng-plants-vs-zombies-2-it-s-about-time-english-waln-walnut-5ab4aed18776e0.5829646215217906735549.png")
     self.wh = 10
     super().__init__(walnut_asset, position)
     self.scale = 0.085
 def __init__(self,position):
     sun_asset = ImageAsset("images/clipart90644.png")
     self.vy = 1
     super().__init__(sun_asset, position)
     self.scale = 0.03
 def __init__(self,position):
     sunflower_asset = ImageAsset("images/clipart644433 (1).png")
     self.sh = 4
     super().__init__(sunflower_asset, position)
     self.scale = 0.17
Example #32
0
 def test_singleimageasset(self):
   a = ImageAsset("bunny.png")
   self.assertEqual(a.GFX.basewidth, 71)
   self.assertEqual(a.GFX.baseheight, 100)
   a.destroy()