from random import randint
import pgzrun
WIDTH = 540
HEIGHT = 960
logo = Actor("biblos.png")
button = Actor("biblos.png", (WIDTH // 2, HEIGHT // 2))
score = 0
game_over = False
time_left = 5
game_started = False
def draw():
screen.clear()
if not game_started:
screen.draw.text("¡Haz clic para iniciar!",
center=(WIDTH // 2, HEIGHT // 4),
fontsize=50, color="white")
button.draw()
elif game_over:
screen.draw.text("¡Tiempo agotado!",
center=(WIDTH // 2, HEIGHT // 2),
fontsize=50, color="white")
screen.draw.text(f"Puntuación final: {score}",
center=(WIDTH // 2, HEIGHT // 2 + 50),
fontsize=40, color="white")
else:
logo.draw()
screen.draw.text(f"Puntuación: {score}", (20, 50),
fontsize=30, color="white")
screen.draw.text(f"Tiempo restante: {int(time_left)}s",
(WIDTH - 230, 50), fontsize=30,
color="white")
def place_logo():
logo.x = randint(100, WIDTH - 50)
logo.y = randint(100, HEIGHT - 200)
def on_mouse_down(pos):
global score, game_started
if not game_started:
if button.collidepoint(pos):
game_started = True
place_logo()
elif not game_over:
if logo.collidepoint(pos):
score += 1
place_logo()
def update(dt):
global time_left, game_over
if game_started and not game_over:
if time_left > 0:
time_left -= dt
else:
game_over = True
pgzrun.go()
from random import randint
import pgzrun
WIDTH = 400
HEIGHT = 400
score = 0
game_over = False
zorro = Actor("zorro.png")
zorro.pos = 100, 100
moneda = Actor("moneda.png")
moneda.pos = 200, 200
def draw():
screen.clear()
screen.fill("green")
zorro.draw()
moneda.draw()
screen.draw.text("Puntuación: " + str(score), color = "black",
topleft = (10, 10))
if game_over:
screen.fill("pink")
screen.draw.text("Puntuación Final: " + str(score), color="black",
topleft=(10, 10), fontsize = 40)
def colocar_moneda():
moneda.x = randint(20, (WIDTH - 20))
moneda.y = randint(20, (HEIGHT - 20))
def time_up():
global game_over
game_over = True
def update():
global score
distancia = 5
if keyboard.left:
zorro.x = zorro.x - distancia
elif keyboard.right:
zorro.x = zorro.x + distancia
elif keyboard.up:
zorro.y = zorro.y - distancia
elif keyboard.down:
zorro.y = zorro.y + distancia
moneda_recogida = zorro.colliderect(moneda)
if moneda_recogida:
score = score + 10
colocar_moneda()
clock.schedule(time_up, 5.0)
colocar_moneda()
pgzrun.go()
from random import randint
import pgzrun
import time
WIDTH = 500
HEIGHT = 500
puntos = []
lineas = []
sig_punto = 0
num_puntos = 5
start_time = 0
tiempo_actual = 0
tiempo_total = None
for _ in range(num_puntos):
actor = Actor("punto")
actor.pos = randint(20, WIDTH - 20), randint(20, HEIGHT - 20)
puntos.append(actor)
def draw():
screen.fill("black")
numero = 1
# Dibujar puntos y sus números
for punto in puntos:
screen.draw.text(str(numero), (punto.pos[0] - 5, punto.pos[1] + 12),
color="white")
punto.draw()
numero += 1
for linea in lineas:
screen.draw.line(linea[0], linea[1], (255, 0, 0))
if tiempo_total is not None:
screen.draw.text(f"Tiempo: {tiempo_total:.2f} s", (10, 10),
color="white", fontsize=30)
else:
screen.draw.text(f"Tiempo: {tiempo_actual:.2f} s", (10, 10),
color="white", fontsize=30)
def update():
global tiempo_actual
if tiempo_total is None:
tiempo_actual = time.time() - start_time
def on_mouse_down(pos):
global sig_punto, lineas, tiempo_total
if puntos[sig_punto].collidepoint(pos):
if sig_punto > 0:
lineas.append((puntos[sig_punto - 1].pos, puntos[sig_punto].pos))
sig_punto += 1
if sig_punto == len(puntos):
tiempo_total = time.time() - start_time
print(f"¡Ganaste! Tiempo total: {tiempo_total:.2f} segundos")
else:
print("¡Fallaste! Reiniciando el juego.")
reiniciar_juego()
def reiniciar_juego():
global sig_punto, lineas, puntos, start_time, tiempo_total, tiempo_actual
sig_punto = 0
lineas = []
tiempo_total = None
tiempo_actual = 0
puntos = []
for _ in range(num_puntos):
actor = Actor("punto")
actor.pos = randint(20, WIDTH - 20), randint(20, HEIGHT - 20)
puntos.append(actor)
start_time = time.time()
start_time = time.time()
pgzrun.go()
import random
import pgzrun
FONT_COLOR = (255, 255, 255)
WIDTH = 800
HEIGHT = 600
CENTER_X = WIDTH / 2
CENTER_Y = HEIGHT / 2
CENTER = (CENTER_X, CENTER_Y)
FINAL_LEVEL = 8
START_SPEED = 10
COLORS = ["green", "blue"]
game_over = False
game_complete = False
current_level = 1
stars = []
def draw():
global game_over, game_complete
screen.clear()
screen.blit("space", (0, 0))
if game_over:
display_message("FIN DEL JUEGO",
"Intentar de nuevo")
elif game_complete:
display_message("GANASTE!", "Bien hecho!")
else:
for star in stars:
star.draw()
def display_message(heading_text, sub_heading_text):
screen.draw.text(heading_text, fontsize=60, center=CENTER, color=FONT_COLOR)
screen.draw.text(sub_heading_text, fontsize=30,
center=(CENTER_X, CENTER_Y + 50), color=FONT_COLOR)
def update():
global stars
if len(stars) == 0:
stars = make_stars(current_level)
def make_stars(number_of_extra_stars):
colors_to_create = get_colors_to_create(number_of_extra_stars)
new_stars = create_stars(colors_to_create)
layout_stars(new_stars)
animate_stars(new_stars)
return new_stars
def get_colors_to_create(number_of_extra_stars):
colors_to_create = ["red"]
for i in range(0, number_of_extra_stars):
random_color = random.choice(COLORS)
colors_to_create.append(random_color)
return colors_to_create
def create_stars(colors_to_create):
new_stars = []
for color in colors_to_create:
star = Actor(color + "-star")
new_stars.append(star)
return new_stars
def layout_stars(stars_to_layout):
number_of_gaps = len(stars_to_layout) + 1
gap_size = WIDTH / number_of_gaps
random.shuffle(stars_to_layout)
for index, star in enumerate(stars_to_layout):
new_x_pos = (index + 1) * gap_size
star.x = new_x_pos
star.y = 0
def animate_stars(stars_to_animate):
for star in stars_to_animate:
duration = START_SPEED - current_level
star.anchor = ("center", "bottom")
animate(star, duration=duration, on_finished=handle_game_over,
y=HEIGHT)
def handle_game_over():
global game_over
game_over = True
def on_mouse_down(pos):
global stars, current_level, game_complete
for star in stars:
if star.collidepoint(pos):
if "red" in star.image:
red_star_click()
else:
handle_game_over()
def red_star_click():
global current_level, stars, game_complete
if current_level == FINAL_LEVEL:
game_complete = True
else:
current_level += 1
stars = []
make_stars(current_level)
pgzrun.go()
import pgzrun
import random
import pygame
WIDTH = 800
HEIGHT = 533
nieve = []
biblos_img = pygame.image.load("biblos logo.png")
biblos_img = pygame.transform.scale(
biblos_img, (biblos_img.get_width()*0.3,
biblos_img.get_height()*0.3))
def crear_nieve():
x = random.randint(0, WIDTH)
y = random.randint(-100, HEIGHT)
tamaño = random.randint(3, 6)
velocidad = random.randint(2, 4)
nieve.append([x, y, tamaño, velocidad])
def mover_nieve():
for copo in nieve:
copo[1] += copo[3]
if copo[1] > HEIGHT:
copo[1] = -copo[2]
copo[0] = random.randint(0, WIDTH)
def draw():
screen.clear()
screen.blit("fondo_navidad", (0, 0))
screen.draw.text("Felices fiestas les desea",
center=(WIDTH // 2, HEIGHT // 2),
fontsize=60, color=(0, 128, 255))
screen.surface.blit(biblos_img, (280, 300))
for copo in nieve:
screen.draw.filled_circle((copo[0], copo[1]), copo[2], "white")
def update():
mover_nieve()
for _ in range(100):
crear_nieve()
pgzrun.go()
import pgzrun
import random
import math
WIDTH = 800
HEIGHT = 600
fireworks = []
class Particle:
def __init__(self, x, y, start_color, end_color, angle, speed, life):
self.x = x
self.y = y
self.start_color = start_color
self.end_color = end_color
self.angle = angle
self.speed = speed
self.life = self.full_life = life
def interpolate_color(self):
t = 1 - (self.life / self.full_life)
r = int(self.start_color[0] * (1 - t) + self.end_color[0] * t)
g = int(self.start_color[1] * (1 - t) + self.end_color[1] * t)
b = int(self.start_color[2] * (1 - t) + self.end_color[2] * t)
return (r, g, b)
def update(self):
self.x += math.cos(self.angle) * self.speed
self.y += math.sin(self.angle) * self.speed
self.speed *= 0.98
self.life -= 1
def draw(self, screen):
if self.life > 0:
color = self.interpolate_color()
screen.draw.filled_circle((self.x, self.y), 1, color)
class Firework:
def __init__(self, x, y, color):
self.x = x
self.y = y
self.color = color
self.particles = []
self.exploded = False
def explode(self):
for _ in range(100):
angle = random.uniform(0, 2 * math.pi)
speed = random.uniform(1, 6)
life = random.randint(10, 60)
start_color = self.color
end_color = (255, 255, 255)
particle = Particle(self.x, self.y, start_color, end_color,
angle, speed, life)
self.particles.append(particle)
self.exploded = True
def update(self):
if not self.exploded:
self.y -= 5
if random.random() < 0.03:
self.explode()
else:
for particle in self.particles:
particle.update()
def draw(self, screen):
if not self.exploded:
screen.draw.filled_circle((self.x, self.y), 1, self.color)
else:
for particle in self.particles:
particle.draw(screen)
def update():
global fireworks
for firework in fireworks:
firework.update()
fireworks = [fw for fw in fireworks if not
(fw.exploded and all(p.life <= 0 for p in fw.particles))]
def draw():
screen.clear()
screen.fill((0, 0, 0))
for firework in fireworks:
firework.draw(screen)
def on_mouse_down(pos):
x, y = pos
color = random.choice([
(255, 0, 0),
(0, 255, 0),
(0, 0, 255),
(255, 255, 0),
(255, 0, 255),
(255, 255, 255)])
firework = Firework(x, y, color)
fireworks.append(firework)
pgzrun.go()