-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTheLunaticPlayer_Draw.cs
114 lines (89 loc) · 3.72 KB
/
TheLunaticPlayer_Draw.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
using HamstarHelpers.Classes.Errors;
using HamstarHelpers.Helpers.Debug;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using System;
using System.Collections.Generic;
using Terraria;
using Terraria.DataStructures;
using Terraria.ModLoader;
using TheLunatic.Items;
namespace TheLunatic {
partial class TheLunaticPlayer : ModPlayer {
public override void ModifyScreenPosition() {
var mymod = (TheLunaticMod)this.mod;
if( !mymod.Config.Enabled ) { return; }
if( this.QuakeDuration != 0 ) {
float quakeScale = this.QuakeScale;
float durationRange = this.QuakeStartDuration > 0f ? this.QuakeStartDuration : this.QuakeStartDuration * 2f;
if( this.player.velocity.Y != 0 ) {
quakeScale /= 8;
} else {
this.player.AddBuff( 32, 2 );
}
float progress = (float)this.QuakeDuration / durationRange;
float spike = 1f - (Math.Abs(progress - 0.5f) * 2f);
float fullSpike = spike * 32f;
float shakeRange = fullSpike * quakeScale;
//Debug.Display["quake"] = "progress: "+progress+" spike: "+spike+" full_spike: "+full_spike+" quake_scale: "+quake_scale;
Main.screenPosition.X += (shakeRange/2) - (Main.rand.NextFloat() * shakeRange);
Main.screenPosition.Y += (shakeRange/2) - (Main.rand.NextFloat() * shakeRange);
}
}
public override void UpdateBiomes() {
var mymod = (TheLunaticMod)this.mod;
var myworld = ModContent.GetInstance<TheLunaticWorld>();
if( !mymod.Config.Enabled ) { return; }
if( myworld.GameLogic == null ) { throw new ModHelpersException( "Game logic not initialized." ); }
myworld.GameLogic.UpdateBiomes( this.player );
}
public override void UpdateBiomeVisuals() {
var mymod = (TheLunaticMod)this.mod;
var myworld = ModContent.GetInstance<TheLunaticWorld>();
if( !mymod.Config.Enabled ) { return; }
if( myworld.GameLogic == null ) { throw new ModHelpersException( "Game logic not initialized." ); }
mymod.Sky.UpdateSky( this.player );
myworld.GameLogic.UpdateBiomeVisuals( this.player );
}
public static readonly PlayerLayer CustomBossMask = new PlayerLayer(
"TheLunatic", "CustomBossMask", PlayerLayer.MiscEffectsFront,
delegate ( PlayerDrawInfo drawInfo ) {
Player player = drawInfo.drawPlayer;
var mod = ModLoader.GetMod( "TheLunatic" );
var myplayer = player.GetModPlayer<TheLunaticPlayer>();
var tex = myplayer.MaskTex;
var se = player.direction != 1 ? SpriteEffects.None : SpriteEffects.FlipHorizontally;
var pos = player.position;
var relPos = pos - Main.screenPosition;
relPos.Y -= 8;
int x = (int)((pos.X + (player.width / 2f)) / 16f);
int y = (int)((pos.Y + (player.headFrame.Height / 2f)) / 16f);
Color lightColor = Lighting.GetColor( x, y );
DrawData data = new DrawData( tex, relPos, new Rectangle(0, 0, tex.Width, tex.Height), lightColor, 0f, new Vector2(), 1f, se, 0 );
Main.playerDrawData.Add( data );
}
);
public override void ModifyDrawLayers( List<PlayerLayer> layers ) {
var mymod = (TheLunaticMod)this.mod;
if( !mymod.Config.Enabled ) { return; }
this.MaskTex = CustomBossMaskItem.GetMaskTextureOfPlayer( this.player );
if( this.MaskTex != null ) {
TheLunaticPlayer.CustomBossMask.visible = !this.player.dead;
layers.Add( TheLunaticPlayer.CustomBossMask );
}
}
////////////////
public void FlashMe() {
var mymod = (TheLunaticMod)this.mod;
mymod.Sky.LightenSky();
}
public void QuakeMeFor( int duration, float scale ) {
this.QuakeScale = scale;
this.QuakeDuration = duration;
this.QuakeStartDuration = duration;
float vol = scale / 2;
int soundSlot = this.mod.GetSoundSlot( SoundType.Custom, "Sounds/Custom/EarthQuake" );
Main.PlaySound( (int)SoundType.Custom, -1, -1, soundSlot, vol );
}
}
}