// Item script #include "script/KevinSystem/kevin_system/Lib_Const.dnh" #include "./Kevin_ItemConst.txt" #include "./Kevin_ItemLib.txt" #include "./ItemSoundLib.txt" //#include "./Kevin_ItemData.txt; float widthSTG = GetStgFrameWidth(); float heightSTG = GetStgFrameHeight(); float PIV = 0; let pointerPIV = LoadAreaCommonDataValuePointer("PIV", "currentvalue", 10000); @Initialize{ SetAutoDeleteObject(true); _ItemSoundTask(); SetDefaultBonusItemEnable(false); LoadItemData(GetCurrentScriptDirectory ~ "./Kevin_ItemData.txt"); SetAreaCommonData("ScriptID", "ItemID", GetOwnScriptID()); //SetCommonDataPtr("ItemIDPtr", GetOwnScriptID()); } int objPlayer = GetPlayerObjectID(); float tmpSpd = 0, tmpScl = 0, tmpMtp = 0; @MainLoop{ //PIV = GetCommonDataPtr(pointerPIV, 10000); for each(item in GetItemIdInCircleA1(widthSTG/2, heightSTG/2, heightSTG)){ tmpSpd = ObjMove_GetSpeed(item); tmpMtp = ObjItem_IsMoveToPlayer(item); if(tmpSpd >= 0){ if (!tmpMtp && GetPlayerState() != STATE_DOWN){ ObjItem_SetMoveToPlayer(item, true); } } if(tmpMtp) { ObjMove_SetAngle(item, GetAngleToPlayer(item)); ObjMove_SetAcceleration(item, 1); ObjMove_SetMaxSpeed(item, 24); } } yield; } @Event { alternative (GetEventType()) case (EV_GET_ITEM){ let obj = GetEventArgument(0); alternative(obj) case(POINT_REGULAR) { AddScore(GetCommonDataPtr(pointerPIV, 10000)); ObjSound_Play(CancelSFX);} case(POINT_BHESTIE) { AddScore(2*GetCommonDataPtr(pointerPIV, 10000)); ObjSound_Play(SpecialItemSFX);} case(POINT_RAINBOW) { AddScore(2*GetCommonDataPtr(pointerPIV, 10000)); ObjSound_Play(SpecialItemSFX);} case(POINT_CANCEL) { AddScore(0.05*GetCommonDataPtr(pointerPIV, 10000)); ObjSound_Play(CancelSFX);} case(EXTEND_LIFE) { AddScore(GetCommonDataPtr(pointerPIV, 10000)); SetPlayerLife(GetPlayerLife()+1); ObjSound_Play(SpellSFX);} case(EXTEND_SPELL) { AddScore(GetCommonDataPtr(pointerPIV, 10000)); SetPlayerSpell(GetPlayerSpell()+1); ObjSound_Play(SpecialItemSFX);} case(PIV_100) { SetCommonDataPtr(pointerPIV, GetCommonDataPtr(pointerPIV, 10000)+100);} //ObjSound_Play(CancelSFX);} case(PIV_250) { SetCommonDataPtr(pointerPIV, GetCommonDataPtr(pointerPIV, 10000)+250);} //ObjSound_Play(CancelSFX);} case(PIV_500) { SetCommonDataPtr(pointerPIV, GetCommonDataPtr(pointerPIV, 10000)+500);} //ObjSound_Play(CancelSFX);} } case (EV_DELETE_SHOT_TO_ITEM){ float[] position = GetEventArgument(1); CreatePIVItem(PIV_250, position[0], position[1]); } case (EV_CANCEL_ITEM) { let obj = GetEventArgument(0); let type = GetEventArgument(1); //ObjItem_SetMoveToPlayer(obj, false); ObjMove_CancelMovement(obj); //_CancelHandling(obj, type); } case (EV_COLLECT_ITEM){ let obj = GetEventArgument(0); let type = GetEventArgument(1); let typeCollect = GetEventArgument(2); //WriteLog(type); //_MoveToPlayer(obj, type, typeCollect); // Separate task is used to move the object to the player at customized speeds. } // Drops point items depending on how close you were to the enemy when you killed them. /* Event arguments: 0: PlayerID 1: EnemyID 2: Minimum number of point items 3: Maximum number of point items */ case(EV_DROP_POINT_ENEMY){ _DropPointItem(GetEventArgument(0), GetEventArgument(1), GetEventArgument(2), GetEventArgument(3), GetEventArgument(4)); } case(EV_DROP_PIV_ENEMY){ _DropPIVItemEnemy(GetEventArgument(0), GetEventArgument(1), GetEventArgument(2), GetEventArgument(3), GetEventArgument(4)); } // Event arguments: Enemy X, Enemy Y, Item Drop Amount, Item Drop Type case(EV_SINGLE_ITEM_DROP){ loop(GetEventArgument(2)){ CreateScoreItem(GetEventArgument(3), GetEventArgument(0)+rand(-100, 100), GetEventArgument(1)+rand(-100, 100)); } } case(EV_DROP_EXTEND){ CreateExtendItem(EXTEND_LIFE, GetEventArgument(0), GetEventArgument(1)); } } task _CancelHandling(int IDItem, int typeItem){ ObjMove_CancelMovement(IDItem); while(GetPlayerState() != STATE_NORMAL){yield;} _MoveToPlayer(IDItem, typeItem, 0); } // Timer is counted in frames (60 frames = 1 second) task _DropPointItem(float[] posEnm, int killTimer, int maxTimer, int pointMin, int pointMax){ // If the player kills enemy within maxTimer, the enemy drops the maximum amount of point items int pointFinal = Interpolate_Smooth(pointMin, pointMax, min(1, maxTimer/killTimer)); //WriteLog(pointFinal); loop(pointFinal){ CreateScoreItem(POINT_REGULAR, posEnm[0]+rand(-60, 60), posEnm[1]+rand(-60, 60)); } _ScorePopup(posEnm[0], posEnm[1], "POINT", pointFinal); return; } task _DropPIVItemEnemy(int IDPlayer, float[] posEnm, int pointMin, int pointMax, int bestDist){ // If the player is within at MOST "bestDist" from the enemy, the enemy drops the maximum amount of PIV items float curDist = hypot(posEnm[0]-ObjMove_GetX(IDPlayer), posEnm[1]-ObjMove_GetY(IDPlayer)); int pointFinal = Interpolate_Smooth(pointMin, pointMax, min(1, bestDist/curDist)); //WriteLog(pointFinal); loop(pointFinal){ CreatePIVItem(PIV_250, posEnm[0]+rand(-60, 60), posEnm[1]+rand(-60, 60)); } _ScorePopup(posEnm[0], posEnm[1], "PIV", pointFinal); return; } task _MoveToPlayer(obj, type, typeCollect){ ObjItem_SetAutoDelete(obj, true); ObjMove_SetAcceleration(obj, 1); //ObjMove_SetMaxSpeed(obj, 2); // The max speed of movement differs based on item. alternative(type) case(POINT_CANCEL) { ObjMove_SetMaxSpeed(obj, 23); } case(PIV_100) { ObjMove_SetMaxSpeed(obj, 18); } case(PIV_250) { ObjMove_SetMaxSpeed(obj, 18); } case(PIV_500) { ObjMove_SetMaxSpeed(obj, 18); } case(POINT_REGULAR) { ObjMove_SetMaxSpeed(obj, 20); } case(POINT_RAINBOW) { ObjMove_SetMaxSpeed(obj, 20); } case(POINT_BHESTIE) { ObjMove_SetMaxSpeed(obj, 20); } others { ObjMove_SetMaxSpeed(obj, 25); } while (!Obj_IsDeleted(obj)) { ObjMove_SetAngle(obj, GetAngleToPlayer(obj)); //WriteLog(ObjMove_GetSpeed(obj)); yield; } } // Text popups. When enemy is defeated, text objects appear showing the number of PIV and point items collected. function CreateTextObject( float mx, my, size, string text, font, int colorTop, colorBottom, int borderColor, borderWidth, int renderPriority ){ let obj = ObjText_Create(); ObjText_SetText(obj, text); ObjText_SetFontSize(obj, size); ObjText_SetFontType(obj, font); ObjText_SetFontColorTop(obj, colorTop); ObjText_SetFontColorBottom(obj, colorBottom); ObjText_SetFontBorderType(obj, BORDER_FULL); ObjText_SetFontBorderColor(obj, borderColor); ObjText_SetFontBorderWidth(obj, borderWidth); Obj_SetRenderPriorityI(obj, renderPriority); ObjRender_SetX(obj, mx); ObjRender_SetY(obj, my); return obj; } task _ScorePopup(float enmX, float enmY, string type, int itemNum){ float offset = 72; // Vertical space between the 2 scoretexts float time = 30; // Time that the text objects (appear+)last on screen float timeDisappear = 15; // Fade time float size = 75; float yDes = 60; // Destination text object moves to, relative to enmY string font = "Unispace"; float borderSize = 6; if (type == "POINT"){ int pointText = CreateTextObject( enmX, enmY, size, "x" ~ IntToString(itemNum), font, 0x7699FF, 0xFFFFFF, 0x2A00C0, borderSize, 42 ); ObjText_SetHorizontalAlignment(pointText, ALIGNMENT_CENTER); ascent(i in 0..time){ ObjRender_SetY(pointText, Interpolate_Decelerate(enmY, enmY-yDes, i/time)); yield; } ascent(i in 0..timeDisappear){ ObjRender_SetAlpha(pointText, Interpolate_Decelerate(255, 0, i/timeDisappear)); yield; } Obj_Delete(pointText); } else{ int pivText = CreateTextObject( enmX, enmY+offset, size, "x" ~ IntToString(itemNum), font, 0xFFB4EC, 0xFFFFFF, 0xB200AD, borderSize, 42 ); ObjText_SetHorizontalAlignment(pivText, ALIGNMENT_CENTER); ascent(i in 0..time){ ObjRender_SetY(pivText, Interpolate_Decelerate(enmY+offset, enmY+offset-yDes, i/time)); yield; } ascent(i in 0..timeDisappear){ ObjRender_SetAlpha(pivText, Interpolate_Decelerate(255, 0, i/timeDisappear)); yield; } Obj_Delete(pivText); } }