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
27
Game.ml
27
Game.ml
|
@ -7,13 +7,18 @@ type game_t = {
|
|||
timeline : Timeline.timeline_t ;
|
||||
}
|
||||
|
||||
let handle event ev =
|
||||
ignore ev
|
||||
let handle_event ev =
|
||||
ignore ev ; []
|
||||
;;
|
||||
|
||||
let rec refresh_input () =
|
||||
(* 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
|
||||
(* key events *)
|
||||
| Sdlevent.KEYDOWN _ -> Keyboard.handle_event
|
||||
|
@ -33,10 +38,10 @@ let rec refresh_input () =
|
|||
| Sdlevent.VIDEOEXPOSE -> Video.handle_event
|
||||
| Sdlevent.ACTIVE _ -> Video.handle_event
|
||||
(* system events *)
|
||||
| Sdlevent.QUIT -> Game.handle_event
|
||||
| Sdlevent.SYSWM -> Game.handle_event
|
||||
| Sdlevent.QUIT -> handle_event
|
||||
| Sdlevent.SYSWM -> handle_event
|
||||
(* user defined events *)
|
||||
| Sdlevent.USER _ -> ignore
|
||||
| Sdlevent.USER _ -> (fun x -> ignore x ; [] )
|
||||
in
|
||||
|
||||
let some_event = Sdlevent.poll ()
|
||||
|
@ -44,11 +49,11 @@ let rec refresh_input () =
|
|||
|
||||
match some_event with
|
||||
| Some ev ->
|
||||
if ev = Sdlevent.QUIT then ()
|
||||
else
|
||||
let handler_fun = get_handler_fun ev
|
||||
let handler = match_handler ev
|
||||
and quit = match_quit ev
|
||||
in
|
||||
handler_fun ev ;
|
||||
refresh_input ()
|
||||
ignore ( handler ev );
|
||||
if not quit then refresh_input ()
|
||||
|
||||
| None -> ()
|
||||
;;
|
||||
|
|
|
@ -1,4 +1,7 @@
|
|||
(* vim: set st=2 sw=2 et : *)
|
||||
|
||||
(** Joystick Management and event handling *)
|
||||
|
||||
let handle_event ev =
|
||||
ignore ev
|
||||
ignore ev ; []
|
||||
;;
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
(* vim: set st=2 sw=2 et : *)
|
||||
|
||||
let handle_event ev =
|
||||
ignore ev
|
||||
ignore ev ; []
|
||||
;;
|
||||
|
|
9
Makefile
9
Makefile
|
@ -3,12 +3,13 @@ PROGRAMS=justnukeit
|
|||
justnukeit_OBJS= \
|
||||
Position \
|
||||
Timeline \
|
||||
Mouse \
|
||||
Joystick \
|
||||
Keyboard \
|
||||
Menu \
|
||||
Level \
|
||||
Player \
|
||||
Joystick \
|
||||
Keyboard \
|
||||
Mouse \
|
||||
Video \
|
||||
Game \
|
||||
main
|
||||
|
||||
|
@ -45,7 +46,7 @@ $(foreach prog,$(PROGRAMS),$(eval $(call PROGRAM_template,$(prog))))
|
|||
.PHONY: all
|
||||
all: $(PROGRAMS)
|
||||
|
||||
doc:
|
||||
doc: $(ML) $(MLI)
|
||||
ocamldoc $(INCS) -d doc -html $(ML) $(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 *)
|
||||
(* vim: set ts=2 sw=2 et : *)
|
||||
|
||||
type text_t = {
|
||||
position: Position.t;
|
||||
|
@ -31,7 +31,7 @@ type t = {
|
|||
};;
|
||||
|
||||
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
|
||||
actions;;
|
||||
|
||||
|
|
2
Mouse.ml
2
Mouse.ml
|
@ -1,6 +1,6 @@
|
|||
(* vim: set ts=2 sw=2 et : *)
|
||||
|
||||
(** Mouse management and event handling. *)
|
||||
(* vim: set ts=2 sw=2 et : *)
|
||||
|
||||
(** Returns a list of "abstract events" generated
|
||||
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 : *)
|
||||
open Event;;
|
||||
|
||||
|
||||
(* open Event;; *)
|
||||
|
||||
type config_t = {
|
||||
mutable width : int ;
|
||||
|
@ -45,6 +44,7 @@ let string_of_keyboard_event event =
|
|||
|
||||
|
||||
|
||||
(*
|
||||
let rec event_loop () =
|
||||
print_endline "Event_loop...";
|
||||
Sdltimer.delay 20;
|
||||
|
@ -71,10 +71,10 @@ let rec event_loop () =
|
|||
| None -> event_loop ()
|
||||
| Some event -> match_event event;
|
||||
;;
|
||||
*)
|
||||
|
||||
|
||||
|
||||
let game_loop ~screen =
|
||||
let rec game_loop ~screen =
|
||||
let image = Sdlloader.load_image image_filename
|
||||
and image_from = Sdlvideo.rect 0 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.flip screen;
|
||||
(* let action_fun = event_loop () ; *)
|
||||
game_loop screen
|
||||
game_loop ~screen:screen
|
||||
;;
|
||||
|
||||
|
||||
|
||||
let main () =
|
||||
let player1 = Player.create ()
|
||||
and map1 = Maze.create ()
|
||||
and map1 = Level.create ()
|
||||
and config = { width = 640 ; height = 480 }
|
||||
in
|
||||
ignore player1 ;
|
||||
|
|
Loading…
Reference in a new issue