Skip to content

Commit

Permalink
Merge branch 'main' into luan.firebase
Browse files Browse the repository at this point in the history
  • Loading branch information
spydon authored Jul 3, 2023
2 parents 351b267 + 4d2dc17 commit f13ad8c
Show file tree
Hide file tree
Showing 10 changed files with 116 additions and 15 deletions.
Binary file added assets/images/powerups/flame.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 added assets/images/powerups/invertase.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 added assets/images/powerups/melos.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 added assets/images/powerups/widgetbook.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion lib/game/components/bullet.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class Bullet extends CircleComponent with HasGameReference<LightRunnersGame> {
required this.velocity,
required this.color,
}) : super(
radius: bulletRadius,
radius: velocity.length / 32,
anchor: Anchor.center,
paint: GamePalette.bulletPaints[ownerPlayerNumber],
);
Expand Down
4 changes: 2 additions & 2 deletions lib/game/components/count_down.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class CountDown extends PositionComponent {
return TextPaint(
style: TextStyle(
fontFamily: GoogleFonts.bungee().fontFamily,
fontSize: 18,
fontSize: 28,
color: GamePalette.white,
),
);
Expand All @@ -39,7 +39,7 @@ class CountDown extends PositionComponent {
timer = timerComponent.timer;
add(timerComponent);

rRect = RRect.fromRectAndRadius(Vector2.zero() & Vector2(180, 50), _radius);
rRect = RRect.fromRectAndRadius(Vector2.zero() & Vector2(250, 60), _radius);
}

@override
Expand Down
88 changes: 88 additions & 0 deletions lib/game/components/powerup.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
import 'dart:math';

import 'package:flame/collisions.dart';
import 'package:flame/components.dart';
import 'package:flame/effects.dart';
import 'package:flame/experimental.dart';
import 'package:flame/extensions.dart';
import 'package:flame/geometry.dart';
import 'package:flutter/animation.dart';
import 'package:lightrunners/game/game.dart';

enum PowerUpType {
speed('invertase.png'),
shots('flame.png'),
secret('melos.png'),
weight('widgetbook.png');

const PowerUpType(this.asset);

final String asset;
}

class PowerUp extends SpriteComponent
with HasGameReference<LightRunnersGame>, CollisionCallbacks {
PowerUp()
: type = (PowerUpType.values.toList()..shuffle(_random)).first,
super(anchor: Anchor.center);

static final Random _random = Random();
final PowerUpType type;

@override
Future<void> onLoad() async {
super.onLoad();
sprite = await game.loadSprite('powerups/${type.asset}');
final sizeRelation = sprite!.image.height / sprite!.image.width;
final width = 50 + 50 * _random.nextDouble();
size = Vector2(width, sizeRelation * width);
position = Vector2.random(_random)
..multiply(game.playArea.deflate(width * 2).toVector2() / 2)
..multiply(
Vector2(_random.nextBool() ? 1 : -1, _random.nextBool() ? 1 : -1),
);

add(CircleHitbox()..collisionType = CollisionType.passive);
add(
ScaleEffect.by(
Vector2.all(1.3),
EffectController(duration: 1.0, alternate: true, infinite: true),
),
);
}

@override
void onCollisionStart(
Set<Vector2> intersectionPoints,
PositionComponent other,
) {
super.onCollisionStart(intersectionPoints, other);
if (other is Ship) {
removeAll(children);
affectShip(other);
addAll(
[
ScaleEffect.to(Vector2.all(0), EffectController(duration: 1.0)),
RotateEffect.by(
tau * 3,
EffectController(duration: 1.0, curve: Curves.elasticIn),
onComplete: removeFromParent,
),
],
);
}
}

void affectShip(Ship ship) {
switch (type) {
case PowerUpType.shots:
ship.bulletSpeed *= 2;
case PowerUpType.speed:
ship.engineStrength *= 2;
case PowerUpType.weight:
ship.weightFactor *= 2;
case PowerUpType.secret:
// Does absolutely nothing, very mysterious!
}
}
}
17 changes: 9 additions & 8 deletions lib/game/components/ship.dart
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,6 @@ class Ship extends SpriteComponent
KeyboardHandler,
HasGameReference<LightRunnersGame>,
CollisionCallbacks {
static const _engine = 125.0;
static const _drag = 5.0;
static const _bulletSpeed = 300.0;
static final _random = Random();

Ship(this.playerNumber, this.gamepadId)
Expand All @@ -102,6 +99,11 @@ class Ship extends SpriteComponent
int score = 0;
late final String spritePath;

double engineStrength = 125.0;
double bulletSpeed = 300.0;
double weightFactor = 1.0;
final double _drag = 5.0;

final Vector2 velocity = Vector2.zero();
final Vector2 drag = Vector2.zero();
final Vector2 engine = Vector2.zero();
Expand Down Expand Up @@ -131,7 +133,6 @@ class Ship extends SpriteComponent
parentSize: size,
),
);
debugMode = true;
}

void fire() {
Expand All @@ -141,7 +142,7 @@ class Ship extends SpriteComponent
Bullet(
ownerPlayerNumber: playerNumber,
position: positionOfAnchor(Anchor.topCenter),
velocity: bulletVector * _bulletSpeed,
velocity: bulletVector * bulletSpeed,
color: paint.color,
),
);
Expand Down Expand Up @@ -204,7 +205,7 @@ class Ship extends SpriteComponent

engine
..setFrom(move)
..scale(_engine);
..scale(engineStrength);
drag
..setFrom(velocity)
..scaleTo(_drag)
Expand Down Expand Up @@ -264,8 +265,8 @@ class Ship extends SpriteComponent
velocity.add(other.velocity..scale(0.1));
other.removeFromParent();
} else if (other is Ship && playerNumber < other.playerNumber) {
_nextVelocity.setFrom(other.velocity);
other.velocity.setFrom(velocity);
_nextVelocity.setFrom(other.velocity.scaled(other.weightFactor));
other.velocity.setFrom(velocity.scaled(weightFactor));
velocity.setFrom(_nextVelocity);
}
}
Expand Down
17 changes: 14 additions & 3 deletions lib/game/lightrunners_game.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ import 'dart:async';
import 'dart:math';
import 'dart:ui';

import 'package:flame/camera.dart';
import 'package:flame/components.dart';
import 'package:flame/game.dart';
import 'package:flame/input.dart';
import 'package:gamepads/gamepads.dart';
import 'package:lightrunners/game/components/background.dart';
import 'package:lightrunners/game/components/game_border.dart';
import 'package:lightrunners/game/components/powerup.dart';
import 'package:lightrunners/game/components/score_panel.dart';
import 'package:lightrunners/game/components/spotlight.dart';
import 'package:lightrunners/game/game.dart';
Expand Down Expand Up @@ -51,8 +52,8 @@ class LightRunnersGame extends FlameGame
world.addAll([Spotlight(), ...ships.values]);
add(world);

late CountDown countDown;
await add(
late final CountDown countDown;
add(
countDown = CountDown(
onTimeUp: () {
countDown.removeFromParent();
Expand All @@ -62,6 +63,16 @@ class LightRunnersGame extends FlameGame
},
),
);

add(
TimerComponent(
period: 10,
repeat: true,
onTick: () {
world.add(PowerUp());
},
),
);
}

void _createShips() {
Expand Down
3 changes: 2 additions & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ flutter:
- shaders/super_crt.glsl
assets:
- google_fonts/
- assets/audio/
- assets/images/
- assets/images/ships/
- assets/audio/
- assets/images/powerups/

0 comments on commit f13ad8c

Please sign in to comment.