diff options
Diffstat (limited to 'JAMtank.py')
-rw-r--r-- | JAMtank.py | 98 |
1 files changed, 98 insertions, 0 deletions
diff --git a/JAMtank.py b/JAMtank.py new file mode 100644 index 0000000..a957c5a --- /dev/null +++ b/JAMtank.py @@ -0,0 +1,98 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +# JAMtank.py por: +# Flavio Danesse <fdanesse@gmail.com> +# CeibalJAM! - Uruguay +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +import pygame +from pygame.locals import * + +import gc +gc.enable() + +import os + +# Constantes para todo el Juego +RESOLUCIONMONITOR = (1200,900) +DIRECTORIODEIMAGENES = os.getcwd()+"/Imagenes/" +DIRECTORIODESONIDOS = os.getcwd()+"/Sonidos/" +MINOMBRE = os.getpid() # me identifica en el servidor + +# importación de clases para objetos del juego en el cliente +from Graficos_JAMtank import Graficos_JAMtank +from Manejador_de_Eventos import Manejador_de_Eventos +from Jugador_JAMtank import Jugador_JAMtank +from Enlace_Red_JAMtank import Enlace_Red_JAMtank + +class JAMtank(): + ''' Motor del Juego. Máquina de estados. ''' + def __init__(self, ip="localhost", PUERTO=5000): + # Todo lo que deba ser dibujado se hace en esta clase + self.objetos_graficos = Graficos_JAMtank(RESOLUCIONMONITOR, DIRECTORIODEIMAGENES, DIRECTORIODESONIDOS) + # Todos los eventos se manejan en esta clase + self.objetos_de_eventos = Manejador_de_Eventos() + # El Jugador Local + self.protagonista = Jugador_JAMtank(imagen=DIRECTORIODEIMAGENES+"Tanque.bmp", nombre=MINOMBRE, + angulo=0, x=0, y=0, resolucion_monitor=RESOLUCIONMONITOR, + directorio_de_imagenes=DIRECTORIODEIMAGENES) # recordar que es un tanque sprite + + # Enlace con el servidor en la red + self.enlace_red = Enlace_Red_JAMtank(ip=ip, PUERTO=PUERTO, protagonista=self.protagonista, objetos_graficos=self.objetos_graficos, nombre=MINOMBRE) + self.reloj = pygame.time.Clock() + + self.Run() # ejecuta el juego. + + def Run(self): + # ----------------------- Comienza el juego --------------------------- + + self.objetos_graficos.setup(Jugador_JAMtank=self.protagonista) # Iniciando pygame + self.objetos_graficos.iniciar_escenario() # Levantando Escenario y Fondo + self.objetos_graficos.set_menu_puntaje() # Levantando Menús para Puntajes + + self.objetos_de_eventos.setup(Jugador_JAMtank=self.protagonista, Enlace_Red=self.enlace_red) # Configurando Eventos para el Jugador Local + self.protagonista.setup() # Configurando al jugador protagónico (el local) + self.objetos_graficos.set_menu_ip_server(self.enlace_red.direccion_servidor[0]) + pygame.time.wait(3) + self.estado = "En Juego" + + #contar = 0 + while self.estado == "En Juego": + self.reloj.tick(35) + + # Detectar eventos y calcular en consecuencia + self.objetos_de_eventos.detectar() + + # recolectar datos para enviar, recordar que los objetos se actualizan cuando los datos vuelven del server + self.enlace_red.buffer_de_salida = self.protagonista.get_datos_para_la_red() + + self.enlace_red.enviar_datos()# enviar datos + self.enlace_red.recibir_datos()# recibir datos + + # Actualiza los datos de puntaje y energia del jugador local en pantalla + self.objetos_graficos.actualiza_puntaje(puntos=self.protagonista.puntaje, energia=self.protagonista.energia) + + # ranking + self.objetos_graficos.set_menu_jugadores(self.enlace_red.get_jugadores_puntos()) + + # Dibuja los cambios en pantalla + self.objetos_graficos.actualizar() + pygame.time.wait(1) + +if __name__ == "__main__": + JAMtank("localhost") + |