# data[].attributes.headline
# generated by mBlock5 for HaloCode# codes make you happyimport event, halo, time# initialize variablescount = 0@event.startdef on_start():    global count    count = 0    while True:        count = count + 1        if count == 1:            halo.led.show_single(count, 255, 0, 0)            time.sleep(1)        if count == 2:            halo.led.show_single(count, 0, 255, 0)            time.sleep(1)        if count == 3:            halo.led.show_single(count, 0, 0, 255)            time.sleep(1)        if count == 4:            halo.led.show_single(count, 255, 255, 0)            time.sleep(1)        if count == 5:            halo.led.show_single(count, 0, 255, 255)            time.sleep(1)        if count == 6:            halo.led.show_single(count, 255, 255, 255)            time.sleep(1)        if count == 7:            halo.led.show_single(count, 255, 0, 0)            time.sleep(1)        if count == 8:            halo.led.show_single(count, 0, 255, 0)            time.sleep(1)        if count == 9:            halo.led.show_single(count, 0, 0, 255)            time.sleep(1)        if count == 10:            halo.led.show_single(count, 255, 255, 0)            time.sleep(1)        if count == 11:            halo.led.show_single(count, 0, 255, 255)            time.sleep(1)        if count == 12:            halo.led.show_single(count, 255, 255, 255)            time.sleep(1)

# data[].attributes.subject
# generated by mBlock5 for HaloCode# codes make you happyimport event, halo, time# initialize variablescount = 0@event.startdef on_start():    global count    count = 0    while True:        count = count + 1        if count == 1:            halo.led.show_single(count, 255, 0, 0)            time.sleep(1)        if count == 2:            halo.led.show_single(count, 0, 255, 0)            time.sleep(1)        if count == 3:            halo.led.show_single(count, 0, 0, 255)            time.sleep(1)        if count == 4:            halo.led.show_single(count, 255, 255, 0)            time.sleep(1)        if count == 5:            halo.led.show_single(count, 0, 255, 255)            time.sleep(1)        if count == 6:            halo.led.show_single(count, 255, 255, 255)            time.sleep(1)        if count == 7:            halo.led.show_single(count, 255, 0, 0)            time.sleep(1)        if count == 8:            halo.led.show_single(count, 0, 255, 0)            time.sleep(1)        if count == 9:            halo.led.show_single(count, 0, 0, 255)            time.sleep(1)        if count == 10:            halo.led.show_single(count, 255, 255, 0)            time.sleep(1)        if count == 11:            halo.led.show_single(count, 0, 255, 255)            time.sleep(1)        if count == 12:            halo.led.show_single(count, 255, 255, 255)            time.sleep(1)

# data[].attributes.attachment_link.readable_text
#Space game
import pygame
import random
import player
import aliens
import misc
import playerProjectile
import alienProjectile

# Start the game
pygame.init()
screen = pygame.display.set_mode((misc.game_width, misc.game_height))
clock = pygame.time.Clock()
running = True

# Load the background image
background_pic = pygame.transform.scale(pygame.image.load("./assets/background.png"),(misc.game_width,misc.game_height))

# Create the player object
player = player.Player(misc.game_width/2, 600)

# Player projectile variables
allPlayerProj = []
projectile_timer = 0
projectile_timer_max = 60
player_ammo = 10
projectile_duplicate = 5

# Main game loop below
while running:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            running = False
        if event.type == pygame.KEYDOWN and event.key == pygame.K_ESCAPE:
            running = False

    # Shoot the player projectile when the spacebar is pressed
    projectile_timer += 1
    keys = pygame.key.get_pressed()
    if keys[pygame.K_SPACE] and player_ammo > 0 and projectile_duplicate > 5:
        allPlayerProj.append(playerProjectile.Projectile(player.x, player.y))
        player_ammo -= 1
        projectile_duplicate = 0
    projectile_duplicate += 1

    # Reload ammo
    projectile_timer += 1
    if projectile_timer >= projectile_timer_max and player_ammo < 10:
        player_ammo += 1
        projectile_timer = 0

    # Draw the background, aliens, player and projectiles
    screen.blit(background_pic,(0,0))
    player.update(screen)

    # Remove projectiles that are out of the screen
    for index in range(len(allPlayerProj), 0, -1):
        playerproj = allPlayerProj[index - 1]
        if playerproj.y < 0 - playerproj.height:
            allPlayerProj.remove(playerproj)
        playerproj.update(screen)


    # Update the game display
    pygame.display.flip()
    clock.tick(50)
    pygame.display.set_caption("MY GAME fps: " + str(clock.get_fps()))


