-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ModEntry.cs
172 lines (161 loc) · 4.93 KB
/
ModEntry.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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Xna.Framework;
using StardewModdingAPI;
using StardewModdingAPI.Events;
using StardewModdingAPI.Utilities;
using StardewValley;
using StardewValley.Menus;
using StardewValley.Tools;
namespace SpeedewValley
{
public class ModEntry : Mod
{
public override void Entry( IModHelper helper )
{
helper.Events.GameLoop.DayStarted += GameLoop_DayStarted;
helper.Events.Input.ButtonPressed += Input_ButtonPressed;
helper.Events.Input.ButtonReleased += Input_ButtonReleased;
helper.Events.GameLoop.UpdateTicking += GameLoop_UpdateTicking;
helper.Events.GameLoop.UpdateTicked += GameLoop_UpdateTicked;
helper.Events.Player.Warped += Player_Warped;
}
private void GameLoop_DayStarted( object sender, DayStartedEventArgs e )
{
map = new bool[ Game1.player.currentLocation.map.Layers[ 0 ].LayerWidth, Game1.player.currentLocation.map.Layers[ 0 ].LayerHeight ];
for( int x = 0; x < Game1.player.currentLocation.map.Layers[ 0 ].LayerWidth; x++ )
{
for( int y = 0; y < Game1.player.currentLocation.map.Layers[ 0 ].LayerHeight; y++ )
{
map[ x, y ] = Game1.player.currentLocation.isCollidingPosition( new Rectangle( x * Game1.tileSize + 1, y * Game1.tileSize + 1, Game1.tileSize - 2, Game1.tileSize - 2 ), Game1.viewport, false, 0, false, Game1.player, true, false, false );
}
}
var name = Game1.player.currentLocation.Name;
}
private void moveLeft( bool move = true )
{
if( move )
{
Input.SendKeyDown( Input.KeyCode.KEY_A );
}
else
{
Input.SendKeyUp( Input.KeyCode.KEY_A );
}
}
private void moveRight( bool move = true )
{
if( move )
{
Input.SendKeyDown( Input.KeyCode.KEY_D );
}
else
{
Input.SendKeyUp( Input.KeyCode.KEY_D );
}
}
private void moveUp( bool move = true )
{
if( move )
{
Input.SendKeyDown( Input.KeyCode.KEY_W );
}
else
{
Input.SendKeyUp( Input.KeyCode.KEY_W );
}
}
private void moveDown( bool move = true )
{
if( move )
{
Input.SendKeyDown( Input.KeyCode.KEY_S );
}
else
{
Input.SendKeyUp( Input.KeyCode.KEY_S );
}
}
private void Input_ButtonPressed( object sender, ButtonPressedEventArgs e )
{
if( Context.IsWorldReady && Context.CanPlayerMove )
{
this.Monitor.Log( Game1.player.Position.X + " " + Game1.player.Position.Y, LogLevel.Info );
//if( e.Button == SButton.LeftShift )
//{
// moveLeft( true );
//}
}
}
private void Input_ButtonReleased( object sender, ButtonReleasedEventArgs e )
{
if( Context.IsWorldReady && Context.CanPlayerMove )
{
//if( e.Button == SButton.LeftShift )
//{
// moveLeft( false );
//}
}
}
bool[,] map = null;
uint gameTickDiff = 0;
private void GameLoop_UpdateTicking( object sender, UpdateTickingEventArgs e )
{
if( Context.IsWorldReady && Context.CanPlayerMove )
{
gameTickDiff = e.Ticks;
if( Game1.player.currentLocation.Name == "FarmHouse" )
{
if( Game1.player.Position.X > 200 )
{
moveLeft( true );
}
else
{
moveLeft( false );
}
if( Game1.player.Position.Y < 730 )
{
moveDown( true );
}
else
{
moveDown( false );
}
}
//var map = new bool[ Game1.player.currentLocation.map.Layers[ 0 ].LayerWidth, Game1.player.currentLocation.map.Layers[ 0 ].LayerHeight ];
//for( int x = 0; x < Game1.player.currentLocation.map.Layers[ 0 ].LayerWidth; x++ )
//{
// for( int y = 0; y < Game1.player.currentLocation.map.Layers[ 0 ].LayerHeight; y++ )
// {
// map[ x, y ] = Game1.player.currentLocation.isCollidingPosition( new Rectangle( x * Game1.tileSize + 1, y * Game1.tileSize + 1, Game1.tileSize - 2, Game1.tileSize - 2 ), Game1.viewport, false, 0, false, Game1.player, true, false, false );
// }
//}
this.Monitor.Log( Game1.player.Position.X + " " + Game1.player.Position.Y, LogLevel.Info );
}
}
private void GameLoop_UpdateTicked( object sender, UpdateTickedEventArgs e )
{
if( Context.IsWorldReady && Context.CanPlayerMove )
{
uint timeDiff = e.Ticks - gameTickDiff;
}
}
private void Player_Warped( object sender, WarpedEventArgs e )
{
this.Monitor.Log( "Player Warped " + e.NewLocation, LogLevel.Info );
map = new bool[ Game1.player.currentLocation.map.Layers[ 0 ].LayerWidth, Game1.player.currentLocation.map.Layers[ 0 ].LayerHeight ];
for( int x = 0; x < Game1.player.currentLocation.map.Layers[ 0 ].LayerWidth; x++ )
{
for( int y = 0; y < Game1.player.currentLocation.map.Layers[ 0 ].LayerHeight; y++ )
{
map[ x, y ] = Game1.player.currentLocation.isCollidingPosition( new Rectangle( x * Game1.tileSize + 1, y * Game1.tileSize + 1, Game1.tileSize - 2, Game1.tileSize - 2 ), Game1.viewport, false, 0, false, Game1.player, true, false, false );
}
}
}
}
}