public Player() { ScreenX = Game.Resolution.X / 2 - Width / 2; ScreenY = 0; Offset = 64; WalkState = WSTATE.STANDING; JumpState = JSTATE.STANDING; Current = Standing; }
public void Input(List <List <int> > tiles) { if (Engine.GetKeyHeld(Key.A)) { WalkState = WSTATE.LEFT; } else if (Engine.GetKeyHeld(Key.D)) { WalkState = WSTATE.RIGHT; } else { WalkState = WSTATE.STANDING; } if (Engine.GetKeyHeld(Key.W) && JumpState == JSTATE.STANDING) { JumpState = JSTATE.JUMPING; } Velocities(); bool cx = false; bool cy = false; //Collision for (int y = 0; y < tiles.Count; y++) { for (int x = 0; x < tiles[y].Count; x++) { Bounds2 tBounds; if (tiles[y][x] != GameScreen.AIR) { tBounds = new Bounds2(((x - GrassBiome.LEVELONEWIDTH / 2) * GrassBiome.TILESIZE) - (Offset + VelocityX), y * GrassBiome.TILESIZE, GrassBiome.TILESIZE, GrassBiome.TILESIZE); if (GetBounds().Overlaps(tBounds)) { cx = true; } tBounds = new Bounds2(((x - GrassBiome.LEVELONEWIDTH / 2) * GrassBiome.TILESIZE) - (Offset), (y * GrassBiome.TILESIZE), GrassBiome.TILESIZE, GrassBiome.TILESIZE); Bounds2 pBounds = new Bounds2(ScreenX + 7, ScreenY + VelocityY, Width, Height); if (pBounds.Overlaps(tBounds)) { cy = true; } tBounds = new Bounds2(((x - GrassBiome.LEVELONEWIDTH / 2) * GrassBiome.TILESIZE) - (Offset), y * GrassBiome.TILESIZE, GrassBiome.TILESIZE, GrassBiome.TILESIZE); float dx = VelocityX / Math.Abs(VelocityX); float dy = VelocityY / Math.Abs(VelocityY); if (GetBounds().Overlaps(tBounds)) { tBounds = new Bounds2(((x - GrassBiome.LEVELONEWIDTH / 2) * GrassBiome.TILESIZE) - (Offset), y * GrassBiome.TILESIZE, GrassBiome.TILESIZE, GrassBiome.TILESIZE); while (GetBounds().Overlaps(tBounds)) { ScreenY -= 1; } } } } } if (cx) { VelocityX = 0; WalkState = WSTATE.STANDING; Current = Standing; } if (cy) { Current = Standing; VelocityY = 0; JumpState = JSTATE.STANDING; } else if (JumpState == JSTATE.STANDING) { JumpState = JSTATE.FALLING; } }
public void SetWState(WSTATE state) { WalkState = state; }