Skip to content

Commit

Permalink
feat: chair
Browse files Browse the repository at this point in the history
  • Loading branch information
guchengxi1994 committed Jul 3, 2024
1 parent 2d359ac commit bd34511
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 3 deletions.
13 changes: 12 additions & 1 deletion assets/images/tiled/maps/city.tmj
Original file line number Diff line number Diff line change
Expand Up @@ -988,6 +988,17 @@
"width":50,
"x":1454.66666666667,
"y":50
},
{
"height":16,
"id":25,
"name":"chair",
"rotation":0,
"type":"",
"visible":true,
"width":17.2727272727273,
"x":159.454545454545,
"y":975.454545454545
}],
"opacity":1,
"type":"objectgroup",
Expand Down Expand Up @@ -1018,7 +1029,7 @@
"y":0
}],
"nextlayerid":16,
"nextobjectid":25,
"nextobjectid":26,
"orientation":"orthogonal",
"renderorder":"right-down",
"tiledversion":"1.10.2",
Expand Down
2 changes: 1 addition & 1 deletion lib/common/toast_utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class ToastUtils {
alignment: Alignment.bottomCenter,
builder: (ctx, holder) {
return SizedBox(
width: 200,
width: tip.length > 10 ? 400 : 200,
height: 50,
child: Center(
child: Text(
Expand Down
34 changes: 34 additions & 0 deletions lib/game/decorations/chair.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import 'package:bonfire/bonfire.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:make_a_dream/common/toast_utils.dart';
import 'package:make_a_dream/game/notifiers/player_notifier.dart';

class Chair extends GameDecoration with Sensor<Player> {
Chair({required super.position, required super.size, required this.ref});

bool isTouched = false;
final WidgetRef ref;

@override
void onContact(Player component) {
super.onContact(component);
if (gameRef.player != null && !isTouched) {
gameRef.player!.stopMove();
isTouched = true;
if (ref.read(playerProvider).current!.knowledge.total > 650) {
ToastUtils.decorationTip(null, tip: "是时候了!");
} else {
ToastUtils.decorationTip(null, tip: "时机尚未成熟,我的朋友...");
// [23 * 16 = 368,58 * 928]
gameRef.player!.translate(Vector2(368 - position.x, 928 - position.y));
gameRef.player!.moveDown();
}
}
}

@override
void onContactExit(Player component) {
isTouched = false;
super.onContactExit(component);
}
}
2 changes: 1 addition & 1 deletion lib/game/decorations/gaoshi.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class Gaoshi extends GameDecoration with Sensor<Player>, DecorationMixin {
gameRef.player!.stopMove();

showGeneralDialog(
barrierLabel: "fes",
barrierLabel: "gaoshi",
barrierDismissible: true,
context: context,
barrierColor: Colors.transparent,
Expand Down
3 changes: 3 additions & 0 deletions lib/game/maps/city_of_dream.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import 'package:bonfire/bonfire.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:make_a_dream/game/decorations/chair.dart';
import 'package:make_a_dream/game/decorations/classroom_entry.dart';
import 'package:make_a_dream/game/decorations/fes.dart';
import 'package:make_a_dream/game/decorations/fountain.dart';
Expand Down Expand Up @@ -49,6 +50,8 @@ class CityOfDream extends ConsumerWidget {
ClassroomEntry(position: p.position, size: p.size, ref: ref),
"gaoshi": (p) =>
Gaoshi(position: p.position, size: p.size, ref: ref),
"chair": (p) =>
Chair(position: p.position, size: p.size, ref: ref)
// "teacher2": (p) => BaseMentor(
// position: p.position,
// size: p.size,
Expand Down
10 changes: 10 additions & 0 deletions lib/isar/player_record.dart
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,16 @@ class PlayerKnowledge {
late double /* 生物 */ biography = 0;
late double /* IT */ it = 0;

double get total =>
math +
language +
history +
geography +
chemistry +
physics +
biography +
it;

String getKnowledgePrompt(
{String teacherType = 'science teacher', String? his}) {
String s = "你的学生基本情况如下:\n";
Expand Down

0 comments on commit bd34511

Please sign in to comment.