diff --git a/Nociones PyGame/Teclado.py b/Nociones PyGame/Teclado.py deleted file mode 100644 index 648f469..0000000 --- a/Nociones PyGame/Teclado.py +++ /dev/null @@ -1,118 +0,0 @@ -# -*- coding: utf-8 -*- - -import pygame, sys -import pygame.locals as GAME_GLOBALS -import pygame.event as GAME_EVENTS - -# Variables de PyGame -pygame.init() -clock = pygame.time.Clock() - -windowWidth = 800 -windowHeight = 800 - -surface = pygame.display.set_mode((windowWidth, windowHeight)) -pygame.display.set_caption('Pruebas de teclado en PyGame') - -# Variables para el cuadrado -playerSize = 20; -playerX = (windowWidth / 2) - (playerSize / 2) -playerY = windowHeight - playerSize -playerVX = 1.0 -playerVY = 0.0 -jumpHeight = 25.0 -moveSpeed = 1.0 -maxSpeed = 10.0 -gravity = 1.0 - -# Variables de teclado que vamos a utilizar -leftDown = False -rightDown = False -haveJumped = False - -def move(): - - global playerX, playerY, playerVX, playerVY, haveJumped, gravity - - # Movimiento izquierda - if leftDown: - #Si nos estamos moviendo a la derecha tenemos que invertir la dirección - if playerVX > 0.0: - playerVX = moveSpeed - playerVX = -playerVX - # Comprobamos que no nos salimos de la ventana - if playerX > 0: - playerX += playerVX - - # Movimento derecha - if rightDown: - # Si nos estamos movimento a la izquierda tenemos que invertir la dirección - if playerVX < 0.0: - playerVX = moveSpeed - # Nos aseguramos de que no nos salimos de la ventana por la derecha - if playerX + playerSize < windowWidth: - playerX += playerVX - - if playerVY > 1.0: - playerVY = playerVY * 0.9 - else : - playerVY = 0.0 - haveJumped = False - - # Comprobamos si el cubo está en el aire - if playerY < windowHeight - playerSize: - playerY += gravity - gravity = gravity * 1.1 - else : - playerY = windowHeight - playerSize - gravity = 1.0 - - playerY -= playerVY - - # Sentencia para que nuestro personaje vaya acelerando - if playerVX > 0.0 and playerVX < maxSpeed or playerVX < 0.0 and playerVX > -maxSpeed: - if haveJumped == False: - playerVX = playerVX * 1.1 - -# Funcion para salir del juego -def quitGame(): - pygame.quit() - sys.exit() - -while True: - - surface.fill((190,190,190)) - - pygame.draw.rect(surface, (255,0,0), (playerX, playerY, playerSize, playerSize)) - - # Miramos los eventos que han ocurrido - for event in GAME_EVENTS.get(): - - if event.type == pygame.KEYDOWN: - - if event.key == pygame.K_LEFT: - leftDown = True - if event.key == pygame.K_RIGHT: - rightDown = True - if event.key == pygame.K_UP: - if not haveJumped: - haveJumped = True - playerVY += jumpHeight - if event.key == pygame.K_ESCAPE: - quitGame() - - if event.type == pygame.KEYUP: - if event.key == pygame.K_LEFT: - leftDown = False - playerVX = moveSpeed - if event.key == pygame.K_RIGHT: - rightDown = False - playerVX = moveSpeed - - if event.type == GAME_GLOBALS.QUIT: - quitGame() - - move() - - clock.tick(60) - pygame.display.update() diff --git a/Nociones PyGame/bordes.py b/Nociones PyGame/bordes.py deleted file mode 100644 index 3424320..0000000 --- a/Nociones PyGame/bordes.py +++ /dev/null @@ -1,24 +0,0 @@ -# -*- coding: utf-8 -*- - -import pygame - -pygame.init() - -window = pygame.display.set_mode( (500, 400) ) - -while True: - - -# pygame.draw.line(window, (255,255,255), (50, 50), (75, 75), 1) -# pygame.draw.line(window, (255,255,255), (75, 75), (25, 75), 1) -# pygame.draw.line(window, (255,255,255), (25, 75), (50, 50), 1) - - - -# pygame.draw.lines(window, (255,255,255), True, ((50, 50), (75, 75), (25, 75)), 1) - - - pygame.draw.lines(window, (0,255,255), True, ( (50, 50), (75, 75), (63, 100), (38, 100), (25, 75) ), 3) - - - pygame.display.update() diff --git a/Nociones PyGame/hola_mundo.py b/Nociones PyGame/hola_mundo.py deleted file mode 100644 index a5f75d8..0000000 --- a/Nociones PyGame/hola_mundo.py +++ /dev/null @@ -1,23 +0,0 @@ -# -*- coding: utf-8 -*- - -import pygame - -pygame.init() - -window = pygame.display.set_mode( (500, 400) ) - -while True: - - pygame.draw.rect(window, (255, 0, 0), (100, 100, 100, 50), 2) - pygame.draw.ellipse(window, (255, 0, 0), (100, 100, 100, 50)) - - pygame.draw.rect(window, (0, 255, 0), (100, 150, 80, 40), 2) - pygame.draw.ellipse(window, (0, 255, 0), (100, 150, 80, 40)) - - pygame.draw.rect(window, (0, 0, 255), (100, 190, 60, 30), 2) - pygame.draw.ellipse(window, (0, 0, 255), (100, 190, 60, 30)) - - #Círculo - pygame.draw.ellipse(window, (0, 0, 255), (100, 250, 40, 40)) - - pygame.display.update() diff --git a/Nociones PyGame/raton.py b/Nociones PyGame/raton.py deleted file mode 100644 index 2793add..0000000 --- a/Nociones PyGame/raton.py +++ /dev/null @@ -1,101 +0,0 @@ -# -*- coding: utf-8 -*- - -import pygame, sys -import pygame.locals as GAME_GLOBALS -import pygame.event as GAME_EVENTS - -# Variables de juego -pygame.init() -clock = pygame.time.Clock() - -windowWidth = 800 -windowHeight = 800 - -surface = pygame.display.set_mode((windowWidth, windowHeight)) - -pygame.display.set_caption('Pruebas de ratón en PyGame') - -# Variables referentes al ratón -mousePosition = None -mousePressed = False - -# Variables para el cuadrado que será el actor de la escena -squareSize = 40 -squareColor = (0, 255, 0) -squareX = windowWidth / 2 -squareY = windowHeight - squareSize -draggingSquare = False -gravity = 9.81 - -def checkBounds(): - - global squareColor, squareX, squareY, draggingSquare - - if mousePressed == True: - # Comprobamos que el ratón está colocado sobre el cuadrado que hemos definido - if mousePosition[0] > squareX and mousePosition[0] < squareX + squareSize: - - if mousePosition[1] > squareY and mousePosition[1] < squareY + squareSize: - - draggingSquare = True - pygame.mouse.set_visible(0) - - else : - squareColor = (255,0,0) - pygame.mouse.set_visible(1) - draggingSquare = False - -def checkGravity(): - - global gravity, squareY, squareSize, windowHeight - - # Comprobamos la posición de nuestro cuadrado - if squareY < windowHeight - squareSize and mousePressed == False: - squareY += gravity - gravity = gravity * 1.1 - else : - squareY = windowHeight - squareSize - gravity = 9.81 - -def drawSquare(): - - global squareColor, squareX, squareY, draggingSquare - - if draggingSquare == True: - - squareColor = (0, 0, 255) - squareX = mousePosition[0] - squareSize / 2 - squareY = mousePosition[1] - squareSize / 2 - - pygame.draw.rect(surface, squareColor, (squareX, squareY, squareSize, squareSize)) - -# How to quit our program -def quitGame(): - pygame.quit() - sys.exit() - -while True: - - mousePosition = pygame.mouse.get_pos() - - surface.fill((190,190,190)) - - # Comprobamos si estamos pulsando el ratón - if pygame.mouse.get_pressed()[0] == True: - mousePressed = True - else : - mousePressed = False - - checkBounds() #Si el ratón está pulsado comprobamos que esté sobre el cuadrado para levantarlo - checkGravity() # Comprobamos si el cuadrado está en el aire para hacerlo caer - drawSquare() # Dibujamos el cuadrado donde esté nuestro ratón - - clock.tick(60) # Limitamos el programa a 60 fps - pygame.display.update() - - for event in GAME_EVENTS.get(): - if event.type == pygame.KEYDOWN: - if event.key == pygame.K_ESCAPE: - quitGame() - if event.type == GAME_GLOBALS.QUIT: - quitGame() diff --git a/Pygame Sonidos/assets/images/cat.png b/Pygame Sonidos/assets/images/cat.png deleted file mode 100644 index 2f9821e..0000000 Binary files a/Pygame Sonidos/assets/images/cat.png and /dev/null differ diff --git a/Pygame Sonidos/assets/images/chicken.png b/Pygame Sonidos/assets/images/chicken.png deleted file mode 100644 index d2842fb..0000000 Binary files a/Pygame Sonidos/assets/images/chicken.png and /dev/null differ diff --git a/Pygame Sonidos/assets/images/cow.png b/Pygame Sonidos/assets/images/cow.png deleted file mode 100644 index 672ba36..0000000 Binary files a/Pygame Sonidos/assets/images/cow.png and /dev/null differ diff --git a/Pygame Sonidos/assets/images/dog.png b/Pygame Sonidos/assets/images/dog.png deleted file mode 100644 index c0819cb..0000000 Binary files a/Pygame Sonidos/assets/images/dog.png and /dev/null differ diff --git a/Pygame Sonidos/assets/images/horse.png b/Pygame Sonidos/assets/images/horse.png deleted file mode 100644 index 9262872..0000000 Binary files a/Pygame Sonidos/assets/images/horse.png and /dev/null differ diff --git a/Pygame Sonidos/assets/images/mouse.png b/Pygame Sonidos/assets/images/mouse.png deleted file mode 100644 index f5ac1d8..0000000 Binary files a/Pygame Sonidos/assets/images/mouse.png and /dev/null differ diff --git a/Pygame Sonidos/assets/images/pig.png b/Pygame Sonidos/assets/images/pig.png deleted file mode 100644 index ccfcfa1..0000000 Binary files a/Pygame Sonidos/assets/images/pig.png and /dev/null differ diff --git a/Pygame Sonidos/assets/images/rooster.png b/Pygame Sonidos/assets/images/rooster.png deleted file mode 100644 index 3d38027..0000000 Binary files a/Pygame Sonidos/assets/images/rooster.png and /dev/null differ diff --git a/Pygame Sonidos/assets/images/sheep.png b/Pygame Sonidos/assets/images/sheep.png deleted file mode 100644 index 12a2287..0000000 Binary files a/Pygame Sonidos/assets/images/sheep.png and /dev/null differ diff --git a/Pygame Sonidos/assets/images/stop.png b/Pygame Sonidos/assets/images/stop.png deleted file mode 100644 index 194da82..0000000 Binary files a/Pygame Sonidos/assets/images/stop.png and /dev/null differ diff --git a/Pygame Sonidos/assets/sounds/MP3/cat.mp3 b/Pygame Sonidos/assets/sounds/MP3/cat.mp3 deleted file mode 100644 index 6a862e9..0000000 Binary files a/Pygame Sonidos/assets/sounds/MP3/cat.mp3 and /dev/null differ diff --git a/Pygame Sonidos/assets/sounds/MP3/chicken.mp3 b/Pygame Sonidos/assets/sounds/MP3/chicken.mp3 deleted file mode 100644 index 05040bd..0000000 Binary files a/Pygame Sonidos/assets/sounds/MP3/chicken.mp3 and /dev/null differ diff --git a/Pygame Sonidos/assets/sounds/MP3/cow.mp3 b/Pygame Sonidos/assets/sounds/MP3/cow.mp3 deleted file mode 100644 index 8099a74..0000000 Binary files a/Pygame Sonidos/assets/sounds/MP3/cow.mp3 and /dev/null differ diff --git a/Pygame Sonidos/assets/sounds/MP3/dog.mp3 b/Pygame Sonidos/assets/sounds/MP3/dog.mp3 deleted file mode 100644 index 2ec7e9d..0000000 Binary files a/Pygame Sonidos/assets/sounds/MP3/dog.mp3 and /dev/null differ diff --git a/Pygame Sonidos/assets/sounds/MP3/farm.mp3 b/Pygame Sonidos/assets/sounds/MP3/farm.mp3 deleted file mode 100644 index 351e40d..0000000 Binary files a/Pygame Sonidos/assets/sounds/MP3/farm.mp3 and /dev/null differ diff --git a/Pygame Sonidos/assets/sounds/MP3/horse.mp3 b/Pygame Sonidos/assets/sounds/MP3/horse.mp3 deleted file mode 100644 index 185d900..0000000 Binary files a/Pygame Sonidos/assets/sounds/MP3/horse.mp3 and /dev/null differ diff --git a/Pygame Sonidos/assets/sounds/MP3/mouse.mp3 b/Pygame Sonidos/assets/sounds/MP3/mouse.mp3 deleted file mode 100644 index 42102c8..0000000 Binary files a/Pygame Sonidos/assets/sounds/MP3/mouse.mp3 and /dev/null differ diff --git a/Pygame Sonidos/assets/sounds/MP3/pig.mp3 b/Pygame Sonidos/assets/sounds/MP3/pig.mp3 deleted file mode 100644 index c0bd3bb..0000000 Binary files a/Pygame Sonidos/assets/sounds/MP3/pig.mp3 and /dev/null differ diff --git a/Pygame Sonidos/assets/sounds/MP3/rooster.mp3 b/Pygame Sonidos/assets/sounds/MP3/rooster.mp3 deleted file mode 100644 index 9142b64..0000000 Binary files a/Pygame Sonidos/assets/sounds/MP3/rooster.mp3 and /dev/null differ diff --git a/Pygame Sonidos/assets/sounds/MP3/sheep.mp3 b/Pygame Sonidos/assets/sounds/MP3/sheep.mp3 deleted file mode 100644 index f3adc47..0000000 Binary files a/Pygame Sonidos/assets/sounds/MP3/sheep.mp3 and /dev/null differ diff --git a/Pygame Sonidos/assets/sounds/OGG/cat.ogg b/Pygame Sonidos/assets/sounds/OGG/cat.ogg deleted file mode 100644 index 6e2ab78..0000000 Binary files a/Pygame Sonidos/assets/sounds/OGG/cat.ogg and /dev/null differ diff --git a/Pygame Sonidos/assets/sounds/OGG/chicken.ogg b/Pygame Sonidos/assets/sounds/OGG/chicken.ogg deleted file mode 100644 index f607bc3..0000000 Binary files a/Pygame Sonidos/assets/sounds/OGG/chicken.ogg and /dev/null differ diff --git a/Pygame Sonidos/assets/sounds/OGG/cow.ogg b/Pygame Sonidos/assets/sounds/OGG/cow.ogg deleted file mode 100644 index 5f7896e..0000000 Binary files a/Pygame Sonidos/assets/sounds/OGG/cow.ogg and /dev/null differ diff --git a/Pygame Sonidos/assets/sounds/OGG/dog.ogg b/Pygame Sonidos/assets/sounds/OGG/dog.ogg deleted file mode 100644 index 0c549a2..0000000 Binary files a/Pygame Sonidos/assets/sounds/OGG/dog.ogg and /dev/null differ diff --git a/Pygame Sonidos/assets/sounds/OGG/farm.ogg b/Pygame Sonidos/assets/sounds/OGG/farm.ogg deleted file mode 100644 index 7ffce02..0000000 Binary files a/Pygame Sonidos/assets/sounds/OGG/farm.ogg and /dev/null differ diff --git a/Pygame Sonidos/assets/sounds/OGG/horse.ogg b/Pygame Sonidos/assets/sounds/OGG/horse.ogg deleted file mode 100644 index 24f122a..0000000 Binary files a/Pygame Sonidos/assets/sounds/OGG/horse.ogg and /dev/null differ diff --git a/Pygame Sonidos/assets/sounds/OGG/mouse.ogg b/Pygame Sonidos/assets/sounds/OGG/mouse.ogg deleted file mode 100644 index 5d94a88..0000000 Binary files a/Pygame Sonidos/assets/sounds/OGG/mouse.ogg and /dev/null differ diff --git a/Pygame Sonidos/assets/sounds/OGG/pig.ogg b/Pygame Sonidos/assets/sounds/OGG/pig.ogg deleted file mode 100644 index cf1ce89..0000000 Binary files a/Pygame Sonidos/assets/sounds/OGG/pig.ogg and /dev/null differ diff --git a/Pygame Sonidos/assets/sounds/OGG/rooster.ogg b/Pygame Sonidos/assets/sounds/OGG/rooster.ogg deleted file mode 100644 index 951d94f..0000000 Binary files a/Pygame Sonidos/assets/sounds/OGG/rooster.ogg and /dev/null differ diff --git a/Pygame Sonidos/assets/sounds/OGG/sheep.ogg b/Pygame Sonidos/assets/sounds/OGG/sheep.ogg deleted file mode 100644 index 4415bbf..0000000 Binary files a/Pygame Sonidos/assets/sounds/OGG/sheep.ogg and /dev/null differ diff --git a/Pygame Sonidos/sonidos.py b/Pygame Sonidos/sonidos.py deleted file mode 100644 index 69c7740..0000000 --- a/Pygame Sonidos/sonidos.py +++ /dev/null @@ -1,120 +0,0 @@ -# -*- coding: utf-8 -*- - -import pygame, sys, random -import pygame.locals as GAME_GLOBALS -import pygame.event as GAME_EVENTS -import pygame.time as GAME_TIME - -# Definimos el tamaño de la ventana - -windowWidth = 600 -windowHeight = 650 - -# Inicializamos el juego y la ventana -pygame.init() -surface = pygame.display.set_mode((windowWidth, windowHeight)) -pygame.display.set_caption('Pruebas sonoras PyGame') - -# Definimos la variable donde guardaremos los diferentes botones -buttons = [] -stopButton = { "image" : pygame.image.load("assets/images/stop.png"), "position" : (275, 585)} - -# Definimos una variable para guardar la posicion del raton y el volumen -mousePosition = None -volume = 1.0 - -pygame.mixer.init() -pygame.mixer.music.load('assets/sounds/OGG/farm.ogg') -pygame.mixer.music.play(-1) - -# Definimos las funciones que usaremos en nuestro codigo - -def drawButtons(): -# Funcion para dibujar los botones dentro de la ventana que hemos definido - - for button in buttons: - surface.blit(button["image"], button["position"]) - - surface.blit(stopButton["image"], stopButton['position']) - -def drawVolume(): -# Funcion para dibujar la barra de volumen y el selector - - pygame.draw.rect(surface, (229, 229, 229), (450, 610, 100, 5)) - - volumePosition = (100 / 100) * (volume * 100) - - pygame.draw.rect(surface, (204, 204, 204), (450 + volumePosition, 600, 10, 25)) - -def handleClick(): -# Funcion para poder conocer la posición del cursor sobre la ventana - - global mousePosition, volume - -# Primero miramos la posicion de todos los botones que hemos colocado y luego comprobamos que tenemos el cursor encima - for button in buttons: - - buttonSize = button['image'].get_rect().size - buttonPosition = button['position'] - - if mousePosition[0] > buttonPosition[0] and mousePosition[0] < buttonPosition[0] + buttonSize[0]: - - if mousePosition[1] > buttonPosition[1] and mousePosition[1] < buttonPosition[1] + buttonSize[1]: - button['sound'].set_volume(volume) - button['sound'].play() - - if mousePosition[0] > stopButton['position'][0] and mousePosition[0] < stopButton['position'][0] + stopButton['image'].get_rect().size[0]: - if mousePosition[1] > stopButton['position'][1] and mousePosition[1] < stopButton['position'][1] + stopButton['image'].get_rect().size[1]: - pygame.mixer.stop() - -def checkVolume(): -# Funcion para poder realizar los cambios en el volumen - - global mousePosition, volume - - if pygame.mouse.get_pressed()[0] == True: - - if mousePosition[1] > 600 and mousePosition[1] < 625: - if mousePosition[0] > 450 and mousePosition[0] < 550: - volume = float((mousePosition[0] - 450)) / 100 - -def quitGame(): - pygame.quit() - sys.exit() - -# Creamos todos los botones dentro de la ventana -buttons.append({ "image" : pygame.image.load("assets/images/sheep.png"), "position" : (25, 25), "sound" : pygame.mixer.Sound('assets/sounds/OGG/sheep.ogg')}) -buttons.append({ "image" : pygame.image.load("assets/images/rooster.png"), "position" : (225, 25), "sound" : pygame.mixer.Sound('assets/sounds/OGG/rooster.ogg')}) -buttons.append({ "image" : pygame.image.load("assets/images/pig.png"), "position" : (425, 25), "sound" : pygame.mixer.Sound('assets/sounds/OGG/pig.ogg')}) -buttons.append({ "image" : pygame.image.load("assets/images/mouse.png"), "position" : (25, 225), "sound" : pygame.mixer.Sound('assets/sounds/OGG/mouse.ogg')}) -buttons.append({ "image" : pygame.image.load("assets/images/horse.png"), "position" : (225, 225), "sound" : pygame.mixer.Sound('assets/sounds/OGG/horse.ogg')}) -buttons.append({ "image" : pygame.image.load("assets/images/dog.png"), "position" : (425, 225), "sound" : pygame.mixer.Sound('assets/sounds/OGG/dog.ogg')}) -buttons.append({ "image" : pygame.image.load("assets/images/cow.png"), "position" : (25, 425), "sound" : pygame.mixer.Sound('assets/sounds/OGG/cow.ogg')}) -buttons.append({ "image" : pygame.image.load("assets/images/chicken.png"), "position" : (225, 425), "sound" : pygame.mixer.Sound('assets/sounds/OGG/chicken.ogg')}) -buttons.append({ "image" : pygame.image.load("assets/images/cat.png"), "position" : (425, 425), "sound" : pygame.mixer.Sound('assets/sounds/OGG/cat.ogg')}) - -# Codigo principal de nuestro juego -while True: - - surface.fill((255,255,255)) - - mousePosition = pygame.mouse.get_pos() - - for event in GAME_EVENTS.get(): - - if event.type == pygame.KEYDOWN: - - if event.key == pygame.K_ESCAPE: - quitGame() - - if event.type == GAME_GLOBALS.QUIT: - quitGame() - - if event.type == pygame.MOUSEBUTTONUP: - handleClick() - - drawButtons() - checkVolume() - drawVolume() - - pygame.display.update() diff --git a/README.md b/README.md deleted file mode 100644 index cfb8386..0000000 --- a/README.md +++ /dev/null @@ -1,8 +0,0 @@ -# Tutoriales de programación de juegos sencillos Python -Estos códigos han sido utilizados para la serie de tutoriales creada por Piensa 3D en su canal de [YouTube](http://youtube.com/piensa3d). Cada tutorial se encontrará en una carpeta indicando el nombre del script y la versión del mismo. - -## Introducción breve a los tutoriales -La idea de estos tutoriales es enseñar de una forma dinámica y lo más amena posible programación orientada a objetos utilizando Python. Para ello se introducirá un mundo de fantasía que se irá construyendo a medida que se avance en los vídeotutoriales. Cada uno de los scripts será más complejo que el anterior y se introducirán nuevos conceptos. - -## Libro en el que se basan los tutoriales -Los vídeotutoriales estarán basados en un libro sobre programación en Python en el que se tratan todos los temas de los que se hablarán. Estos códigos son una mera traducción de los mismos con alguna pequeña modificación. Puede acceder al libro original desde [aquí](https://www.packtpub.com/application-development/learning-python-application-development) diff --git a/Sprites Personajes/kate.png b/Sprites Personajes/kate.png deleted file mode 100644 index a86a173..0000000 Binary files a/Sprites Personajes/kate.png and /dev/null differ diff --git a/Sprites Personajes/main.py b/Sprites Personajes/main.py deleted file mode 100644 index a316afe..0000000 --- a/Sprites Personajes/main.py +++ /dev/null @@ -1,31 +0,0 @@ -# -*- coding: utf-8 -*- - -import pygame -import player - -pygame.init() - -# Definimos algunas variables que usaremos en nuestro código - -ancho_ventana = 640 -alto_ventana = 480 -screen = pygame.display.set_mode((ancho_ventana, alto_ventana)) -pygame.display.set_caption("Tutorial sprites Piensa 3D") -clock = pygame.time.Clock() -player = player.Kate((ancho_ventana/2, alto_ventana/2)) -game_over = False - -while game_over == False: - - for event in pygame.event.get(): - if event.type == pygame.QUIT: - game_over = True - - player.handle_event(event) - screen.fill(pygame.Color('gray')) - screen.blit(player.image, player.rect) - - pygame.display.flip() - clock.tick(20) - -pygame.quit () diff --git a/Sprites Personajes/player.py b/Sprites Personajes/player.py deleted file mode 100644 index 7b50784..0000000 --- a/Sprites Personajes/player.py +++ /dev/null @@ -1,80 +0,0 @@ -# -*- coding: utf-8 -*- - -import pygame - -class Kate(pygame.sprite.Sprite): - def __init__(self, position): - self.sheet = pygame.image.load('kate.png') - self.sheet.set_clip(pygame.Rect(0, 0, 52, 76)) - self.image = self.sheet.subsurface(self.sheet.get_clip()) - self.rect = self.image.get_rect() - self.rect.topleft = position - self.frame = 0 - self.left_states = { 0: (0, 76, 52, 76), 1: (52, 76, 52, 76), 2: (156, 76, 52, 76) } - self.right_states = { 0: (0, 152, 52, 76), 1: (52, 152, 52, 76), 2: (156, 152, 52, 76) } - self.up_states = { 0: (0, 228, 52, 76), 1: (52, 228, 52, 76), 2: (156, 228, 52, 76) } - self.down_states = { 0: (0, 0, 52, 76), 1: (52, 0, 52, 76), 2: (156, 0, 52, 76) } - - def get_frame(self, frame_set): - self.frame += 1 - if self.frame > (len(frame_set) - 1): - self.frame = 0 - return frame_set[self.frame] - - def clip(self, clipped_rect): - if type(clipped_rect) is dict: - self.sheet.set_clip(pygame.Rect(self.get_frame(clipped_rect))) - else: - self.sheet.set_clip(pygame.Rect(clipped_rect)) - return clipped_rect - - def update(self, direction): - if direction == 'left': - self.clip(self.left_states) - self.rect.x -= 5 - if direction == 'right': - self.clip(self.right_states) - self.rect.x += 5 - if direction == 'up': - self.clip(self.up_states) - self.rect.y -= 5 - if direction == 'down': - self.clip(self.down_states) - self.rect.y += 5 - - if direction == 'stand_left': - self.clip(self.left_states[0]) - if direction == 'stand_right': - self.clip(self.right_states[0]) - if direction == 'stand_up': - self.clip(self.up_states[0]) - if direction == 'stand_down': - self.clip(self.down_states[0]) - - self.image = self.sheet.subsurface(self.sheet.get_clip()) - - def handle_event(self, event): - if event.type == pygame.QUIT: - game_over = True - - if event.type == pygame.KEYDOWN: - - if event.key == pygame.K_LEFT: - self.update('left') - if event.key == pygame.K_RIGHT: - self.update('right') - if event.key == pygame.K_UP: - self.update('up') - if event.key == pygame.K_DOWN: - self.update('down') - - if event.type == pygame.KEYUP: - - if event.key == pygame.K_LEFT: - self.update('stand_left') - if event.key == pygame.K_RIGHT: - self.update('stand_right') - if event.key == pygame.K_UP: - self.update('stand_up') - if event.key == pygame.K_DOWN: - self.update('stand_down') diff --git a/Sprites Personajes/player.pyc b/Sprites Personajes/player.pyc deleted file mode 100644 index 30fbed7..0000000 Binary files a/Sprites Personajes/player.pyc and /dev/null differ