2023-08-26 13:58:47 -04:00
|
|
|
program main
|
|
|
|
use iso_c_binding
|
|
|
|
use raylib
|
|
|
|
implicit none
|
|
|
|
|
2023-09-03 18:29:47 -04:00
|
|
|
integer(c_int) :: screen_width = 800
|
|
|
|
integer(c_int) :: screen_height = 450
|
2023-08-26 13:58:47 -04:00
|
|
|
|
|
|
|
type(camera3d), target :: camera
|
2023-09-03 18:29:47 -04:00
|
|
|
type(vector3) :: npc_position
|
|
|
|
type(vector3) :: player_position
|
|
|
|
real(c_float) :: npc_dir
|
2023-09-10 18:51:11 -04:00
|
|
|
logical :: player_updated
|
2023-08-26 13:58:47 -04:00
|
|
|
|
2023-09-03 18:29:47 -04:00
|
|
|
!
|
|
|
|
! 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
|
|
|
|
!
|
2023-08-26 13:58:47 -04:00
|
|
|
|
2023-09-03 18:29:47 -04:00
|
|
|
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
|
2023-08-26 13:58:47 -04:00
|
|
|
|
2023-09-03 18:29:47 -04:00
|
|
|
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
|
2023-08-26 13:58:47 -04:00
|
|
|
|
|
|
|
call set_target_fps(60_c_int)
|
|
|
|
|
2023-09-10 18:51:11 -04:00
|
|
|
!
|
|
|
|
! do login stuff here
|
|
|
|
!
|
|
|
|
|
2023-08-26 13:58:47 -04:00
|
|
|
!Main game loop
|
|
|
|
do while (.not. window_should_close()) ! Detect window close button or ESC key
|
|
|
|
|
2023-09-03 18:29:47 -04:00
|
|
|
if (is_key_down(KEY_RIGHT)) then
|
|
|
|
player_position%x = player_position%x + 0.2_c_float
|
|
|
|
else if (is_key_down(KEY_LEFT)) then
|
|
|
|
player_position%x = player_position%x - 0.2_c_float
|
|
|
|
else if (is_key_down(KEY_DOWN)) then
|
|
|
|
player_position%z = player_position%z + 0.2_c_float
|
|
|
|
else if (is_key_down(KEY_UP)) then
|
|
|
|
player_position%z = player_position%z - 0.2_c_float
|
|
|
|
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
|
|
|
|
|
|
|
|
|
2023-09-10 18:51:11 -04:00
|
|
|
! if player updated
|
|
|
|
! send new player postition to server
|
|
|
|
! 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
|
2023-08-26 13:58:47 -04:00
|
|
|
|
|
|
|
call begin_drawing()
|
2023-09-03 18:29:47 -04:00
|
|
|
call clear_background(RAYWHITE)
|
|
|
|
|
|
|
|
call begin_mode_3d(camera)
|
|
|
|
! Draw floor
|
|
|
|
call draw_grid(30_c_int, 1.0_c_float)
|
|
|
|
|
2023-09-10 18:51:11 -04:00
|
|
|
! Draw other users
|
2023-09-03 18:29:47 -04:00
|
|
|
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()
|
2023-08-26 13:58:47 -04:00
|
|
|
call end_drawing()
|
|
|
|
|
|
|
|
end do
|
|
|
|
|
2023-09-10 18:51:11 -04:00
|
|
|
!
|
|
|
|
! send logout call to server
|
|
|
|
!
|
|
|
|
|
2023-08-26 13:58:47 -04:00
|
|
|
call close_window() !Close window and OpenGL context
|
|
|
|
|
|
|
|
contains
|
|
|
|
|
|
|
|
end program main
|