Page MenuHomec4science

checkCelluloGame.dart
No OneTemporary

File Metadata

Created
Sat, Jun 1, 00:43

checkCelluloGame.dart

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