Imagen de Pygame con movimiento.
Imagen de Pygame con movimiento
En este post podrás encontrara una imagen en Pygame con movimiento para ello es importante que hayas consultado el post anterior donde aprenderás a realizar una imagen en pygame (este post es un complemento del anterior).
# -*- coding: utf-8 -*-
import pygame
import random
import time
def dibujar_lluvia(window, limites, listaPuntos):
for i in range(len(listaPuntos)):
r = listaPuntos[i][2]
x = listaPuntos[i][0]
y = listaPuntos[i][1]
pygame.draw.circle(window,(255,255,255), [x, y], r, 0)
listaPuntos[i][1] += 1
if listaPuntos[i][1] > limites[1]:
y = random.randrange(-50, -10)
listaPuntos[i][1] = y
x = random.randrange(50, limites[0])
listaPuntos[i][0] = x
def crearPuntosAletorios(cantidad, rangos):
listaPuntos = []
for i in range(cantidad):
radio = 1
x = random.randrange(1, 640)
y = random.randrange(0, 500)
listaPuntos.append([x, y, radio])
return listaPuntos
pygame.init()
running = True
window = pygame.display.set_mode( (640,500) )
while running:
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
listaPuntos = crearPuntosAletorios(15, [640,500])
dibujar_lluvia(window, [640, 500], listaPuntos)
OrejaIzquierda = (0, 0, 0)
OrejaDerecha = (0, 0, 0)
Cabeza = (0, 0, 0)
Cara = (0, 0, 0)
CaraMejillas = (255, 0, 255)
SombraCara = (192, 192, 192)
Cuerpo = (0, 0, 0)
SombraCuerpo = (192, 192, 192)
Cola = (0, 0, 0)
SombraCola = (192, 192, 192)
PataDerecha = (0, 0, 0)
PataIzquierda = (0, 0, 0)
# OrejaIzquierda
pygame.draw.polygon(window, OrejaIzquierda, [(70, 20), (80, 20), (80, 30), (70, 30), (70, 20)], 0)
pygame.draw.polygon(window, OrejaIzquierda, [(60, 30), (70, 30), (70, 50), (60, 50), (60, 30)], 0)
pygame.draw.polygon(window, OrejaIzquierda, [(80, 30), (90, 30), (90, 40), (80, 40), (80, 30)], 0)
# OrejaDerecha
pygame.draw.polygon(window, OrejaDerecha, [(120, 30), (130, 30), (130, 40), (120, 40), (120, 30)], 0)
pygame.draw.polygon(window, OrejaDerecha, [(130, 20), (140, 20), (140, 30), (130, 30), (130, 20)], 0)
pygame.draw.polygon(window, OrejaDerecha, [(140, 30), (150, 30), (150, 50), (140, 50), (140, 30)], 0)
# Cabeza
pygame.draw.polygon(window, Cabeza, [(90, 40), (120, 40), (120, 50), (90, 50), (90, 40)], 0)
# Cara
pygame.draw.polygon(window, Cara, [(70, 80), (80, 80), (80, 90), (70, 90), (70, 80)], 0)
pygame.draw.polygon(window, Cara, [(130, 80), (140, 80), (140, 90), (130, 90), (130, 80)], 0)
pygame.draw.polygon(window, Cara, [(90, 90), (100, 90), (100, 100), (90, 100), (90, 90)], 0)
pygame.draw.polygon(window, Cara, [(100, 80), (110, 80), (110, 90), (100, 90), (100, 80)], 0)
pygame.draw.polygon(window, Cara, [(110, 90), (120, 90), (120, 100), (110, 100), (110, 90)], 0)
# CaraMejillas
pygame.draw.polygon(window, CaraMejillas, [(60, 90), (70, 90), (70, 100), (60, 100), (60, 90)], 0)
pygame.draw.polygon(window, CaraMejillas, [(140, 90), (150, 90), (150, 100), (140, 100), (140, 90)], 0)
# Sombracara
pygame.draw.polygon(window, SombraCara, [(60, 60), (70, 60), (70, 70), (60, 70), (60, 60)], 0)
pygame.draw.polygon(window, SombraCara, [(80, 40), (90, 40), (90, 50), (80, 50), (80, 40)], 0)
pygame.draw.polygon(window, SombraCara, [(90, 50), (120, 50), (120, 60), (90, 60), (90, 50)], 0)
pygame.draw.polygon(window, SombraCara, [(120, 40), (130, 40), (130, 50), (120, 50), (120, 40)], 0)
pygame.draw.polygon(window, SombraCara, [(140, 50), (150, 50), (150, 60), (140, 60), (140, 50)], 0)
pygame.draw.polygon(window, SombraCara, [(150, 70), (160, 70), (160, 80), (150, 80), (150, 70)], 0)
# Cuerpo
pygame.draw.polygon(window, Cuerpo, [(50, 50), (60, 50), (60, 70), (50, 70), (50, 50)], 0)
pygame.draw.polygon(window, Cuerpo, [(40, 70), (50, 70), (50, 100), (40, 100), (40, 70)], 0)
pygame.draw.polygon(window, Cuerpo, [(30, 100), (40, 100), (40, 140), (30, 140), (30, 100)], 0)
pygame.draw.polygon(window, Cuerpo, [(20, 140), (30, 140), (30, 210), (20, 210), (20, 140)], 0)
pygame.draw.polygon(window, Cuerpo, [(30, 210), (40, 210), (40, 220), (30, 220), (30, 210)], 0)
pygame.draw.polygon(window, Cuerpo, [(40, 220), (60, 220), (60, 230), (40, 230), (40, 220)], 0)
pygame.draw.polygon(window, Cuerpo, [(90, 220), (120, 220), (120, 230), (90, 230), (90, 220)], 0)
pygame.draw.polygon(window, Cuerpo, [(180, 140), (190, 140), (190, 200), (180, 200), (180, 140)], 0)
pygame.draw.polygon(window, Cuerpo, [(170, 100), (180, 100), (180, 140), (170, 140), (170, 100)], 0)
pygame.draw.polygon(window, Cuerpo, [(160, 70), (170, 70), (170, 100), (160, 100), (160, 70)], 0)
pygame.draw.polygon(window, Cuerpo, [(150, 50), (160, 50), (160, 70), (150, 70), (150, 50)], 0)
# SombraCuerpo
pygame.draw.polygon(window, SombraCuerpo, [(40, 100), (50, 100), (50, 120), (40, 120), (40, 100)], 0)
pygame.draw.polygon(window, SombraCuerpo, [(160, 100), (170, 100), (170, 120), (160, 120), (160, 100)], 0)
pygame.draw.polygon(window, SombraCuerpo, [(30, 140), (50, 140), (50, 150), (30, 150), (30, 140)], 0)
pygame.draw.polygon(window, SombraCuerpo, [(30, 150), (40, 150), (40, 160), (30, 160), (30, 150)], 0)
pygame.draw.polygon(window, SombraCuerpo, [(160, 140), (180, 140), (180, 150), (160, 150), (160, 140)], 0)
pygame.draw.polygon(window, SombraCuerpo, [(170, 150), (180, 150), (180, 160), (170, 160), (170, 150)], 0)
pygame.draw.polygon(window, SombraCuerpo, [(30, 170), (50, 170), (50, 180), (30, 180), (30, 170)], 0)
pygame.draw.polygon(window, SombraCuerpo, [(30, 180), (40, 180), (40, 190), (30, 190), (30, 180)], 0)
pygame.draw.polygon(window, SombraCuerpo, [(40, 210), (50, 210), (50, 220), (40, 220), (40, 210)], 0)
pygame.draw.polygon(window, SombraCuerpo, [(30, 200), (40, 200), (40, 210), (30, 210), (30, 200)], 0)
pygame.draw.polygon(window, SombraCuerpo, [(160, 210), (170, 210), (170, 220), (160, 220), (160, 210)], 0)
pygame.draw.polygon(window, SombraCuerpo, [(170, 200), (180, 200), (180, 210), (170, 210), (170, 200)], 0)
# Cola
pygame.draw.polygon(window, Cola, [(150, 220), (220, 220), (220, 230), (150, 230), (150, 220)], 0)
pygame.draw.polygon(window, Cola, [(220, 210), (230, 210), (230, 220), (220, 220), (220, 210)], 0)
pygame.draw.polygon(window, Cola, [(170, 210), (180, 210), (180, 220), (170, 220), (170, 210)], 0)
pygame.draw.polygon(window, Cola, [(230, 170), (240, 170), (240, 210), (230, 210), (230, 170)], 0)
pygame.draw.polygon(window, Cola, [(210, 160), (230, 160), (230, 170), (210, 170), (210, 160)], 0)
pygame.draw.polygon(window, Cola, [(200, 170), (210, 170), (210, 180), (200, 180), (200, 170)], 0)
pygame.draw.polygon(window, Cola, [(210, 180), (220, 180), (220, 200), (210, 200), (210, 180)], 0)
pygame.draw.polygon(window, Cola, [(180, 200), (210, 200), (210, 210), (180, 210), (180, 200)], 0)
# SombraCola
pygame.draw.polygon(window, SombraCola, [(220, 180), (230, 180), (230, 190), (220, 190), (220, 180)], 0)
pygame.draw.polygon(window, SombraCola, [(200, 210), (210, 210), (210, 220), (200, 220), (200, 210)], 0)
# PataDerecha
pygame.draw.polygon(window, PataDerecha, [(60, 190), (70, 190), (70, 240), (60, 240), (60, 200)], 0)
pygame.draw.polygon(window, PataDerecha, [(70, 230), (80, 230), (80, 240), (70, 240), (70, 230)], 0)
pygame.draw.polygon(window, PataDerecha, [(80, 210), (90, 210), (90, 240), (80, 240), (80, 210)], 0)
# PataIzquierda
pygame.draw.polygon(window, PataIzquierda, [(120, 210), (130, 210), (130, 240), (120, 240), (120, 210)], 0)
pygame.draw.polygon(window, PataIzquierda, [(130, 230), (140, 230), (140, 240), (130, 240), (130, 230)], 0)
pygame.draw.polygon(window, PataIzquierda, [(140, 190), (150, 190), (150, 240), (140, 240), (140, 190)], 0)
pygame.display.update()
pygame.display.quit()
Comentarios
Publicar un comentario