You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The first thing you need to know about ooc is that it compiles down to C. Sure, in theory you could compile it to JavaScript or whatever, but it was really designed to spit out C under the hood.
Apart from being shorter, allowing code outside the main function, and having a few nice things built-ins, ooc allows you to go object-oriented, like so:
Bullet: classextends Actor {
init: func (.game) {
super(game)
}
explode: func {
game boombox play("bullet-explosion")
destroy() // defined in Actor
}
}
And then use it like so:
// Let's assume we have a game object from beforeb:=Bullet new(game)
game on("random", ||b explode()
)
Wow, wow, wow, back up.
Okay, that was probably pretty fast. But you did see some nice things, e.g.:
How to define a class - that inherits from another class
How to use dot-parameters to shorten parameter lists
How to call member methods and super-constructor
That you don't always need parameter lists
How to define a closure
How to define a variable with an inferred type
String literals
What's next?
I don't feel like going through each feature of the language individually so I'll just write example code and comment as I go.
Also, I have no idea if I'll follow through with this series, so don't expect much.
As we mentioned earlier, ooc compilers just generate C code. Which means once the C code is generated, it still has to be compiled to produce an executable.
Which ooc compiler to use?
Nowadays, everybody uses rock. I used to maintain it but now it's our dear friend Alexandros. Thanks dude!
(Make sure you have XCode installed, it needs to compile C code - but homebrew should have told you that already)
Homebrew packages are stored somewhere in /usr/local/Cellar/, but usually formulas will put binaries in your path, which means rock should work out of the box:
rock -V
Should output its version number.
Instructions for Linux
There might be a package for your distribution, but compiling it is easy. Make sure you have the basics to build software (ie. a C compiler, make, etc. - the build-essential package takes care of that on Ubuntu), and go ahead and clone the git repository:
git clone git://github.com/nddrylliog/rock.git
cd rock
make rescue
And that's it! You now have a rock executable in bin/. You can check that it's working by running:
bin/rock -V
And it should output its version number. You probably want to add it to your $PATH, so edit your ~/.bashrc or ~/.zshrc to add a line like:
export PATH=$PATH:/path/to/rock/bin/
Where /path/to/rock/ is the path to where you cloned your rock.
Note: do not copy the rock executable elsewhere! It uses its location to find the SDK, which is needed to compile ooc programs.
(You can override the SDK path with the ROCK_SDK environment variable, but chances are, you probably won't need this)
Instructions for Windows
While rock does work on Windows, it's one of the least comfortable platforms to develop in. My personal favorite is Linux, then I can live with OSX, and I can survive on Windows, but I really wouldn't do any serious development there (except on the Microsoft toolchain, but that's another story.)
However, nothing stops you from developing most of your game on Linux/OSX and then come up with a Windows build for the release. Also, if you make music / graphics on Windows, nothing stops you from committing them to a git repository that you'll later pull from Linux/OSX and use them while developing your game.
If you should have to compile rock under Win32, however, here are a few tips:
First, you need to get mingw32. Long story short, it's a GCC port for Windows. Install the latest GCC (no need for C++/Java/Fortran/whatnot support) along with MSYS so you get a nice MinGW Shell shortcut with bash, vim, and all the utilities you're used to.
Then, you probably want to be able to deal with git repositories, if only to compile rock. Grab msysgit and install it. That'll provide you with another start menu entry: Git Bash.
Launch Git Bash, cd to somewhere comfy, and run:
git clone git://github.com/nddrylliog/rock.git
Then, exit Git Bash, launch MinGW Shell, cd to that same directory, and run:
make rescue
If everything goes fine, it should leave you a nice rock.exe file in bin/. In MinGW, you can use Unix-style paths (with /) and you don't have to specify the .exe extension, so this command should display the version number:
bin/rock -V
Be aware that some parts of the SDK have different underlying implementations for *nix and Windows. Even though they should behave the same, there might be some subtle differences.
@FredericJacobs Haha, almost :) There are lots of trick you still need to learn...
@Shamanas Welp, I have pretty much declared ldkit deprecated. I wanna show how to build your own kit, how to cover libraries, write modular code, some physics, audio code, event-based system.. pretty much everything you need in small bits and pieces.
Nice. I know ooc now. :)