Import base files.
This commit is contained in:
commit
fec786f6c1
6 changed files with 246 additions and 0 deletions
80
Makefile
Normal file
80
Makefile
Normal file
|
@ -0,0 +1,80 @@
|
|||
PROGRAMS=justnukeit
|
||||
|
||||
justnukeit_OBJS=Position.cmx Maze.cmx Player.cmx main.cmx
|
||||
justnukeit_LIBS=graphics.cmxa
|
||||
|
||||
MODULES=$(patsubst %.mli,%,$(wildcard *.mli)) $(patsubst %.ml,%,$(wildcard *.ml))
|
||||
|
||||
CMI=$(patsubst %.ml,%.cmi,$(MODULES:=.ml))
|
||||
CMO=$(patsubst %.ml,%.cmo,$(MODULES:=.ml))
|
||||
CMX=$(patsubst %.ml,%.cmx,$(MODULES:=.ml))
|
||||
#LIB=unix.cmxa str.cmxa graphics.cmxa
|
||||
LIB=
|
||||
|
||||
OCAMLDEP=ocamldep
|
||||
OCAMLOPT=ocamlopt
|
||||
OCAMLC=ocamlc
|
||||
|
||||
|
||||
SOURCE=main.ml
|
||||
|
||||
OPTS=-w A -g
|
||||
|
||||
define PROGRAM_template
|
||||
ALL_OBJS += $$($(1)_OBJS)
|
||||
$(1): $$($(1)_OBJS)
|
||||
@echo -n -e "\x1B[31;1m"
|
||||
@echo "[O] $@"
|
||||
@echo -n -e "\x1B[0m"
|
||||
$(OCAMLOPT) $(OPTS) $($(1)_LIBS) $($(1)_OBJS) -o $(1)
|
||||
@echo ""
|
||||
endef
|
||||
|
||||
$(foreach prog,$(PROGRAMS),$(eval $(call PROGRAM_template,$(prog))))
|
||||
|
||||
.PHONY: all
|
||||
all: $(PROGRAMS)
|
||||
|
||||
%.cmi: %.mli
|
||||
@echo -n -e "\x1B[31;1m"
|
||||
@echo "[I] $<"
|
||||
@echo -n -e "\x1B[0m"
|
||||
@$(OCAMLC) -i $<
|
||||
#@$(OCAMLC) $(OPTS) -c $<
|
||||
@$(OCAMLOPT) $(OPTS) -c $<
|
||||
@echo ""
|
||||
|
||||
%.cmx: %.ml
|
||||
@echo -n -e "\x1B[31;1m"
|
||||
@echo "[C] $<"
|
||||
@echo -n -e "\x1B[0m"
|
||||
@$(OCAMLOPT) -i $<
|
||||
@$(OCAMLOPT) $(OPTS) -c $<
|
||||
@echo ""
|
||||
|
||||
%.cmo %.cmi: %.ml %.cmi %.mli
|
||||
@echo "[O] $<"
|
||||
@$(OCAMLC) -i $<
|
||||
@$(OCAMLC) $(OPTS) -c $<
|
||||
echo ""
|
||||
|
||||
%.cmo %.cmi: %.ml
|
||||
@echo -n -e "\x1B[31;1m"
|
||||
@echo "[O] $<"
|
||||
@echo -n -e "\x1B[0m"
|
||||
@$(OCAMLC) -i $<
|
||||
@$(OCAMLC) $(OPTS) -c $<
|
||||
echo ""
|
||||
|
||||
clean:
|
||||
rm -f $(PROGRAMS) *~ *.cm* *.o *.a *.so .depend *.cmxa *.cma
|
||||
|
||||
.depend: $(MODULES:=.ml)
|
||||
$(OCAMLDEP) $(MODULES:=.ml) $(MODULES:=.mli) > .depend
|
||||
@echo ""
|
||||
|
||||
|
||||
.SUFFIXES:
|
||||
|
||||
-include .depend
|
||||
|
31
Maze.ml
Normal file
31
Maze.ml
Normal file
|
@ -0,0 +1,31 @@
|
|||
type item_t =
|
||||
| Bonus
|
||||
| Malus
|
||||
| NoItem
|
||||
;;
|
||||
|
||||
type block_t =
|
||||
| Solid
|
||||
| Breakable
|
||||
| NoBlock
|
||||
;;
|
||||
|
||||
type t = {
|
||||
mutable size_x : int ;
|
||||
mutable size_y : int ;
|
||||
mutable items : item_t array array ;
|
||||
mutable blocks : block_t array array ;
|
||||
};;
|
||||
|
||||
|
||||
let default_x = 10;;
|
||||
|
||||
let default_y = 10;;
|
||||
|
||||
let create () = {
|
||||
size_x = default_x ;
|
||||
size_y = default_y ;
|
||||
items = Array.make_matrix default_x default_y NoItem ;
|
||||
blocks = Array.make_matrix default_x default_y NoBlock ;
|
||||
}
|
||||
;;
|
12
Player.ml
Normal file
12
Player.ml
Normal file
|
@ -0,0 +1,12 @@
|
|||
|
||||
type t = {
|
||||
mutable name : string ;
|
||||
mutable lifes : int ;
|
||||
mutable position : Position.t;
|
||||
}
|
||||
|
||||
let create () = {
|
||||
name = "Unnamed player" ;
|
||||
lifes = 3 ;
|
||||
position = Position.zero ;
|
||||
}
|
10
Position.ml
Normal file
10
Position.ml
Normal file
|
@ -0,0 +1,10 @@
|
|||
type t = {
|
||||
mutable x : int ;
|
||||
mutable y : int ;
|
||||
}
|
||||
|
||||
let zero = {
|
||||
x = 0 ;
|
||||
y = 0 ;
|
||||
}
|
||||
|
46
main.ml
Normal file
46
main.ml
Normal file
|
@ -0,0 +1,46 @@
|
|||
(* vim: set ts=2 sw=2 et : *)
|
||||
|
||||
type game_event_t =
|
||||
| MoveLeft
|
||||
| MoveRight
|
||||
| MoveUp
|
||||
| MoveDown
|
||||
| Action
|
||||
| ActionTwo
|
||||
| Help
|
||||
| Quit
|
||||
| None
|
||||
;;
|
||||
|
||||
let dispatch_event status =
|
||||
if status.Graphics.keypressed then
|
||||
match status.Graphics.key with
|
||||
| 'q' -> Quit
|
||||
| _ -> None
|
||||
else
|
||||
None
|
||||
;;
|
||||
|
||||
let game_loop () =
|
||||
let continue = ref true
|
||||
in
|
||||
while !continue do
|
||||
match dispatch_event ( Graphics.wait_next_event [Graphics.Poll] ) with
|
||||
| Quit ->
|
||||
continue := false ;
|
||||
print_string "Exiting...\n";
|
||||
| _ -> print_string "nothing...\n";
|
||||
done
|
||||
;;
|
||||
|
||||
let main () =
|
||||
let player1 = Player.create ()
|
||||
and map1 = Maze.create ()
|
||||
in
|
||||
Graphics.open_graph " 320x200+50+50";
|
||||
Graphics.set_window_title "Just Nuke It";
|
||||
game_loop ();
|
||||
Graphics.close_graph ()
|
||||
;;
|
||||
|
||||
main ();
|
67
main.old
Normal file
67
main.old
Normal file
|
@ -0,0 +1,67 @@
|
|||
type maze_t = Block of string
|
||||
| Wall of int
|
||||
| Empty of int
|
||||
|
||||
type bonus_t =
|
||||
| Add_one_life
|
||||
| Steal_one_life (* graal *)
|
||||
| Speed
|
||||
;;
|
||||
|
||||
type malus_t =
|
||||
| Remove_one_life
|
||||
| Slow_down
|
||||
;;
|
||||
|
||||
type item_t =
|
||||
| Lifelong_bonus of bonus_t
|
||||
| Lifelong_malus of malus_t
|
||||
| Limited_malus of malus_t * int (* seconds *)
|
||||
| Limited_bonus of bonus_t * int (* seconds *)
|
||||
|
||||
type bomb_action_t =
|
||||
| Explode
|
||||
|
||||
type direction_t =
|
||||
| Top
|
||||
| Bottom
|
||||
| Left
|
||||
| Right
|
||||
;;
|
||||
|
||||
type player_action_t =
|
||||
| Move of direction_t
|
||||
| Push_bomb of direction_t
|
||||
| Jump_walls of int
|
||||
;;
|
||||
|
||||
type bomb_modifier_t =
|
||||
| Cross of int
|
||||
| Square of int
|
||||
| Fungus of int (* time to live *)
|
||||
;;
|
||||
|
||||
type bomb = {
|
||||
player: player_t ;
|
||||
modifiers: bomb_modifier_t list
|
||||
};;
|
||||
|
||||
type bomb_action_t =
|
||||
| Appear_at of int * int
|
||||
| Explode;;
|
||||
|
||||
type action_t =
|
||||
| Bomb of bomb_action_t
|
||||
| Player of player_action_t
|
||||
| Display of int * int * string
|
||||
;;
|
||||
|
||||
|
||||
let main () =
|
||||
Graphics.open_graph " 320x200+50+50";
|
||||
Graphics.set_window_title "Just Nuke It";
|
||||
Graphics.wait_next_event [];
|
||||
Graphics.close_graph ()
|
||||
;;
|
||||
|
||||
main ();
|
Loading…
Reference in a new issue