# data[].attributes.attachment_link.readable_text
#Space game
import pygame
import misc

#player class
class Player:
    def __init__(self, x, y):
        self.width = 100
        self.height = 100
        self.speed = 10
        self.x = x
        self.y = y
        self.dir = 'right'
        self.pic_right = pygame.transform.scale(pygame.image.load("./assets/tankRight.png"),(self.width, self.height))
        self.pic_left = pygame.transform.scale(pygame.image.load("./assets/tankLeft.png"), (self.width, self.height))
        self.hitbox = pygame.Rect(self.x, self.y, self.width, self.height)

    def update(self,screen):
        # Move the player when the keys are pressed, set direction to be the one it is facing
        keys = pygame.key.get_pressed()
        if keys[pygame.K_RIGHT]:
            self.x += self.speed
            self.dir = 'right'
        elif keys[pygame.K_LEFT]:
            self.x -= self.speed
            self.dir = 'left'

        #Set boundaries for player movement
        if self.x >= misc.game_width - self.width:
            self.x = misc.game_width - self.width
        elif self.x < 0:
            self.x = 0

        # Draw the correct image depending on the direction
        if self.dir is 'right':
            screen.blit(self.pic_right, (self.x, self.y))
        else:
            screen.blit(self.pic_left, (self.x, self.y))

        #Update hitbox
        self.hitbox = misc.hitbox(self.hitbox, self.x, self.y)

# data[].attributes.attachment_link.readable_text
Welcome to Singapore!

Welcome to Singapore

A sunny island in Southeast Asia!

Gardens by the Bay

Merlion

Singapore Zoo

Attractions

View Our Attractions

Hotel

Book a Hotel

Food

Explore Local Food

Visit Sentosa

Find out more

Explore Singapore

# data[].attributes.attachment_link.readable_text
Welcome to Singapore!

Welcome to Singapore

A sunny island in Southeast Asia!

Gardens by the Bay

Merlion

Singapore Zoo

Attractions

View Our Attractions

Hotel

Book a Hotel

Food

Explore Local Food

Visit Sentosa

Find out more

Explore Singapore

# data[].attributes.attachment_link.readable_text
Welcome to Singapore!

Welcome to Singapore

Attractions

View Our Attractions

Hotel

Book a Hotel

Food

Explore Local Food

Visit Sentosa

Find out more

Explore Singapore

# data[].attributes.attachment_link.readable_text
#Underwater World
import pygame
import random

#Set up the Bubble class
class Bubble():
    def __init__ (self, x, y):
        self.x = x
        self.y = y
        self.speed = random.randint (1,3)
        self.pic = pygame.image.load ("./assets/Bubble.png")
        self.on_screen = True

        self.pic = pygame.transform.scale(self.pic, (15,15))

    def update (self, screen):
        self.y -= self.speed
        screen.blit (self.pic, (self.x, self.y))

        if self.y < -self.pic.get_height ():
            self.on_screen = False

#Set up the Enemy class
class Enemy():
    #Enemy Constructor Function
    def __init__(self,x,y,speed,size):
        self.x = x
        self.y = y
        self.type = random.randint(0,3)
        if self.type == 0:
            self.pic = pygame.image.load("./assets/fish03.png")
        if self.type == 1:
            self.pic = pygame.image.load("./assets/fish02.png")
        if self.type == 2:
            self.pic = pygame.image.load("./assets/fish04.png")
        if self.type == 3:
            self.pic = pygame.image.load("./assets/fish05.png")
        self.speed = speed
        self.size = size
        self.hitbox = pygame.Rect(self.x + self.size/10, self.y + self.size/10,
                                  self.size - self.size/5, self.size - self.size/5)

        #Shrink the enemy pic
        self.pic = pygame.transform.scale(self.pic, (self.size, self.size))

        #Flip the pic if the Enemy is moving to the left
        if self.speed < 0:
            self.pic = pygame.transform.flip(self.pic,True,False)

    def update(self, screen):
        self.x += self.speed
        self.hitbox.x += self.speed
        #pygame.draw.rect(screen,(0,255,255),self.hitbox)
        screen.blit(self.pic,(self.x, self.y))

