Skip to content
This repository was archived by the owner on Dec 26, 2023. It is now read-only.

Commit 6b53edf

Browse files
committed
started lvl 2
1 parent a604bd8 commit 6b53edf

File tree

2 files changed

+177
-11
lines changed

2 files changed

+177
-11
lines changed

lib/main.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,8 @@ class MyApp extends StatelessWidget {
6464
home: const MyHomePage(),
6565
routes: {
6666
'/page1': (context) => const Page1(),
67-
'/page2': (context) => Page2(),
68-
'/page3': (context) => const Page3(),
67+
'/page2': (context) => const Page2(),
68+
'/Page2': (context) => const Page2(),
6969
'/page4': (context) => const MyGame(),
7070
},
7171
);
@@ -97,7 +97,7 @@ class MyHomePage extends StatelessWidget {
9797
500), // Adjust the amount of space before the buttons
9898
ElevatedButton(
9999
onPressed: () {
100-
Navigator.pushNamed(context, '/page1');
100+
Navigator.pushNamed(context, '/page2');
101101
},
102102
child: const Text('Start'),
103103
),

lib/page2.dart

Lines changed: 174 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,185 @@
1-
import 'package:chemistry_game/page3.dart';
21
import 'package:flutter/material.dart';
2+
import 'dart:async';
33

4-
class Page2 extends StatelessWidget {
4+
double balloonPositionX = 0.5; // Initial horizontal position of the balloon
5+
double balloonPositionY = 2.0; // Initial vertical position of the balloon
6+
bool gameStarted = false;
7+
bool gameResultShown = false;
8+
bool gameWon = false;
9+
10+
class Page2 extends StatefulWidget {
11+
const Page2({Key? key}) : super(key: key);
12+
@override
13+
_Page2State createState() => _Page2State();
14+
}
15+
16+
class _Page2State extends State<Page2> {
517
@override
618
Widget build(BuildContext context) {
19+
@override
20+
void initState() {
21+
super.initState();
22+
} // dont mess with this func, cause idk why it is even alive xd, jk...
23+
24+
void startGame() {
25+
setState(() {
26+
balloonPositionX = 0.5; // Reset horizontal position of the balloon
27+
balloonPositionY = 0.8; // Reset vertical position of the balloon
28+
gameStarted = true;
29+
gameResultShown = false;
30+
gameWon = false;
31+
});
32+
33+
Timer.periodic(const Duration(milliseconds: 20), (timer) {
34+
// setState(() {
35+
// balloonPositionY -= 0.0005; // Move the balloon upwards
36+
// });
37+
});
38+
}
39+
40+
void moveBalloonRight() {
41+
if (balloonPositionX < 1) {
42+
setState(() {
43+
balloonPositionX += 0.05; // Move the balloon to the right
44+
});
45+
}
46+
}
47+
48+
void moveBalloonLeft() {
49+
if (balloonPositionX > 0) {
50+
setState(() {
51+
balloonPositionX -= 0.05; // Move the balloon to the left
52+
});
53+
}
54+
}
55+
56+
void restartGame() {
57+
setState(() {
58+
balloonPositionX = 0.5; // Reset balloon position
59+
// currentBlockIndex = 0; // Reset the current block index
60+
gameStarted = false;
61+
gameResultShown = false;
62+
gameWon = false;
63+
});
64+
}
65+
766
return Scaffold(
867
appBar: AppBar(
9-
title: Text('Page 2'),
68+
title: const Text('Level 3'),
1069
),
1170
body: Center(
12-
child: ElevatedButton(
13-
onPressed: () {
14-
Navigator.pushNamed(context, '/page3');
15-
},
16-
child: const Text("Move to page 3")),
71+
child: Column(
72+
mainAxisAlignment: MainAxisAlignment.center,
73+
children: <Widget>[
74+
SizedBox(
75+
width: double.infinity,
76+
height: 400,
77+
child: Stack(
78+
children: [
79+
Positioned(
80+
top: balloonPositionY * 400,
81+
left: MediaQuery.of(context).size.width * balloonPositionX -
82+
25,
83+
child: GestureDetector(
84+
onTap: () {
85+
if (!gameStarted) {
86+
startGame();
87+
}
88+
},
89+
child: SizedBox(
90+
width: 50,
91+
height: 50,
92+
child: Image.asset(
93+
'player.png',
94+
width: 100,
95+
height: 100,
96+
),
97+
// decoration: const BoxDecoration(
98+
// color: Colors.red,
99+
// shape: BoxShape.circle,
100+
// ),
101+
),
102+
),
103+
),
104+
// Render all four blocks at fixed positions
105+
106+
Positioned(
107+
top: 0,
108+
left: MediaQuery.of(context).size.width * 0.1,
109+
child: Column(
110+
children: [
111+
Container(
112+
width: 10,
113+
height: 100,
114+
color: Colors.blue,
115+
),
116+
const Text('Block A'),
117+
],
118+
),
119+
),
120+
121+
Positioned(
122+
top: 0,
123+
left: MediaQuery.of(context).size.width * 0.7,
124+
child: Column(
125+
children: [
126+
Container(
127+
width: 10,
128+
height: 100,
129+
color: Colors.orange,
130+
),
131+
const Text('Block C'),
132+
],
133+
),
134+
),
135+
],
136+
),
137+
),
138+
const SizedBox(height: 20),
139+
if (gameResultShown)
140+
Text(
141+
gameWon ? 'You Win!' : 'You Lose!',
142+
style: const TextStyle(fontSize: 20),
143+
),
144+
const SizedBox(height: 20),
145+
Column(
146+
children: [
147+
ElevatedButton(
148+
onPressed: () {
149+
if (!gameStarted) {
150+
startGame();
151+
}
152+
},
153+
child: const Text('Start'),
154+
),
155+
],
156+
),
157+
const SizedBox(height: 20),
158+
Column(
159+
children: [
160+
ElevatedButton(
161+
onPressed: moveBalloonLeft,
162+
child: const Text('Left'),
163+
),
164+
],
165+
),
166+
const SizedBox(height: 20),
167+
Column(
168+
children: [
169+
ElevatedButton(
170+
onPressed: moveBalloonRight,
171+
child: const Text('Right'),
172+
),
173+
],
174+
),
175+
const SizedBox(height: 20),
176+
if (gameStarted && gameResultShown && gameWon == false)
177+
ElevatedButton(
178+
onPressed: restartGame,
179+
child: const Text('Restart'),
180+
),
181+
],
182+
),
17183
),
18184
);
19185
}

0 commit comments

Comments
 (0)