Example #1
0
    def run(self):
        while Direction.direction_p_1.value != 7:
            for x in self.rain_drops:
                api.cuboid_off(x, 1, 2, 1)

            # Set new location for falling rain_drops
            for rain_drop in self.rain_drops:
                if rain_drop[1] - self.fall_speed < 0:
                    self.rain_drops.remove(rain_drop)
                else:
                    rain_drop[1] -= self.fall_speed

            for x in range(self.intensity):
                self.rain_drops = self.rain_drops + [[
                    random.random(), 1, random.random()
                ]]

            for x in self.rain_drops:
                if x[1] < 1 / (self.cube_size - 1):
                    api.cuboid_on(x, 1, 1, 1)
                else:
                    api.cuboid_on(x, 1, 2, 1)

            time.sleep(1 / self.speed)

            api.display(api.leds)
Example #2
0
    def run(self):
        c = 0
        while Direction.direction_p_1.value != 7:
            for x in self.cloud_stripes:
                api.cuboid_off(x, 2, 2, 3)

            for cloud_stripe in self.cloud_stripes:
                if cloud_stripe[2] + self.fall_speed > 1:
                    self.cloud_stripes.remove(cloud_stripe)
                else:
                    cloud_stripe[2] += self.fall_speed

            if c == 0:
                self.cloud_stripes = self.cloud_stripes + [[
                    random.random(), 1, 0
                ]]
                c += 1
            elif c == 11 - (self.intensity % 11):
                c = 0
            else:
                c += 1

            for x in self.cloud_stripes:
                api.cuboid_on(x, 2, 2, 3)

            time.sleep(1 / self.speed)

            api.display(api.leds)
Example #3
0
    def run(self):
        while Direction.direction_p_1.value != 7:
            for x in self.snow_drops:
                api.cuboid_off(x, 1, 1, 1)

            for snow_drop in self.snow_drops:
                if snow_drop[1] - self.fall_speed < 0:
                    self.snow_drops.remove(snow_drop)
                else:
                    snow_drop[1] -= self.fall_speed

            for x in range(self.intensity):
                self.snow_drops = self.snow_drops + [[
                    random.random(), 1, random.random()
                ]]

            for x in self.snow_drops:
                api.cuboid_on(x, 1, 1, 1)

            time.sleep(1 / self.speed)

            api.display(api.leds)
Example #4
0
    def run(self):
        while Direction.direction_p_1.value != 7:
            for x in self.fog_stripes:
                api.cuboid_off(x, 1, 1, 3)

            for fog_stripe in self.fog_stripes:
                if fog_stripe[2] + self.fall_speed > 7:
                    self.fog_stripes.remove(fog_stripe)
                else:
                    fog_stripe[2] += self.fall_speed

            for x in range(self.intensity):
                self.fog_stripes = self.fog_stripes + [[
                    random.random(),
                    random.random(),
                    random.random()
                ]]

            for x in self.fog_stripes:
                api.cuboid_on(x, 1, 1, 3)

            time.sleep(1 / self.speed)

            api.display(api.leds)
