Esempio n. 1
0
 def respawn(self, position):
     self.death += 1
     self.respawnTime = 3
     self.timeout = time.time()
     self.health = 100
     self.velocity = [0, 0]
     self.gun = Gun(7, 21)
     self.position = position
     self.angle = 0
     return self
Esempio n. 2
0
class GunTests(unittest.TestCase):

    def setUp(self):
        self.gun = Gun()

    def test_shoot(self):
        shell = self.gun.shoot()
        self.assertIsInstance(shell, Shell)

    def test_load_shell(self):
        self.gun.load(NormalShell)
        shell = self.gun.shoot()
        self.assertIsInstance(shell, NormalShell)
Esempio n. 3
0
 def __init__(self, cam_id=1):
     self.gun = Gun.Gun()
     self.camera = Camera.Camera(_id=cam_id,
                                 crop_bounds=(200, 1080, 210, 1760),
                                 scale_to_height=500)
     self.camera.calibrate(
         img_path='C:/Nadav/Repos/paper_dome/camera_calib/')
Esempio n. 4
0
 def __init__(self, player):
     self.kind = "arm"
     pygame.sprite.Sprite.__init__(self, self.containers)
     self.player = player
     self.gun = Gun("M4A1")
     self.runRight = pygame.transform.scale(
         pygame.image.load("rsc/ball/PlayerArm" + self.gun.kind + ".png"),
         [100, 100])
     self.runLeft = pygame.transform.scale(
         pygame.image.load("rsc/ball/PlayerArmLeft" + self.gun.kind +
                           ".png"), [100, 100])
     self.restRight = pygame.transform.scale(
         pygame.image.load("rsc/ball/PlayerArm" + self.gun.kind + ".png"),
         [100, 100])
     self.restLeft = pygame.transform.scale(
         pygame.image.load("rsc/ball/PlayerArmLeft" + self.gun.kind +
                           ".png"), [100, 100])
     self.baseImage = self.restRight
     self.image = self.baseImage
     self.state = "rest right"
     self.prevState = "rest right"
     self.side = "right"
     self.offset = [43, 36]
     self.rect = self.image.get_rect()
     self.angle = 0
Esempio n. 5
0
 def __init__(self, filename, x, y, width, height, columns, rows, enemyAI):
     SpriteClass.__init__(self, filename,x, y, width, height, columns, rows)
     self.attackKey = pygame.K_RCTRL
     self.keyLeft = pygame.K_LEFT
     self.keyRight = pygame.K_RIGHT
     self.keyUp = pygame.K_UP
     self.keyDown = pygame.K_DOWN
     self.width = self.get_width()
     self.height = self.get_height()
     self.targetLocationUL = Point2D(0,0)
     self.targetLocationLR = Point2D(0,0)
     self.resetTargetLocation = 0
     self.atTargetLocation = True
     self.velocity = Point2D(3, 3)
     self.animationSwitchUpDown = False
     self.animationSwitchLeftRight = False
     self.isAlive = True
     self.health = 100
     self.gun = Gun(False)
     self.fireDelay = 30
     self.delay = 0
     self.attackFlag = moveDirection.NULL
     ###
     #variables for timer
     ###
     self.timer = 0 #timer to reset the path
     self.timingFlag = False #flag to set to make the path reset after the timer
     self.delay = 1000 #1 second
    def __init__(self):
        self.gun = Gun.Gun(gameDisplay)

        #creating ten balls for game, we can make it configurable later
        for i in range(1, self.ball_count):
            self.balls.append(
                Ball.RandomBall(gameDisplay, gc.screen_width, gc.screen_height,
                                ""))
Esempio n. 7
0
 def __init__(self):
     """Параметры игры"""
     self.root = tk.Tk()
     self.fr = tk.Frame(self.root)
     self.root.geometry('800x600')
     self.canv = tk.Canvas(self.root, bg='white')
     self.canv.pack(fill=tk.BOTH, expand=1)
     self.t = [None] * 2
     self.screen1 = self.canv.create_text(400, 300, text='', font='28')
     self.g1 = G.Gun(self.canv)
     self.bullet = 0
     self.id_points = self.canv.create_text(30, 30, text=0, font='28')
     self.canv.bind('<Button-1>', self.g1.fire2_start)
     self.canv.bind('<ButtonRelease-1>', self.g1.fire2_end)
     self.canv.bind('<Motion>', self.g1.targetting)
     self.event = ''
     self.zzz = 0.03
