lib.rs 961 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. use bolt_lang::*;
  2. declare_id!("FSa6qoJXFBR3a7ThQkTAMrC15p6NkchPEjBdd4n6dXxA");
  3. #[system]
  4. pub mod system_simple_movement {
  5. pub fn execute(ctx: Context<Components>, args: Args) -> Result<()> {
  6. // Compute the new position based on the direction
  7. let (dx, dy) = match args.direction {
  8. Direction::Left => (-1, 0),
  9. Direction::Right => (1, 0),
  10. Direction::Up => (0, 1),
  11. Direction::Down => (0, -1),
  12. };
  13. ctx.accounts.position.x += dx;
  14. ctx.accounts.position.y += dy;
  15. Ok(())
  16. }
  17. #[system_input]
  18. pub struct Components {
  19. #[component_id("Fn1JzzEdyb55fsyduWS94mYHizGhJZuhvjX6DVvrmGbQ")]
  20. pub position: Position,
  21. }
  22. // Define the structs to deserialize the arguments
  23. #[arguments]
  24. struct Args {
  25. direction: Direction,
  26. }
  27. #[arguments]
  28. pub enum Direction {
  29. Left,
  30. Right,
  31. Up,
  32. Down,
  33. }
  34. }