コード例 #1
0
ファイル: ggmath.py プロジェクト: feifeimao666/ggame
 def _buildAsset(self):
     pcenter = self.spposinputs.pos
     try:
         pradius = MathApp.distance(
             self.posinputs.pos(),
             self.nposinputs.radius()) * MathApp._scale
     except AttributeError:
         pradius = self.nposinputs.radius() * MathApp._scale
     style = self.stdinputs.style()
     fill = self.stdinputs.color()
     ymax = pcenter[1] + pradius
     ymin = pcenter[1] - pradius
     xmax = pcenter[0] + pradius
     xmin = pcenter[0] - pradius
     try:
         if ymin > MathApp.height or ymax < 0 or xmax < 0 or xmin > MathApp.width:
             return CircleAsset(pradius, style, fill)
         elif pradius > 2 * MathApp.width:
             # here begins unpleasant hack to overcome crappy circles
             poly = self._buildPolygon(pcenter, pradius)
             if len(poly):
                 passet = PolygonAsset(poly, style, fill)
                 return passet
     except AttributeError:
         return CircleAsset(pradius, style, fill)
     return CircleAsset(pradius, style, fill)
コード例 #2
0
 def prepGame(self, colors):
     self.unlistenMouseEvent('mousedown', self.buttonClick)
     classDestroy(Button)
     classDestroy(PlayerColor)
     classDestroy(FlashingText)
     classDestroy(Instructions)
     Player1(CircleAsset(50, thinline, colors[0]),
             (SCREEN_WIDTH / 4, SCREEN_HEIGHT))
     Player2(CircleAsset(50, thinline, colors[1]),
             (SCREEN_WIDTH * 3 / 4, SCREEN_HEIGHT))
     self.getSpritesbyClass(PlayerCover)[1].follow = Player2
     Ball((SCREEN_WIDTH / 2, SCREEN_HEIGHT / 2))
     for x in [(0, 0, 10, SCREEN_HEIGHT),
               (SCREEN_WIDTH - 5, 0, 10, SCREEN_HEIGHT),
               (0, SCREEN_HEIGHT - 5, SCREEN_WIDTH + 5, 10),
               (0, 0, SCREEN_WIDTH + 5, 10)]:
         Border(RectangleAsset(x[2], x[3], noline, black), (x[0], x[1]))
     Goal((SCREEN_WIDTH - 50, SCREEN_HEIGHT - 300))
     Goal((0, SCREEN_HEIGHT - 300))
     ScoreText((SCREEN_WIDTH / 2, SCREEN_HEIGHT / 2))
     self.start = time()
     self.timeGame()
     self.frameTime = time()
     #self.go = True
     self.stage = 'play'
コード例 #3
0
ファイル: pacman-game-2.py プロジェクト: sth23/pacman-game
 def __init__(self, position, color, radius):
     self.circ = CircleAsset(radius, noline, color)
     super().__init__(self.circ, position, CircleAsset(radius))
     self.vx = 0
     self.vy = 0
     self.speed = 3
     self.count = 0
     self.chance = 0
コード例 #4
0
ファイル: Projectv2.py プロジェクト: KraweDad/Final-Project
    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)
コード例 #5
0
class Cell(Sprite):
    """
    Cell that is either new or old.
    Pass True for new if it shall be a new color.
    """
    bluecircle = CircleAsset(4, noline, blue)
    redcircle = CircleAsset(4, noline, red)

    def __init__(self, new, pos):
        asset = Cell.bluecircle
        if new:
            asset = Cell.redcircle
        super().__init__(asset, pos)
コード例 #6
0
    def __init__(self, position, width, height):
        self.radius = 15
        super().__init__(Ship.ship, position, CircleAsset(self.radius))
        self.gamewidth = width
        self.gameheight = height
        self.speedlimit = 7.5
        self.rotatespeed = 0.1
        self.maxspin = 1
        self.thrust = 0.25
        self.vx = 0
        self.vy = 0
        self.vr = 0
        self.deltavx = 0
        self.deltavy = 0
        self.speed = 0
        self.fxcenter = self.fycenter = 0.5
        self.extralives = 3
        self.shootcooldown = 0
        
        AsteroidsGame.listenKeyEvent("keydown", "space", self.shoot)

        AsteroidsGame.listenKeyEvent("keydown", "right arrow", self.rotateRightOn)
        AsteroidsGame.listenKeyEvent("keyup", "right arrow", self.rotateRightOff)
        AsteroidsGame.listenKeyEvent("keydown", "left arrow", self.rotateLeftOn)
        AsteroidsGame.listenKeyEvent("keyup", "left arrow", self.rotateLeftOff)
        AsteroidsGame.listenKeyEvent("keydown", "up arrow", self.thrustOn)
