This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <iostream> | |
| #include <vector> // Cabecera necesaria para usar vector | |
| // Creamos dos typedef para declarar vectores | |
| typedef std::vector<int> VI; | |
| typedef std::vector<VI> VVI; | |
| int main() | |
| { | |
| // Declaramos un vector de vector int llamado v |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # detecta eventos | |
| self.scene.on_event() | |
| # actualiza la escena | |
| self.scene.on_update() | |
| # dibuja la pantalla | |
| self.scene.on_draw(self.screen) | |
| pygame.display.flip() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def change_scene(self, scene): | |
| "Altera la escena actual." | |
| self.scene = scene |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env python | |
| # -*- coding: utf-8 -*- | |
| # Módulos | |
| import pygame | |
| import director | |
| import scene_home | |
| def main(): | |
| dir = director.Director() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class SceneHome(scene.Scene): | |
| """Escena inicial del juego, esta es la primera que se carga cuando inicia""" | |
| def __init__(self, director): | |
| scene.Scene.__init__(self, director) | |
| def on_update(self): | |
| pass | |
| def on_event(self): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Scene: | |
| """Representa un escena abstracta del videojuego. | |
| Una escena es una parte visible del juego, como una pantalla | |
| de presentación o menú de opciones. Tiene que crear un objeto | |
| derivado de esta clase para crear una escena utilizable.""" | |
| def __init__(self, director): | |
| self.director = director | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # -*- encoding: utf-8 -*- | |
| # Módulos | |
| import pygame | |
| import sys | |
| class Director: | |
| """Representa el objeto principal del juego. | |
| El objeto Director mantiene en funcionamiento el juego, se |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include "Pong.hpp" | |
| #include "config.hpp" | |
| Pong::Pong() | |
| { | |
| // Creamos la ventana | |
| window.create(sf::VideoMode(WIDTH, HEIGHT, BPP), "Pong GenbetaDev", sf::Style::Close); | |
| // Activa la sincronización vertical (60 fps) | |
| window.setVerticalSyncEnabled(true); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #ifndef PONG_HPP | |
| #define PONG_HPP | |
| #include <SFML/Graphics.hpp> | |
| #include <SFML/Audio.hpp> | |
| #include "Ball.hpp" | |
| #include "Paddle.hpp" | |
| #include "Score.hpp" | |
| class Pong |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| void Ball::update(sf::Time& delta, sf::FloatRect& p1, sf::FloatRect& p2, Score& score) | |
| { | |
| // Obtenemos los cuatro laterales de la bola | |
| float left = this->getPosition().x - this->getOrigin().x; | |
| float right = this->getPosition().x + this->getOrigin().x; | |
| float top = this->getPosition().y - this->getOrigin().y; | |
| float bottom = this->getPosition().y + this->getOrigin().y; | |
| // Comprobamos si choca contra las paredes | |
| if (left <= 0 && speed.x < 0) |