Skip to content

Commit 086e557

Browse files
committed
feat: Enable bat movement via drag on PlayArea
This commit refactors the bat's movement logic. The responsibility for handling drag events is moved from the `Bat` component to the `PlayArea` component. This change allows the player to drag anywhere within the `PlayArea` to move the bat, rather than requiring a direct drag on the bat itself, which improves usability. - **`PlayArea`**: - Implements `DragCallbacks`. - The `onDragUpdate` method now updates the `Bat`'s horizontal position. - **`Bat`**: - Removes the `DragCallbacks` mixin and its associated `onDragUpdate` method.
1 parent 32be1b7 commit 086e557

3 files changed

Lines changed: 84 additions & 12 deletions

File tree

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
name: Bump Version Number
2+
3+
# 1. Trigger the workflow on pushes to the 'master' branch
4+
on:
5+
push:
6+
branches: [ "master" ]
7+
8+
# 2. Define the job
9+
jobs:
10+
bump-version:
11+
12+
# 3. This "if" condition is CRUCIAL to prevent infinite loops!
13+
# It checks if the commit message already contains [skip ci].
14+
# The bot's own commit will contain this, so it won't re-trigger itself.
15+
if: "!contains(github.event.head_commit.message, '[skip ci]')"
16+
17+
# Use the standard Ubuntu runner
18+
runs-on: ubuntu-latest
19+
20+
steps:
21+
# 4. Check out your repository's code
22+
- name: Checkout code
23+
uses: actions/checkout@v4
24+
25+
# 5. This step runs the script to increment the version
26+
- name: Bump version
27+
run: |
28+
PUBSPEC_FILE="pubspec.yaml"
29+
30+
# Get the current version line (e.g., "version: 1.0.0+1")
31+
VERSION_LINE=$(grep 'version: ' $PUBSPEC_FILE)
32+
33+
# Extract the version string (e.g., "1.0.0+1")
34+
VERSION=$(echo $VERSION_LINE | cut -d ' ' -f 2)
35+
36+
# Get base version (e.g., "1.0.0")
37+
BASE_VERSION=$(echo $VERSION | cut -d '+' -f 1)
38+
39+
# Get build number (e.g., "1")
40+
BUILD_NUMBER=$(echo $VERSION | cut -d '+' -f 2)
41+
42+
# Increment the build number
43+
NEW_BUILD_NUMBER=$((BUILD_NUMBER + 1))
44+
45+
# Create new version string (e.g., "1.0.0+2")
46+
NEW_VERSION="$BASE_VERSION+$NEW_BUILD_NUMBER"
47+
48+
# Replace the old version line with the new one in pubspec.yaml
49+
sed -i "s/version: .*/version: $NEW_VERSION/" $PUBSPEC_FILE
50+
51+
# Expose the new version as an environment variable for the next step
52+
echo "NEW_VERSION=$NEW_VERSION" >> $GITHUB_ENV
53+
shell: bash
54+
55+
# 6. This step commits the updated pubspec.yaml back to your repo
56+
- name: Commit and push changes
57+
run: |
58+
# Configure the git user for the commit
59+
git config --global user.name 'GitHub Actions Bot'
60+
git config --global user.email 'github-actions-bot@github.com'
61+
62+
# Add the modified file
63+
git add pubspec.yaml
64+
65+
# Commit the change
66+
# We MUST add [skip ci] to the commit message to prevent the loop
67+
git commit -m "ci: Bump version to ${{ env.NEW_VERSION }} [skip ci]"
68+
69+
# Push the commit
70+
git push

lib/src/components/bat.dart

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
import 'package:flame/collisions.dart';
22
import 'package:flame/components.dart';
33
import 'package:flame/effects.dart';
4-
import 'package:flame/events.dart';
54
import 'package:flutter/material.dart';
65

76
import '../brick_breaker.dart';
87

9-
class Bat extends PositionComponent
10-
with DragCallbacks, HasGameReference<BrickBreaker> {
8+
class Bat extends PositionComponent with HasGameReference<BrickBreaker> {
119
Bat({
1210
required this.cornerRadius,
1311
required super.position,
@@ -29,12 +27,6 @@ class Bat extends PositionComponent
2927
);
3028
}
3129

32-
@override
33-
void onDragUpdate(DragUpdateEvent event) {
34-
super.onDragUpdate(event);
35-
position.x = (position.x + event.localDelta.x).clamp(0, game.width);
36-
}
37-
3830
void moveBy(double dx) {
3931
add(
4032
MoveToEffect(
@@ -43,4 +35,4 @@ class Bat extends PositionComponent
4335
),
4436
);
4537
}
46-
}
38+
}

lib/src/components/play_area.dart

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,14 @@ import 'dart:async';
22

33
import 'package:flame/collisions.dart'; // Add this import
44
import 'package:flame/components.dart';
5+
import 'package:flame/events.dart';
56
import 'package:flutter/material.dart';
67

78
import '../brick_breaker.dart';
9+
import 'bat.dart';
810

9-
class PlayArea extends RectangleComponent with HasGameReference<BrickBreaker> {
11+
class PlayArea extends RectangleComponent
12+
with DragCallbacks, HasGameReference<BrickBreaker> {
1013
PlayArea()
1114
: super(
1215
paint: Paint()..color = const Color(0xfff2e8cf),
@@ -18,4 +21,11 @@ class PlayArea extends RectangleComponent with HasGameReference<BrickBreaker> {
1821
super.onLoad();
1922
size = Vector2(game.width, game.height);
2023
}
21-
}
24+
25+
@override
26+
void onDragUpdate(DragUpdateEvent event) {
27+
super.onDragUpdate(event);
28+
final bat = game.world.children.query<Bat>().first;
29+
bat.position.x = (bat.position.x + event.localDelta.x).clamp(0, game.width);
30+
}
31+
}

0 commit comments

Comments
 (0)