#End of Enemy Class

#Start the game
pygame.init()
game_width = 1000
game_height = 650
screen = pygame.display.set_mode((game_width, game_height))
clock = pygame.time.Clock()
running = True

#Load the images
background_pic = pygame.image.load("./assets/Scene_A.png")
background_pic2 = pygame.image.load("./assets/Scene_B.png")
player_pic = pygame.image.load("./assets/fish01A.png")
player_eating_pic = pygame.image.load ("./assets/fish01B.png")

#Variables for the background animation
bg_animation_timer_max = 25
bg_animation_timer = bg_animation_timer_max
bg_animation_frame = background_pic

#Variables for player animation
player_eating_timer_max = 6
player_eating_timer = 0

#Player's variables
player_starting_x = 480
player_starting_y = 310
player_starting_size = 50
player_x = player_starting_x
player_y = player_starting_y
player_speed = 3
player_size = player_starting_size
player_facing_left = False
player_hitbox = pygame.Rect(player_x,player_y, player_size, player_size)
player_alive = True

#Variables for Heads up Display
score = 0
score_font = pygame.font.SysFont("default", 30)
score_text = score_font.render ("Score: " + str(score), 1, (0, 0 ,0))
play_button_pic = pygame.image.load ("./assets/BtnPlayIcon.png")
play_button_x = game_width/2 - play_button_pic.get_width()/2
play_button_y = game_height/2 - play_button_pic.get_height()/2

#Enemy Spawn Timer
enemy_timer_max = 40
enemy_timer = enemy_timer_max

#Make the Enemies array
enemies = []

# Make the bubbles array
bubbles = []
bubble_timer = 0

#Main game loop below
while running:
    # Makes the game stop if the player clicks the X or presses esc
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            running = False
        if event.type == pygame.KEYDOWN and event.key == pygame.K_ESCAPE:
            running = False

    #Check if key pressed and Player movement
    keys = pygame.key.get_pressed()
    if keys[pygame.K_RIGHT]:
        player_facing_left = False
        player_x += player_speed
    if keys[pygame.K_LEFT]:
        player_facing_left = True
        player_x -= player_speed
    if keys[pygame.K_UP]:
        player_y -= player_speed
    if keys[pygame.K_DOWN]:
        player_y += player_speed
    if keys[pygame.K_SPACE]:
        player_size += 2

    #Background animation
    bg_animation_timer -= 1
    if bg_animation_timer == 0:
        bg_animation_frame = background_pic if bg_animation_frame == background_pic2 else background_pic2
        bg_animation_timer = bg_animation_timer_max
    screen.blit(bg_animation_frame,(0,0))

    #Spawn a new Enemy when enemy_timer hits 0
    enemy_timer -= 1
    if enemy_timer <= 0:
        new_enemy_y = random.randint(0,game_height)
        new_enemy_speed = random.randint(2,5)
        new_enemy_size = random.randint(player_size/2, player_size*2)

        if random.randint(0,1) == 0:
            enemies.append(Enemy(-new_enemy_size*2, new_enemy_y,
                                 new_enemy_speed, new_enemy_size))
        else:
            enemies.append(Enemy(game_width, new_enemy_y,
                                 -new_enemy_speed, new_enemy_size))
        enemy_timer = enemy_timer_max

    #update enemies
    for enemy in enemies:
        enemy.update(screen)
        if enemy.x < - 1000 or enemy.x > game_width + 1000:
            enemies.remove(enemy)

    #Bubble timer
    bubble_timer -= 1
    if bubble_timer <= 0 and player_alive:
        if player_facing_left:
            bubbles.append (Bubble (player_x, player_y))
        else:
            bubbles.append (Bubble (player_x + player_size, player_y))
        bubble_timer = random.randint (40,90)

    #Draw/delete bubbles
    for bubble in bubbles:
        if bubble.on_screen:
            bubble.update(screen)
        else:
            bubbles.remove(bubble)

    if player_alive:
        #Collision detection
        for enemy in enemies:
            if player_hitbox.colliderect(enemy.hitbox):
                if player_size >= enemy.size:
                    score += enemy.size
                    player_size += 2
                    enemies.remove(enemy)
                    player_eating_timer = player_eating_timer_max
                else:
                    player_alive = False

        #Player hitbox properties
        player_hitbox.x = player_x + player_size/8
        player_hitbox.y = player_y + player_size/5
        player_hitbox.width = player_size - player_size/4
        player_hitbox.height = player_size - player_size/2
        #pygame.draw.rect(screen,(225,0,225),player_hitbox)

        #Draw the player
        if player_eating_timer > 0:
            player_pic_small = pygame.transform.scale(player_eating_pic, (player_size, player_size))
            player_eating_timer -= 1
        else:
            player_pic_small = pygame.transform.scale(player_pic, (player_size, player_size))
        if player_facing_left:
            player_pic_small = pygame.transform.flip(player_pic_small, True, False)
        screen.blit(player_pic_small, (player_x, player_y))

    #Display the score
    if player_alive:
        score_text = score_font.render("Score: " + str(score), 1, (0, 0, 0))
    else:
        score_text = score_font.render("Final Score " + str(score), 1, (0, 0, 0))
    screen.blit(score_text, (30, 30))

    #Reset the game
    if not player_alive:
        screen.blit(play_button_pic, (play_button_x, play_button_y))
        mouse_x, mouse_y = pygame.mouse.get_pos()
        if pygame.mouse.get_pressed()[0]:
            if mouse_x > play_button_x and mouse_x < play_button_x + play_button_pic.get_width():
                if mouse_y > play_button_y and mouse_y < play_button_y + play_button_pic.get_height():
                    player_alive = True
                    score = 0
                    player_x = player_starting_x
                    player_y = player_starting_y
                    player_size = player_starting_size
                    enemies = []

    #Player boundary
    if player_x < 0:
        player_x = 0
    if player_x > game_width - player_size:
        player_x = game_width - player_size
    if player_y < 0:
        player_y = 0
    if player_y > game_height - player_size:
        player_y = game_height - player_size

    pygame.display.flip()
    clock.tick(50)
    pygame.display.set_caption("MY GAME fps: " + str(clock.get_fps()))

