Skip to content

Commit facbfce

Browse files
committed
Start game init
1 parent 9d256b4 commit facbfce

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+373
-532
lines changed

src/font.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ open Iter.Infix
88
4: standard
99
*)
1010

11-
type font =
11+
type t =
1212
{
1313
ascii_first: char;
1414
ascii_last: char;

src/game.ml

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
open Containers
2+
3+
let data_dir = "./data/"
4+
5+
let map_names =
6+
let open Gmap in
7+
[
8+
EastUS, "EASTUS.PIC";
9+
WestUS, "WESTUS.PIC";
10+
Britain, "BRITAIN.PIC";
11+
Europe, "EUROPE.PIC"
12+
]
13+
14+
let load_pics () =
15+
let load_ndarray s = Pic.ndarray_of_file @@ data_dir ^ s ^ ".PIC" in
16+
let images = Hashtbl.create 20 in
17+
let filenames = [
18+
"SPRITES"; "TRACKS"; "STATION"; "FACES"; "LOCOS"; "LOCOSM"; "TITLE";
19+
"LOGO"; "LABS"; "CREDITS2"; "ADVERT";
20+
"DIFFS"; "DIFFSP"; "COUNCIL";
21+
"PAGE0"; "PAGE1"; "PAGE2"; "PAGE3"; "PAGE4"; "PAGE5"; "PAGE6"; "PAGE7"; "PAGE8"; "PAGE9";
22+
"ELOC0"; "ELOC1"; "ELOC2"; "ELOC3"; "LOCOS0"; "LOCOS1"; "LOCOS2"
23+
]
24+
in
25+
List.iter (fun s ->
26+
let ndarray = load_ndarray s in
27+
Hashtbl.replace images s ndarray)
28+
filenames;
29+
images
30+
31+
(* The actual game state *)
32+
type t = {
33+
map : Gmap.t;
34+
}
35+
36+
(* All game resources *)
37+
type resources = {
38+
maps: (Gmap.area * Gmap.t) list;
39+
pics: (string, Pic.ndarray) Hashtbl.t;
40+
fonts: Font.t array;
41+
}
42+
43+
type state = {
44+
game: t;
45+
screen: Screen.t;
46+
resources: resources;
47+
}
48+
49+
let run ?(view=Screen.MapGen) ?(area=Gmap.WestUS) () =
50+
Printf.printf "Loading resources...";
51+
let maps = List.map (fun (x,s) -> x, "./data/" ^ s |> Gmap.of_file) map_names in
52+
let pics = load_pics () in
53+
let fonts = Font.load_all () in
54+
let resources = {maps; pics; fonts} in
55+
56+
let screen = Screen.make view in
57+
58+
let map = List.assoc ~eq:(Stdlib.(=)) area maps in
59+
let v = {map} in
60+
61+
let state = {game=v; screen; resources} in
62+
Printf.printf "done.\n"
63+
64+
65+

0 commit comments

Comments
 (0)