| 1 | /* |
| 2 | * Don Ceferino Hazaña - video game similary to Super Pang! |
| 3 | * Copyright (c) 2004, 2005 Hugo Ruscitti |
| 4 | * web site: http://www.loosersjuegos.com.ar |
| 5 | * |
| 6 | * This file is part of Don Ceferino Hazaña (ceferino). |
| 7 | * Written by Hugo Ruscitti <[email protected]> |
| 8 | * |
| 9 | * Don Ceferino Hazaña is free software; you can redistribute it and/or modify |
| 10 | * it under the terms of the GNU General Public License as published by |
| 11 | * the Free Software Foundation; either version 2 of the License, or |
| 12 | * (at your option) any later version. |
| 13 | * |
| 14 | * Don Ceferino Hazaña is distributed in the hope that it will be useful, |
| 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 17 | * GNU General Public License for more details. |
| 18 | * |
| 19 | * You should have received a copy of the GNU General Public License |
| 20 | * along with this program; if not, write to the Free Software |
| 21 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 22 | * |
| 23 | */ |
| 24 | |
| 25 | |
| 26 | #include <string.h> |
| 27 | #include <ctype.h> |
| 28 | |
| 29 | #include "fuente.h" |
| 30 | #include "procesos.h" |
| 31 | #include "juego.h" |
| 32 | |
| 33 | ///estados del mensaje de texto |
| 34 | enum {ENTRANDO, NORMAL, SALIENDO, ENTRA_RAPIDO, NORMAL_RAPIDO, SALE_RAPIDO}; |
| 35 | |
| 36 | /*! |
| 37 | * \brief vincula el objeto al juego |
| 38 | */ |
| 39 | void fuente :: iniciar (class fuente2 * fuente, int _x, int _y, char * cadena,\ |
| 40 | int animacion) |
| 41 | { |
| 42 | paso = 0; |
| 43 | this->fuente = fuente; |
| 44 | x = _x; |
| 45 | y = _y; |
| 46 | |
| 47 | if (animacion) |
| 48 | estado = ENTRANDO; |
| 49 | else |
| 50 | estado = ENTRA_RAPIDO; |
| 51 | |
| 52 | strcpy (this->cadena, cadena); |
| 53 | } |
| 54 | |
| 55 | /*! |
| 56 | * \brief actualizacion logica de la cadena |
| 57 | */ |
| 58 | void fuente :: actualizar(void) |
| 59 | { |
| 60 | |
| 61 | switch (estado) |
| 62 | { |
| 63 | case ENTRANDO: |
| 64 | |
| 65 | if (paso >= 5) |
| 66 | { |
| 67 | estado = NORMAL; |
| 68 | paso = 0; |
| 69 | } |
| 70 | else |
| 71 | paso ++; |
| 72 | |
| 73 | break; |
| 74 | |
| 75 | case NORMAL: |
| 76 | if (paso >= 200) |
| 77 | estado = SALIENDO; |
| 78 | else |
| 79 | paso ++; |
| 80 | |
| 81 | break; |
| 82 | |
| 83 | case SALIENDO: |
| 84 | y += (-150 - y) >> 3; |
| 85 | |
| 86 | if (y <= -30) |
| 87 | estado = -1; |
| 88 | break; |
| 89 | |
| 90 | |
| 91 | case ENTRA_RAPIDO: |
| 92 | |
| 93 | if (paso >= 5) |
| 94 | { |
| 95 | estado = NORMAL_RAPIDO; |
| 96 | paso = 0; |
| 97 | } |
| 98 | else |
| 99 | paso ++; |
| 100 | |
| 101 | break; |
| 102 | |
| 103 | case NORMAL_RAPIDO: |
| 104 | if (paso >= 100) |
| 105 | { |
| 106 | paso = 0; |
| 107 | estado = SALE_RAPIDO; |
| 108 | } |
| 109 | else |
| 110 | paso ++; |
| 111 | |
| 112 | break; |
| 113 | |
| 114 | case SALE_RAPIDO: |
| 115 | if (paso >= 5) |
| 116 | { |
| 117 | estado = -1; |
| 118 | paso = 0; |
| 119 | } |
| 120 | else |
| 121 | paso ++; |
| 122 | |
| 123 | break; |
| 124 | } |
| 125 | } |
| 126 | |
| 127 | |
| 128 | /*! |
| 129 | * \brief muestra la letra en pantalla |
| 130 | * \param screen pantalla principal |
| 131 | * \param rect rectángulo de area modificada |
| 132 | */ |
| 133 | void fuente :: imprimir (SDL_Surface *screen, SDL_Rect *rect) |
| 134 | { |
| 135 | SDL_Rect tmprect [256]; |
| 136 | int n = 0; |
| 137 | |
| 138 | if (estado!=NORMAL && estado!=NORMAL_RAPIDO) |
| 139 | fuente->myprintf (screen, x, y, tmprect, &n, true, CENTRADO, \ |
| 140 | cadena); |
| 141 | else |
| 142 | fuente->myprintf (screen, x, y, tmprect, &n, false, CENTRADO, \ |
| 143 | cadena); |
| 144 | |
| 145 | rect [0].x = tmprect[0].x; |
| 146 | rect [0].y = tmprect[0].y; |
| 147 | rect [0].w = tmprect [n-1].x + tmprect [n-1].w - tmprect[0].x; |
| 148 | rect [0].h = tmprect[0].h; |
| 149 | } |