# data[].attributes.attachment_link.readable_text
#Space game
import pygame
import random
import player
import aliens
import misc
import playerProjectile
import alienProjectile

# Start the game
pygame.init()
screen = pygame.display.set_mode((misc.game_width, misc.game_height))
clock = pygame.time.Clock()
running = True

# Load the background image
background_pic = pygame.transform.scale(pygame.image.load("./assets/background.png"),(misc.game_width,misc.game_height))

# Load sounds
player_sound = pygame.mixer.Sound("./assets/playerexplosion.wav")
alien_sound = pygame.mixer.Sound("./assets/alienexplosion.wav")
lose_sound = pygame.mixer.Sound("./assets/playerlose.wav")
reload_sound = pygame.mixer.Sound("./assets/reload.wav")
projectile_sound = pygame.mixer.Sound("./assets/projectile.wav")

# Play background audio
pygame.mixer.music.load("./assets/background.wav")
pygame.mixer.music.play(-1)

# Create the player object
player = player.Player(misc.game_width/2, 600)

# Initialise gamestate
gamestate = 'start'

# Alien variables
alien_timer = 0
allAliens = []

# Player projectile variables
allPlayerProj = []
projectile_timer = 0
projectile_timer_max = 60
player_ammo = 10
projectile_duplicate = 5

# Alien projectile variables
allAlienProj = []
alienProj_timer = random.randint(50,200)

# Heads up display
score = 0
font = pygame.font.Font("./assets/font.ttf",30)
start_font = pygame.font.Font("./assets/font.ttf",50)
allscores = []

# Player health
health = 300

