def make_bubbles(bubbles, speed_tuples): number = 0 old_bubbles = [] x, y = pygame.mouse.get_pos() for sprite in bubbles: if sprite.rect.collidepoint(x, y): old_bubbles.append(sprite) bubb1 = tsk.Sprite("Bubble.png", sprite.x, sprite.y) bubb2 = tsk.Sprite("Bubble.png", sprite.center_x, sprite.center_y) bubb1.scale = .5 * sprite.scale bubb2.scale = bubb1.scale bubbles.append(bubb1) bubbles.append(bubb2) rand_x = random.randint(5, 15) / 100 rand_y = random.randint(5, 15) / 100 rand_speed1 = (rand_x, rand_y) rand_speed2 = (rand_x * -1, rand_y * -1) speed_tuples.append(rand_speed1) speed_tuples.append(rand_speed2) for bubble_to_remove in old_bubbles: number += 1 curr_index = bubbles.index(bubble_to_remove) speed_tuples.remove(speed_tuples[curr_index]) bubbles.remove(bubble_to_remove) return number
def draw_sprites(x, y): panda = tsk.Sprite("PandaPilot.png", 0, 0) puffin = tsk.Sprite("PuffinWalk.png", 0, 0) panda.center_x = x panda.center_y = y puffin.center_x = -20 + x puffin.center_y = -280 + y panda.draw() puffin.draw()
def create_animal(sprite_name): if sprite_name != "Dog" or sprite_name != "Cat": return sprite_name += ".png" sprite = tsk.Sprite(sprite_name, random.randint(0, 900), random.randint(150, 500)) sprite.draw()
def make_stars(all_stars): num_stars = random.randint(1, 20) for i in range(num_stars): x = random.randint(0, 990) y = random.randint(0, 540) star = tsk.Sprite("Star.png", x, y) all_stars.append(star) return num_stars
def draw_bee(direction): x = random.randint(0, 950) y = random.randint(0, 500) bee = tsk.Sprite("Bee.png", x, y) if direction == "left": bee.flip_x = True bee.draw()
def __init__(self, position, mass, volume): self.position = position self.mass = mass self.volume = volume self.velocity = Vector2(0, 0) self.gravitationalForce = Vector2(0, mass * PhysicsVariables.g) self.buoyantForce = Vector2( 0, -PhysicsVariables.airDensity * PhysicsVariables.g * volume) self.netMomentum = Vector2(0, 0) self.sprite = tsk.Sprite("BalloonRed.png", 0, 0) self.sprite.scale = 0.2
def draw_ships(num_ships): if num_ships <= 0: return draw_increment = 1018 / num_ships x = 0 y = 200 for i in range(num_ships): ship = tsk.Sprite("RoundShip.png", x, y) ship.draw() x += draw_increment
import pygame import tsk pygame.init() window = pygame.display.set_mode([1018, 573]) c = pygame.time.Clock() background = tsk.Sprite("Grass.jpg", 0, 0) ball = tsk.Sprite("GolfBall.png", 50, 250) bush = tsk.Sprite("BushesRight.png", 600, 350) drawing = True while drawing: for event in pygame.event.get(): if event.type == pygame.QUIT: drawing = False # old_center is the position the ball was in on the previous frame old_center = ball.center x, y = pygame.mouse.get_pos() ball.center = x, y if pygame.sprite.collide_rect(ball, bush): ball.center = old_center background.draw() bush.draw() ball.draw() pygame.display.flip() c.tick(30)
import pygame import tsk pygame.init() window = pygame.display.set_mode([1018, 573]) sky = tsk.Sprite("OutdoorEmptySky.png", 0, 0) panda = tsk.Sprite("PandaPilot.png", 0, 0) drawing = True while drawing: for event in pygame.event.get(): if event.type == pygame.QUIT: drawing = False sky.draw() panda.draw() pygame.display.flip()
import tsk import pygame pygame.init() window = pygame.display.set_mode([1018, 573]) c = pygame.time.Clock() background = tsk.Sprite("HedgehogHouse.jpg", 0, 0) sleep_sheet = tsk.ImageSheet("HedgehogSleep.png", 5, 6) brush_sheet = tsk.ImageSheet("HedgehogBrush.png", 5, 6) run_sheet = tsk.ImageSheet("HedgehogRun.png", 5, 6) hedgehog = tsk.Sprite(sleep_sheet, 100, 100) drawing = True while drawing: for event in pygame.event.get(): if event.type == pygame.QUIT: drawing = False x, y = pygame.mouse.get_pos()
""" SideProject: Reaction Timer/wild west Description: """ import pygame import tsk pygame.init() window = pygame.display.set_mode([1018, 572]) background = tsk.Sprite("RockCityCenter.jpg", 0, 0) boulder = tsk.Sprite("Boulder.png", 450, 300) enemy = tsk.Sprite("AlienBeetle.png", 100, 300) drawing = True flip_x = True while drawing: for event in pygame.event.get(): if event.type == pygame.QUIT: drawing = False enemy.scale = 0.5 background.draw() boulder.draw() enemy.draw() pygame.display.flip()
import random import tsk import pygame pygame.init() window = pygame.display.set_mode([1018, 573]) background = tsk.Sprite("SkyScrolling.jpg", 0, 0) c = pygame.time.Clock() clouds = [] cloud_names = ["Cloud1.png", "Cloud2.png", "Cloud3.png"] time_between_clouds = 3500 cloud_timer = 0 cloud_move_speed = .2 game_over = False while not game_over: for event in pygame.event.get(): if event.type == pygame.QUIT: game_over = True cloud_timer += c.get_time()
import pygame import tsk import random pygame.init() window = pygame.display.set_mode([1018, 573]) c = pygame.time.Clock() background = tsk.Sprite("CodeUI.jpg", 0, 0) button = tsk.Sprite("MysteryButton.png", 420, 250) drawing = True while drawing: for event in pygame.event.get(): if event.type == pygame.QUIT: drawing = False if event.type == pygame.MOUSEBUTTONDOWN: x, y = pygame.mouse.get_pos() if button.rect.collidepoint(x, y): button.center_x = random.randint(269, 699) button.center_y = random.randint(297, 353) window.fill((0, 0, 0)) background.draw() button.draw() pygame.display.flip() c.tick(30)
""" Rolex_pt1 Description: """ import tsk import pygame pygame.init() import random window = pygame.display.set_mode([1018, 573]) drawing = True back = tsk.Sprite("Fair.jpg", 0, 0) dart = tsk.Sprite("Dart.png", 500, 500) c = pygame.time.Clock() dart_flying = False current_why = 0 why = 0 strength = 0 dart.scale = 1.0 mouse = True while drawing: for event in pygame.event.get(): if event.type == pygame.QUIT: drawing = False if event.type == pygame.MOUSEBUTTONDOWN and mouse: dart_flying = True mouse = False why = pygame.mouse.get_pos() why[1]
import tsk import pygame pygame.init() window = pygame.display.set_mode([1018, 573]) background = tsk.Sprite("space_background.jpg", 0, 0) galaxies = tsk.Sprite("galaxies_scrolling.png", 0, 0) stars = tsk.Sprite("stars_scrolling.png", 0, 0) asteroids = tsk.Sprite("asteroids_scrolling.png", 0, 0) galaxies_speed = -1 stars_speed = -2 asteroids_speed = -7 drawing = True while drawing: for event in pygame.event.get():
sprite = tsk.Sprite(image, x, y) all_sprites.append(sprite) def find_rock(all_sprites): for sprite in all_sprites: if sprite.image == "SmallBrownRock.png": return sprite return -1 w = pygame.display.set_mode([1018, 573]) c = pygame.time.Clock() background = tsk.Sprite("Desert.jpg", 0, 0) sprite_list = [background] possible_keys = [ pygame.K_x, pygame.K_t, pygame.K_b, pygame.K_q, pygame.K_w, pygame.K_z, pygame.K_y, pygame.K_l ] hidden_key = random.choice(possible_keys) remove_rock_timer = 2000 drawing = True while drawing: for event in pygame.event.get(): if event.type == pygame.QUIT: drawing = False
def new_sprite(all_sprites, image="SmallBrownRock.png"): x = random.randint(20, 950) y = random.randint(100, 400) sprite = tsk.Sprite(image, x, y) all_sprites.append(sprite)
import pygame import tsk pygame.init() window = pygame.display.set_mode([1018, 573]) c = pygame.time.Clock() background = tsk.Sprite("CodeUI.jpg", 0, 0) yes_button = tsk.Sprite("YesButton.png", 270, 250) no_button = tsk.Sprite("NoButton.png", 570, 250) drawing = True while drawing: for event in pygame.event.get(): if event.type == pygame.QUIT: drawing = False if event.type == pygame.MOUSEBUTTONDOWN: x, y = pygame.mouse.get_pos() if yes_button.rect.collidepoint(x, y): print("Yes!") if no_button.rect.collidepoint(x, y): print("No!") window.fill((0, 0, 0)) background.draw() yes_button.draw() no_button.draw() pygame.display.flip() c.tick(30)
import pygame import tsk pygame.init() window = pygame.display.set_mode([1018, 573]) c = pygame.time.Clock() background = tsk.Sprite("Desert.jpg", 0, 0) gem = tsk.Sprite("RoundGemBlue.png", 320, 230) gem_timer = 0 drawing = True while drawing: for event in pygame.event.get(): if event.type == pygame.QUIT: drawing = False if event.type == pygame.MOUSEBUTTONDOWN: x, y = pygame.mouse.get_pos() if gem.rect.collidepoint(x, y): gem.image = "RoundGemRed.png" pygame.time.wait(1000) gem.image = "RoundGemBlue.png" background.draw() gem.draw() pygame.display.flip() c.tick(30)
import pygame import tsk pygame.init() window = pygame.display.set_mode([1018, 573]) c = pygame.time.Clock() background = tsk.Sprite("OutdoorLake.jpg", 0, 0) walking = tsk.ImageSheet("Puffin_Walk.png", 5, 6) swimming = tsk.ImageSheet("Puffin_Swim.png", 5, 6) puffin = tsk.Sprite(walking, 400, 100) drawing = True while drawing: for event in pygame.event.get(): if event.type == pygame.QUIT: drawing = False elif event.type == pygame.MOUSEBUTTONDOWN: if puffin.image == walking: print("Switching to swimming!") puffin.image = swimming else: print("Switching to walking.") puffin.image = walking puffin.center_y += 0.03 * c.get_time() background.draw() puffin.draw()
import pygame import tsk pygame.init() window = pygame.display.set_mode([1018, 573]) c = pygame.time.Clock() background = tsk.Sprite("Stage.png", 0, 0) pug = tsk.Sprite("PugBee.png", 900, 250) pug.flip_x = True drawing = True while drawing: for event in pygame.event.get(): if event.type == pygame.QUIT: drawing = False pug.center_x -= 0.2 * c.get_time() background.draw() pug.draw() pygame.display.flip() c.tick(30)
import tsk import pygame pygame.init() window = pygame.display.set_mode([1018, 573]) background = tsk.Sprite("Restaurant.jpg", 0, 0) bread = tsk.Sprite("BreadSlice.png", 360, 420) filenames = ["BreadSlice.png", "BurgerPatty.png", "CheeseSlice.png", "HamSlice.png", "LettuceLeaf.png", "TomatoSlice.png"] icons = [] ingredients = [bread] for i in range(6): icon = tsk.Sprite(filenames[i], 0, 0) icon.scale = 0.55 icon.x = 25 + 165 * i icon.center_y = 70
pygame.init() def create_animal(sprite_name): if sprite_name != "Dog" or sprite_name != "Cat": return sprite_name += ".png" sprite = tsk.Sprite(sprite_name, random.randint(0, 900), random.randint(150, 500)) sprite.draw() w = pygame.display.set_mode([1018, 573]) background = tsk.Sprite("LivingRoom.jpg", 0, 0) background.draw() pygame.display.flip() drawing = True while drawing: for event in pygame.event.get(): if event.type == pygame.QUIT: drawing = False pet = input("Do you want to make a Dog or a Cat (q to quit)? ") if pet == "q" or pet == "Q": break create_animal(pet)
import pygame import tsk pygame.init() window = pygame.display.set_mode([1018, 573]) c = pygame.time.Clock() background = tsk.Sprite("OutdoorHills.jpg", 0, 0) sleep = tsk.ImageSheet("HedgehogSleep.png", 5, 6) run = tsk.ImageSheet("HedgehogRun.png", 5, 6) hedgehog = tsk.Sprite(sleep, 170, 170) drawing = True while drawing: for event in pygame.event.get(): if event.type == pygame.QUIT: drawing = False elif event.type == pygame.MOUSEBUTTONDOWN: print("Switching to run!") hedgehog.image = run elif event.type == pygame.MOUSEBUTTONUP: print("Switching to sleep!") hedgehog.image = sleep background.draw() hedgehog.draw() hedgehog.update(c.get_time())
pygame.init() def draw_bee(direction): x = random.randint(0, 950) y = random.randint(0, 500) bee = tsk.Sprite("Bee.png", x, y) if direction == "left": bee.flip_x = True bee.draw() w = pygame.display.set_mode([1018, 573]) background = tsk.Sprite("OutdoorBushes.jpg", 0, 0) background.draw() drawing = True while drawing: for event in pygame.event.get(): if event.type == pygame.QUIT: drawing = False elif event.type == pygame.KEYDOWN: if event.key == pygame.K_LEFT: draw_bee("left") elif event.key == pygame.K_RIGHT: draw_bee("right")
def find_winner(): print("Winning Bee") max_x = 0 for bee in bees: if bee.x > max_x: max_x = bee.x print("The farthest bee was at " + str(max_x)) w = pygame.display.set_mode([1018, 573]) c = pygame.time.Clock() timer = 3000 bees = [] background = tsk.Sprite("OutdoorBushes.jpg", 0, 0) for i in range(10): bee = tsk.Sprite("Bee.png", 0, 50 + (i * 50)) bees.append(bee) drawing = True while drawing: for event in pygame.event.get(): if event.type == pygame.QUIT: drawing = False for bee in bees: bee.x += random.randint(1, 20) * .025 * c.get_time() background.draw()
def draw_ships(num_ships): if num_ships <= 0: return draw_increment = 1018 / num_ships x = 0 y = 200 for i in range(num_ships): ship = tsk.Sprite("RoundShip.png", x, y) ship.draw() x += draw_increment w = pygame.display.set_mode([1018, 573]) background = tsk.Sprite("AlienSpace.jpg", 0, 0) ships = int(input("How many ships should there be? ")) drawing = True while drawing: for event in pygame.event.get(): if event.type == pygame.QUIT: drawing = False background.draw() draw_ships(ships) pygame.display.flip()
def get_bug_name(num): if num == 1: return "Bee.png" else: return "Butterfly.png" def get_bug_dir(num): if num == 1: return True else: return False w = pygame.display.set_mode([1018, 573]) background = tsk.Sprite("OutdoorBushes.jpg", 0, 0) all_bugs = [] for i in range(random.randint(3, 15)): random_bug = random.randint(1, 2) random_direction = random.randint(1, 2) bug_dir = get_bug_dir(random_direction) bug = tsk.Sprite(get_bug_name(random_bug), random.randint(0, 900), random.randint(0, 500)) bug.flip_x = bug_dir all_bugs.append(bug) drawing = True
if vase.center_x < x: butterfly.flip_x = True x -= speed elif vase.center_x > x: butterfly.flip_x = False x += speed butterfly.center_x = x return w = pygame.display.set_mode([1018, 573]) c = pygame.time.Clock() background = tsk.Sprite("Grass.jpg", 0, 0) vase = tsk.Sprite("ShortVase.png", 0, 200) bug = tsk.Sprite("Butterfly.png", 500, 250) drawing = True while drawing: for event in pygame.event.get(): if event.type == pygame.QUIT: drawing = False elif event.type == pygame.MOUSEBUTTONDOWN: vase.x = random.choice([0, 848]) move_towards(bug, vase, .1 * c.get_time())
import pygame import tsk pygame.init() window = pygame.display.set_mode([1018, 573]) background = tsk.Sprite("OutdoorBushScene.jpg", 0, 0) beehive = tsk.Sprite("Beehive.png", 140, 0) bee = tsk.Sprite("Bee.png", 0, 0) drawing = True while drawing: for event in pygame.event.get(): if event.type == pygame.QUIT: drawing = False x, y = pygame.mouse.get_pos() bee.center = x, y background.draw() bee.draw() beehive.draw() pygame.display.flip()