Case study 4: Custom Boss

From Open Surge Wiki
Jump to: navigation, search
Stub
This article is a stub. This typically means the article is a placeholder for more content to come. Knowledgeable users are encouraged to help expand the article.

Setting up

It is recommended that you use a text editor with advanced functions such as Notepad++ or Vim for best results. Such programs include line numbering, text highlighting, mass search and replace, and multiple file editing.

Simple text editors are ok, but may give you some extra work searching for that error in line XX, or searching text in files one by one. This slows down the debugging process considerably.


Make sure you already have a sprite sheet and script ready for your boss. You don't need the full thing, placeholder graphics such as colored shapes are ok.

Should you want any sounds or special music, please get those into their respective folders, and remember the paths to them, usually "samples/" or "musics/", unless you are using sub-folders, like "samples/level1/boss" for example.

If you have no sounds available you can add them later after getting your boss scripted.


Setting up the arena

Create a new level, and set up an area around no more than two screens wide and two screens high. Unless your boss flies and ignores walls, this is advised. It will prevent your boss from disappearing or becoming disabled.

For now add some ground. don't worry about adding walls now, just start building at 0, 0 (top left corner of level space), and the camera will lock at the level bounds and ground edges automatically.

Bossarena.png

alternatively, you can disregard this and build the level without any limitations, as long as you script the boss to lock the camera.

add some hazards and/or powerups if you wish.


The script

Object Properties

It is preferable that the boss is always_active, so you won't experience any "warping". This is when a non-always_active goes too far from the camera, it is temporarily disabled, "warps" back into its initial position, and only becomes active again inside camera bounds.

Specifying a category is highly optional, but it will allow you to organize and find your objects easily in the editor.

The script

this script is thoroughly commented so you should find your way easily.

object "boss"
{
always_active
category "boss"

	state "main" //main will be a setup state and ran only once
	{
	
	if "$initialized" "loop" //if initialized switch is on move straight to loop state
	set_animation "boss1" 0 //base animation shown when the object appears
	let "$hits = 0" //you will need 8 hits to destroy this boss, and we'll be counting up.
	let "$speed = 128" //normal movement speed
	let "$topspeed = 256" //ramming speed
	
	let "initialized = 1" //flip the initialized switch on
	
	change_state "loop" //in theory you don't need to do this because <if "$initialized" "loop"> will do it, but it's best if you do unless you are familiar with variable switches
	}
	
		state "loop" // loop is the main behavior. here is where all the actions are decided.
		{
		set_animation "boss1" 1 //let's pretend it's a running animation
		walk $speed //we make him walk around the arena
		on_player_attack "hit_me" //detect attacks - to me
		on_player_collision "hit_player" //detect attacks - from me
		}
		
			state "hit_me"
			{
			set_animation "boss1" 2 //this will be a flashing animation
			//by not using <walk> the boss will stop for a moment
			let "$hits += 1" //add one hit_me
			if "$hits >= 8" "explode" //if hit limit is reached play destruction sequence
			change_state "timeout" //we process the timeout separately because of the variable operation(s) in this state
			}
			
				state "timeout"
				{
				on_timeout 1 "ram" //after hit, this boss will become invincible and ram the player for a short timeout
				}
				
					state "ram"
					{
					look_at_player //this will lock the boss on to the player
					set_animation "boss1" 3 //you can use the same running animation, but a different animation gives more personality
					walk "$topspeed" //use ramming speed here
					on_player_attack "bounce_player" //he will be invincible by rejecting attacks
					on_player_collision "hit_player" //will still hurt the player
					on_timeout 3 "loop" //3 seconds in this state then back to normal
					}
						
						state "bounce_player"
						{
						bounce_player // you don't say... :p
						return_to_previous_state //what it says
						}
						
			state "hit_player"
			{
			hit_player
			return_to_previous_state
			}
			
		state "explode" //or die
		{
		set_animation "boss1" 4 //death animation. make sure it is not set to repeat in the .spr so the animation can end this state
		on_animation_finished "destroy" //final state
		}
		
		state "destroy"
		{
		destroy
		clear_level
		}
}


TODO

Conclusion.