# Main game loop below
while running:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            running = False
        if event.type == pygame.KEYDOWN and event.key == pygame.K_ESCAPE:
            running = False

    # Shoot the player projectile when the spacebar is pressed
    keys = pygame.key.get_pressed()
    if keys[pygame.K_SPACE] and player_ammo > 0 and projectile_duplicate > 5:
        allPlayerProj.append(playerProjectile.Projectile(player.x, player.y))
        player_ammo -= 1
        projectile_duplicate = 0
        pygame.mixer.Sound.play(projectile_sound)
    projectile_duplicate += 1

    projectile_timer += 1
    if projectile_timer >= projectile_timer_max and player_ammo < 10:
        pygame.mixer.Sound.play(reload_sound)
        player_ammo += 1
        projectile_timer = 0

    # Draw the background, aliens, player and projectiles
    screen.blit(background_pic,(0,0))
    player.update(screen)

    # Remove projectiles that are out of the screen
    for index in range(len(allPlayerProj), 0, -1):
        playerproj = allPlayerProj[index - 1]
        if playerproj.y < 0 - playerproj.height:
            allPlayerProj.remove(playerproj)
        playerproj.update(screen)

    # Display the player ammo
    ammo_text = font.render("Ammo " + str(player_ammo),1, (255,255,255))
    screen.blit(ammo_text,(30,650))

    # Display the game score
    score_text = font.render("Score " + str(score), 1, (255, 255, 255))
    screen.blit(score_text, (30, 30))

    # Display the player health
    health_rect = pygame.Rect(950, 30, health, 30)
    health_rect_max = pygame.Rect(950, 30, 300, 30)
    pygame.draw.rect(screen, (255, 0, 0), health_rect_max)
    pygame.draw.rect(screen, (0, 255, 0), health_rect)
    health_text = font.render("Health  " + str(health), 1, (255, 255, 255))
    screen.blit(health_text, (950, 60))

    if gamestate is 'start':
        # Reset game variables
        allAliens = []
        allAlienProj = []
        score = 0
        health = 300

        start_text = start_font.render("Press ENTER to start!" , 1, (255, 255, 255))
        screen.blit(start_text, (misc.game_width/2 - 250, misc.game_height/2 - 100))

        keys = pygame.key.get_pressed()
        if keys[pygame.K_RETURN]:
            gamestate = 'play'

    # When the game is in play
    if gamestate is 'play':
        # Randomly create new aliens over time
        if alien_timer <= 0:
            alien_timer = random.randint(50,150)
            allAliens.append(aliens.Alien(random.randint(200,750), 0, 2))
        else:
            alien_timer -= 1

        for index in range(len(allAliens)-1, -1, -1):
            #Randomly create alien projectiles
            alien = allAliens[index]
            if alienProj_timer <= 0:
                allAlienProj.append(alienProjectile.Projectile(alien.x, alien.y))
                alienProj_timer = random.randint(50,150)
            else:
                alienProj_timer -= 1
            # Check for collision between player projectiles and aliens and remove aliens that are hit
            for projectile in allPlayerProj:
                if projectile.hitbox.colliderect(alien.hitbox):
                    alien.health -= 1
                    allPlayerProj.remove(projectile)
                    pygame.mixer.Sound.play(alien_sound)
                if alien.health <= 0:
                    allAliens.remove(alien)
                    score += 1
                    break
            # Check if game is lost
            if alien.y > 500 or health <= 0:
                pygame.mixer.Sound.play(lose_sound)
                gamestate = 'end'
             #Update all aliens
            alien.update(screen)

        # Check for collision between alien projectiles and player
        for projectile in allAlienProj:
            if projectile.hitbox.colliderect(player.hitbox):
                allAlienProj.remove(projectile)
                health -= 30
                pygame.mixer.Sound.play(player_sound)

        # Remove projectiles that are out of screen
        for index in range(len(allAlienProj), 0, -1):
            alienproj = allAlienProj[index - 1]
            if alienproj.y > misc.game_height:
                allAlienProj.remove(alienproj)
            alienproj.update(screen)

    if gamestate is 'end':
        # Reset game variables
        allAliens = []
        allAlienProj = []
        ammo = 10
        # Store game score
        allscores.append(score)

        restart_text = start_font.render("Press ENTER to play again!", 1, (255, 255, 255))
        game_score_text = font.render("Your score was " + str(score), 1, (255, 255, 255))
        high_score = font.render("Your high score is " + str(max(allscores)), 1, (255, 255, 255))
        screen.blit(restart_text, (misc.game_width / 2 - 300, misc.game_height / 2 - 100))
        screen.blit(game_score_text, (misc.game_width / 2 - 120, misc.game_height / 2 - 30))
        screen.blit(high_score, (misc.game_width / 2 - 150, misc.game_height / 2))

        keys = pygame.key.get_pressed()
        if keys[pygame.K_RETURN]:
            score = 0
            health = 300
            gamestate = 'play'

    # Update the game display
    pygame.display.flip()
    clock.tick(50)
    pygame.display.set_caption("MY GAME fps: " + str(clock.get_fps()))