diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..4ea05a1 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +venv/ +__pycache__/ \ No newline at end of file diff --git a/main.py b/main.py index d889e93..cd631cb 100644 --- a/main.py +++ b/main.py @@ -1,82 +1,32 @@ import pygame from pygame.locals import * - -import numpy as np - -import parametros as pr from parametros import * +from robotin import Robotin -pygame.init() -screen = pygame.display.set_mode((0,0),pygame.FULLSCREEN) - - -pestañeo = 0 -cont = 0 - - -run = 1 -while run: - for event in pygame.event.get(): - if event.type == KEYDOWN: - if event.key == K_ESCAPE: - run = 0 - - elif event.type == QUIT: - run = 0 - screen.fill(COLOR_CARA) - - - cont += 1 +if __name__ == '__main__': + pygame.init() + screen = pygame.display.set_mode((0,0),pygame.FULLSCREEN) - if cont > 1000: - if cont < 1000 + 60: - if cont%5 == 0: - pestañeo += OJO_STEP - elif cont < 1000 + 60 + 60: - if cont%5 == 0: - pestañeo -= OJO_STEP - if cont > 1000 + 60 + 60: - pestañeo = 0 - cont = 0 + robotin = Robotin() + clock = pygame.time.Clock() + run = 1 + while run: + clock.tick(FRAMERATE) + for event in pygame.event.get(): + if event.type == KEYDOWN: + if event.key == K_ESCAPE: + run = 0 - punto = pygame.mouse.get_pos() - x = (SCREEN_WIDTH - punto[0])/80 - y = (SCREEN_HEIGHT - punto[1])/80 - - - - pygame.draw.ellipse(screen, (0, 0, 0), - Rect(SCREEN_WIDTH/2 - PASO_W*3 - x*3, SCREEN_HEIGHT/2 - PASO_H*2 + pestañeo - y*3, - OJO_ANCHO, OJO_ALTO - pestañeo*2)) - - pygame.draw.ellipse(screen, (0, 0, 0), - Rect(SCREEN_WIDTH/2 + PASO_W*3 - OJO_ANCHO - x*3, SCREEN_HEIGHT/2 - PASO_H*2 + pestañeo - y*3, - OJO_ANCHO, OJO_ALTO - pestañeo*2)) - - pygame.draw.ellipse(screen, (0, 0, 0), - Rect(SCREEN_WIDTH/2-90 - x, SCREEN_HEIGHT/2 - y, - 180, 100)) - - pygame.draw.ellipse(screen, COLOR_CARA, - Rect(SCREEN_WIDTH/2-70 - x, SCREEN_HEIGHT/2 - y, - 140, 80)) - - pygame.draw.rect(screen, COLOR_CARA, - Rect(SCREEN_WIDTH/2-90 - x, SCREEN_HEIGHT/2 - y, - 180, 50)) - - pygame.draw.ellipse(screen, (0, 0, 0), - Rect(SCREEN_WIDTH/2-90 - x, SCREEN_HEIGHT/2+40 - y, - 22, 20)) - - pygame.draw.ellipse(screen, (0, 0, 0), - Rect(SCREEN_WIDTH/2+90-22 - x, SCREEN_HEIGHT/2+40 - y, - 22, 20)) + elif event.type == QUIT: + run = 0 + screen.fill(COLOR_CARA) + robotin.update() + robotin.draw(screen) - pygame.display.flip() \ No newline at end of file + pygame.display.flip() \ No newline at end of file diff --git a/parametros.py b/parametros.py index 45d4ee1..77bb3af 100644 --- a/parametros.py +++ b/parametros.py @@ -2,6 +2,7 @@ pygame.init() +FRAMERATE = 60 SCREEN_WIDTH = pygame.display.Info().current_w SCREEN_HEIGHT = pygame.display.Info().current_h diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..f49224f --- /dev/null +++ b/requirements.txt @@ -0,0 +1,2 @@ +numpy==1.23.3 +pygame==2.1.2 diff --git a/robotin.py b/robotin.py new file mode 100644 index 0000000..e12228c --- /dev/null +++ b/robotin.py @@ -0,0 +1,63 @@ +from parametros import * +from pygame.locals import Rect + +class Robotin: + def __init__(self, *args, **kwargs): + super().__init__(*args, **kwargs) + + self.pestaneo = 0 + self.contador = 0 + + def update(self): + self.contador += 1 + self.pestanear() + + def draw(self, screen): + # Get mouse position + punto = pygame.mouse.get_pos() + x = (SCREEN_WIDTH - punto[0])/80 + y = (SCREEN_HEIGHT - punto[1])/80 + + + pygame.draw.ellipse(screen, (0, 0, 0), + Rect(SCREEN_WIDTH/2 - PASO_W*3 - x*3, SCREEN_HEIGHT/2 - PASO_H*2 + self.pestaneo - y*3, + OJO_ANCHO, OJO_ALTO - self.pestaneo*2)) + + pygame.draw.ellipse(screen, (0, 0, 0), + Rect(SCREEN_WIDTH/2 + PASO_W*3 - OJO_ANCHO - x*3, SCREEN_HEIGHT/2 - PASO_H*2 + self.pestaneo - y*3, + OJO_ANCHO, OJO_ALTO - self.pestaneo*2)) + + pygame.draw.ellipse(screen, (0, 0, 0), + Rect(SCREEN_WIDTH/2-90 - x, SCREEN_HEIGHT/2 - y, + 180, 100)) + + pygame.draw.ellipse(screen, COLOR_CARA, + Rect(SCREEN_WIDTH/2-70 - x, SCREEN_HEIGHT/2 - y, + 140, 80)) + + pygame.draw.rect(screen, COLOR_CARA, + Rect(SCREEN_WIDTH/2-90 - x, SCREEN_HEIGHT/2 - y, + 180, 50)) + + pygame.draw.ellipse(screen, (0, 0, 0), + Rect(SCREEN_WIDTH/2-90 - x, SCREEN_HEIGHT/2+40 - y, + 22, 20)) + + pygame.draw.ellipse(screen, (0, 0, 0), + Rect(SCREEN_WIDTH/2+90-22 - x, SCREEN_HEIGHT/2+40 - y, + 22, 20)) + + + + def pestanear(self): + if self.contador > 1000: + if self.contador < 1000 + 60: + if self.contador % 5 == 0: + self.pestaneo += OJO_STEP + elif self.contador < 1000 + 120: + if self.contador % 5 == 0: + self.pestaneo -= OJO_STEP + if self.contador > 1000 + 120: + self.pestaneo = 0 + self.contador = 0 +