Example #1
0
class Ventana(QtGui.QFrame):
    def __init__(self):
        super().__init__()
        self.setObjectName("Ventana")
        self.setMouseTracking(True)
        self.setGeometry(200, 100, 800, 600)
        self.setStyleSheet("#Ventana {background-image: url('img/bg.gif');background-color:green;}")
        self.setWindowTitle("Zombitch")
        self.shooter = Shooter(parent=self, x=400, y=300)
        self.timer = QtCore.QTimer(self)
        self.timer.timeout.connect(self.create_zombie)
        self.timer.setInterval(1000)
        self.timer.start()
        self.zombies = [Zombie(parent=self, x=0, y=0, target=self.shooter)]
        self.packages = []
        self.__kills = 0
        self.start_time = datetime.now()
        self.status = Status(parent=self)
        self.overlay = Overlay(parent=self)
        self.message = Message(parent=self)

    @property
    def kills(self):
        return self.__kills

    @kills.setter
    def kills(self, value):
        self.__kills = value
        self.status.update_kills()

    def actualizarImagen(self, myImageEvent):
        label = myImageEvent.image
        label.move(myImageEvent.x, myImageEvent.y)

    def keyPressEvent(self, QKeyEvent):
        if QKeyEvent.key() == QtCore.Qt.Key_Z:
            vehicle = Vehicle(parent=self, x=100, y=600)
            vehicle.summon()
        elif QKeyEvent.key() == QtCore.Qt.Key_Space:
            self.message.set_text("Paused")
            self.message.show()
            self.pause()
        else:
            self.shooter.move(QKeyEvent.key())

    def mouseMoveEvent(self, QMouseEvent):
        x = QMouseEvent.x()
        y = QMouseEvent.y()
        self.shooter.guide((x,y))

    def mousePressEvent(self, QMouseEvent):
        x = QMouseEvent.x()
        y = QMouseEvent.y()
        self.shooter.shoot((x,y))
        self.shooter.guide((x,y))

    def send_care_package(self):
        if random.random() > 0.93 and len(self.packages) <= 1:
            care = CarePackage(parent=self, shooter=self.shooter)
            care.summon()
            self.packages.append(care)

    def zombie_interval(self):
        if (datetime.now() - self.start_time).total_seconds() > 200:
            interval = random.expovariate(1/250)
        else:
            interval = 1000 - 50*self.kills
            interval = random.expovariate(1/max(interval, 500))
        self.timer.setInterval(interval)

    def create_zombie(self):
        choice = random.randint(0,1)
        if choice == 0:
            x = random.randint(0,1)*800
            y = random.randint(0,60)*10
        elif choice == 1:
            x = random.randint(0,80)*10
            y = random.randint(0,1)*600
        if len(self.zombies) < 20:
            if random.random() > 0.60:
                self.zombies.append(SuperZombie(parent=self, x=x, y=y, target=self.shooter))
            else:
                self.zombies.append(Zombie(parent=self, x=x, y=y, target=self.shooter))
            self.zombie_interval()

        if (datetime.now() - self.start_time).total_seconds() > 20:
            self.send_care_package()

    def pause(self):
        self.timer.stop()
        for event in ["mouseMoveEvent", "mousePressEvent", "keyPressEvent"]:
            setattr(self, event, self.pass_event)
        for zombie in self.zombies:
            zombie.pause()

    def play(self):
        self.timer.start()

    def pass_event(self, *args):
        pass

    def end(self):
        self.message.set_text("Game Over")
        self.message.show()
        self.pause()
Example #2
0
# A group containing all of the lasers the Shooter shoots
laserGroup = pygame.sprite.Group()
# A group containing all mushrooms in the game
mushroomGroup = pygame.sprite.Group()
mushroomGroup.add(randomlyGenerateMushrooms(width, height))

# All the non player character sprites
npcGroups = [laserGroup, centipede, mushroomGroup]

while 1:
    for event in pygame.event.get():
        if event.type == pygame.QUIT: sys.exit()
        if event.type == pygame.KEYDOWN:
            if event.key == pygame.K_SPACE:
                newLaser = shooter.shoot()
                laserGroup.add(newLaser)
                allSpriteGroup.add(newLaser)

    pressedKeys = pygame.key.get_pressed()

    shooter.update(pressedKeys)

    # Move everything in the game (referring to the underlying positions of game objects)
    for gameSprite in list(itertools.chain(npcGroups)):
        gameSprite.update()

    screen.fill(black)

    # Draw all the game objects on the screen in their new positions
    for gameSprite in allSpriteGroup:
Example #3
0
class Robot(wpilib.TimedRobot):
    def robotInit(self):
        """
        This function is called upon program startup and
        should be used for any initialization code.
        """
        self.driver_stick = wpilib.Joystick(0)
        self.codriver_stick = wpilib.Joystick(1)

        self.left_shooter_motor = ctre.WPI_TalonSRX(0)
        self.left_drivetrain_motor = ctre.WPI_TalonSRX(1)
        self.right_drivetrain_motor = ctre.WPI_TalonSRX(2)
        self.right_shooter_motor = ctre.WPI_TalonSRX(3)

        self.intake_motor = wpilib.Spark(8)
        self.arm_pivot_motor = wpilib.Spark(6)
        self.arm_lock_motor = wpilib.Spark(5)

        self.timer = wpilib.Timer()
        #self.navx       = navx.AHRS.create_spi()

        self.duration = 20

        self.drivetrain = DriveTrain(self.left_drivetrain_motor,
                                     self.right_drivetrain_motor)
        self.shooter = Shooter(self.intake_motor, self.left_shooter_motor,
                               self.right_shooter_motor)
        self.arm = Arm(self.arm_pivot_motor, self.arm_lock_motor)

    def autonomousInit(self):
        pass

    def autonomousPeriodic(self):
        self.teleopPeriodic()

    def teleopInit(self):
        pass

    def teleopPeriodic(self):
        """This function is called periodically during operator control."""
        start = self.timer.getMsClock()

        self.drivetrain.drive(self.driver_stick)
        self.shooter.shoot(self.codriver_stick)
        self.arm.lift(self.codriver_stick)
        """
        wpilib.SmartDashboard.putNumber("NavX", self.navx.getAngle())
        """
        wpilib.SmartDashboard.putNumber(
            "Left drivetrain speed",
            self.left_drivetrain_motor.getQuadratureVelocity())
        wpilib.SmartDashboard.putNumber(
            "Right drivetrain speed",
            self.right_drivetrain_motor.getQuadratureVelocity())
        """
        wpilib.SmartDashboard.putNumber("Left shooter position", self.left_shooter_motor.getQuadraturePosition())
        wpilib.SmartDashboard.putNumber("Right shooter position", self.right_shooter_motor.getQuadraturePosition())
        """
        wpilib.SmartDashboard.putNumber(
            "Left shooter", self.left_shooter_motor.getQuadratureVelocity())
        wpilib.SmartDashboard.putNumber(
            "Right shooter", self.right_shooter_motor.getQuadratureVelocity())
        """
        wpilib.SmartDashboard.putNumber("Left shooter RPM error", self.left_shooter_motor.getClosedLoopError(0) * 600/4096)
        wpilib.SmartDashboard.putNumber("Right shooter RPM error", self.right_shooter_motor.getClosedLoopError(0) * 600/4096)
        """

        self.duration = self.timer.getMsClock() - start

        wpilib.SmartDashboard.putNumber("Loop duration", self.duration)