1- //--------------------------------------------------------------------------------
2- // Player
3- //
4- // This is a simple player class that makes use of MonoGame.Aseprite.AnimatedSprite
5- // in order to render the player with animations
6- //
7- //--------------------------------------------------------------------------------
8- //
9- // License
10- //
11- // Copyright(c) 2018 Chris Whitley
12- //
13- // Permission is hereby granted, free of charge, to any person obtaining a copy
14- // of this software and associated documentation files (the "Software"), to deal
15- // in the Software without restriction, including without limitation the rights
16- // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
17- // copies of the Software, and to permit persons to whom the Software is
18- // furnished to do so, subject to the following conditions:
19- //
20- // The above copyright notice and this permission notice shall be included in
21- // all copies or substantial portions of the Software.
22- //
23- // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
24- // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25- // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
26- // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
27- // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
28- // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
29- // THE SOFTWARE.
30- //--------------------------------------------------------------------------------
31-
32-
33- using Microsoft . Xna . Framework ;
1+ using Microsoft . Xna . Framework ;
342using Microsoft . Xna . Framework . Content ;
353using Microsoft . Xna . Framework . Graphics ;
364using Microsoft . Xna . Framework . Input ;
@@ -51,7 +19,7 @@ public class Player
5119 Vector2 _currentDirection = Vector2 . UnitY ;
5220
5321
54-
22+
5523
5624
5725 /// <summary>
@@ -64,7 +32,7 @@ public Vector2 Position
6432 {
6533 if ( this . _position == value ) { return ; }
6634 this . _position = value ;
67- if ( _sprite != null )
35+ if ( _sprite != null )
6836 {
6937 _sprite . Position = value ;
7038 }
@@ -91,9 +59,11 @@ public Player(Vector2 position)
9159 /// <param name="content"></param>
9260 public void LoadContent ( ContentManager content )
9361 {
94- AnimationDefinition animationDefinition = content . Load < AnimationDefinition > ( "playerAnimation" ) ;
95- Texture2D texture = content . Load < Texture2D > ( "player" ) ;
96- _sprite = new AnimatedSprite ( texture , animationDefinition , this . Position ) ;
62+ AsepriteImportResult aseprite = content . Load < AsepriteImportResult > ( "sokoban_player" ) ;
63+ _sprite = new AnimatedSprite ( aseprite , Position ) ;
64+ //AnimationDefinition animationDefinition = content.Load<AnimationDefinition>("playerAnimation");
65+ //Texture2D texture = content.Load<Texture2D>("player");
66+ //_sprite = new AnimatedSprite(texture, animationDefinition, this.Position);
9767
9868 }
9969
@@ -130,36 +100,36 @@ private void UpdateInput(GameTime gameTime)
130100 // Move up
131101 this . _currentDirection = Vector2 . UnitY * - 1 ;
132102 this . Position += this . _currentDirection * _speed * delatTime ;
133- this . _sprite . Play ( "walk up " ) ;
103+ this . _sprite . Play ( "walk_up " ) ;
134104 }
135105 else if ( Keyboard . GetState ( ) . IsKeyDown ( Keys . Down ) || Keyboard . GetState ( ) . IsKeyDown ( Keys . S ) )
136106 {
137107 // Move down
138108 this . _currentDirection = Vector2 . UnitY ;
139109 this . Position += this . _currentDirection * _speed * delatTime ;
140- this . _sprite . Play ( "walk down " ) ;
110+ this . _sprite . Play ( "walk_down " ) ;
141111 }
142112 else if ( Keyboard . GetState ( ) . IsKeyDown ( Keys . Left ) || Keyboard . GetState ( ) . IsKeyDown ( Keys . A ) )
143113 {
144114 // Move left
145115 this . _currentDirection = Vector2 . UnitX * - 1 ;
146116 this . Position += this . _currentDirection * _speed * delatTime ;
147- this . _sprite . Play ( "walk left " ) ;
117+ this . _sprite . Play ( "walk_left " ) ;
148118 }
149119 else if ( Keyboard . GetState ( ) . IsKeyDown ( Keys . Right ) || Keyboard . GetState ( ) . IsKeyDown ( Keys . D ) )
150120 {
151121 // Move right
152122 this . _currentDirection = Vector2 . UnitX ;
153123 this . Position += this . _currentDirection * _speed * delatTime ;
154- this . _sprite . Play ( "walk right " ) ;
124+ this . _sprite . Play ( "walk_right " ) ;
155125 }
156126 else
157127 {
158128 // No movement, so use the current direction value to set the idle animation
159- if ( this . _currentDirection == Vector2 . UnitY * - 1 ) { this . _sprite . Play ( "idle up " ) ; }
160- else if ( this . _currentDirection == Vector2 . UnitY ) { this . _sprite . Play ( "idle down " ) ; }
161- else if ( this . _currentDirection == Vector2 . UnitX * - 1 ) { this . _sprite . Play ( "idle left " ) ; }
162- else if ( this . _currentDirection == Vector2 . UnitX ) { this . _sprite . Play ( "idle right " ) ; }
129+ if ( this . _currentDirection == Vector2 . UnitY * - 1 ) { this . _sprite . Play ( "idle_up " ) ; }
130+ else if ( this . _currentDirection == Vector2 . UnitY ) { this . _sprite . Play ( "idle_down " ) ; }
131+ else if ( this . _currentDirection == Vector2 . UnitX * - 1 ) { this . _sprite . Play ( "idle_left " ) ; }
132+ else if ( this . _currentDirection == Vector2 . UnitX ) { this . _sprite . Play ( "idle_right " ) ; }
163133
164134 }
165135 }
@@ -175,32 +145,32 @@ public void Render(SpriteBatch spriteBatch)
175145
176146 // Get the slice rectangle for the current frame. The name passed
177147 // must be the same as the name of the slice in Aseprite
178- var bodyHitBox = this . _sprite . GetCurrentFrameSlice ( "body-hit-box " ) ;
179- var hatHitBox = this . _sprite . GetCurrentFrameSlice ( "hat-hit-box " ) ;
180- var footHitBox = this . _sprite . GetCurrentFrameSlice ( "foot-on-ground-hitbox" ) ;
148+ var bodyHitBox = this . _sprite . GetCurrentFrameSlice ( "body_hitbox " ) ;
149+ var hatHitBox = this . _sprite . GetCurrentFrameSlice ( "hat_hitbox " ) ;
150+ // var footHitBox = this._sprite.GetCurrentFrameSlice("foot-on-ground-hitbox");
181151
182152 // Check if there is a value. We have to check since the return above is a nullable Rectangle.
183153 // If it doesn't have a value, that means there was no SliceKey defined for the current frame of
184154 // animation for the slice
185- if ( bodyHitBox . HasValue )
155+ if ( bodyHitBox . HasValue )
186156 {
187157 // If you want to use the same colors you used in Aseprite for the color of the slice
188158 // you can retrive that like this
189- Color sliceColor = this . _sprite . GetSliceColor ( "body-hit-box " ) ;
159+ Color sliceColor = this . _sprite . GetSliceColor ( "body_hitbox " ) ;
190160 spriteBatch . DrawHollowRectangle ( bodyHitBox . Value , sliceColor ) ;
191161 }
192162
193- if ( hatHitBox . HasValue )
163+ if ( hatHitBox . HasValue )
194164 {
195- Color sliceColor = this . _sprite . GetSliceColor ( "hat-hit-box " ) ;
165+ Color sliceColor = this . _sprite . GetSliceColor ( "hat_hitbox " ) ;
196166 spriteBatch . DrawHollowRectangle ( hatHitBox . Value , sliceColor ) ;
197167 }
198168
199- if ( footHitBox . HasValue )
200- {
201- Color sliceColor = this . _sprite . GetSliceColor ( "foot-on-ground-hitbox" ) ;
202- spriteBatch . DrawHollowRectangle ( footHitBox . Value , sliceColor ) ;
203- }
169+ //if (footHitBox.HasValue)
170+ // {
171+ // Color sliceColor = this._sprite.GetSliceColor("foot-on-ground-hitbox");
172+ // spriteBatch.DrawHollowRectangle(footHitBox.Value, sliceColor);
173+ // }
204174 }
205175 }
206176}
0 commit comments