Sin Costan
Eye of Cthulhu
Ok, I'll explain it here then...Mr. Sin Costan honestly do not really understand what he had seen in the .cs file![]()
First off, you need your projectile json file (a given...). So I'll just use the example from the zip as the example.
Code:
{
"displayName": "Flame Blast",
"size": [8, 42],
"scale": 1,
"aiStyle": 0, //Gonna use this for a custom AI (since aiStyle 0 does nothing)
"timeLeft": 180,
"friendly": true,
"hostile": false,
"tileCollide": true,
"ignoreWater": false,
"frameCount": 3 //How many frames are there in the image, in this case it is 3 images
}
Now we need our .cs file, FlameBlast.cs.
Code:
using System;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using TAPI;
using Terraria;
namespace MPT.Projectiles
{
public class FlameBlast : ModProjectile
{
public override void AI()
{
projectile.light = 5f; //Makes the projectile light
projectile.rotation = (float)Math.Atan2((double)projectile.velocity.Y, (double)projectile.velocity.X) + 1.57f; //Makes sure the projectile rotates so it is pointing at where you are shooting.
if(projectile.frameCounter < 20) //If the frame's counter is less than 20.
{
projectile.frame = 2; //Set it to the 3rd frame, since the frames go from 0 to 2.
if(projectile.damage <= 100) //Increases the projectile damage if it is less than or equal to 100
projectile.damage += 1;
else
projectile.damage = 100;
projectile.velocity.Y *= 1.01f; //increases the velocity by 1.01 times.
projectile.velocity.X *= 1.01f;
}
else if(projectile.frameCounter >= 20 && projectile.frameCounter < 50) //If the projectile's frame counter greater than or equal to 20 and less than 50
{
projectile.frame = 1; //Set the frame to the second frame
if(projectile.damage <= 100) //Increase the damage again
projectile.damage += 2;
else
projectile.damage = 100;
projectile.velocity.Y *= 1.02f; //Increase velocity even further
projectile.velocity.X *= 1.02f;
int DustID1 = Dust.NewDust(new Vector2(projectile.position.X, projectile.position.Y + 2f), projectile.width/2 + 4, projectile.height/2 + 4, 64, projectile.velocity.X * 0.2f, projectile.velocity.Y * 0.2f, 120, default(Color), 0.75f); //Add Dust to it too
Main.dust[DustID1].noGravity = true;
}
else //If the frame counter is something other than the two statements
{
projectile.frame = 0; //Set the frame to the first frame
if(projectile.damage <= 100) //Increase damage even further
projectile.damage += 3;
else
projectile.damage = 100;
projectile.velocity.Y *= 1.03f; //Increase speed even further
projectile.velocity.X *= 1.03f;
int DustID2 = Dust.NewDust(new Vector2(projectile.position.X, projectile.position.Y + 2f), projectile.width + 4, projectile.height + 4, 64, projectile.velocity.X * 0.2f, projectile.velocity.Y * 0.2f, 120, default(Color), 0.75f); //Add dust
Main.dust[DustID2].noGravity = true;
}
projectile.frameCounter++; //A seperate counter used for animation.
}
}
}
So to top it all off, all you need to know from this example is that you need one property in the json file and about 2 properties in your cs file.
Code:
In the .json file
- "frameCount": int frameNumber, //How many frames are there in your texture
in the .cs file
- frame = int frameNumber; //Select the certain frame to show, goes from 0 to the frameCount minus 1 (0, frameCount - 1)
- int frameCounter; //The counter to help you animate. (like a stop watch)
And here is one last example, only with the AI() hook though. Let's pretend I already did all the JSON file, with a frameCount of 4 this time and have it animate infinitely.
Code:
public override void AI()
[
projectile.frameCounter++; //Make the counter go up, just remember that each time it goes through the AI hook, it is 1/60 of a second, so you are counting by 1/60 of a second.
if(projectile.frameCounter < 10) //If the counter is less than 10
{
projectile.frame = 0; //Set it to the first frame
}
else if (projectile.frameCounter >= 10 && projectile.frameCounter < 20) //If the frameCounter is greater than or equal to 10 and less than 20...
{
projectile.frame = 1; //Set it to the second frame
}
else if (projectile.frameCounter >= 20 && projectile.frameCounter < 30) //If the frameCounter is greater than or equal to 20 and less than 30....
{
projectile.frame = 2; //Set it to the third frame
}
else if (projectile.frameCounter >= 30 && projectile.frameCounter < 40) //If the frameCounter is greater than or equal to 30 and less than 40...
{
projectile.frame = 3; //Set it to the fourth frame
}
else //Let's just say this assumes that the frameCounter is greater than or equal to 40.
{
projectile.frame = 0; //Reset it to the first frame
projectile.frameCounter = 0; //Reset the counter so it goes back to the beginning
}
}