Example #5
0
    def run(self):
        Direction.direction_p_1.value = 0
        while not self.failed and Direction.direction_p_1.value != 7:
            api.cuboid_off(self.ball_loc, self.ball_size, self.ball_size,
                           self.ball_size)

            # Ball moving
            self.ball_loc[0] += self.ball_vel_x
            self.ball_loc[1] += self.ball_vel_y
            self.ball_loc[2] += self.ball_vel_z

            # Ball turning on wall impact
            if self.ball_loc[0] - self.ball_radius < 0 or self.ball_loc[
                    0] + self.ball_radius > 1:
                self.ball_vel_x *= -1

            if self.ball_loc[1] - self.ball_radius < 0 or self.ball_loc[
                    1] + self.ball_radius > 1:
                self.ball_vel_y *= -1

            if self.ball_loc[2] - self.ball_radius < 0 or self.ball_loc[
                    2] + self.ball_radius > 1:
                self.ball_vel_z *= -1

            # Player1 moving
            self.player1_action = Direction.direction_p_1.value

            if self.player1_action is not None:
                if self.player1_action == int(Direction.Direction.UP):
                    api.cuboid_off(self.player1_loc, self.player1_size,
                                   self.player1_size, 1)

                    if self.player1_loc[1] + self.mov_val <= 1:
                        self.player1_loc[1] += self.mov_val
                    else:
                        self.player1_loc[1] = 0.99

                    api.cuboid_on(self.player1_loc, self.player1_size,
                                  self.player1_size, 1)

                if self.player1_action == int(Direction.Direction.DOWN):
                    api.cuboid_off(self.player1_loc, self.player1_size,
                                   self.player1_size, 1)

                    if self.player1_loc[1] - self.mov_val >= 0:
                        self.player1_loc[1] -= self.mov_val
                    else:
                        self.player1_loc[1] = 0.01

                    api.cuboid_on(self.player1_loc, self.player1_size,
                                  self.player1_size, 1)

                if self.player1_action == int(Direction.Direction.BACK):
                    api.cuboid_off(self.player1_loc, self.player1_size,
                                   self.player1_size, 1)

                    if self.player1_loc[0] + self.mov_val <= 1:
                        self.player1_loc[0] += self.mov_val
                    else:
                        self.player1_loc[0] = 0.99

                    api.cuboid_on(self.player1_loc, self.player1_size,
                                  self.player1_size, 1)

                if self.player1_action == int(Direction.Direction.FORTH):
                    api.cuboid_off(self.player1_loc, self.player1_size,
                                   self.player1_size, 1)

                    if self.player1_loc[0] - self.mov_val >= 0:
                        self.player1_loc[0] -= self.mov_val
                    else:
                        self.player1_loc[0] = 0.01

                    api.cuboid_on(self.player1_loc, self.player1_size,
                                  self.player1_size, 1)

                Direction.direction_p_1.value = 0

            # Player2 moving
            self.player2_action = Direction.direction_p_2.value

            if self.player2_action is not None:
                if self.player2_action == int(Direction.Direction.UP):
                    api.cuboid_off(self.player2_loc, self.player2_size,
                                   self.player2_size, 1)

                    if self.player2_loc[1] + self.mov_val <= 1:
                        self.player2_loc[1] += self.mov_val
                    else:
                        self.player2_loc[1] = 0.99

                    api.cuboid_on(self.player2_loc, self.player2_size,
                                  self.player2_size, 1)

                if self.player2_action == int(Direction.Direction.DOWN):
                    api.cuboid_off(self.player2_loc, self.player2_size,
                                   self.player2_size, 1)

                    if self.player2_loc[1] - self.mov_val >= 0:
                        self.player2_loc[1] -= self.mov_val
                    else:
                        self.player2_loc[1] = 0.01

                    api.cuboid_on(self.player2_loc, self.player2_size,
                                  self.player2_size, 1)

                if self.player2_action == int(Direction.Direction.BACK):
                    api.cuboid_off(self.player2_loc, self.player2_size,
                                   self.player2_size, 1)

                    if self.player2_loc[0] + self.mov_val <= 1:
                        self.player2_loc[0] += self.mov_val
                    else:
                        self.player2_loc[0] = 0.99

                    api.cuboid_on(self.player2_loc, self.player2_size,
                                  self.player2_size, 1)

                if self.player2_action == int(Direction.Direction.FORTH):
                    api.cuboid_off(self.player2_loc, self.player2_size,
                                   self.player2_size, 1)

                    if self.player2_loc[0] - self.mov_val >= 0:
                        self.player2_loc[0] -= self.mov_val
                    else:
                        self.player2_loc[0] = 0.01

                    api.cuboid_on(self.player2_loc, self.player2_size,
                                  self.player2_size, 1)

                Direction.direction_p_2.value = 0

            if self.ball_loc[2] - self.ball_radius < 1 / self.cube_size:
                if ((self.player1_loc[1] + self.player1_radius * 2 >
                     self.ball_loc[1] >
                     self.player1_loc[1] - self.player1_radius * 2)
                        and (self.player1_loc[0] + self.player1_radius * 2 >
                             self.ball_loc[0] >
                             self.player1_loc[0] - self.player1_radius * 2)):
                    self.ball_vel_z *= -1

            if self.ball_loc[2] + self.ball_radius > 1 - (1 / self.cube_size):
                if ((self.player2_loc[1] + self.player2_radius * 2 >
                     self.ball_loc[1] >
                     self.player2_loc[1] - self.player2_radius * 2)
                        and (self.player2_loc[0] + self.player2_radius * 2 >
                             self.ball_loc[0] >
                             self.player2_loc[0] - self.player2_radius * 2)):
                    self.ball_vel_z *= -1

            # If Ball hits player1 wall
            if self.ball_loc[2] - self.ball_radius < 0:
                if not ((self.player1_loc[1] + self.player1_radius * 2 >
                         self.ball_loc[1] >
                         self.player1_loc[1] - self.player1_radius * 2) and
                        (self.player1_loc[0] + self.player1_radius * 2 >
                         self.ball_loc[0] >
                         self.player1_loc[0] - self.player1_radius * 2)):
                    self.player2_score += 1
                    api.cuboid_off(self.ball_loc, self.ball_size,
                                   self.ball_size, self.ball_size)
                    self.ball_loc = [0.4, 0.6, 0.5]
                    api.cuboid_on(self.ball_loc, self.ball_size,
                                  self.ball_size, self.ball_size)
                    time.sleep(3)

            # If Ball hits player2 wall
            if self.ball_loc[2] + self.ball_radius > 1:
                if not ((self.player2_loc[1] + self.player2_radius * 2 >
                         self.ball_loc[1] >
                         self.player2_loc[1] - self.player2_radius * 2) and
                        (self.player2_loc[0] + self.player2_radius * 2 >
                         self.ball_loc[0] >
                         self.player2_loc[0] - self.player2_radius * 2)):
                    self.player1_score += 1
                    api.cuboid_off(self.ball_loc, self.ball_size,
                                   self.ball_size, self.ball_size)
                    self.ball_loc = [0.4, 0.6, 0.5]
                    api.cuboid_on(self.ball_loc, self.ball_size,
                                  self.ball_size, self.ball_size)
                    time.sleep(3)

            # If Ball hits the paddle bounce off of it and do not go into the paddle P1
            if self.ball_loc[0] == 0 and any(loc in [self.ball_loc]
                                             for loc in self.player1_loc):
                self.ball_loc[0] = 1

            # If Ball hits the paddle bounce off of it and do not go into the paddle P2
            if self.ball_loc[0] == 7 and any(loc in [self.ball_loc]
                                             for loc in self.player2_loc):
                self.ball_loc[0] = 6

            if self.player1_score == 8 or self.player2_score == 8:
                self.failed = True
                api.change_face(
                    api.Face.LEFT, 0,
                    Frames.number_to_frame(int(self.player1_score)))
                api.change_face(
                    api.Face.RIGHT, 0,
                    Frames.number_to_frame(int(self.player2_score)))

                self.done()

            # Turn on new position
            # api.led_on(self.ball_loc)
            api.cuboid_on(self.ball_loc, self.ball_size, self.ball_size,
                          self.ball_size)
            api.cuboid_on(self.player1_loc, self.player1_size,
                          self.player2_size, 1)
            api.cuboid_on(self.player2_loc, self.player2_size,
                          self.player2_size, 1)

            api.display(api.leds)
            time.sleep(0.1)