コード例 #7
0
ファイル: grapher.py プロジェクト: voidJeff/Final-Project
class Dot(Sprite):
    
    asset = CircleAsset(2, thinline, pink)

    def __init__(self, position):
        super().__init__(Dot.asset, position)
        
        if mode == "l":
            if k >= 0.5625:
                self.x = (840*k-100*b-580)/k
            elif 0.5625 > k > 0:
                self.x = 0
            elif k <= -0.5625:
                self.x = (840*k+500-100*b)/k
            elif 0 > k > -0.5625:
                self.x = 0
        elif mode == "t":
            self.x = 0
        elif mode == "p":
            if a > 0:
                self.x = 100*(-b-math.sqrt(b**2-4*a*c+20*a))/(2*a)
            elif a < 0:
                self.x = -100*(-b+math.sqrt(b**2-4*a*c+23.2*a))/(2*a)
        self.loop = False
        self.visible = False
        else:
コード例 #8
0
    def __init__(self, position):
        self.x1 = 30 + random.randint(-10, 10)
        self.y1 = 0 + random.randint(-10, 10)
        self.x2 = 60 + random.randint(-10, 10)
        self.y2 = 0 + random.randint(-10, 10)
        self.x3 = 90 + random.randint(-10, 10)
        self.y3 = 30 + random.randint(-10, 10)
        self.x4 = 90 + random.randint(-10, 10)
        self.y4 = 60 + random.randint(-10, 10)
        self.x5 = 60 + random.randint(-10, 10)
        self.y5 = 90 + random.randint(-10, 10)
        self.x6 = 30 + random.randint(-10, 10)
        self.y6 = 90 + random.randint(-10, 10)
        self.x7 = 0 + random.randint(-10, 10)
        self.y7 = 60 + random.randint(-10, 10)
        self.x8 = 0 + random.randint(-10, 10)
        self.y8 = 30 + random.randint(-10, 10)
        self.points = [(self.x1, self.y1), (self.x2, self.y2),
                       (self.x3, self.y3), (self.x4, self.y4),
                       (self.x5, self.y5), (self.x6, self.y6),
                       (self.x7, self.y7), (self.x8, self.y8)]
        self.poly = PolygonAsset(self.points, noline, black)

        super().__init__(self.poly, position, CircleAsset(45))
        self.speed = 1
        self.rotation = random.random() * 2 * math.pi
        self.vx = self.speed * math.sin(self.rotation)
        self.vy = self.speed * math.cos(self.rotation)
        self.vr = 0.02 * random.random()
        self.fxcenter = self.fycenter = 0.5
コード例 #9
0
ファイル: MMRadar.py プロジェクト: averywallis/Radar
    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))
コード例 #10
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')
コード例 #11
0
class Bullet(Sprite):
    asset = CircleAsset(3, noline, white)

    def __init__(self, x, y, targetx, targety, damage, source):
        super().__init__(Bullet.asset)
        self.x = x + 45
        self.y = y + 30
        self.source = source
        self.targetx = targetx + 35
        self.targety = targety + 30
        self.rotation = atan((self.targety - self.y) / (self.targetx - self.x))
        if self.targetx < self.x:
            self.rotation += radians(180)
        self.damage = damage

    def step(self):
        if self.source == 'E':
            for char in myapp.getSpritesbyClass(Member):
                if self.x > char.x + 30 and self.x < char.x + 62 and self.y > char.y + 5 and self.y < char.y + 75 and char.state != 'hidden' and char.state != 'dead':
                    char.hit(self.damage)
                    self.source = 'None'
        elif self.source == 'M':
            for char in myapp.getSpritesbyClass(Enemy):
                if self.x > char.x + 30 and self.x < char.x + 75 and self.y > char.y + 5 and self.y < char.y + 80 and char.state != 'dead':
                    char.hit(self.damage)
                    self.source = 'None'
        if self.x < myapp.width and self.y < myapp.height and self.y > 0 and self.x > 0:
            self.x += (6 * cos(self.rotation))
            self.y += (6 * sin(self.rotation))
        else:
            self.source = 'None'
        if self.source == 'None':
            self.destroy()
