Updated event-related functions.
This commit is contained in:
parent
95fba9023c
commit
54d4870b77
9 changed files with 43 additions and 28 deletions
0
Event.ml
Normal file
0
Event.ml
Normal file
31
Game.ml
31
Game.ml
|
@ -7,13 +7,18 @@ type game_t = {
|
||||||
timeline : Timeline.timeline_t ;
|
timeline : Timeline.timeline_t ;
|
||||||
}
|
}
|
||||||
|
|
||||||
let handle event ev =
|
let handle_event ev =
|
||||||
ignore ev
|
ignore ev ; []
|
||||||
;;
|
;;
|
||||||
|
|
||||||
let rec refresh_input () =
|
let rec refresh_input () =
|
||||||
(* poll events *)
|
(* poll events *)
|
||||||
let get_handler_fun ev =
|
let match_quit ev =
|
||||||
|
if ev = Sdlevent.QUIT then true
|
||||||
|
else false
|
||||||
|
in
|
||||||
|
|
||||||
|
let match_handler ev =
|
||||||
match ev with
|
match ev with
|
||||||
(* key events *)
|
(* key events *)
|
||||||
| Sdlevent.KEYDOWN _ -> Keyboard.handle_event
|
| Sdlevent.KEYDOWN _ -> Keyboard.handle_event
|
||||||
|
@ -33,10 +38,10 @@ let rec refresh_input () =
|
||||||
| Sdlevent.VIDEOEXPOSE -> Video.handle_event
|
| Sdlevent.VIDEOEXPOSE -> Video.handle_event
|
||||||
| Sdlevent.ACTIVE _ -> Video.handle_event
|
| Sdlevent.ACTIVE _ -> Video.handle_event
|
||||||
(* system events *)
|
(* system events *)
|
||||||
| Sdlevent.QUIT -> Game.handle_event
|
| Sdlevent.QUIT -> handle_event
|
||||||
| Sdlevent.SYSWM -> Game.handle_event
|
| Sdlevent.SYSWM -> handle_event
|
||||||
(* user defined events *)
|
(* user defined events *)
|
||||||
| Sdlevent.USER _ -> ignore
|
| Sdlevent.USER _ -> (fun x -> ignore x ; [] )
|
||||||
in
|
in
|
||||||
|
|
||||||
let some_event = Sdlevent.poll ()
|
let some_event = Sdlevent.poll ()
|
||||||
|
@ -44,11 +49,11 @@ let rec refresh_input () =
|
||||||
|
|
||||||
match some_event with
|
match some_event with
|
||||||
| Some ev ->
|
| Some ev ->
|
||||||
if ev = Sdlevent.QUIT then ()
|
let handler = match_handler ev
|
||||||
else
|
and quit = match_quit ev
|
||||||
let handler_fun = get_handler_fun ev
|
in
|
||||||
in
|
ignore ( handler ev );
|
||||||
handler_fun ev ;
|
if not quit then refresh_input ()
|
||||||
refresh_input ()
|
|
||||||
| None -> ()
|
| None -> ()
|
||||||
;;
|
;;
|
||||||
|
|
|
@ -1,4 +1,7 @@
|
||||||
|
(* vim: set st=2 sw=2 et : *)
|
||||||
|
|
||||||
|
(** Joystick Management and event handling *)
|
||||||
|
|
||||||
let handle_event ev =
|
let handle_event ev =
|
||||||
ignore ev
|
ignore ev ; []
|
||||||
;;
|
;;
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
|
(* vim: set st=2 sw=2 et : *)
|
||||||
|
|
||||||
let handle_event ev =
|
let handle_event ev =
|
||||||
ignore ev
|
ignore ev ; []
|
||||||
;;
|
;;
|
||||||
|
|
9
Makefile
9
Makefile
|
@ -3,12 +3,13 @@ PROGRAMS=justnukeit
|
||||||
justnukeit_OBJS= \
|
justnukeit_OBJS= \
|
||||||
Position \
|
Position \
|
||||||
Timeline \
|
Timeline \
|
||||||
|
Mouse \
|
||||||
|
Joystick \
|
||||||
|
Keyboard \
|
||||||
Menu \
|
Menu \
|
||||||
Level \
|
Level \
|
||||||
Player \
|
Player \
|
||||||
Joystick \
|
Video \
|
||||||
Keyboard \
|
|
||||||
Mouse \
|
|
||||||
Game \
|
Game \
|
||||||
main
|
main
|
||||||
|
|
||||||
|
@ -45,7 +46,7 @@ $(foreach prog,$(PROGRAMS),$(eval $(call PROGRAM_template,$(prog))))
|
||||||
.PHONY: all
|
.PHONY: all
|
||||||
all: $(PROGRAMS)
|
all: $(PROGRAMS)
|
||||||
|
|
||||||
doc:
|
doc: $(ML) $(MLI)
|
||||||
ocamldoc $(INCS) -d doc -html $(ML) $(MLI)
|
ocamldoc $(INCS) -d doc -html $(ML) $(MLI)
|
||||||
|
|
||||||
%.cmi: %.mli
|
%.cmi: %.mli
|
||||||
|
|
4
Menu.ml
4
Menu.ml
|
@ -1,6 +1,6 @@
|
||||||
|
(* vim: set ts=2 sw=2 et : *)
|
||||||
|
|
||||||
(* position are not absolutes, but percentage *)
|
(* position are not absolutes, but percentage *)
|
||||||
(* vim: set ts=2 sw=2 et : *)
|
|
||||||
|
|
||||||
type text_t = {
|
type text_t = {
|
||||||
position: Position.t;
|
position: Position.t;
|
||||||
|
@ -31,7 +31,7 @@ type t = {
|
||||||
};;
|
};;
|
||||||
|
|
||||||
let handle_event ev =
|
let handle_event ev =
|
||||||
let actions = (Mouse.handle_event ev) :: (Mouse.handle_event ev)
|
let actions = (Keyboard.handle_event ev) :: (Mouse.handle_event ev)
|
||||||
in
|
in
|
||||||
actions;;
|
actions;;
|
||||||
|
|
||||||
|
|
2
Mouse.ml
2
Mouse.ml
|
@ -1,6 +1,6 @@
|
||||||
|
(* vim: set ts=2 sw=2 et : *)
|
||||||
|
|
||||||
(** Mouse management and event handling. *)
|
(** Mouse management and event handling. *)
|
||||||
(* vim: set ts=2 sw=2 et : *)
|
|
||||||
|
|
||||||
(** Returns a list of "abstract events" generated
|
(** Returns a list of "abstract events" generated
|
||||||
by this SDL event *)
|
by this SDL event *)
|
||||||
|
|
5
Video.ml
Normal file
5
Video.ml
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
(* vim: set st=2 sw=2 et : *)
|
||||||
|
|
||||||
|
let handle_event ev =
|
||||||
|
ignore ev ; []
|
||||||
|
;;
|
12
main.ml
12
main.ml
|
@ -1,7 +1,6 @@
|
||||||
(* 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 ;
|
||||||
|
@ -45,6 +44,7 @@ let string_of_keyboard_event event =
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
(*
|
||||||
let rec event_loop () =
|
let rec event_loop () =
|
||||||
print_endline "Event_loop...";
|
print_endline "Event_loop...";
|
||||||
Sdltimer.delay 20;
|
Sdltimer.delay 20;
|
||||||
|
@ -71,10 +71,10 @@ let rec event_loop () =
|
||||||
| None -> event_loop ()
|
| None -> event_loop ()
|
||||||
| Some event -> match_event event;
|
| Some event -> match_event event;
|
||||||
;;
|
;;
|
||||||
|
*)
|
||||||
|
|
||||||
|
|
||||||
|
let rec 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
|
||||||
and image_to = Sdlvideo.rect 100 0 300 300
|
and image_to = Sdlvideo.rect 100 0 300 300
|
||||||
|
@ -82,14 +82,14 @@ let game_loop ~screen =
|
||||||
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:screen
|
||||||
;;
|
;;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
let main () =
|
let main () =
|
||||||
let player1 = Player.create ()
|
let player1 = Player.create ()
|
||||||
and map1 = Maze.create ()
|
and map1 = Level.create ()
|
||||||
and config = { width = 640 ; height = 480 }
|
and config = { width = 640 ; height = 480 }
|
||||||
in
|
in
|
||||||
ignore player1 ;
|
ignore player1 ;
|
||||||
|
|
Loading…
Reference in a new issue