Example #6
0
 def done(self):
     for x in range(0, 8):
         api.led_on([0, x, 0], [7, x, 0], [0, x, 7], [7, x, 7])
         api.display(api.leds)
         time.sleep(1)
Example #7
0
 def run(self):
     api.draw_sun([0.5, 0.5, 0.5], 8, 8, 8)
     api.display(api.leds)
     while Direction.direction_p_1.value != 7:
         time.sleep(0.5)
Example #8
0
    def run(self):
        Direction.direction_p_1.value = int(Direction.Direction.UP)
        while not self.failed:
            if Direction.direction_p_1.value == 0:
                Direction.direction_p_1.value = int(Direction.Direction.UP)
            if self.snake_length > len(self.snake_loc):
                self.snake_loc.append(self.snake_loc[len(self.snake_loc) - 1])
                self.snake_length = len(self.snake_loc)

            api.led_off(self.snake_loc[self.snake_length - 1])
            for x in range(1, self.snake_length):
                self.snake_loc[self.snake_length -
                               x] = self.snake_loc[self.snake_length - x - 1]
            if Direction.direction_p_1.value == int(Direction.Direction.FORTH):
                y = self.snake_loc[0]
                self.snake_loc[0] = [y[0], y[1] + 1, y[2]]
            elif Direction.direction_p_1.value == int(
                    Direction.Direction.BACK):
                y = self.snake_loc[0]
                self.snake_loc[0] = [y[0], y[1] - 1, y[2]]
            elif Direction.direction_p_1.value == int(
                    Direction.Direction.RIGHT):
                y = self.snake_loc[0]
                self.snake_loc[0] = [y[0], y[1], y[2] + 1]
            elif Direction.direction_p_1.value == int(
                    Direction.Direction.LEFT):
                y = self.snake_loc[0]
                self.snake_loc[0] = [y[0], y[1], y[2] - 1]
            elif Direction.direction_p_1.value == int(Direction.Direction.UP):
                y = self.snake_loc[0]
                self.snake_loc[0] = [y[0] + 1, y[1], y[2]]
            elif Direction.direction_p_1.value == int(
                    Direction.Direction.DOWN):
                y = self.snake_loc[0]
                self.snake_loc[0] = [y[0] - 1, y[1], y[2]]
            for s in self.snake_loc:
                api.led_on(s)

            api.led_on(self.pickup_loc)

            for loc in self.snake_loc:
                loc[0] = loc[0] % 8
                loc[1] = loc[1] % 8
                loc[2] = loc[2] % 8
            if self.snake_loc[0] in self.snake_loc[1:]:
                self.failed = True
                api.change_face(api.Face.LEFT, 0,
                                Frames.number_to_frame(int(self.score / 100)))
                api.change_face(
                    api.Face.FRONT, 0,
                    Frames.number_to_frame(int((self.score % 100) / 10)))
                api.change_face(api.Face.RIGHT, 0,
                                Frames.number_to_frame(int(self.score % 10)))

                # Timer for cooldown
                for x in range(0, 8):
                    api.led_on([0, x, 0], [7, x, 0], [0, x, 7], [7, x, 7])
                    api.display(api.leds)
                    time.sleep(1)

            if self.snake_loc[0][0] % 8 == self.pickup_loc[0] and self.snake_loc[0][1] % 8 == self.pickup_loc[1] and \
                    self.snake_loc[0][2] % 8 == self.pickup_loc[2]:
                self.snake_length += 1
                self.score += 1
                found_spawn = False
                while not found_spawn:
                    self.pickup_loc = [
                        random.randint(0, 7),
                        random.randint(0, 7),
                        random.randint(0, 7)
                    ]
                    if self.pickup_loc not in self.snake_loc:
                        found_spawn = True

            api.display(api.leds)
            time.sleep(0.2)