コード例 #12
0
ファイル: project.py プロジェクト: CuPyrtch/Final-Project
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
コード例 #13
0
    def __init__(self, position):
        self.x1 = 7.5 + random.randint(-3, 3)
        self.y1 = 0 + random.randint(-3, 3)
        self.x2 = 15 + random.randint(-3, 3)
        self.y2 = 0 + random.randint(-3, 3)
        self.x3 = 22.5 + random.randint(-3, 3)
        self.y3 = 7.5 + random.randint(-3, 3)
        self.x4 = 22.5 + random.randint(-3, 3)
        self.y4 = 15 + random.randint(-3, 3)
        self.x5 = 15 + random.randint(-3, 3)
        self.y5 = 22.5 + random.randint(-3, 3)
        self.x6 = 7.5 + random.randint(-3, 3)
        self.y6 = 22.5 + random.randint(-3, 3)
        self.x7 = 0 + random.randint(-3, 3)
        self.y7 = 15 + random.randint(-3, 3)
        self.x8 = 0 + random.randint(-3, 3)
        self.y8 = 7.5 + random.randint(-3, 3)
        self.points = [(self.x1, self.y1), (self.x2, self.y2),
                       (self.x3, self.y3), (self.x4, self.y4),
                       (self.x5, self.y5), (self.x6, self.y6),
                       (self.x7, self.y7), (self.x8, self.y8)]
        self.poly = PolygonAsset(self.points, noline, black)

        super().__init__(self.poly, position, CircleAsset(11.25))

        self.speed = 3
        self.rotation = random.random() * 2 * math.pi
        self.vx = self.speed * math.sin(self.rotation)
        self.vy = self.speed * math.cos(self.rotation)
        self.vr = 0.04 * random.random()
        self.fxcenter = self.fycenter = 0.5
コード例 #14
0
 def __init__(self, position, rotation):
     super().__init__(Bullet.circ, position, CircleAsset(5))
     self.speed = 10
     self.rotation = rotation
     self.fxcenter = self.fycenter = 0
     self.vx = -self.speed * math.sin(self.rotation)
     self.vy = -self.speed * math.cos(self.rotation)
コード例 #15
0
    def __init__(self, position):
        self.radius = 7
        super().__init__(Lander.ship, position, CircleAsset(self.radius))
        self.vx = 0
        self.vy = 0
        self.gravity = 0.01
        self.wind = 0
        self.thrust = 0.05
        self.vr = 0.1
        self.rotation = 0
        self.paused = True
        self.fxcenter = self.fycenter = 0.5
        self.speed = 0
        self.speedlimit = 1
        self.landed = False
        self.crashed = False
        self.thrusting = False
        self.landingarea = False
        self.fuellimit = 100
        self.fuel = self.fuellimit

        MarsLanderGame.listenKeyEvent("keydown", "up arrow", self.thrustOn)
        MarsLanderGame.listenKeyEvent("keyup", "up arrow", self.thrustOff)
        MarsLanderGame.listenKeyEvent("keydown", "right arrow",
                                      self.rotateRight)
        MarsLanderGame.listenKeyEvent("keydown", "left arrow", self.rotateLeft)
        MarsLanderGame.listenKeyEvent("keydown", "space", self.togglePause)
コード例 #16
0
 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
コード例 #17
0
ファイル: pacman-game-2.py プロジェクト: sth23/pacman-game
 def __init__(self, position, radius):
     self.radius = radius
     self.circ = CircleAsset(self.radius, noline, yellow)
     super().__init__(self.circ, position, CircleAsset(self.radius))
     self.vx = 0
     self.vy = 0
     self.speed = 3
     self.fxcenter = self.fycenter = 0.5
     self.gameover = False
     
     self.mouth = PacMouth(self.x, self.y, self.vx, self.vy, self.radius)
     
     # Setup Player Controls
     PacmanGame.listenKeyEvent("keydown", "right arrow", self.goRight)
     PacmanGame.listenKeyEvent("keydown", "left arrow", self.goLeft)
     PacmanGame.listenKeyEvent("keydown", "up arrow", self.goUp)
     PacmanGame.listenKeyEvent("keydown", "down arrow", self.goDown)
コード例 #18
0
ファイル: pongish.py プロジェクト: oliviaosimon/Final-Project
 def __init__(self, position):
     global myapp
     #self.c = color
     #self.d = diameter
     self.vy = 0
     self.vx = 0
     rollypolly = CircleAsset(7, thinline, white)
     #myapp.listenKeyEvent('keydown', 'space', self.spaceKey)
     super().__init__(rollypolly, position)
コード例 #19
0
class point(Sprite):
    pt = CircleAsset(5, outline, red)
    def __init__(self, position, color, equation, depVar):
        self.vy = 0
        self.vx = 0
        #print(funcInterpreter("y", "x", equation, 0.1))
        self.equation = equation
        self.depVar = depVar
        super().__init__(point.pt, position)
