Fortraneries/BloubWorld/bloubspace.f90

123 lines
3.0 KiB
Fortran
Raw Normal View History

2022-02-06 23:45:08 +01:00
!
! fonctions de base de gestion des bloubs
!
module bloubspace
implicit none
! ----------------------------------------------------------------
type t_bloubs
character(8) :: nick
logical :: alive
integer :: num
real :: px, py, pz
real :: vx, vy, vz
real :: radius
integer :: seq
end type t_bloubs
contains ! -----------------------------------------
subroutine random_pv (blb)
type(t_bloubs), intent (inout) :: blb
2022-02-09 00:42:32 +01:00
blb%px = 1.3 * (rand() - 0.50)
2022-02-10 19:41:42 +01:00
blb%py = 0.50 + rand() * 0.50
2022-02-08 18:56:51 +01:00
blb%pz = 2.0 * (rand() - 0.50)
2022-02-06 23:45:08 +01:00
2022-02-10 19:38:44 +01:00
blb%vx = (rand() - 0.5) / 2.500
blb%vy = (rand() - 0.5) / 4.000
blb%vz = (rand() - 0.5) / 2.500
2022-02-06 23:45:08 +01:00
2022-02-08 02:53:49 +01:00
blb%alive = .TRUE.
2022-02-06 23:45:08 +01:00
end subroutine
2022-02-08 02:53:49 +01:00
! ----------------------------------------------------------------
subroutine display_bloub (blb, message)
type(t_bloubs), intent (in) :: blb
character(*), intent (in) :: message
character(5) :: life
2022-02-06 23:45:08 +01:00
2022-02-08 02:53:49 +01:00
if (blb%alive) then
life = "alive"
else
life = "dead"
endif
2022-02-08 18:56:51 +01:00
write (0, '(4X, A)') '+------------ ' // message
write (0, '(4X,A3,A8,2X,I6,4X,A5)') '| ', blb%nick, blb%num, life
write (0, '(4X,A3,3X,3(F8.3, 4X))') '| P', blb%px, blb%py, blb%pz
write (0, '(4X,A3,3X,3(F8.3, 4X))') '| V', blb%vx, blb%vy, blb%vz
2022-02-08 02:53:49 +01:00
write (0, '()')
end subroutine
2022-02-06 23:45:08 +01:00
! ----------------------------------------------------------------
subroutine move_bloub (blb, coef)
type(t_bloubs), intent (inout) :: blb
real, intent (in) :: coef
2022-02-07 02:08:17 +01:00
! we must check that this bloub is alive ?
2022-02-06 23:45:08 +01:00
blb%px = blb%px + (blb%vx * coef)
blb%py = blb%py + (blb%vy * coef)
blb%pz = blb%pz + (blb%vz * coef)
end subroutine
! ----------------------------------------------------------------
2022-02-08 02:53:49 +01:00
subroutine bound_a_blob (blb)
type(t_bloubs), intent (inout) :: blb
if (5.0 .lt. blb%px) then
blb%vx = -1.0 * blb%vx
blb%px = 5.0
blb%seq = blb%seq + 1
endif
if (-5.0 .gt. blb%px) then
blb%vx = -1.0 * blb%vx
blb%px = -5.0
blb%seq = blb%seq + 1
endif
if (0.0 .gt. blb%py) then
blb%vy = -1.0 * blb%vy
blb%py = 0.0
2022-02-08 18:56:51 +01:00
blb%seq = blb%seq + 1
2022-02-08 02:53:49 +01:00
endif
2022-02-09 19:36:27 +01:00
if (5.0 .lt. blb%py) then
2022-02-08 02:53:49 +01:00
blb%vy = -1.0 * blb%vy
2022-02-08 18:56:51 +01:00
blb%seq = blb%seq + 1
2022-02-09 19:36:27 +01:00
blb%py = 5.0
2022-02-08 02:53:49 +01:00
endif
if (5.0 .lt. blb%pz) then
blb%vz = -1.0 * blb%vz
2022-02-08 18:56:51 +01:00
blb%seq = blb%seq + 1
2022-02-08 02:53:49 +01:00
blb%pz = 5.0
endif
if (-5.0 .gt. blb%pz) then
blb%vz = -1.0 * blb%vz
2022-02-08 18:56:51 +01:00
blb%seq = blb%seq + 1
2022-02-08 02:53:49 +01:00
blb%pz = -5.0
endif
end subroutine
! ----------------------------------------------------------------
subroutine green_soylent (blb)
type(t_bloubs), intent (inout) :: blb
2022-02-10 19:38:44 +01:00
if (blb%seq .gt. 6) then
2022-02-08 02:53:49 +01:00
blb%alive = .FALSE.
endif
end subroutine
! ----------------------------------------------------------------
2022-02-06 23:45:08 +01:00
end module