Example #9
0
    def run(self):
        counter = 0
        while not self.failed:
            # Turn off last position
            # api.led_off(self.ball_loc)

            # Ball moving
            """
            self.ball_loc[0] += self.ball_vel_x
            self.ball_loc[1] += self.ball_vel_y
            self.ball_loc[2] += self.ball_vel_z
            """

            api.cuboid_off(self.b_loc, self.b_size, self.b_size, self.b_size)

            if counter == 7:
                self.b_loc[0] += self.ball_vel_x
                self.b_loc[1] += self.ball_vel_y
                self.b_loc[2] += self.ball_vel_z

                changed = False

                if self.b_loc[0] - self.b_radius < 0 or self.b_loc[0] + self.b_radius > 1:
                    self.ball_vel_x *= -1
                    changed = True

                if self.b_loc[1] - self.b_radius < 0 or self.b_loc[1] + self.b_radius > 1:
                    self.ball_vel_y *= -1
                    changed = True

                if self.b_loc[2] - self.b_radius < 0 or self.b_loc[2] + self.b_radius > 1:
                    self.ball_vel_z *= -1
                    changed = True

                if self.b_loc[1] - self.b_radius < 1 / self.cube_size and not changed:
                    if ((self.p_loc[0] + self.p_radius > self.b_loc[0] > self.p_loc[0] - self.p_radius) and (
                            self.p_loc[2] + self.p_radius > self.b_loc[2] > self.p_loc[2] - self.p_radius)):
                        self.ball_vel_y *= -1

                if self.b_loc[1] - self.b_radius < 0:
                    if not ((self.p_loc[0] + self.p_radius > self.b_loc[0] > self.p_loc[0] - self.p_radius) and (
                            self.p_loc[2] + self.p_radius > self.b_loc[2] > self.p_loc[2] - self.p_radius)):
                        self.failed = True

                        self.done()

            # Player moving
            self.player_action = Direction.direction_p_1.value
            if self.player_action is not None:
                if self.player_action == int(Direction.Direction.UP):

                    api.cuboid_off(self.p_loc, self.p_size, 1, self.p_size)

                    if self.p_loc[0] + self.mov_val <= 1:
                        self.p_loc[0] += self.mov_val
                    else:
                        self.p_loc[0] = 0.99

                    api.cuboid_on(self.p_loc, self.p_size, 1, self.p_size)
                if self.player_action == int(Direction.Direction.DOWN):
                    api.cuboid_off(self.p_loc, self.p_size, 1, self.p_size)

                    if self.p_loc[0] - self.mov_val >= 0:
                        self.p_loc[0] -= self.mov_val
                    else:
                        self.p_loc[0] = 0.01

                    api.cuboid_on(self.p_loc, self.p_size, 1, self.p_size)
                if self.player_action == int(Direction.Direction.RIGHT):
                    api.cuboid_off(self.p_loc, self.p_size, 1, self.p_size)

                    if self.p_loc[2] + self.mov_val <= 1:
                        self.p_loc[2] += self.mov_val
                    else:
                        self.p_loc[2] = 0.99

                    api.cuboid_on(self.p_loc, self.p_size, 1, self.p_size)
                if self.player_action == int(Direction.Direction.LEFT):
                    api.cuboid_off(self.p_loc, self.p_size, 1, self.p_size)

                    if self.p_loc[2] - self.mov_val >= 0:
                        self.p_loc[2] -= self.mov_val
                    else:
                        self.p_loc[2] = 0.01

                    api.cuboid_on(self.p_loc, self.p_size, 1, self.p_size)
                Direction.direction_p_1.value = 0

            # Turn on new position
            # api.led_on(self.ball_loc)
            api.cuboid_on(self.b_loc, self.b_size, self.b_size, self.b_size)
            api.cuboid_on(self.p_loc, self.p_size, 1, self.p_size)

            api.display(api.leds)

            counter = (counter + 1) % 8

            time.sleep(0.1)