public Sprite(int x,int y, int type , ContentManager cm, GraphicsDevice gd,int [,] movedata) { this.movedata = movedata; position = new Vector2(x, y); contentManager = cm; graphicsDevice = gd; status = State.Waiting; }
public Sprite(Texture2D image, Point playerFrameSize, Vector2 position, Vector2 velocity, int collisionOffset, int type, int[,] movedata, SceneManager sm) { this.image = image; this.playerFrameSize = playerFrameSize; this.position = position; this.velocity = velocity; this.collisionOffset = collisionOffset; this.type = type; this.movedata = movedata; sceneManager = sm; status = State.Waiting; }
/* public Sprite(Texture2D player1, Point playerFrameSize, Vector2 playerPosition, Vector2 velocity, int collisionOffset, int curFrame, int direction, float timer, bool walking, bool keepmoving) : this(player1, playerFrameSize, playerPosition, velocity, collisionOffset, curFrame, direction, timer, walking, keepmoving, defaultMSPerFrame) { } */ public Sprite(Texture2D image, Point playerFrameSize, Vector2 position, Vector2 velocity, int collisionOffset, int type, int[,] movedata) { this.image = image; this.playerFrameSize = playerFrameSize; this.position = position; this.velocity = velocity; this.collisionOffset = collisionOffset; this.type = type; this.movedata = movedata; //Initialize(); //LoadContent(); status = State.Waiting; }
public virtual void Update(GameTime gametime) { //Console.WriteLine(position.X / (16 * 3)); //Console.WriteLine(movedata[(int)(position.Y/48 % 16), (int)(position.X/48 % 16)]); var newState = Keyboard.GetState(); timer += (float)gametime.ElapsedGameTime.TotalMilliseconds; Console.WriteLine(status); switch (status) { //(movedata[(int)(((position.Y + 48) / 48) % 16), (int)((position.X / 48) % 16)] == 0) case State.Waiting: { if (newState.IsKeyDown(Keys.Right)) { status = State.MoveRight; } else if (newState.IsKeyDown(Keys.Left)) { status = State.MoveLeft; } else if (newState.IsKeyDown(Keys.Up)) { status = State.MoveUp; } else if (newState.IsKeyDown(Keys.Down)) { status = State.MoveDown; } break; } case State.MoveRight: { if (walking) { if (movedata[(int)(((position.Y) / 48) % 16), (int)(((position.X + 48) / 48) % 16)] == 0 && keepmoving) { position.X += 4; keepmoving = true; if (timer > 100f) { curFrame++; timer = 0f; } if (curFrame == 4) { curFrame = 0; } if ((int)position.X % 48 == 0) { keepmoving = false; walking = false; status = State.Waiting; } } else { keepmoving = false; walking = false; status = State.Waiting; } } else { curFrame = 0; direction = 2; walking = true; keepmoving = true; } break; } case State.MoveDown: { if (walking) { if (movedata[(int)(((position.Y + 48) / 48) % 16), (int)((position.X / 48) % 16)] == 0 && keepmoving) { position.Y += 4; keepmoving = true; if (timer > 100f) { curFrame++; timer = 0f; } if (curFrame == 4) { curFrame = 0; } if ((int)position.Y % 48 == 0) { keepmoving = false; walking = false; status = State.Waiting; } } else{ keepmoving = false; walking = false; status = State.Waiting; } } else { curFrame = 0; direction = 0; walking = true; keepmoving = true; } break; } case State.MoveUp: { if (walking) { if (movedata[(int)(((position.Y-1) / 48) % 16), (int)((position.X / 48) % 16)] == 0 && keepmoving) { position.Y -= 4; keepmoving = true; if (timer > 100f) { curFrame++; timer = 0f; } if (curFrame == 4) { curFrame = 0; } if ((int)position.Y % 48 == 0) { keepmoving = false; walking = false; status = State.Waiting; } } else { curFrame = 0; keepmoving = false; walking = false; status = State.Waiting; } } else { curFrame = 0; direction = 3; walking = true; keepmoving = true; } break; } case State.MoveLeft: { if (walking) { if (movedata[(int)(((position.Y) / 48) % 16), (int)(((position.X-1 ) / 48) % 16)] == 0 && keepmoving) { position.X -= 4; keepmoving = true; if (timer > 100f) { curFrame++; timer = 0f; } if (curFrame == 4) { curFrame = 0; } if ((int)position.X % 48 == 0) { keepmoving = false; walking = false; status = State.Waiting; } } else { keepmoving = false; walking = false; status = State.Waiting; } } else { curFrame = 0; direction = 1; walking = true; keepmoving = true; } break; } } oldState = newState; }