108 lines
3.6 KiB
Fortran
108 lines
3.6 KiB
Fortran
program main
|
|
use iso_fortran_env
|
|
use iso_c_binding
|
|
use raylib
|
|
use player_mod
|
|
implicit none
|
|
|
|
integer(c_int) :: screen_width = 800
|
|
integer(c_int) :: screen_height = 450
|
|
|
|
type(camera3d), target :: camera
|
|
type(player) :: me
|
|
type(player), dimension(:), allocatable :: players
|
|
character(len=24):: username
|
|
character(len=24):: password
|
|
integer :: i, status, in_pipe, out_pipe
|
|
logical :: player_updated, exist
|
|
|
|
inquire (file="debug.log", exist=exist)
|
|
if (exist) then
|
|
open (12, file="debug.log", status="old", position="append", action="write")
|
|
else
|
|
open (12, file="debug.log", status="new", action="write")
|
|
end if
|
|
|
|
call execute_command_line('rm fortran-mmo-in.pipe')
|
|
write(12, *) 'removed fortran-mmo-in.pipe'
|
|
call execute_command_line('rm fortran-mmo-out.pipe')
|
|
write(12, *) 'removed fortran-mmo-out.pipe'
|
|
call execute_command_line('mkfifo fortran-mmo-in.pipe && mkfifo fortran-mmo-out.pipe')
|
|
write(12, *) 'created new pipes'
|
|
call execute_command_line('nc localhost 35565 < fortran-mmo-in.pipe > fortran-mmo-out.pipe', wait=.false.)
|
|
write(12, *) 'started coms'
|
|
|
|
in_pipe = 13
|
|
open (unit=in_pipe, file="fortran-mmo-in.pipe", form='formatted', access='stream', iostat=status)
|
|
write(12, *) 'fortran-mmo-in.pipe open success', status
|
|
|
|
out_pipe = 14
|
|
open (unit=out_pipe, file="fortran-mmo-out.pipe", form='formatted', access='stream', iostat=status)
|
|
write(12, *) 'fortran-mmo-out.pipe open success', status
|
|
|
|
call getarg(1, username)
|
|
call getarg(2, password)
|
|
|
|
me = player(username, vector3( 0.0_c_float, 1.0_c_float, 2.0_c_float ), PURPLE, in_pipe, out_pipe)
|
|
players = me%login(password)
|
|
|
|
camera%position = vector3(0.0_c_float, 10.0_c_float, 10.0_c_float) !Camera position
|
|
camera%target = vector3(0.0_c_float, 0.0_c_float, 0.0_c_float) !Camera looking at point
|
|
camera%up = vector3(0.0_c_float, 1.0_c_float, 0.0_c_float) !Camera up vector(rotation towards target)
|
|
camera%fovy = 45.0_c_float !Camera field - of - view Y
|
|
camera%projection = CAMERA_PERSPECTIVE !Camera projection type
|
|
|
|
call init_window(screen_width, screen_height, "fortran client : raylib"//c_null_char)
|
|
call set_target_fps(60_c_int)
|
|
|
|
!Main game loop
|
|
do while (.not. window_should_close()) ! Detect window close button or ESC key
|
|
|
|
if (is_key_down(KEY_RIGHT)) then
|
|
me%position%x = me%position%x + 0.2_c_float
|
|
player_updated = .true.
|
|
else if (is_key_down(KEY_LEFT)) then
|
|
me%position%x = me%position%x - 0.2_c_float
|
|
player_updated = .true.
|
|
else if (is_key_down(KEY_DOWN)) then
|
|
me%position%z = me%position%z + 0.2_c_float
|
|
player_updated = .true.
|
|
else if (is_key_down(KEY_UP)) then
|
|
me%position%z = me%position%z - 0.2_c_float
|
|
player_updated = .true.
|
|
end if
|
|
|
|
call me%sync_camera(camera)
|
|
|
|
if (player_updated) then
|
|
players = me%move()
|
|
else
|
|
players = me%ping()
|
|
end if
|
|
|
|
call begin_drawing()
|
|
call clear_background(RAYWHITE)
|
|
|
|
call begin_mode_3d(camera)
|
|
! Draw floor
|
|
call draw_grid(30_c_int, 1.0_c_float)
|
|
|
|
do i=1,size(players)
|
|
call draw_cube(players(i)%position, 0.5_c_float, 0.5_c_float, 0.5_c_float, players(i)%apperance)
|
|
end do
|
|
call end_mode_3d()
|
|
call end_drawing()
|
|
|
|
end do
|
|
|
|
players = me%logout()
|
|
deallocate(players)
|
|
call close_window() !Close window and OpenGL context
|
|
close(in_pipe)
|
|
close(out_pipe)
|
|
close(12)
|
|
call execute_command_line('rm fortran-mmo-in.pipe')
|
|
call execute_command_line('rm fortran-mmo-out.pipe')
|
|
|
|
end program main
|