views:

410

answers:

2

hi everyone, am developing a small game (worms), and am using OCAML Sdl for that, actually i didn't find any documentation out there about it, so i have three questions:

  1. I want to use ocaml sdl under windows, so anyone can help how can I compile it, (I already gave up and installed linux on a virtual pc)
  2. Is there any documentation on how to use OCAML SDL?
  3. I am using a 800x600 window, and i wanna represent some graphics inside, for example that pixel represents the background, the other represents a rock and so on, what is the best representation of that (the 800x600) window? as a general case am using an array ok 800 * 600 cells, I know it's the ugliest representation, but any suggestions please

thank you all

+1  A: 

1 - I want to use ocaml sdl under windows, so anyone can help how can I compile it, (I already gave up and installed linux on a virtual pc)

Can you get the SDL working under windows and compile C programs with it? If so you should then get up on reading the chapter on compiling ocaml with c programs in the manual.

2 - Is there any documentation on how to use OCAML SDL?

In the package there is documentation. I imagine that this isn't the best, since there really isn't a single package in ocaml that has decent documentation --I'm allowed to exaggerate, aren't I?

To get around this, you'll need to explore what functions you need in the SDL then find the corresponding one in MLI files in the source directory of the ocamlSDL. It shouldn't be too bad. It seems like it's pretty organized. I had to do this with other packages. The programmers have some standard naming conventions, and then you really just need to know the functions signature and you're a go.

I would try, as hard as possible, to go about your business pretending you are just calling the SDL directly --for the most part it should be that easy.

3 - I am using a 800x600 window, and i wanna represent some graphics inside, for example that pixel represents the background, the other represents a rock and so on, what is the best representation of that (the 800x600) window? as a general case am using an array of 800 * 600 cells, I know it's the ugliest representation, but any suggestions please

Hashtbls in ocaml are pretty efficient --ocaml actually uses them for scope of variables. Plus any hash collisions result in a list of elements, which could be nice for multiple layers of data.

Other then that, you might want to use sprites. But I think you should get the basics going, then implement sprites later --sorry for being presumptuous, it's my method of implementation.

EDIT:

Based on your comments and your current experience I want to make a final suggestion... Do not use the ocamlSDL. For what you are doing there is no reason, especially someone who is just learning the language --which is what I gathered, please correct me if I am wrong. My recommendation is to use the Graphics module that is machine independent that is built into ocaml! It has all the functionality you will need to do what you need to do for this simple game. The module is pretty straight forward and you should be able to jump right into setting things up.

nlucaroni
oh God...well, for sdl under windows, it's not wrking under windows since i must make (in the linux like means) it before referencing it, for the documentation it's ok, and for hashtbls and sprites, i can't figure out really how to use this, since am a newbe in the domain,but thanx very well!!!
martani_net
and you cannot make the SDL under windows? Well then, of course ocaml isn't going to know how to access a library that isn't there!
nlucaroni
ya thanks, but they provide us already provide us some drawing modules that use ocamlsdl, so we have to use them,anyway that was a good answer thank you.
martani_net
OH! in that case. we can talk a little more about writing a C-Interface to those modules so they don't have to be re-written! Probably should be in another question, look at the c-interface documentation first! enjoy!
nlucaroni
A: 

for example here is the interface of the module draw, that we can you to draw the pixels on the screen:

val draw_player: int -> int -> unit

val draw_missile: int -> int -> unit

val draw_text_center: int -> int -> string -> unit

type playfield

val empty_playfield: int -> int -> playfield

type pixel = Background | Dirt | Rock

val set_playfield_pixel: playfield -> int -> int -> pixel -> unit

val draw_playfield: playfield -> unit

val update: unit -> unit

these are the function that we use to design our game!!! so poor ha! anyway, to utilise that module in windows (which itself use ocamlsdl) i should compile it first, my question is, is it a good idea to draw a screen of 800x600 pixel per pixel? and to represent that screen, to say for example that the pixel (x y) represents a background or another piece of the game, what can be the best representaion of that?an array of 800x600, peronnaly i don't feel comfortable with that, the performance and... you kno!

martani_net