Esempio n. 8
0
    def __init__(self, name, moteur):
        #Permet d'appeler la fonction __init__() d'Objet
        super().__init__(name, moteur)

        self.engine.player = self

        self.InitSprite("Assets/Soldier(Holding).png")
        self.InitRect([moteur.Rlongueur // 2, moteur.Rlargeur // 2], [16, 16])
        self.collideRect = pygame.Rect((self.Rect.left, self.Rect.bottom - 2),
                                       (16, 2))

        #On attribue une arme
        self.Gun = Gun.Gun(self, self.engine)

        #Mise en place du système de dash
        self.isDashing = False
        self.ableToDash = True
        self.dashRechargeTime = 5
        self.lastDashTime = 0
        self.dashFrames = 0
        self.t = 1

        #Mise en place du système de power
        self.PowerList = [
            "Bullet-Time", "Speed", "Invincible", "Confusion", "Fire-Rate"
        ]
        self.Power = "Bullet-Time"
        self.PowerChoose = 0
        self.isPower = False
        self.ableToPower = True
        self.powerFrames = 600

        #Autres
        self.SpriteDos = pygame.image.load("Assets/Soldier(Dos).png")
        self.canFlip = True
        self.colorShiftDuration = 0
        self.mouseDuration = 30
        self.playerHp = 5
Esempio n. 9
0
 def setUp(self):
     self.gun = Gun()
Esempio n. 10
0
class Player:
    def __init__(self, game, position=[0, 0], color=Color(255, 127, 127),
                 bot=False):
        self.name = "Unknown"
        self.pid = 0
        self.game = game
        self.color = color
        self.bot = bot
        self.speed = 200
        self.delegate = None
        self.death = 0
        self.respawn(position)
        self.death = 0

    def respawn(self, position):
        self.death += 1
        self.respawnTime = 3
        self.timeout = time.time()
        self.health = 100
        self.velocity = [0, 0]
        self.gun = Gun(7, 21)
        self.position = position
        self.angle = 0
        return self

    def shoot(self):
        if self.respawnTime > 0:
            return []
        return self.gun.shoot(self, self.angle, 10)

    def onRender(self, renderer):
        oldColor = renderer.getColor()
        renderer.setColor(self.color)
        if self.respawnTime > 0:
            renderer.setColor(Color(100, 100, 100))
        renderer.drawOval(self.position, [20, 20])

        renderer.setColor(Color(192, 192, 192))
        px, py = self.position
        renderer.drawPolygon([
            (px+math.sin(self.angle)*8, py+math.cos(self.angle)*8),
            (
                px+math.sin(self.angle-(math.pi/4))*5,
                py+math.cos(self.angle-(math.pi/4))*5
            ), (
                px+math.sin(self.angle+(math.pi/4))*5,
                py+math.cos(self.angle+(math.pi/4))*5
            )
        ])

        if ((not self.delegate and self.respawnTime <= 0) or
                (self.delegate and self.delegate(self, "HealthBar"))):
            renderer.setColor(Color(127, 127, 127))
            renderer.drawRect([px-12, py-17], [25, 2])
            if self.health > 0:
                renderer.setColor(Color(127, 255, 127))
                renderer.fillRect([px-12, py-17], [self.health*25/100, 2])

        renderer.setColor(oldColor)

    def doAI(self):
        angle_deg = self.angle*180/math.pi
        angle_deg += (random.randint(0, 44)-22)
        self.angle = angle_deg*math.pi/180
        x, y = self.position
        w, h = self.game.getSize()
        # min(x*5/100, 5)
        # min((w-x)*5/(w-100), 5)
        # min(y*5/100, 5)
        # min((h-y)*5/(h-100), 5)
        friction_offset = 20
        max_speed = 200  # 3
        self.setSpeed(
            min(
                min((x-friction_offset)*max_speed/friction_offset, max_speed),
                min((w-x-friction_offset)*max_speed/friction_offset, max_speed),
                min((y-friction_offset)*max_speed/friction_offset, max_speed),
                min((h-y-friction_offset)*max_speed/friction_offset, max_speed)
            )
        )
        vx, vy = self.velocity
        vx = math.sin(self.angle)*self.getSpeed()
        vy = math.cos(self.angle)*self.getSpeed()
        self.velocity = [vx, vy]

    def clamp(self, value, minVal, maxVal):
        return max(minVal, min(value, maxVal))

    def onUpdate(self, delta):
        if self.isBot():
            self.doAI()

        x, y = self.position
        vx, vy = self.velocity
        x += vx*delta
        y += vy*delta
        if self.respawnTime > 0:
            self.respawnTime -= delta
        elif self.respawnTime < 0:
            self.respawnTime = 0
        w, h = self.game.getSize()
        self.position = [
            self.clamp(x, 17, w - 12),
            self.clamp(y, 20, h - 12)
        ]
        self.gun.onUpdate(delta)

    def isBot(self):
        return self.bot

    def setDelegate(self, delegate):
        self.delegate = delegate

    def setPlayerId(self, pid):
        self.pid = pid

    def getPlayerId(self):
        return self.pid

    def setPlayerName(self, name):
        self.name = name

    def getPlayerName(self):
        return self.name

    def setPosition(self, position):
        self.position = position

    def getPosition(self):
        return self.position

    def setVelocity(self, velocity):
        self.velocity = velocity

    def getVelocity(self):
        return self.velocity

    def setSpeed(self, speed):
        self.speed = speed

    def getSpeed(self):
        return self.speed

    def setGun(self, gun):
        self.gun = gun

    def getGun(self):
        return self.gun

    def setAngle(self, angle):
        self.angle = angle

    def getAngle(self):
        return self.angle

    def setHealth(self, health):
        self.health = health

    def getHealth(self):
        return self.health

    def setDeath(self, death):
        self.death = death

    def getDeath(self):
        return self.death

    def setRespawnTime(self, respawnTime):
        self.respawnTime = respawnTime

    def getRespawnTime(self):
        return max(0, self.respawnTime)

    def resetTimeout(self):
        self.timeout = time.time()

    def isDead(self):
        return self.health <= 0 or self.timeout+3.0 < time.time()

    def isIntersectObject(self, obj):
        px, py = self.position
        bx, by = obj.getPosition()
        distance = math.sqrt(((px-bx)**2)+((py-by)**2))
        return distance < 10+(obj.getSize()/2)

    def takeBonus(self, bonus):
        self.getGun().setTotalBullet(
            self.getGun().getTotalBullet()+bonus.getTotalBullet()
        )
        bonus.kill()

    def takeDamage(self, bullet):
        if self.isBot():
            self.setSpeed(1)
        self.health -= bullet.getDamage()
        if self.health < 0:
            self.health = 0
        bullet.kill()
Esempio n. 11
0
while new_game.play_game:
    #obsluga przyciskow
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            new_game.play_game = False
        if event.type == pygame.KEYDOWN:
            if event.key == pygame.K_s:
                new_game.Victim.moveLeft()
            elif event.key == pygame.K_f:
                new_game.Victim.moveRight()
            if event.key == pygame.K_e:
                new_game.Victim.moveUp()
            elif event.key == pygame.K_d:
                new_game.Victim.moveDown()
            if event.key == pygame.K_SPACE:
                new_game.RailGun = gun.Gun(new_game.Victim, new_game.Obstacles,
                                           new_game.Predators)
        if event.type == pygame.KEYUP:
            if event.key == pygame.K_s or event.key == pygame.K_f:
                new_game.Victim.stop(False)
            if event.key == pygame.K_e or event.key == pygame.K_d:
                new_game.Victim.stop(True)
        if event.type == pygame.MOUSEBUTTONDOWN:
            new_game.RailGun = gun.Gun(new_game.Victim, new_game.Obstacles,
                                       new_game.Predators)

    if new_game.Victim.health < 0 or len(new_game.Predators) == 0:
        if new_game.Victim.health < 0:
            func.displayMessage("You're dead! Play again? Y/N?",
                                (display_width, display_height),
                                screen,
                                fontSize=50,
Esempio n. 12
0
class Enemy(SpriteClass):
    def __init__(self, filename, x, y, width, height, columns, rows, enemyAI):
        SpriteClass.__init__(self, filename,x, y, width, height, columns, rows)
        self.attackKey = pygame.K_RCTRL
        self.keyLeft = pygame.K_LEFT
        self.keyRight = pygame.K_RIGHT
        self.keyUp = pygame.K_UP
        self.keyDown = pygame.K_DOWN
        self.width = self.get_width()
        self.height = self.get_height()
        self.targetLocationUL = Point2D(0,0)
        self.targetLocationLR = Point2D(0,0)
        self.resetTargetLocation = 0
        self.atTargetLocation = True
        self.velocity = Point2D(3, 3)
        self.animationSwitchUpDown = False
        self.animationSwitchLeftRight = False
        self.isAlive = True
        self.health = 100
        self.gun = Gun(False)
        self.fireDelay = 30
        self.delay = 0
        self.attackFlag = moveDirection.NULL
        ###
        #variables for timer
        ###
        self.timer = 0 #timer to reset the path
        self.timingFlag = False #flag to set to make the path reset after the timer
        self.delay = 1000 #1 second
        
    def damage(self, amount = 7):
        if self.health > 0:
            self.health -= amount
            
    def setUpSprite(self):
        self.set_animation_delay()
        self.play(True)
            
    def handleAI(self):
        if(self.atTargetLocation == True):
            self.generateTargetLocation()
             
        if(self.targetLocationUL.x < self.upperLeft.x):
            self.upperLeft.x  -= self.velocity.x
            self.updateLowerRight()
            
        if(self.targetLocationUL.x > self.upperLeft.x):
            self.upperLeft.x  += self.velocity.x
            self.updateLowerRight() 
    
        if(self.targetLocationUL.y < self.upperLeft.y):
            self.upperLeft.y  -= self.velocity.y
            self.updateLowerRight()
        
        if(self.targetLocationUL.y > self.upperLeft.y):
            self.upperLeft.y  += self.velocity.y
            self.updateLowerRight()
        
        if(self.upperLeft.x <= self.targetLocationLR.x) and (self.lowerRight.x >= self.targetLocationUL.x):
            if(self.upperLeft.y <= self.targetLocationLR.y) and (self.lowerRight.y >= self.targetLocationUL.y):
                self.atTargetLocation = True
    
    def generateTargetLocation(self):
        self.targetLocationUL.x = random.randint(5, screenWidth - 70)
        self.targetLocationUL.y = random.randint(5, screenHeight - 190)
        self.targetLocationLR.x = self.targetLocationUL.x + self.get_width()
        self.targetLocationLR.y = self.targetLocationUL.y + self.get_height()
        self.atTargetLocation = False
        
    def handleAttack(self, player):
        self.fireDelay = 50
        if(self.delay >= self.fireDelay):
            if(self.attackFlag != moveDirection.ATTACK):
                newBullet = Bullet("Bullets.gif", self.upperLeft.x + (self.get_width() / 2), self.upperLeft.y + (self.get_height() / 2), 30, 30, 3, 3, player)
                newBullet.play(True)
                newBullet.scale_sprite(3)
                self.gun.addBullet(newBullet)
                self.attackFlag = moveDirection.ATTACK
            else:
                self.attackFlag = moveDirection.NULL
            self.delay = 0
        else:
            self.delay += random.randint(2, 5)

    def updateLowerRight(self):
        self.lowerRight.x = self.upperLeft.x + self.width
        self.lowerRight.y = self.upperLeft.y + self.height

    def checkScreenBounds(self):
        if(self.upperLeft.y <= 0):
            self.upperLeft.y = 1
        if(self.upperLeft.y + self.height >= screenHeight - 115):
            self.upperLeft.y = screenHeight - self.height - 115 
        if(self.upperLeft.x <= 0):
            self.upperLeft.x = 1
        if(self.upperLeft.x + self.width >= screenWidth):
            self.upperLeft.x = screenWidth - self.width - 1
        self.updateLowerRight()
        
    def update(self, screen, player):
        if self.health > 0:
            self.checkScreenBounds()
            self.handleAI()
            self.handleAttack(player)
            self.gun.update(screen, player)
Esempio n. 13
0
# time.sleep(3)
# controller.set_target(0, 40, 20)
# time.sleep(3)
# controller.set_target(90, 0, 20)
# time.sleep(3)
# controller.go_to_zero(20)
# time.sleep(3)
# controller.set_trigger(True)
# time.sleep(2)
# controller.set_trigger(False)

# controller.close()

movement = 20

gun = Gun.Gun()
gun.go_to_zero(speed=10)
time.sleep(2)
gun.set_target(0, movement, speed=10)
time.sleep(2)
gun.set_target(0, -movement, speed=10)
time.sleep(3)
gun.go_to_zero(speed=10)
time.sleep(2)
gun.set_target(movement, 0, speed=10)
time.sleep(2)
gun.set_target(-movement, 0, speed=10)
time.sleep(3)
gun.go_to_zero(speed=10)
time.sleep(2)
gun.fire()