ScarletBlackMarket/KevinSystem/Kevin_PlayerLib.txt

345 lines
12 KiB
Plaintext
Raw Normal View History

/* --------------------------------------------------------------------
UNIVERSAL/GENERAL FUNCTIONS USED FOR PLAYERS
These functions may/will be reused for future scripts as well.
--------------------------------------------------------------------
*/
#include "script/KevinSystem/kevin_system/Kevin_ItemConst.txt"
#include "script/KevinSystem/kevin_system/Kevin_ItemLib.txt"
float universalAlpha = GetAreaCommonData("Config", "PlayerShotOpacity", 60);
task _DeleteEffect(obj){
ObjRender_SetBlendType(obj, BLEND_ADD_ARGB);
Obj_SetRenderPriorityI(obj, 41);
ascent(i in 0..30){
ObjRender_SetAlpha(obj, Interpolate_Decelerate(100*(universalAlpha/100), 0, i/30));
ObjRender_SetScaleXYZ(obj, Interpolate_Decelerate(0.5, 1.5, i/30));
ObjMove_SetSpeed(obj, 12);
yield;
}
Obj_Delete(obj);
}
// Renders player movement. Assumes that all sprites are ORGANIZED HORIZONTALLY IN THE SHEET.
// flipscale can only be 1 or -1.
task _RenderPlayerMovement(int obj, int frame, int offsetleft, int offsettop, int width, int height, float flipscale, int frameno, int speed){
ObjSprite2D_SetSourceRect(obj, offsetleft+width*floor(frame/speed), offsettop, width+width*floor(frame/speed), offsettop+height);
ObjRender_SetScaleX(objPlayer, flipscale);
}
// Bullet rescaling... for player shots.
task _BulletRescalePlayer(int target, float scale, bool hitboxscale, float hitboxlevel){
ObjRender_SetScaleXYZ(target, scale, scale, 1);
if (hitboxscale){
ObjShot_SetIntersectionScaleXY(target, scale*hitboxlevel, scale*hitboxlevel);
}
}
// Handles death/respawn sigil. Assumes sigils are 512x512 in size.
// If death is true (the player dies), the circle expands outwards. Otherwise (the player bombs/respawns), it shrinks inwards.
task _SigilCall(bool death, texture, int rectleft, int recttop, int rectright, int rectbottom, int objPlayer, int time){
let DeathCircle = ObjPrim_Create(OBJ_SPRITE_2D);
ObjPrim_SetTexture(DeathCircle,teamimg);
ObjSprite2D_SetSourceRect(DeathCircle, rectleft, recttop, rectright, rectbottom);
ObjSprite2D_SetDestCenter(DeathCircle);
ObjRender_SetBlendType(DeathCircle,BLEND_ALPHA);
ObjRender_SetAlpha(DeathCircle,255);
ObjRender_SetPosition(DeathCircle,GetPlayerX(),GetPlayerY(),1);
Obj_SetRenderPriorityI(DeathCircle,Obj_GetRenderPriorityI(objPlayer)-1);
alternative(death)
case(true){
ascent(i in 0..time){
float scaliealpha = Interpolate_Decelerate(255, 0, i/time);
float scaliesize = Interpolate_Decelerate(0.1, 1.5, i/time);
ObjRender_SetAlpha(DeathCircle, scaliealpha);
ObjRender_SetPosition(DeathCircle,GetPlayerX(),GetPlayerY(),1);
ObjRender_SetScaleXYZ(DeathCircle, scaliesize, scaliesize, 1);
yield;
}
}
case(false){
ascent(i in 0..time){
float scaliealpha = Interpolate_Accelerate(255, 0, i/time);
float scaliesize = Interpolate_Accelerate(1.5, 0.1, i/time);
ObjRender_SetAlpha(DeathCircle, scaliealpha);
ObjRender_SetPosition(DeathCircle,GetPlayerX(),GetPlayerY(),1);
ObjRender_SetScaleXYZ(DeathCircle, scaliesize, scaliesize, 1);
yield;
}
}
while(ObjRender_GetAlpha(DeathCircle) > 0){yield;}
Obj_Delete(DeathCircle);
}
// Handles the hitbox and its aura. What the fuck.
task _HitboxRender(
bool playerdeathbool, int objPlayer, texture_hbox, texture_aura,
int rectleft_hbox, int recttop_hbox, int rectright_hbox, int rectbottom_hbox,
int rectleft_aura, int recttop_aura, int rectright_aura, int rectbottom_aura,
float scale_hbox, float scale_aura){
// Handle hitbox
bool visible = false;
int hitbox = ObjPrim_Create(OBJ_SPRITE_2D);
ObjPrim_SetTexture(hitbox, texture_hbox);
ObjSprite2D_SetSourceRect(hitbox, rectleft_hbox, recttop_hbox, rectright_hbox, rectbottom_hbox);
ObjSprite2D_SetDestCenter(hitbox);
ObjRender_SetScaleXYZ(hitbox, scale_hbox, scale_hbox, 1);
ObjRender_SetBlendType(hitbox, BLEND_ALPHA);
Obj_SetRenderPriorityI(hitbox, 79);
Obj_SetVisible(hitbox, false);
// Handle hitbox's aura
int aura = ObjPrim_Create(OBJ_SPRITE_2D);
ObjPrim_SetTexture(aura, texture_aura);
ObjSprite2D_SetSourceRect(aura, rectleft_aura, recttop_aura, rectright_aura, rectbottom_aura);
ObjSprite2D_SetDestCenter(aura);
ObjRender_SetScaleXYZ(aura, scale_aura, scale_aura, 1);
ObjRender_SetAlpha(aura, 70);
//ObjRender_SetBlendType(aura, BLEND_ADD_ARGB);
Obj_SetRenderPriorityI(aura, Obj_GetRenderPriorityI(objPlayer)+3);
Obj_SetVisible(aura, false);
loop{
if (visible && (!Obj_IsVisible(objPlayer) || GetVirtualKeyState(VK_SLOWMOVE) != KEY_HOLD)){
visible = false;
Obj_SetVisible(hitbox, false);
Obj_SetVisible(aura, false);
}
else if (!visible && (Obj_IsVisible(objPlayer) && (GetVirtualKeyState(VK_SLOWMOVE) == KEY_HOLD || GetVirtualKeyState(VK_SLOWMOVE) == KEY_PUSH))){
visible = true;
Obj_SetVisible(aura, true);
Obj_SetVisible(hitbox, true);
async{
while(Obj_IsVisible(aura)){
float curang = ObjRender_GetAngleZ(aura);
ObjRender_SetAngleZ(aura, curang+1);
yield;
}
}
async{
ascent(i in 0..20){
float scalie = Interpolate_Decelerate(scale_aura*1.5, scale_aura, i/20);
ObjRender_SetScaleXYZ(aura, scalie, scalie, 1);
yield;
}
}
async{
ascent(i in 0..20){
float scalie = Interpolate_Decelerate(0, 80, i/20);
ObjRender_SetAlpha(aura, scalie);
yield;
}
}
}
ObjRender_SetPosition(hitbox, ObjMove_GetX(objPlayer), ObjMove_GetY(objPlayer), 1);
ObjRender_SetPosition(aura, ObjMove_GetX(objPlayer), ObjMove_GetY(objPlayer), 1);
yield;
}
}
/*
Simple function that handles player options. These options simply follow the player at an offset - they do not have any trajectories of their own like spinning around the player, etc.
If the options have animations, set triggeranimation to true and adjust the number of frames + speed using delay and frameno.
If the options rotate (in place), set triggerspin to true and adjust spinning speed using spinspeed.
If the options only appear unfocused or focused, set either onlyFocus or onlyUnfocus to true. Setting both to true or false makes the options always visible.
*/
function PlayerOption(
float offsetx, float offsety,
texture,
int left, int top, int right, int bottom, float scale,
int width, int animdelay, int frameno, bool triggeranimation,
bool triggerspin, float spinspeed,
bool onlyFocus, bool onlyUnfocus
){
let option = ObjPrim_Create(OBJ_SPRITE_2D);
bool visible;
int animate = 0;
float optx;
float opty;
ObjPrim_SetTexture(option, texture);
ObjSprite2D_SetSourceRect(option, left, top, right-1, bottom-1); // Allows the options to spin smoothly should the user choose to do so.
ObjSprite2D_SetDestCenter(option);
ObjRender_SetScaleXYZ(option, scale);
ObjRender_SetBlendType(option, BLEND_ALPHA);
ObjRender_SetAlpha(option, 225);
Obj_SetRenderPriorityI(option, 41);
ObjRender_SetPosition(option, offsetx, offsety, 1);
// Animation
async{
while(triggeranimation){
ObjSprite2D_SetSourceRect(option, left+width*floor(animate/animdelay), top, right+width*floor(animate/animdelay)-1, bottom-1);
animate++;
if (animate >= animdelay*frameno){animate = 0;}
yield;
}
}
// Rotation
async{
float i = 0;
while(triggerspin){
//ObjRender_SetPosition(option, GetPlayerX()+offsetx, GetPlayerY()+offsety, 1);
ObjRender_SetAngleZ(option, i);
i += spinspeed;
yield;
}
}
// Follow
async{
while(true){
ObjRender_SetPosition(option, GetPlayerX()+offsetx, GetPlayerY()+offsety, 1);
yield;
}
}
// Visibility
async{
// Always visible
if((onlyFocus && onlyUnfocus) || (!onlyFocus && !onlyUnfocus)) {
loop
{
if(GetPlayerState != STATE_NORMAL && GetPlayerState != STATE_HIT){ObjRender_SetAlpha(option, max(0, ObjRender_GetAlpha(option)-15)); visible = false;}
else {ObjRender_SetAlpha(option, min(225, ObjRender_GetAlpha(option)+15)); visible = true;}
yield;
}
}
// Visible when focused only
else if(onlyFocus && !onlyUnfocus){
loop
{
if((GetPlayerState != STATE_NORMAL && GetPlayerState != STATE_HIT) || GetVirtualKeyState(VK_SLOWMOVE) == KEY_FREE){ObjRender_SetAlpha(option, max(0, ObjRender_GetAlpha(option)-15)); visible = false;}
else {ObjRender_SetAlpha(option, min(225, ObjRender_GetAlpha(option)+15)); visible = true;}
yield;
}
}
// Visible when unfocused only
else if(!onlyFocus && onlyUnfocus){
loop
{
if((GetPlayerState != STATE_NORMAL && GetPlayerState != STATE_HIT) || GetVirtualKeyState(VK_SLOWMOVE) != KEY_FREE){ObjRender_SetAlpha(option, max(0, ObjRender_GetAlpha(option)-15)); visible = false;}
else {ObjRender_SetAlpha(option, min(225, ObjRender_GetAlpha(option)+15)); visible = true;}
yield;
}
}
}
function _FadeIn(){
ascent(i in 0..15){
ObjRender_SetAlpha(option, Interpolate_Decelerate(0, 225, i/15));
yield;
}
}
function _FadeOut(){
ascent(i in 0..15){
ObjRender_SetAlpha(option, Interpolate_Decelerate(225, 0, i/15));
yield;
}
}
return option;
}
/*
------------------------------------------------------
POINTBLANK-PIV MECHANIC FUNCTIONS
Will be optimized somewhere down the line.
------------------------------------------------------
*/
// Selects an enemy in the @MainLoop-updated _enemyArray, executes _PetalDrop, and adds it to _existArray so the task isn't called again for the same enemy. maxX and maxY are the bounds of the playing field.
task _Mechanic(bool playerdeathbool, int[] _enemyArray, int [] _existArray, float maxX, float maxY, int objPlayer, int bossScene, int maxrate, int addrate, float adddist){
while(!playerdeathbool){
_enemyArray = GetIntersectionRegistedEnemyID();
bossScene = GetEnemyBossSceneObjectID();
for each (int enemy in ref _enemyArray){
float enemyX = ObjMove_GetX(enemy);
float enemyY = ObjMove_GetY(enemy);
if (0 < enemyX && enemyX < maxX && 0 < enemyY && enemyY < maxY && !contains(_existArray, enemy)){
_PetalDrop(enemy, playerdeathbool, objPlayer, bossScene, maxrate, addrate, adddist);
_existArray = _existArray ~ [enemy];
}
else{continue;}
}
yield;
}
}
// Checks the boss scene type (nonspell/spell/last spell/invalid), the ID of the player object, and the target enemy. Drops petals with a type and drop rate that depends on the boss scene type and how close the player is to the target enemy. The last three parameters control the drop rate, and are significantly higher for Erika & Tenshi.
task _PetalDrop(int target, bool playerdeathbool, int objPlayer, int bossScene, int maxrate, int addrate, float adddist){
while(!Obj_IsDeleted(target) && !playerdeathbool){
float dist = hypot(ObjMove_GetX(target)-ObjMove_GetX(objPlayer), ObjMove_GetY(target)-ObjMove_GetY(objPlayer));
let atktype = GetEnemyBossSceneObjectID();
if(dist <= (GetStgFrameHeight()-100) && atktype != ID_INVALID && ObjEnemy_GetInfo(target, INFO_SHOT_HIT_COUNT) >= 1){
NotifyEventAll(EV_PIV_250, [ObjMove_GetX(target), ObjMove_GetY(target)]);
wait(maxrate + addrate*floor(dist/adddist));
}
else{yield;}
}
}
function <int> _Create2DImage(imgpath, int[] rectarray){
int imgname = ObjPrim_Create(OBJ_SPRITE_2D);
ObjPrim_SetTexture(imgname, imgpath);
ObjSprite2D_SetSourceRect(imgname, rectarray);
ObjSprite2D_SetDestCenter(imgname);
//ObjRender_SetPosition(imgname, positionstart)
return imgname;
}
task _DeathbombWarning(imgpath, int[] imgrectarray, int deathbombframes, float basescale){
int circle = _Create2DImage(imgpath, imgrectarray);
Obj_SetRenderPriorityI(circle, 75);
ObjRender_SetAlpha(circle, 255);
ObjRender_SetPosition(circle, ObjRender_GetX(GetPlayerObjectID()), ObjRender_GetY(GetPlayerObjectID()), 1);
ObjRender_SetBlendType(circle, BLEND_INV_DESTRGB);
ascent(i in 0..deathbombframes-1){
ObjRender_SetScaleXYZ(circle, Interpolate_Accelerate(basescale, 0, i/(deathbombframes-1)));
yield;
}
Obj_Delete(circle);
return;
}