Templates in IB2

3 min read

Deviation Actions

shock-value's avatar
By
Published:
1.7K Views
First, a new video: www.youtube.com/watch?v=gQRhTj…

Now some context: I have implemented some "control templates" as I am calling them, so that it is very easy for me and other script designers to get functionality like throwing objects or attaching object silhouettes to the mouse (both of which seen in this video). This allows for very precise yet still very easy and fun control over object creation and placement. It also means that all throwable objects, for example, will be thrown the same way (i.e. click and drag to set trajectory, let go to create object) so players will get the hang of things very easy and controls will be consistent from item to item (including user created items, if they choose to use these templates).

Basically, what these templates are are ShockScript functions (well, more specifically, constructors) that take your own defined functions as arguments and automatically implement the necessary player controls and associated graphics. For example, an example script that uses the template "Throw":

exec

(set makeCircle (func x y xv yv (exec
  (set cir (new SimpleCircle x y 20))
  (cir.setXYVel xv yv)
)))

/* (comment) so now we have defined a function "makeCircle" that takes four parameters: the x and y position of the object to be made, and the x and y velocity of it. This is perfect because the Throw template expects to be given a function with these four parameters. So, let's invoke the template */

(new templates.Throw makeCircle 4)

/* (comment) As you can see, we have instantiated the Throw template (must be instantiated and not just called because it needs to have some persistent variables, and also so we can have a reference to it if we want so that we can modify it using its methods). We fed it our makeCircle function, which will be called at the appropriate time (i.e. after the user has clicked and dragged and released). At that time our SimpleCircle will be created with the appropriate trajectory, with no extra effort on our part. And all of the trajectory graphics will be taken care of too. The '4' parameter is just a multiplier for the trajectory--basically how "sensitive" the function is to how far you move the mouse from the initial point. */

And that's it. With just one line all the code for throwing an object (just like the bowling balls in the video) is taken care of, and any function that accepts an x and y position, and an x and y velocity as parameters, can be fitted to this throw behavior.

Right now I have the templates 'Throw', 'Drop', 'Stream' (for flamethrowers and the like), and 'AttachToMouse'. There will surely be more later. This will make it easy for myself and script writers to invoke standardized, consistent behavior for their created items (if they choose to, of course--using these templates is by no means mandatory). And it will ensure that players have a consistent control experience across items.

P.S.: anyone know how to get code blocks in these journals? That code formatting above is very ugly and I'd like to be able to include whitespace and have a fixed width font. Any help much appreciated!
© 2009 - 2024 shock-value
Comments8
Join the community to add your comment. Already a deviant? Log In
DavidJCobb's avatar
Whitespace is tedious but possible with  ; monospaced fonts are possible with the CODE tag. Unfortunately, you'd still have word-wrapping issues, among other things (because it wouldn't actually be a block).