Fortraneries/BloubWorld/bloubspace.f90

141 lines
3.4 KiB
Fortran

!
! 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 :: age
end type t_bloubs
contains ! -----------------------------------------
subroutine random_pv (blb)
type(t_bloubs), intent (inout) :: blb
blb%px = 1.3 * (rand() - 0.50)
blb%py = 0.50 + rand() * 0.50
blb%pz = 2.0 * (rand() - 0.50)
blb%vx = (rand() - 0.5) / 2.500
blb%vy = (rand() - 0.5) / 4.000
blb%vz = (rand() - 0.5) / 2.500
blb%alive = .TRUE.
end subroutine
! ----------------------------------------------------------------
subroutine display_bloub (blb, message)
type(t_bloubs), intent (in) :: blb
character(*), intent (in) :: message
character(5) :: life
if (blb%alive) then
life = "alive"
else
life = "dead"
endif
write (0, '(4X, A)') '+--------------- ' // message // " -------"
write (0, '(4X,A3,A8,2X,I6,4X,A5,4X,I5)') '| ', &
blb%nick, blb%num, life, blb%age
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
write (0, '()')
end subroutine
! ----------------------------------------------------------------
subroutine move_bloub (blb, coef)
type(t_bloubs), intent (inout) :: blb
real, intent (in) :: coef
! we must check that this bloub is alive ?
blb%px = blb%px + (blb%vx * coef)
blb%py = blb%py + (blb%vy * coef)
blb%pz = blb%pz + (blb%vz * coef)
end subroutine
! ----------------------------------------------------------------
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%age = blb%age + 1
endif
if (-5.0 .gt. blb%px) then
blb%vx = -1.0 * blb%vx
blb%px = -5.0
blb%age = blb%age + 1
endif
if (0.0 .gt. blb%py) then
blb%vy = -1.0 * blb%vy
blb%py = 0.0
blb%age = blb%age + 1
endif
if (5.0 .lt. blb%py) then
blb%vy = -1.0 * blb%vy
blb%age = blb%age + 1
blb%py = 5.0
endif
if (5.0 .lt. blb%pz) then
blb%vz = -1.0 * blb%vz
blb%age = blb%age + 1
blb%pz = 5.0
endif
if (-5.0 .gt. blb%pz) then
blb%vz = -1.0 * blb%vz
blb%age = blb%age + 1
blb%pz = -5.0
endif
end subroutine
! ----------------------------------------------------------------
function distance_of_bloubs(bla, blb)
type(t_bloubs), intent(in) :: bla, blb
real :: distance_of_bloubs
real :: dx, dy, dz
dx = (bla%px-blb%px)**2
dy = (bla%py-blb%py)**2
dz = (bla%pz-blb%pz)**2
distance_of_bloubs = sqrt(dx + dy +dz)
end function
! ----------------------------------------------------------------
! kill a bloub under condition(s)
subroutine green_soylent (blb)
type(t_bloubs), intent (inout) :: blb
if (blb%age .gt. 5) then
blb%alive = .FALSE.
endif
end subroutine
! ----------------------------------------------------------------
end module