mmo-project/fortran/client/app/main.f90

90 lines
2.8 KiB
Fortran
Raw Normal View History

2023-08-26 13:58:47 -04:00
program main
2023-09-17 13:20:12 -04:00
use iso_fortran_env
2023-08-26 13:58:47 -04:00
use iso_c_binding
use raylib
2023-09-17 13:20:12 -04:00
use player_mod
2023-08-26 13:58:47 -04:00
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-17 13:20:12 -04:00
type(player) :: me
type(player), dimension(:), allocatable :: players
character(len=24):: username
character(len=24):: password
2023-09-17 15:34:49 -04:00
integer :: i, status
2023-09-17 13:20:12 -04:00
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 getarg(1, username)
call getarg(2, password)
2023-09-17 15:34:49 -04:00
me = player(username, vector3( 0.0_c_float, 1.0_c_float, 2.0_c_float ), PURPLE)
!players = me%login(password)
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
2023-09-17 13:20:12 -04:00
call init_window(screen_width, screen_height, "fortran client : raylib"//c_null_char)
2023-08-26 13:58:47 -04:00
call set_target_fps(60_c_int)
!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
2023-09-17 13:20:12 -04:00
me%position%x = me%position%x + 0.2_c_float
2023-09-17 09:40:35 -04:00
player_updated = .true.
2023-09-03 18:29:47 -04:00
else if (is_key_down(KEY_LEFT)) then
2023-09-17 13:20:12 -04:00
me%position%x = me%position%x - 0.2_c_float
2023-09-17 09:40:35 -04:00
player_updated = .true.
2023-09-03 18:29:47 -04:00
else if (is_key_down(KEY_DOWN)) then
2023-09-17 13:20:12 -04:00
me%position%z = me%position%z + 0.2_c_float
2023-09-17 09:40:35 -04:00
player_updated = .true.
2023-09-03 18:29:47 -04:00
else if (is_key_down(KEY_UP)) then
2023-09-17 13:20:12 -04:00
me%position%z = me%position%z - 0.2_c_float
2023-09-17 09:40:35 -04:00
player_updated = .true.
2023-09-03 18:29:47 -04:00
end if
2023-09-17 13:20:12 -04:00
call me%sync_camera(camera)
if (player_updated) then
2023-09-17 15:34:49 -04:00
!players = me%move()
2023-09-17 13:20:12 -04:00
else
2023-09-17 15:34:49 -04:00
!players = me%ping()
2023-09-17 13:20:12 -04:00
end if
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-17 15:34:49 -04:00
call draw_cube(me%position, 0.5_c_float, 0.5_c_float, 0.5_c_float, me%apperance)
!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
2023-09-03 18:29:47 -04:00
call end_mode_3d()
2023-08-26 13:58:47 -04:00
call end_drawing()
end do
2023-09-17 15:34:49 -04:00
!players = me%logout()
if (allocated(players)) then
deallocate(players)
end if
2023-08-26 13:58:47 -04:00
call close_window() !Close window and OpenGL context
2023-09-17 13:20:12 -04:00
close(12)
2023-08-26 13:58:47 -04:00
2023-09-17 13:20:12 -04:00
end program main