Thread: Scorpion Engine
View Single Post
Old 03 October 2019, 11:59   #228
earok
Registered User

 
Join Date: Dec 2013
Location: Auckland
Posts: 2,194
I had bit of a setback with my laptop, and had to Reinstall Windows 10 and I've only just been able to get back into doing some Scorpion things :/ anyway, new mini tutorial.

The second mine level of TOG1 has two different kinds of block walls than the previous one:
- It has walls that can just be walked through, but cannot be torn down, and..
- It has walls that need five shots to destroy.

Implementing the first kind is super easy. We just need to add the tiles to the foreground layer.



Note that we also need to draw those tiles on the background layer. Scorpion only renders foreground tiles when there's actually something behind them.

The second bit is a little harder. Blocks don't have variables per se, so we can't just assign a health value to them. But what we can do is make identical blocks and handle them a little differently in code. Let's add four new blocks to the project.txt file:

Code:
[Block BreakBlock5]
source=sprites\talesofgorluth-enemy-blk\000.png:0:0
solid=true
divert_playerprojectilecollision=BreakBlockTL_Hit

[Block BreakBlock4]
source=sprites\talesofgorluth-enemy-blk\000.png:0:0
solid=true
divert_playerprojectilecollision=BreakBlockTL_Hit

[Block BreakBlock3]
source=sprites\talesofgorluth-enemy-blk\000.png:0:0
solid=true
divert_playerprojectilecollision=BreakBlockTL_Hit

[Block BreakBlock2]
source=sprites\talesofgorluth-enemy-blk\000.png:0:0
solid=true
divert_playerprojectilecollision=BreakBlockTL_Hit
These represent the blocks at health levels 2, 3 4 and 5.

Next, we need to expand the routine from the previous tutorial:

Code:
=== BreakBlockTL_Hit ===
//Destroy the player's projectile
~ PlayerProjectile_Type = null

{ Block_Type == BreakBlock5:
	~ Block_Type = BreakBlock4
	-> GAME
}
{ Block_Type == BreakBlock4:
	~ Block_Type = BreakBlock3
	-> GAME
}
{ Block_Type == BreakBlock3:
	~ Block_Type = BreakBlock2
	-> GAME
}
{ Block_Type == BreakBlock2:
	~ Block_Type = BreakBlockTL
	-> GAME
}

//The rest of the code is the same as last time
So each time we run the code for handling a hit, we change the block to a block representing a lower level of health.

@Clydos, technically there's no "type casting" in Scorpion. There's only one data type at the moment (16-bit signed integer). The block names here (BreakBlock2, BreakBlock3 etc) are constants generated by the compiler that link the name of the block to the numeric ID. So when we set the variable block_type, we're assigning it a numeric value, which in turn signals to the Scorpion Engine that we want to change the block.
earok is offline  
 
Page generated in 0.04246 seconds with 11 queries