UN ESPACIO PARA COLISIONES Y DISPAROS CON BLITZ3D
Este es un programa con movimiento de un avatar con las teclas cursoras y con programción de disparos
;================================================================
; funcion: disparos sin POO. Con matrices
; fecha: 24-08-2025
; lenguaje: Blitz3D
; autor: Edgar Ramos
; archivo: disparo_1.bb
; ===============================================================
; variables:
Global avatar
x#=0
y#=0
z#=0
; activar entorno gráfico 3D, #s: ancho, alto, profundidad color, pantalla completa (2: ventana)
Graphics3D 1024,768, 32,2
;==============================================================
;creacion del heroe
avatar=CreateCube()
; Crear la cámara
camera = CreateCamera(avatar) ; la camara sigue al avatar
PositionEntity camera, 0, 5,-15
RotateEntity camera, 0, 0, 0
ScaleEntity avatar,2,2,2
PositionEntity avatar,x#,y#,z#
luz1=CreateLight()
;creacion del escenario de juego
plano = CreatePlane ()
PositionEntity plano , 0, 0 , 0
; colocar pasto al plano
textura = LoadTexture ("pasto1.bmp") ; hay que crear una textura para el piso
ScaleTexture textura,20,20
EntityTexture plano,textura
Global vel_disparo# = 1
; Variables para disparo
bulletSpeed# = 0.8
Dim bullets(100)
Dim bulletActive(100)
While Not KeyDown(1) ; Loop principal
Cls
; Movimiento del jugador con teclas
If KeyDown(205) Then TurnEntity avatar, 0, -2, 0 ; Rotar izquierda
If KeyDown(203) Then TurnEntity avatar, 0, 2, 0 ; Rotar derecha
If KeyDown(200) Then MoveEntity avatar, 0, 0, 0.2 ; Avanzar
If EntityCollided(avatar, 2) Then PositionEntity avatar, EntityX(avatar), EntityY(plancha1) + 1, EntityZ(avatar)
MoveEntity avatar,x#,y#,z#
If KeyDown(208) Then MoveEntity avatar, 0, 0, -0.2 ; Retroceder
; Disparar con la tecla ESPACIO
If KeyHit(57)
For i = 0 To 99
If bulletActive(i) = 0 Then ; Encuentra una bala inactiva en la posicion 0
bullets(i) = CreateSphere(5) ; Se crea una esfera como bala
bala=LoadTexture("bala.bmp") ; hay que crear una textura para la bala
EntityTexture bullets(i),bala
PositionEntity bullets(i), EntityX(avatar), EntityY(avatar), EntityZ(avatar)
RotateEntity bullets(i), EntityPitch(avatar), EntityYaw(avatar), EntityRoll(avatar)
bulletActive(i) = 1 ; activa la bala en posicion 0 de la matriz
Exit
EndIf
Next
EndIf
; Mover balas activas en la dirección del jugador
For i = 0 To 99
If bulletActive(i) = 1 Then
MoveEntity bullets(i), 0, 0, bulletSpeed#
If EntityZ(bullets(i)) > 300 Or EntityZ(bullets(i)) < -300 Then ; Si sale del área: rango del disparo
FreeEntity bullets(i)
bulletActive(i) = 0 ; inactiva todas las 101 balas de la matriz
EndIf
EndIf
Next
UpdateWorld
RenderWorld
Text 1,1,"x= "+EntityX(avatar)
Text 1,20,"z= "+EntityZ(avatar)
Flip
Wend
End
;============================================================
; fin de programa
; ===========================================================
Nota: si el programa no "corre" puedes indicarme el error del compilador para corregirlo.
No hay comentarios:
Publicar un comentario
Porque en mi llevo el caos puedo hacer una estrella.