Advertisement
Guest User

Untitled

a guest
Dec 12th, 2019
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.41 KB | None | 0 0
  1. using System;
  2. using System.IO;
  3. using System.Linq;
  4. using System.Collections.Generic;
  5.  
  6. namespace CSharp_Shell
  7. {
  8.     class Vector2 {
  9.        
  10.         public int x, y;
  11.        
  12.         public Vector2(int x, int y) {
  13.             this.x = x;
  14.             this.y = y;
  15.         }
  16.        
  17.         public void clear(){
  18.             x = 0;
  19.             y = 0;
  20.         }
  21.     }
  22.    
  23.     class TouchControl {
  24.        
  25.         private int maxSpeed;
  26.         private int maxLengthVector = 0;
  27.         private Vector2 pos = new Vector2(0,0);
  28.        
  29.         public TouchControl(int max_speed, int width){
  30.             this.maxLengthVector = width / 3;
  31.             this.maxSpeed = max_speed;
  32.         }
  33.        
  34.         private int getSpeed(int d){
  35.             d = d < 0 ? (-d > maxLengthVector ? -maxLengthVector : d) : (d > maxLengthVector ? maxLengthVector : d);
  36.             return maxSpeed * d / maxLengthVector;
  37.         }
  38.        
  39.         public Vector2 downTouch(int x, int y){
  40.             if (pos.x == 0) pos.x = x;
  41.             if (pos.y == 0) pos.y = y;
  42.             return new Vector2(getSpeed(pos.x >= x ? -(pos.x - x) : x - pos.x), getSpeed(pos.y >= y ? -(pos.y - y) : y - pos.y));
  43.         }
  44.        
  45.         public void upTouch(){
  46.             pos.clear();
  47.         }
  48.     }
  49.  
  50.     public static class Program
  51.     {
  52.         public static void Main()
  53.         {
  54.             TouchControl th = new TouchControl(15, 400);
  55.             int x = 100, y = 200;
  56.             for (int i = 20; i > 0; i--){
  57.                 x -= 2;
  58.                 y -= 1;
  59.                 Vector2 z = th.downTouch(x, y);
  60.                 Console.WriteLine(z.x+" "+z.y);
  61.             }
  62.             th.upTouch();
  63.         }
  64.     }
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement