update main.ml (broken).

This commit is contained in:
Glenn Y. Rolland 2008-02-20 17:57:49 +01:00
parent 28a12ac806
commit fae903d5ec

20
main.ml
View file

@ -1,16 +1,22 @@
(* vim: set ts=2 sw=2 et : *) (* vim: set ts=2 sw=2 et : *)
open Event;; open Event;;
type config_t = { type config_t = {
mutable width : int ; mutable width : int ;
mutable height : int; mutable height : int;
} }
type notification_t = type notification_t =
| Graphics_status of Graphics.status | Graphics_status of Graphics.status
| Tick | Tick
;; ;;
type game_event_t = type game_event_t =
| MoveLeft | MoveLeft
| MoveRight | MoveRight
@ -26,6 +32,8 @@ type game_event_t =
let image_filename = "images/test.png" let image_filename = "images/test.png"
;; ;;
let string_of_keyboard_event event = let string_of_keyboard_event event =
try try
let chr = Sdlkey.char_of_key event.Sdlevent.keysym let chr = Sdlkey.char_of_key event.Sdlevent.keysym
@ -35,6 +43,8 @@ let string_of_keyboard_event event =
| Invalid_argument _ -> "unknown-key" | Invalid_argument _ -> "unknown-key"
;; ;;
let rec event_loop () = let rec event_loop () =
print_endline "Event_loop..."; print_endline "Event_loop...";
Sdltimer.delay 20; Sdltimer.delay 20;
@ -44,7 +54,7 @@ let rec event_loop () =
print_endline "You pressed escape! The fun is over now." print_endline "You pressed escape! The fun is over now."
| Sdlevent.KEYDOWN event -> | Sdlevent.KEYDOWN event ->
Keyboard.handle_event event Keyboard.handle_event event;
let keystr = string_of_keyboard_event event let keystr = string_of_keyboard_event event
in in
print_endline ("You pressed " ^ keystr); print_endline ("You pressed " ^ keystr);
@ -53,13 +63,17 @@ let rec event_loop () =
| _ -> | _ ->
event_loop () event_loop ()
) in ) in
let event_opt = Sdlevent.poll () let event_opt = Sdlevent.poll ()
in in
match event_opt with match event_opt with
| None -> event_loop () | None -> event_loop ()
| Some event -> match_event event; | Some event -> match_event event;
;; ;;
let game_loop ~screen = let game_loop ~screen =
let image = Sdlloader.load_image image_filename let image = Sdlloader.load_image image_filename
and image_from = Sdlvideo.rect 0 0 300 300 and image_from = Sdlvideo.rect 0 0 300 300
@ -67,10 +81,12 @@ let game_loop ~screen =
in in
Sdlvideo.blit_surface ~src:image ~src_rect:image_from ~dst:screen ~dst_rect:image_to (); Sdlvideo.blit_surface ~src:image ~src_rect:image_from ~dst:screen ~dst_rect:image_to ();
Sdlvideo.flip screen; Sdlvideo.flip screen;
let action_fun = event_loop (); (* let action_fun = event_loop () ; *)
game_loop screen game_loop screen
;; ;;
let main () = let main () =
let player1 = Player.create () let player1 = Player.create ()
and map1 = Maze.create () and map1 = Maze.create ()