program main use iso_c_binding use raylib implicit none integer(c_int) :: screen_width = 800 integer(c_int) :: screen_height = 450 type(camera3d), target :: camera type(vector3) :: npc_position type(vector3) :: player_position real(c_float) :: npc_dir logical :: player_updated ! ! implement a login and logout screen ! https://www.raylib.com/examples/core/loader.html?name=core_basic_screen_manager ! https://www.raylib.com/examples/text/loader.html?name=text_input_box ! call init_window(screen_width, screen_height, "fortran client : raylib"//c_null_char) player_position = vector3( 0.0_c_float, 1.0_c_float, 2.0_c_float ) npc_position = vector3( -4.0_c_float, 1.0_c_float, 0.0_c_float ) npc_dir = 0.1_c_float 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 set_target_fps(60_c_int) ! ! do login stuff here ! !call execute_command_line('mkfifo /tmp/fortran-mmo-in.pipe && mkfifo /tmp/fortran-mmo-out.pipe') !Main game loop do while (.not. window_should_close()) ! Detect window close button or ESC key if (is_key_down(KEY_RIGHT)) then player_position%x = player_position%x + 0.2_c_float player_updated = .true. else if (is_key_down(KEY_LEFT)) then player_position%x = player_position%x - 0.2_c_float player_updated = .true. else if (is_key_down(KEY_DOWN)) then player_position%z = player_position%z + 0.2_c_float player_updated = .true. else if (is_key_down(KEY_UP)) then player_position%z = player_position%z - 0.2_c_float player_updated = .true. end if camera%position%x = player_position%x camera%position%y = player_position%y + 10.0_c_float camera%position%z = player_position%z + 10.0_c_float camera%target%x = player_position%x camera%target%y = player_position%y camera%target%z = player_position%z ! if player updated ! send new player postition to server ! call execute_command_line('nc localhost 35565 < /tmp/fortran-mmo-in.pipe > /tmp/fortran-mmo-out.pipe') ! else ! send ping to server ! read response ! for each user in logged in ! if (npc_position%x < -10) then ! npc_dir = 0.1_c_float ! else if (npc_position%x > 10) then ! npc_dir = -0.1_c_float ! end if ! npc_position%x = npc_position%x + npc_dir call begin_drawing() call clear_background(RAYWHITE) call begin_mode_3d(camera) ! Draw floor call draw_grid(30_c_int, 1.0_c_float) ! Draw other users call draw_cube(npc_position, 0.5_c_float, 0.5_c_float, 0.5_c_float, GRAY) call draw_cube_wires(npc_position, 0.5_c_float, 0.5_c_float, 0.5_c_float, DARKGRAY) !Draw player cube call draw_cube(player_position, 0.5_c_float, 0.5_c_float, 0.5_c_float, PURPLE) call draw_cube_wires(player_position, 0.5_c_float, 0.5_c_float, 0.5_c_float, DARKPURPLE) call end_mode_3d() call end_drawing() end do ! ! send logout call to server ! call close_window() !Close window and OpenGL context call execute_command_line('rm /tmp/fortran-mmo.pipe') end program main