Skip to content
This repository has been archived by the owner on Mar 6, 2024. It is now read-only.

Commit

Permalink
Merge branch 'main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
Peddinti-Sriram-Bharadwaj authored Jan 1, 2024
2 parents 513c94b + d599132 commit 21dc31c
Show file tree
Hide file tree
Showing 22 changed files with 153 additions and 14 deletions.
2 changes: 1 addition & 1 deletion android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<application
android:label="Super Dash"
android:name="${applicationName}"
android:icon="@mipmap/launcher_icon">
android:icon="@mipmap/ic_launcher">
<activity
android:name=".MainActivity"
android:screenOrientation="portrait"
Expand Down
2 changes: 0 additions & 2 deletions android/app/src/main/res/drawable/launch_background.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Modify this file to customize your launch splash screen -->
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@android:color/white" />

Expand Down
16 changes: 16 additions & 0 deletions android/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
<foreground android:drawable="@mipmap/ic_launcher_foreground" />

<background>
<inset
android:insetBottom="18dp"
android:insetLeft="18dp"
android:insetRight="18dp"
android:insetTop="18dp">
<shape android:shape="oval">
<solid android:color="#5ec7db" />
</shape>
</inset>
</background>
</adaptive-icon>
Binary file removed android/app/src/main/res/mipmap-hdpi/ic_launcher.png
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed android/app/src/main/res/mipmap-mdpi/ic_launcher.png
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed android/app/src/main/res/mipmap-xhdpi/ic_launcher.png
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed icon.png
Binary file not shown.
131 changes: 126 additions & 5 deletions lib/game/components/player_camera_anchor.dart
Original file line number Diff line number Diff line change
@@ -1,17 +1,131 @@
import 'package:flame/components.dart';
import 'package:flame/effects.dart';
import 'package:flutter/material.dart';
import 'package:super_dash/game/super_dash_game.dart';

class CameraBounds extends PositionComponent {
CameraBounds({
required this.reference,
required this.bound,
this.showBounds = false,
});

final PositionComponent reference;
final double bound;
final bool showBounds;

late final Vector2 referenceOffset;

double translateValue = 0;
double translatedValue = 0;

void _updatePosition(double dt) {
position.x = reference.position.x + referenceOffset.x;

final playerPosition = reference.position.y + referenceOffset.y;
final difference = playerPosition - position.y;
if (difference.abs() > bound) {
translateValue = difference;
}

if (translateValue.abs() > 0) {
final translationDifference =
(translateValue.abs() - translatedValue.abs()) / translateValue.abs();
var speed = 1.0 - translationDifference;
speed = 1 - speed * speed * speed * speed;

final step = (800 * speed) * dt * translateValue.sign;

position.y += step;
translatedValue += step.abs();

if (translateValue.abs() - translatedValue.abs() < 10) {
translateValue = 0;
translatedValue = 0;
}
}
}

@override
void onMount() {
super.onMount();

referenceOffset = Vector2(
reference.size.x,
reference.size.y,
);
position.y = reference.position.y + referenceOffset.y;

_updatePosition(0);

if (showBounds) {
const referenceLine = 150.0;
add(
RectangleComponent(
position: Vector2(
-referenceLine / 2,
-bound,
),
size: Vector2(
referenceLine,
2,
),
paint: Paint()..color = Colors.red,
),
);

add(
RectangleComponent(
position: Vector2(
-referenceLine / 2,
0,
),
size: Vector2(
referenceLine,
2,
),
paint: Paint()..color = Colors.green,
),
);

add(
RectangleComponent(
position: Vector2(
-referenceLine / 2,
bound,
),
size: Vector2(
referenceLine,
2,
),
paint: Paint()..color = Colors.red,
),
);
}
}

@override
void update(double dt) {
super.update(dt);

_updatePosition(dt);
}
}

class PlayerCameraAnchor extends Component
with ParentIsA<PositionComponent>
with ParentIsA<PositionComponent>, HasGameRef<SuperDashGame>
implements ReadOnlyPositionProvider {
PlayerCameraAnchor({
required this.levelSize,
required this.cameraViewport,
this.showCameraBounds = false,
});

final Vector2 levelSize;
final Vector2 cameraViewport;
final Vector2 _anchor = Vector2.zero();
late final PositionComponent _bounds;
final bool showCameraBounds;

late final Vector2 _cameraMin = Vector2(
cameraViewport.x * .4,
Expand All @@ -36,8 +150,15 @@ class PlayerCameraAnchor extends Component
}

@override
Future<void> onLoad() async {
await super.onLoad();
void onMount() {
super.onMount();

_bounds = CameraBounds(
reference: parent,
bound: 128,
showBounds: showCameraBounds,
);
gameRef.world.add(_bounds);

final value = parent.position.clone();
_setAnchor(value.x, value.y);
Expand All @@ -48,8 +169,8 @@ class PlayerCameraAnchor extends Component
super.update(dt);

_setAnchor(
parent.position.x,
parent.position.y,
_bounds.position.x,
_bounds.position.y,
);
}
}
1 change: 1 addition & 0 deletions lib/game/entities/player.dart
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ class Player extends JumperCharacter<SuperDashGame> {
cameraAnchor = PlayerCameraAnchor(
cameraViewport: cameraViewport,
levelSize: levelSize,
showCameraBounds: gameRef.inMapTester,
);

add(cameraAnchor);
Expand Down
15 changes: 9 additions & 6 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -78,19 +78,22 @@ flutter:
- assets/sfx/

flutter_launcher_icons:
android: 'launcher_icon'
image_path: 'android_icon.png'
android: true
adaptive_icon_foreround: "./android_icon.png"
adaptive_icon_background: "#5ec7db"
min_sdk_android: 26
image_path: './android_icon.png'
ios: 'ios_icon.png'
min_sdk_android: 21 # android min sdk min:16, default 21
remove_alpha_ios: true
web:
generate: true
image_path: 'icon.png'
image_path: 'android_icon.png'
background_color: '#0046a3'
theme_color: '#5ec7db'
windows:
generate: true
image_path: 'icon.png'
image_path: 'android_icon.png'
icon_size: 48 # min:48, max:256, default: 48
macos:
generate: true
image_path: 'icon.png'
image_path: 'android_icon.png'
Binary file modified web/favicon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified web/icons/Icon-192.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified web/icons/Icon-512.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified web/icons/Icon-maskable-192.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified web/icons/Icon-maskable-512.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 21dc31c

Please sign in to comment.