コード例 #20
0
 def __init__(self, color, diameter, x, y):
     global myapp
     self.c = color
     self.d = diameter
     self.vy = 0
     self.vx = 0
     theball = CircleAsset(self.d, thinline, self.c)
     myapp.listenKeyEvent('keydown', 'space', self.spaceKey)
     super().__init__(theball, (x, y))
コード例 #21
0
class Circle(App):
    def __init__(self, radius):
         super().__init__(radius)
    radius=int(input("Radius?"))
    black=Color(0,1)
    red=Color(0xA62A2A)
    ogline=Linestyle(1, black)
    Circle_Asset=CircleAsset(radius, ogline, red)
    Circle=Sprite(Circle_Asset, (100,100))
コード例 #22
0
ファイル: ggmath.py プロジェクト: feifeimao666/ggame
 def __init__(self, *args, **kwargs):
     """
     Required Inputs
     
     * **pos** position of point
     """
     super().__init__(
         CircleAsset(self.defaultsize, self.defaultstyle,
                     self.defaultcolor), *args, **kwargs)
コード例 #23
0
    def __init__(self, mArray, cStack):
        self.mazeArray = mArray
        self.cellStack = cStack

        self.state = 'Playing'
        self.currentCell = random.randint(0, cTotalCells - 1)
        dx = int(self.currentCell % cWidth) * cCellSize + cCellSize / 2
        dy = int(self.currentCell / cWidth) * cCellSize + cCellSize / 2

        aRunner = CircleAsset(cCellSize / 2 - 3, noline, yellow)
        super().__init__(aRunner, (dx, dy))
        self.circularCollisionModel()
コード例 #24
0
class pacman(Sprite):
    pacmanSprite = CircleAsset(10, noline, yellow)

    #pacman=RectangleAsset(20,10,noline,yellow)
    def __init__(self, position):
        super().__init__(pacman.pacmanSprite, position)
        self.position = position
        self.vx = 0
        self.vy = 0
        self.vr = 0
        self.moving = 0
        self.movingframe = 1
        '''
        When keys are pressed
        '''

        pacmanGame.listenKeyEvent("keydown", "right arrow", self.rightmoving)
        pacmanGame.listenKeyEvent("keydown", "left arrow", self.leftmoving)
        pacmanGame.listenKeyEvent("keydown", "down arrow", self.downmoving)
        pacmanGame.listenKeyEvent("keydown", "up arrow", self.upmoving)
        '''
        When keys are released
        '''

    '''
    When keys are pressed they do these things
    '''

    def rightmoving(self, event):
        self.vx = 1
        self.vy = 0

    def leftmoving(self, event):
        self.vx = -1
        self.vy = 0

    def downmoving(self, event):
        self.vy = 1
        self.vx = 0

    def upmoving(self, event):
        self.vy = -1
        self.vx = 0

    '''
    When keys are released they do these things
    '''

    def step(self):
        self.x += self.vx
        self.y += self.vy
        self.rotation += self.vr
コード例 #25
0
ファイル: DonkeyKong.py プロジェクト: DRBarnum/Final-Project
class Barrel(Sprite):
    brown = Color(0x996633, 1.0)
    Black = Color(1, 0)
    yellow = Color(0xfdd835, 1.0)
    noline = LineStyle(1, Black)
    asset = CircleAsset(15, noline, brown)

    def __init__(self, position):
        super().__init__(Barrel.asset, position)
        self.vx = 0
        self.vy = 0
        self.vr = 0
        self.falling = False
        self.mover = False
        self.movel = False
        self.fxcenter = self.fycenter = 0.25

    def step(self):
        self.x += self.vx
        self.y += self.vy
        if self.mover == True:
            self.vy = 0
            self.vx = 2.5
        if self.movel == True:
            self.vy = 0
            self.vx = -2.5
        if self.falling == True:
            self.vy = 2.5
            self.vx = 0
        if self.y == 145:
            self.falling = False
            self.mover = True
        if self.x >= 620 and self.y == 145:
            self.mover = False
            self.falling = True
        if self.y >= 312 and self.x >= 620:
            self.falling = False
            self.movel = True
        if self.x <= 130 and self.y >= 312:
            self.movel = False
            self.falling = True
        if self.x <= 130 and self.y >= 482:
            self.falling = False
            self.mover = True
        if self.x >= 569 and self.y >= 482:
            self.mover = False
            self.falling = True
        if self.y >= 651:
            self.falling = False
            self.movel = True
コード例 #26
0
class Cell(Sprite):
    """
    
    """
    cellsprite = CircleAsset(cell_size, thinline, white)
    cellsprite_New = CircleAsset(cell_size, thinline, green)
    cellsprite_Old = CircleAsset(cell_size, thinline, yellow)

    #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.cellsprite, position)
        self.setImage(0)

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

    def step(self):
        self.ageCell()

    def getPosition(self):
        return ((self.x, self.y))
