|
Author |
Topic: blow game_calculating average angle (Read 3140 times) |
|
julijas
|
blow game_calculating average angle
« on: Nov 21st, 2004, 4:47pm » |
|
this is sketch of game with serial interface.. this game is based on concept that several people can control the ball position on graphical display through windmills.. game have three inputs- -from BASIC STAMP2 with three pots (in future I 'll raplace pots with windmills).. so in future this game will be with blow'able interface (five windmills). these windmills are set around round display. every windmill's speed is related to its angle equivalent of circle. if I blow to the first windmill (angle equivalent = 120 degrees; speed= 255) and other windmill speed will be zero.. ball motion direction will be 120 degree and speed = i=i+255//// ////several weeks I am calculating how to simulate ball game around round table with blowable control../// _______________________________________________________ How clearly calculate relations between inputs (speed) and their equivalents (degrees)? _______________________________________________________ //this is game sketch ,wich represents game concept int e1_size = 20; float xx, yy = 0.0; float r = 200.0; // radius float i = 0; //angle float theta = 0; int n = 10; float x,y =0.00; //ball coordinate float mx = 0.00; // void setup() { size(400, 400); background (100); stroke(102); ellipseMode(CENTER_DIAMETER); framerate(80); } void loop() { background (0); xx = (cos (theta))*r; yy = (sin (theta))*r; i=mouseY;// mouseY controls rotational motion float D = dist( xx, yy, x, y); float mx = (mouseX -D) /9000.00; /*mouseX controls speed of ball motion */ x= x-mx*xx; y= y- mx*yy; if (x/cos(atan2(y,x)) > r&& y/sin(atan2(y,x))>r) { x=0; y=0; delay (1000);} if ( i> 360) { i=0; } theta = ((TWO_PI)/360.0)*i; noStroke(); fill(255,0,0); translate (200,200); ellipse(xx, yy, 20, 20); rectMode(CENTER_DIAMETER); rect (x, y, 12,12); stroke( 233); line (xx, yy, -xx, -yy); stroke( 233,0,0); point(0,0); noFill(); ellipse (0,0,2*r,2*r); }
|
|
|
|
julijas
|
blow game_calculating average angle
« Reply #1 on: Nov 21st, 2004, 5:02pm » |
|
/*this is my sketch with serial event...please check my "my trashy prototype calculator of average angle" - - any advice will be very needful*/ String serialString = ""; int serialCount = 0; int mill_1, mill_2, mill_3 =0; // speed of windmills int e1_size = 20; float xx, yy = 0.0; // ball coordinates float r = 200.0; // radius float i = 0; //angle float theta = 0; int n = 10;// float x,y =0.00; //rect coordinates float mx = 0.00; // float angle = 0.0; //average angle float m1,m2,m3; // relation between speed of windmills and their angle equivalents float main_speed = 0.00;// average speed void setup(){ beginSerial(); size(500, 500); background (100); stroke(102); ellipseMode(CENTER_DIAMETER); framerate(30); } void loop() { background (0); xx = (cos (theta))*r; yy = (sin (theta))*r; theta = ((TWO_PI)/360.0)*angle; main_speed = (mill_1 + mill_2 + mill_3)/3; m1 = 100*mill_1; m2 = 220*mill_2; m3 = 340*mill_3; angle = (m1 + m2 + m3)/ (mill_1 + mill_2 + mill_3); /*my trashy prototype calculator of average angle calculator*/ float D = dist( xx, yy, x, y); float mx = (main_speed -D) /12000.00; // relation between ball and blow source //k = (yy/xx); x= x+mx*xx; y= y+mx*yy; if (x/cos(atan2(y,x)) > r&& y/sin(atan2(y,x))>r) // when ball reaches circle border x&y=0 { x=0; y=0; delay (1000);} noStroke(); fill(255); translate (200,200); ellipse(xx, yy, e1_size, e1_size); rectMode(CENTER_DIAMETER); rect (x, y, 12,12); stroke( 233); stroke( 233,0,0); point(0,0); noFill(); ellipse (0,0,2*r,2*r); serialWrite(65); } void serialEvent() { processString ((char)serial); } void processString (char inByte) { serialString += inByte; serialCount = serialString.length(); if (serialCount > 2) { mill_1 = (int)serialString.charAt(0); mill_2 = (int)serialString.charAt(1); mill_3 = (int)serialString.charAt(2); serialString = ""; } }
|
|
|
|
|