elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: Security Series.XSS. [Cross Site Scripting]


+  Foro de elhacker.net
|-+  Programación
| |-+  Scripting
| | |-+  Duda_Python_Juego
0 Usuarios y 1 Visitante están viendo este tema.
Páginas: [1] Ir Abajo Respuesta Imprimir
Autor Tema: Duda_Python_Juego  (Leído 1,194 veces)
Tuplado

Desconectado Desconectado

Mensajes: 43


Ver Perfil
Duda_Python_Juego
« en: 10 Noviembre 2012, 19:52 pm »

Hola chicos/as:

Estoy terminando un juego y solo me falta un detalle por hacer.

Les comento tengo un cuadrado azul que representa a una nave y meteoritos que van saliendo aleatoriamente.

Lo único que me queda es hacer que si la nave coge el espacio del meteorito, me ponga un mensaje en pantalla "Chocastes" y con la misma salga del juego.


Les facilito el código, otra cosa esto lo estoy haciendo en PythonG, se que es antiguo pero ya lo empece con este.



Nota del MOD: Usa el botón "Insertar código"

CÓDIGO FUENTE
===========

# EJERCICIO COMPLETO DEL LIBRO_Introducción a la programación con Python
    _EJERCICIO 149

Andrés Marzal Isabel Gracia
Departamento de Lenguajes y Sistemas Informáticos
Universitat Jaume

------------------------------------------------------------------------------------------------
Código
  1. from modulepythong import *
  2. from math import sin, cos, pi
  3. import random
  4. window_style('The Spaceship Game','white','TODO') # FONDO DE COLOR BLANCO
  5.  
  6.  
  7. # Paisaje
  8. altura_paisaje = 400
  9. anchura_paisaje = 400
  10. window_coordinates(0, 0, anchura_paisaje, altura_paisaje)
  11.  
  12. # Gravedad
  13. g = 0.00001
  14.  
  15. # Nave
  16. tamanyo_nave = 10
  17. x = anchura_paisaje / 2
  18. y = altura_paisaje - 100
  19. vy = 0
  20. impulso_y = 2*g
  21. impulso_x = 0.00001
  22. vx = 0
  23. nave = create_filled_rectangle(x, y, x+tamanyo_nave, y+tamanyo_nave, 'blue')
  24.  
  25. # Plataforma
  26. px = anchura_paisaje / 2
  27. py = 0
  28. vpx = .05
  29. anchura_plataforma = 40
  30. altura_plataforma = 3
  31. plataforma = create_rectangle(px, py,px+anchura_plataforma, py+altura_plataforma, 'red')
  32.  
  33. # Tanque de combustible
  34. color = "green" # combustible lleno
  35. fuel = 1000
  36. consumo = 0.01
  37. create_rectangle(0,altura_paisaje, 10, altura_paisaje-100, 'black')
  38. lleno = create_filled_rectangle(1,altura_paisaje, 9, altura_paisaje-fuel/10, color)
  39. create_text(25, altura_paisaje-8, '0%', 10, 'W')
  40. create_text(30, altura_paisaje-95, '100%', 10, 'W')
  41.  
  42. #---------------#
  43. tamanyo_meteorito = 8
  44. punto1=create_filled_circle(100,400,tamanyo_meteorito,"red","brown")
  45. g_m = 0.00001 #Gravedad del meteorito
  46.  
  47. vy_m = 0
  48.  
  49. y_m = 405
  50.  
  51. cord_x = 100
  52. cord_y = 405
  53.  
  54. #----------------#
  55.  
  56. # Dial de velocidad
  57. create_circle(anchura_paisaje-50, altura_paisaje-50, 50, 'black')
  58. for i in range(0, 360, 10):
  59.  create_line(anchura_paisaje-50 + 40 * sin(i*pi/180), \
  60.  altura_paisaje-50 + 40 * cos(i*pi/180), \
  61.  anchura_paisaje-50 + 50 * sin(i*pi/180), \
  62.  altura_paisaje-50 + 50 * cos(i*pi/180))
  63.  if i % 30 == 0:
  64.    create_text(anchura_paisaje-50 + 30 * sin(i*pi/180), \
  65.    altura_paisaje-50 + 30 * cos(i*pi/180), str(i), 5, 'CENTER')
  66.  
  67.    aguja = create_line(anchura_paisaje-50, altura_paisaje-50, \
  68.    anchura_paisaje-50 + 50 * sin(0*pi/180), \
  69.    altura_paisaje-50 + 50 * cos(0*pi/180), 'blue')
  70.  
  71. # Simulacion
  72. while y > 0 and y < altura_paisaje and x > 0 and x < anchura_paisaje - tamanyo_nave:
  73.  vy -= g
  74.  if keypressed(1) == 'Up' and fuel > 0:
  75.    vy += impulso_y
  76.    fuel -= consumo
  77.    if fuel < 350:
  78.      color = "red" # combustible vaciandose
  79.  
  80.  
  81.  elif keypressed(1) == 'Left' and fuel > 0:
  82.    vx -= impulso_x
  83.    fuel -= consumo
  84.    if fuel < 350:
  85.      color = "red" # combustible vaciandose
  86.  
  87.  
  88.  elif keypressed(1) == 'Right' and fuel > 0:
  89.    vx += impulso_x
  90.    fuel -= consumo
  91.    if fuel < 350:
  92.      color = "red" # combustible vaciandose    
  93.  
  94.  
  95.  vy_m = vy_m-g_m
  96.  y_m+=vy_m
  97.  
  98.  move(punto1,0,vy_m)
  99.  
  100.  
  101.  if y_m <= -2:
  102.    erase(punto1)
  103.    cord_x = random.randrange(0,400)
  104.    punto1 = create_filled_circle(cord_x, cord_y, 8,"red","brown")
  105.    y_m = 405
  106.    vy_m = 0
  107.    g_m = 0.00001
  108.  
  109.  y += vy
  110.  x += vx
  111.  px += vpx
  112.  
  113.  if px <= 0 or px >= anchura_paisaje - anchura_plataforma:
  114.    vpx = -vpx
  115.  move(nave, vx, vy)
  116.  move(plataforma, vpx, 0)
  117.  
  118.  viejo_lleno = lleno
  119.  lleno = create_filled_rectangle(1,altura_paisaje, 9, altura_paisaje-fuel/10, color)
  120.  erase(viejo_lleno)
  121.  vieja_aguja = aguja
  122.  aguja = create_line(anchura_paisaje-50, altura_paisaje-50, \
  123.  anchura_paisaje-50 + 50 * sin(1000*vy*pi/180), \
  124.  altura_paisaje-50 + 50 * cos(1000*vy*pi/180), 'blue')
  125.  erase(vieja_aguja)
  126.  
  127. msg_x = anchura_paisaje/2
  128. msg_y1 = altura_paisaje/2
  129. msg_y2 = altura_paisaje/3
  130.  
  131. if y >= altura_paisaje:
  132.  create_text(msg_x, msg_y1, 'Perdiste', 24, 'CENTER')
  133.  create_text(msg_x, msg_y2, 'Rumbo a las estrellas?', 12, 'CENTER')
  134.  
  135. elif y <= 0 and vy < -0.1:
  136.  create_text(msg_x, msg_y1, 'Perdiste', 24, 'CENTER')
  137.  create_text(msg_x, msg_y2, 'Te has estrellado.', 12, 'CENTER')
  138.  
  139. elif y <= 0 and \
  140. abs((px+anchura_plataforma/2)-(x+tamanyo_nave/2)) >= anchura_plataforma/2:
  141.  create_text(msg_x, msg_y1, 'Perdiste', 24, 'CENTER')
  142.  create_text(msg_x, msg_y2, ' !Que mala puntería!', 12, 'CENTER')
  143.  
  144. elif x <= 0 or x >= anchura_paisaje - tamanyo_nave:
  145.  create_text(msg_x, msg_y1, 'Perdiste', 24, 'CENTER')
  146.  create_text(msg_x, msg_y2, 'Chocaste con la pared.', 12, 'CENTER')
  147.  
  148. else:
  149.  create_text(msg_x, msg_y1, 'Ganaste', 24, 'CENTER')
  150.  create_text(msg_x, msg_y2, ' !Enhorabuena, piloto!', 12, 'CENTER')
  151.  
  152. raw_input() # Espera a que pulses una tecla

------------------------------------------------------------------------------------------------
_Links para descagar el PythonG y la version de python compatible.

http://www.mediafire.com/?kfonzec60va8rjr # PythonG
http://www3.uji.es/~dllorens/downloads/pythong/ # Página oficial de descargas PythonG
-----------------------------------------------------------------------------------------------------

http://www.mediafire.com/?ymay3b3bbm6uen6 # Versión de Python 2.3.2
http://www.python.org/download/releases/2.2.3/ # Página Oficial de Python

Muchas Gracias de antemano a todos


« Última modificación: 11 Noviembre 2012, 13:34 pm por Tuplado » En línea

Páginas: [1] Ir Arriba Respuesta Imprimir 

Ir a:  
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines