Skip to content

Commit

Permalink
Merge branch 'dev' into app
Browse files Browse the repository at this point in the history
  • Loading branch information
m-r-davari committed Feb 11, 2024
2 parents 7ae86a8 + 50c5d5d commit 175849d
Show file tree
Hide file tree
Showing 7 changed files with 209 additions and 147 deletions.
132 changes: 92 additions & 40 deletions lib/asphalt_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,80 +2,132 @@ import 'package:flutter/material.dart';
import 'package:nostalgia_nitro/tile_widget.dart';
import 'package:nostalgia_nitro/utils.dart';
import 'car_widget.dart';
import 'dart:math' as math;

class AsphaltWidget extends StatelessWidget {

final List<GlobalKey> npcCarKeys;
final bool isEmpty;
const AsphaltWidget({Key? key,required this.npcCarKeys,this.isEmpty = false}) : super(key: key);

//final bool isEmpty;
final bool isLap;

const AsphaltWidget({Key? key, required this.npcCarKeys, this.isLap = false}) : super(key: key);

@override
Widget build(BuildContext context) {
return Container(
width: 230,
height: 470,
color: const Color(0xffEDEDED),
child: Row(
child: Stack(
children: [
generateSide(),
const SizedBox(width: 10,),
Expanded(
child: Container(
//color: Colors.red.withOpacity(0.5),
height: double.infinity,
child: isEmpty ? const Center(child: Text('New Lap')) : GridView.count(
physics: const NeverScrollableScrollPhysics(),
shrinkWrap: true,
scrollDirection: Axis.vertical,
crossAxisCount: 3,
crossAxisSpacing: 15,//10
mainAxisSpacing: 15,//10
childAspectRatio: 0.75,
children: generateCars(),
Row(
children: [
generateSide(),
const SizedBox(
width: 10,
),
Expanded(
child: Container(
//color: Colors.red.withOpacity(0.5),
height: double.infinity,
child: isLap
? const SizedBox()
: GridView.count(
physics: const NeverScrollableScrollPhysics(),
shrinkWrap: true,
scrollDirection: Axis.vertical,
crossAxisCount: 3,
crossAxisSpacing: 15,
//10
mainAxisSpacing: 15,
//10
childAspectRatio: 0.75,
children: generateCars(),
),
),
)
),
const SizedBox(
width: 10,
),
generateSide()
],
),
const SizedBox(width: 10,),
generateSide()
isLap
? Positioned(
left: -5,
right: -5,
child: Container(
height: 55,
color: const Color(0xffEDEDED),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
mainAxisSize: MainAxisSize.max,
children: [
const Icon(
Icons.flag,
size: 40,
color: Colors.blueGrey,
),
const Text(
'Nostalgia Nitro',
style: TextStyle(color: Colors.black),
),
Transform(
alignment: Alignment.center,
transform: Matrix4.rotationY(math.pi),
child: const Icon(Icons.flag, size: 40, color: Colors.blueGrey),
),
],
),
),
)
: const SizedBox()
],
),
);
}

List<Widget> generateCars(){
//widget.hasKey ? CarWidget(key: carKey3,carColor: Colors.red,) : Container(),
List<Widget> generateCars() {
List<Widget> widLst = [];
List<int> npcCarsIndex = [];
npcCarsIndex.add(Utils.generateRandomNumFromRange(0, 2));
npcCarsIndex.add(Utils.generateRandomNumFromRange(3, 5));
npcCarsIndex.add(Utils.generateRandomNumFromRange(6, 8));
npcCarsIndex.add(Utils.generateRandomNumFromRange(9, 11));

for(int i = 0 ; i < 12 ; i++){
if(npcCarsIndex.contains(i)){
widLst.add(CarWidget(key: npcCarKeys[i],isNpc: true,));
}
else{
widLst.add(Container());
for (int i = 0; i < 12; i++) {
if (npcCarsIndex.contains(i)) {
widLst.add(CarWidget(
key: npcCarKeys[i],
isNpc: true,
));
} else {
widLst.add(const SizedBox());
}
}

return widLst;

}

Widget generateSide() {
List<Widget> widLst = [];
for (int i = 0; i < 45; i=i+5) {

widLst.add(const SizedBox(height: 10,),);
widLst.add(const SizedBox(height: 10,),);
widLst.add(const TileWidget(width:10,height: 10));
widLst.add(const TileWidget(width:10,height: 10));
widLst.add(const TileWidget(width:10,height: 10));

for (int i = 0; i < 45; i = i + 5) {
widLst.add(
const SizedBox(
height: 10,
),
);
widLst.add(
const SizedBox(
height: 10,
),
);
widLst.add(const TileWidget(width: 10, height: 10));
widLst.add(const TileWidget(width: 10, height: 10));
widLst.add(const TileWidget(width: 10, height: 10));
}
return Column(children: widLst,);
return Column(
children: widLst,
);
}
}
2 changes: 1 addition & 1 deletion lib/car_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class CarWidget extends StatelessWidget {
: Container(
width: carWidth, height: carHeight,
alignment: Alignment.center,
//color: Colors.amberAccent.withOpacity(0.6),
//color: Colors.amberAccent.withOpacity(0.6),//
child: ScrollConfiguration(
behavior: ScrollConfiguration.of(context).copyWith(scrollbars: false),
child: GridView.count(
Expand Down
18 changes: 9 additions & 9 deletions lib/race_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class RaceController extends GetxController {

void handleAsphalts(ScrollController scrollController){

// print('--- adding new asphalt --- ${scrollController.offset} --- asphalt length : ${asphalts.length}');
print('--- handling asphalt --- offset : ${scrollController.offset} --- asphalt length : ${asphalts.length}');


if(asphalts.length == 20){
Expand All @@ -36,7 +36,7 @@ class RaceController extends GetxController {
scrollController.jumpTo(scrollController.position.minScrollExtent);
for(int i = 0 ; i < 10 ; i++){
if(i==0){
asphalts.add(AsphaltWidget(key: GlobalKey(),isEmpty: true,npcCarKeys: [],));
asphalts.add(AsphaltWidget(key: GlobalKey(),isLap: true, npcCarKeys: const []));
}
else{
asphalts.add(AsphaltWidget(key: GlobalKey(),npcCarKeys: generateMpcKeys(),));
Expand All @@ -56,7 +56,7 @@ class RaceController extends GetxController {

for(int i = 0 ; i < 10 ; i++){
if(asphalts.length==19){
asphalts.add(AsphaltWidget(key: GlobalKey(),isEmpty: true,npcCarKeys: [],));
asphalts.add(AsphaltWidget(key: GlobalKey(),isLap: true, npcCarKeys: const [],));
}
else{
asphalts.add(AsphaltWidget(key: GlobalKey(),npcCarKeys: generateMpcKeys(),));
Expand All @@ -81,9 +81,9 @@ class RaceController extends GetxController {
final carsInshow = asphaltsInShow.expand<GlobalKey>((element) => element.npcCarKeys.where((element) => element.currentContext!=null));
// print('cars ---> len : ${carsInshow.length} --- $carsInshow');
final carsInCrashZone = carsInshow.where((element) {
RenderBox mpcCarBox = element.currentContext!.findRenderObject() as RenderBox;
Offset mpcCarPosition = mpcCarBox.localToGlobal(Offset.zero);
return mpcCarPosition.dy + carHeight > 440 && mpcCarPosition.dy + carHeight < 600;
RenderBox npcCarBox = element.currentContext!.findRenderObject() as RenderBox;
Offset npcCarPosition = npcCarBox.localToGlobal(Offset.zero);
return npcCarPosition.dy + carHeight > 440 && npcCarPosition.dy + carHeight < 600;
});
// print('cars in crash zone ---> len : ${carsInCrashZone.length} --- $carsInCrashZone');

Expand All @@ -98,9 +98,9 @@ class RaceController extends GetxController {
if(mainCarPosition.dx.ceil()==mpcCarPosition.dx.ceil()){
double mainCarTop = mainCarPosition.dy;
double mainCarBottom = mainCarPosition.dy + carHeight;
double mpcCarTop = mpcCarPosition.dy;
double mpcCarBottom = mpcCarPosition.dy + carHeight;
if((mpcCarBottom >= mainCarTop && mpcCarBottom <= mainCarBottom) || (mpcCarTop >= mainCarTop && mpcCarTop <= mainCarBottom)){
double npcCarTop = mpcCarPosition.dy;
double npcCarBottom = mpcCarPosition.dy + carHeight;
if((npcCarBottom >= mainCarTop && npcCarBottom <= mainCarBottom) || (npcCarTop >= mainCarTop && npcCarTop <= mainCarBottom)){
if(tempNpcCar!=npcCarBox){
armor.value -= 1;
if(armor.value==0){
Expand Down
37 changes: 18 additions & 19 deletions lib/scores_widget.dart → lib/race_info_widget.dart
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:nostalgia_nitro/race_controller.dart';
import 'package:nostalgia_nitro/tile_widget.dart';

class ScoreWidget extends StatelessWidget {
final int score;
final int lap;
final int hiScore;
final int armor;
final double nitroPercent;
const ScoreWidget({super.key,required this.score,required this.lap,required this.hiScore,required this.armor,required this.nitroPercent});
class RaceInfoWidget extends StatelessWidget {

RaceInfoWidget({super.key});

final raceController = Get.find<RaceController>();

@override
Widget build(BuildContext context) {
//print('---rebuildddddzzz--info--');
return Column(
mainAxisAlignment: MainAxisAlignment.center,
mainAxisSize: MainAxisSize.min,
Expand All @@ -20,7 +21,7 @@ class ScoreWidget extends StatelessWidget {
const SizedBox(height: 8,),
Padding(
padding: const EdgeInsets.symmetric(horizontal: 8),
child: FittedBox(child: Text(hiScore.toString(),maxLines: 1,style: const TextStyle(fontWeight: FontWeight.bold),)),
child: FittedBox(child: Obx(()=>Text(raceController.hiScore.value.toString(),maxLines: 1,style: const TextStyle(fontWeight: FontWeight.bold),))),
),
const SizedBox(height: 24,),
const Divider(height: 1,thickness: 0.8,indent: 8,endIndent: 8,color: Colors.grey,),
Expand All @@ -29,32 +30,30 @@ class ScoreWidget extends StatelessWidget {
const SizedBox(height: 8,),
Padding(
padding: const EdgeInsets.symmetric(horizontal: 8),
child: FittedBox(child: Text(score.toString(),maxLines: 1,style: const TextStyle(fontWeight: FontWeight.bold),)),
child: FittedBox(child: Obx(()=>Text(raceController.score.value.toString(),maxLines: 1,style: const TextStyle(fontWeight: FontWeight.bold),))),
),
const SizedBox(height: 16,),
const Text('Lap'),
const SizedBox(height: 8,),
Padding(
padding: const EdgeInsets.symmetric(horizontal: 8),
child: FittedBox(child: Text(lap.toString(),maxLines: 1,style: const TextStyle(fontWeight: FontWeight.bold),)),
child: FittedBox(child: Obx(()=>Text(raceController.lap.value.toString(),maxLines: 1,style: const TextStyle(fontWeight: FontWeight.bold),))),
),
const SizedBox(height: 24,),
const Divider(height: 1,thickness: 0.8,indent: 8,endIndent: 8,color: Colors.grey,),
const SizedBox(height: 24,),
const Text('Armor'),
const SizedBox(height: 8,),
generateArmor(armor),
Obx(() => generateArmor(raceController.armor.value)),
const SizedBox(height: 24,),
const Divider(height: 1,thickness: 0.8,indent: 8,endIndent: 8,color: Colors.grey,),
const SizedBox(height: 24,),//
Container(
child: Stack(
alignment: Alignment.center,
children: [
const Text('Nitro'),
SizedBox(width: 50,height: 50,child: CircularProgressIndicator(value: nitroPercent,color: Colors.black,backgroundColor: Colors.grey)),
],
)
Stack(
alignment: Alignment.center,
children: [
const Text('Nitro'),
SizedBox(width: 50,height: 50,child: Obx(()=>CircularProgressIndicator(value: raceController.nitroPercent.value,color: Colors.black,backgroundColor: Colors.grey))),
],
)
],
);
Expand Down
Loading

0 comments on commit 175849d

Please sign in to comment.