Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.IO;
- using System.Linq;
- using System.Collections.Generic;
- namespace CSharp_Shell
- {
- class Vector2 {
- public int x, y;
- public Vector2(int x, int y) {
- this.x = x;
- this.y = y;
- }
- public void clear(){
- x = 0;
- y = 0;
- }
- }
- class TouchControl {
- private int maxSpeed;
- private int maxLengthVector = 0;
- private Vector2 pos = new Vector2(0,0);
- public TouchControl(int max_speed, int width){
- this.maxLengthVector = width / 3;
- this.maxSpeed = max_speed;
- }
- private int getSpeed(int d){
- d = d < 0 ? (-d > maxLengthVector ? -maxLengthVector : d) : (d > maxLengthVector ? maxLengthVector : d);
- return maxSpeed * d / maxLengthVector;
- }
- public Vector2 downTouch(int x, int y){
- if (pos.x == 0) pos.x = x;
- if (pos.y == 0) pos.y = y;
- return new Vector2(getSpeed(pos.x >= x ? -(pos.x - x) : x - pos.x), getSpeed(pos.y >= y ? -(pos.y - y) : y - pos.y));
- }
- public void upTouch(){
- pos.clear();
- }
- }
- public static class Program
- {
- public static void Main()
- {
- TouchControl th = new TouchControl(15, 400);
- int x = 100, y = 200;
- for (int i = 20; i > 0; i--){
- x -= 2;
- y -= 1;
- Vector2 z = th.downTouch(x, y);
- Console.WriteLine(z.x+" "+z.y);
- }
- th.upTouch();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement