This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
prpl:prplsnippets [2017/12/16 21:00] – added buildable and chargable unit example kajacx | prpl:prplsnippets [2025/02/14 14:57] (current) – external edit 127.0.0.1 | ||
---|---|---|---|
Line 7: | Line 7: | ||
If you are looking for what is possible in PRPL or some inspiration for your own units, this is a good place to start, provided you know [[prpl: | If you are looking for what is possible in PRPL or some inspiration for your own units, this is a good place to start, provided you know [[prpl: | ||
- | (TODO: buildable/ | + | (TODO: buildable/ |
===== Discovering units/ | ===== Discovering units/ | ||
Line 261: | Line 261: | ||
Aslo, when checking if the ehalth is low enought, `Self GetUnitHealth 10 lt if # health is low enought to flip` it is wise to choose a slightly larger number, like `10`, so that even when multiple lathes are targeting the unit, they will not destroy it before it can flip and fully heal itself. | Aslo, when checking if the ehalth is low enought, `Self GetUnitHealth 10 lt if # health is low enought to flip` it is wise to choose a slightly larger number, like `10`, so that even when multiple lathes are targeting the unit, they will not destroy it before it can flip and fully heal itself. | ||
+ | </ | ||
+ | |||
+ | ===== Working with images ===== | ||
+ | |||
+ | Let's try a new format - we will start with a simple script of showing a star image, and then we will add new features gradually. So, here is the basics of adding an image: First, create the image you want. It must have exactly one if the following sizes: 64x64 pixels, 128x128 pixels, or 256x256 pixels. You download the 2 images used in this tutorial right here: | ||
+ | |||
+ | < | ||
+ | {{: | ||
+ | < | ||
+ | |||
+ | (It's a white image on a transparent background, so some images viewers might display it as a white square, but don't worry, it will work fine). | ||
+ | |||
+ | Next, you need to register the images into the game. In the PF map editor, go to Editor -> Map -> Custom Images -> 256x256 tab -> Select on the first slot, and then open the downlaoded file in the file chooser. | ||
+ | |||
+ | {{: | ||
+ | |||
+ | Finally, once the images are loaded into the game, you can write a PRPL script that will use the images: | ||
+ | |||
+ | <code prpl> | ||
+ | $StarFill:" | ||
+ | $StarBorder:" | ||
+ | |||
+ | once | ||
+ | Self " | ||
+ | Self " | ||
+ | Self " | ||
+ | | ||
+ | Self " | ||
+ | Self " | ||
+ | Self " | ||
+ | endonce | ||
+ | </ | ||
+ | |||
+ | Again, search for " | ||
+ | |||
+ | How it looks: | ||
+ | {{: | ||
+ | |||
+ | The interesting part here is that the image itself is whire, but the color is set in PRPL. The advantage over having the image itself colored is that we can now compute and change the color with PRPL to our liking, which we will do momentary. | ||
+ | |||
+ | But first, a few notes: | ||
+ | |||
+ | Next, let's take a look at '' | ||
+ | |||
+ | Finally, '' | ||
+ | |||
+ | ==== Making the star change color ==== | ||
+ | |||
+ | Now we are getting into some fun. Let's start by chaning the color from red to yellow by keeping the red color channel at 255 and changing the green color channel: | ||
+ | |||
+ | <code prpl> | ||
+ | $StarFill:" | ||
+ | $StarBorder:" | ||
+ | $Step:2 #the speed of color change | ||
+ | |||
+ | once | ||
+ | Self " | ||
+ | #Self " | ||
+ | Self " | ||
+ | | ||
+ | Self " | ||
+ | Self " | ||
+ | Self " | ||
+ | | ||
+ | 0 ->green | ||
+ | 1 -> | ||
+ | endonce | ||
+ | |||
+ | < | ||
+ | <-green <-Step add ->green | ||
+ | <-green 255 gt if | ||
+ | # the green color is more than the maximum value of 255 | ||
+ | 255 ->green #set it back to maximum | ||
+ | 0 -> | ||
+ | endif | ||
+ | else | ||
+ | <-green <-Step sub ->green | ||
+ | <-green 0 lt if | ||
+ | # the green color is less than the minimum value of 0 | ||
+ | 0 ->green #set it back to minimum | ||
+ | 1 -> | ||
+ | endif | ||
+ | endif | ||
+ | |||
+ | Self " | ||
+ | </ | ||
+ | |||
+ | How it looks: | ||
+ | {{: | ||
+ | |||
+ | The code should be pretty self-explanatory. If you have never worked with RGb values before and ar ewondering where the 255 number comes from, it's from the fact taht computers store color as 3 8-bit numbers, one for Red, one for Green and one for Blue (RGB). And since 8 bits can hold 256 diffent values, the color values are from the range 0-255. Finally, if you want to see some examples of colors and their RGB values, jsut any [[http:// | ||
+ | |||
+ | ==== Setting position and rotation ==== | ||
+ | |||
+ | Next we are going to make the start rotate around the core by chaning it's position, as well as rotate as an image to make it spin. Code: | ||
+ | |||
+ | <code prpl> | ||
+ | $StarFill:" | ||
+ | $StarBorder:" | ||
+ | $Step:2 #the speed of color change | ||
+ | $Distance: | ||
+ | $OrbitingSpeed: | ||
+ | $SpinningSpeed: | ||
+ | |||
+ | once | ||
+ | Self " | ||
+ | #Self " | ||
+ | Self " | ||
+ | | ||
+ | Self " | ||
+ | Self " | ||
+ | Self " | ||
+ | | ||
+ | 0 ->green | ||
+ | 1 -> | ||
+ | | ||
+ | 0 -> | ||
+ | 0 -> | ||
+ | endonce | ||
+ | |||
+ | # set the color | ||
+ | < | ||
+ | <-green <-Step add ->green | ||
+ | <-green 255 gt if | ||
+ | # the green color is more than the maximum value of 255 | ||
+ | 255 ->green #set it back to maximum | ||
+ | 0 -> | ||
+ | endif | ||
+ | else | ||
+ | <-green <-Step sub ->green | ||
+ | <-green 0 lt if | ||
+ | # the green color is less than the minimum value of 0 | ||
+ | 0 ->green #set it back to minimum | ||
+ | 1 -> | ||
+ | endif | ||
+ | endif | ||
+ | |||
+ | Self " | ||
+ | |||
+ | #set the position | ||
+ | < | ||
+ | Self " | ||
+ | Self " | ||
+ | Self " | ||
+ | Self " | ||
+ | |||
+ | #set the rotation | ||
+ | < | ||
+ | Self " | ||
+ | Self " | ||
+ | </ | ||
+ | |||
+ | Result: | ||
+ | {{: | ||
+ | |||
+ | The key to making it look good is balancing the rotations speeds properly. I definetely like it more when the start is spinning in the oposite derection than the orbit (positiv/ | ||
+ | |||
+ | ==== The homework ==== | ||
+ | |||
+ | We could go on and on, making the star bigger/ | ||
+ | |||
+ | Preview: | ||
+ | |||
+ | {{: | ||
+ | |||
+ | Solution: | ||
+ | < | ||
+ | <code prpl> | ||
+ | $StarFill:" | ||
+ | $StarBorder:" | ||
+ | $Step:2 #the speed of color change | ||
+ | $Distance: | ||
+ | $OrbitingSpeed: | ||
+ | $SpinningSpeed: | ||
+ | $Stars:6 #the amount of stars | ||
+ | |||
+ | once | ||
+ | Self RemoveImages | ||
+ | |||
+ | <-Stars 0 do | ||
+ | Self " | ||
+ | Self " | ||
+ | | ||
+ | Self " | ||
+ | Self " | ||
+ | Self " | ||
+ | loop | ||
+ | | ||
+ | 0 ->green | ||
+ | 1 -> | ||
+ | | ||
+ | 0 -> | ||
+ | 0 -> | ||
+ | endonce | ||
+ | |||
+ | # set the color | ||
+ | < | ||
+ | <-green <-Step add ->green | ||
+ | <-green 255 gt if | ||
+ | # the green color is more than the maximum value of 255 | ||
+ | 255 ->green #set it back to maximum | ||
+ | 0 -> | ||
+ | endif | ||
+ | else | ||
+ | <-green <-Step sub ->green | ||
+ | <-green 0 lt if | ||
+ | # the green color is less than the minimum value of 0 | ||
+ | 0 ->green #set it back to minimum | ||
+ | 1 -> | ||
+ | endif | ||
+ | endif | ||
+ | |||
+ | |||
+ | < | ||
+ | < | ||
+ | |||
+ | <-Stars 0 do | ||
+ | Self " | ||
+ | |||
+ | #set the position | ||
+ | TWOPI <-Stars div I mul ->offset | ||
+ | Self " | ||
+ | Self " | ||
+ | Self " | ||
+ | Self " | ||
+ | |||
+ | #set the rotation | ||
+ | Self " | ||
+ | Self " | ||
+ | loop | ||
+ | </ | ||
</ | </ |