コード例 #27
0
class Bullet(Sprite):
    circ = CircleAsset(2, noline, black)
    
    def __init__(self, position, rotation):
        super().__init__(Bullet.circ, position, CircleAsset(5))
        self.speed = 10
        self.rotation = rotation
        self.fxcenter = self.fycenter = 0
        self.vx = -self.speed * math.sin(self.rotation)
        self.vy = -self.speed * math.cos(self.rotation)
        
    def step(self):
        self.x += self.vx
        self.y += self.vy
コード例 #28
0
class Bullet(Sprite):
    asset = CircleAsset(3, noline, black)

    def __init__(self, x, y, direc):
        super().__init__(Bullet.asset)
        self.x = x
        self.y = y
        self.rotation = direc

    def step(self):
        if self.x < myapp.width and self.y < myapp.height and self.y > 0 and self.x > 0:
            self.x += (3 * sin(self.rotation))
            self.y += (3 * cos(self.rotation))
        else:
            self.destroy()
コード例 #29
0
 def __init__(self, position,n):
     super().__init__(Player.asset, position, CircleAsset(10))
     self.vx = 0
     self.vy = 0
     self.thrust = 0
     self.left=0
     self.right=0
     self.collidingwithsprites=0
     self.resting=0
     self.collidetop=Collide(position,12,5,green)
     self.collidebottom=Collide(position,8,5,blue)
     self.collideleft=Collide(position,5,15,red)
     self.collideright=Collide(position,5,15,pink)
     self.leftslide=False
     self.stabhit=Collide(position,50,5,brown)
     self.rightslide=False
     self.leftleap=False
     self.rightleap=False
     self.leap=False
     self.attack=False
     self.attackp=True
     self.thrustframe=1
     self.width=64
     self.Attacking=False
     self.Attackcount=0
     if n==0:
         SpaceGame.listenKeyEvent("keydown", "space", self.thrustOn)
         SpaceGame.listenKeyEvent("keyup", "space", self.thrustOff)
         SpaceGame.listenKeyEvent("keydown", "left arrow", self.lefton)
         SpaceGame.listenKeyEvent("keyup", "left arrow", self.leftoff)
         SpaceGame.listenKeyEvent("keydown", "right arrow", self.righton)
         SpaceGame.listenKeyEvent("keyup", "right arrow", self.rightoff)
         SpaceGame.listenKeyEvent("keydown", "space", self.Leap)
         SpaceGame.listenKeyEvent("keyup", "space", self.noLeap)
         SpaceGame.listenKeyEvent("keydown", "m", self.Attack)
         SpaceGame.listenKeyEvent("keyup", "m", self.noAttack)
     if n==1:
         SpaceGame.listenKeyEvent("keydown", "w", self.thrustOn)
         SpaceGame.listenKeyEvent("keyup", "w", self.thrustOff)
         SpaceGame.listenKeyEvent("keydown", "a", self.lefton)
         SpaceGame.listenKeyEvent("keyup", "a", self.leftoff)
         SpaceGame.listenKeyEvent("keydown", "d", self.righton)
         SpaceGame.listenKeyEvent("keyup", "d", self.rightoff)
         SpaceGame.listenKeyEvent("keydown", "s", self.Leap)
         SpaceGame.listenKeyEvent("keyup", "s", self.noLeap)
         SpaceGame.listenKeyEvent("keydown", "c", self.Attack)
         SpaceGame.listenKeyEvent("keyup", "c", self.noAttack)
     self.fxcenter = self.fycenter = 0.5
コード例 #30
0
ファイル: spacewar.py プロジェクト: tiggerntatie/Spacewar
class Bullet(GravitySprite):

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

    def __init__(self, app, sun):
        super().__init__(Bullet.asset, Bullet.collisionasset, (0, 0), (0, 0),
                         sun)
        self.visible = False
        self.firing = False
        self.time = 0
        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):
        self.time = self.time - dT
        if self.visible:
            if self.time <= 0:
                self.visible = False
            else:
                self.nextImage(True)
                super().step(T, dT)
                if self.collidingWith(self.sun):
                    self.visible = False
                    ExplosionSmall(self.position)
                else:
                    ships = self.collidingWithSprites(Ship1)
                    ships.extend(self.collidingWithSprites(Ship2))
                    for ship in ships:
                        if not self.firing and ship.visible:
                            ship.explode()
                            self.visible = False
                    if not ships:
                        self.firing = False