Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F65125428
checkCelluloGame.dart
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Sat, Jun 1, 00:43
Size
6 KB
Mime Type
text/x-java
Expires
Mon, Jun 3, 00:43 (1 d, 23 h)
Engine
blob
Format
Raw Data
Handle
18007728
Attached To
R10646 Orchestration
checkCelluloGame.dart
View Options
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:student/model/Cellulo.dart';
import 'dart:math' as math;
List<int> checkCelluloGame(var mapShape, Offset celluloTargetPosition,
Offset celluloXPosition, Offset celluloYPosition, int score) {
var insideBorder = false;
var insideShape = false;
final double coeffHaptic = 10;
double radiuosBorder = 10;
bool enterBorder = false;
bool enterShape = false;
var XVelocityCelluloX;
var YVelocityCelluloX;
var XVelocityCelluloY;
var YVelocityCelluloY;
int trappedCircle;
double celluloXYdistances = math.sqrt(
math.pow((celluloXPosition.dx - celluloYPosition.dx), 2) +
math.pow((celluloXPosition.dy - celluloYPosition.dy), 2));
double distanceThreshold = 120;
print(score.toString());
print(enterBorder.toString());
for (int i = 0; i < mapShape['numCircles']; i++) {
var distancePointCenter = math.sqrt(math.pow(
(celluloTargetPosition.dx - mapShape['originCircles'][i].dx), 2) +
math.pow(
(celluloTargetPosition.dy - mapShape['originCircles'][i].dy), 2));
if (distancePointCenter <= mapShape['radiuosCircles'][i] + radiuosBorder) {
insideBorder = true;
XVelocityCelluloX =
coeffHaptic * (celluloXPosition.dx - mapShape['originCircles'][i].dx);
YVelocityCelluloX =
coeffHaptic * (celluloXPosition.dy - mapShape['originCircles'][i].dy);
XVelocityCelluloY =
coeffHaptic * (celluloYPosition.dx - mapShape['originCircles'][i].dx);
YVelocityCelluloY =
coeffHaptic * (celluloYPosition.dy - mapShape['originCircles'][i].dy);
cellulox.setVelocity(XVelocityCelluloX, YVelocityCelluloX);
celluloy.setVelocity(XVelocityCelluloY, YVelocityCelluloY);
if (enterBorder == false) {
score = score - 1;
enterBorder = true;
}
trappedCircle = i;
break;
} else if (i == trappedCircle) {
enterBorder = false;
/*
insideBorder = false;
if (distancePointCenter <= mapShape['radiuosCircles'][i]) {
insideShape = true;
} else {
insideShape = false;
enterShape = false;
}
if (insideShape == true) {
if (enterShape == false) {
score = score - 1;
enterShape = true;
}
}
*/
}
cellulox.clearrobot();
celluloy.clearrobot();
}
return [score];
/*
for (int i = 0; i < mapShape['numPolygons']; i++) {
double distancePointCenter = math.sqrt(math.pow(
(celluloTargetPosition.dx - mapShape['centerPolygon'][i].dx), 2) +
math.pow(
(celluloTargetPosition.dy - mapShape['centerPolygon'][i].dy), 2));
//print('radious' + distancePointCenter.toString());
if (distancePointCenter + radiuosBorder <= mapShape['radiusPolygon'][i]) {
insideBorder = true;
} else {
enterBorder = false;
}
if (distancePointCenter <= mapShape['radiusPolygon'][i]) {
insideShape = true;
} else {
enterShape = false;
}
if (insideBorder == true) {
XVelocityCelluloX =
coeffHaptic * (celluloXPosition.dx - mapShape['centerPolygon'][i].dx);
YVelocityCelluloX =
coeffHaptic * (celluloXPosition.dy - mapShape['centerPolygon'][i].dy);
XVelocityCelluloY =
coeffHaptic * (celluloYPosition.dx - mapShape['centerPolygon'][i].dx);
YVelocityCelluloY =
coeffHaptic * (celluloYPosition.dy - mapShape['centerPolygon'][i].dy);
//cellulox.setVelocity(hapticXVelocityCelluloX, hapticYVelocityCelluloX);
//celluloy.setVelocity(hapticXVelocityCelluloY, hapticYVelocityCelluloY);
if (enterBorder == false) {
score = score - 1;
enterBorder = true;
}
break;
}
if (insideShape == true) {
if (enterShape == false) {
score = score - 1;
enterShape = true;
}
}
}
for (int i = 0; i < mapShape['numRectangles']; i++) {
if (Rect.fromCenter(
center: mapShape['originRectangles'][i],
width: mapShape['widthRectangles'][i],
height: mapShape['heightRectangles'][i])
.contains(celluloTargetPosition)) {
insideBorder = true;
} else {
enterBorder = false;
}
if (Rect.fromCenter(
center: mapShape['originRectangles'][i],
width: mapShape['widthRectangles'][i],
height: mapShape['heightRectangles'][i])
.contains(celluloTargetPosition)) {
insideShape = true;
} else {
enterShape = false;
}
if (insideBorder == true) {
XVelocityCelluloX = coeffHaptic *
(celluloXPosition.dx - mapShape['originRectangles'][i].dx);
YVelocityCelluloX = coeffHaptic *
(celluloXPosition.dy - mapShape['originRectangles'][i].dy);
XVelocityCelluloY = coeffHaptic *
(celluloYPosition.dx - mapShape['originRectangles'][i].dx);
YVelocityCelluloY = coeffHaptic *
(celluloYPosition.dy - mapShape['originRectangles'][i].dy);
//cellulox.setVelocity(hapticXVelocityCelluloX, hapticYVelocityCelluloX);
//celluloy.setVelocity(hapticXVelocityCelluloY, hapticYVelocityCelluloY);
if (enterBorder == false) {
score = score - 1;
enterBorder = true;
}
break;
}
if (insideShape == true) {
if (enterShape == false) {
score = score - 1;
enterShape = true;
}
}
if (celluloXYdistances < distanceThreshold) {
XVelocityCelluloX =
coeffHaptic * (celluloXPosition.dx - mapShape['centerPolygon'][i].dx);
YVelocityCelluloX =
coeffHaptic * (celluloXPosition.dy - mapShape['centerPolygon'][i].dy);
XVelocityCelluloY =
coeffHaptic * (celluloYPosition.dx - mapShape['centerPolygon'][i].dx);
YVelocityCelluloY =
coeffHaptic * (celluloYPosition.dy - mapShape['centerPolygon'][i].dy);
cellulox.robotVibrate(10, 10, 0, 100, 100);
celluloy.robotVibrate(10, 10, 0, 100, 100);
// cellulox.setVelocity(XVelocityCelluloX, YVelocityCelluloX);
// celluloy.setVelocity(XVelocityCelluloY, YVelocityCelluloY);
} else {
cellulox.clearrobot();
celluloy.clearrobot();
}
}
*/
}
Event Timeline
Log In to Comment