fireworks added for every 5th coin gathered.

This commit is contained in:
Marco Salazar 2021-09-09 16:56:26 -06:00
parent 7689a62616
commit d56f87fef0
12 changed files with 235 additions and 46 deletions

Binary file not shown.

Binary file not shown.

94
assets/fonts/OFL.txt Normal file
View File

@ -0,0 +1,94 @@
Copyright (c) 2012, Font Diner (www.fontdiner.com),
with Reserved Font Name "Codystar".
This Font Software is licensed under the SIL Open Font License, Version 1.1.
This license is copied below, and is also available with a FAQ at:
http://scripts.sil.org/OFL
-----------------------------------------------------------
SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007
-----------------------------------------------------------
PREAMBLE
The goals of the Open Font License (OFL) are to stimulate worldwide
development of collaborative font projects, to support the font creation
efforts of academic and linguistic communities, and to provide a free and
open framework in which fonts may be shared and improved in partnership
with others.
The OFL allows the licensed fonts to be used, studied, modified and
redistributed freely as long as they are not sold by themselves. The
fonts, including any derivative works, can be bundled, embedded,
redistributed and/or sold with any software provided that any reserved
names are not used by derivative works. The fonts and derivatives,
however, cannot be released under any other type of license. The
requirement for fonts to remain under this license does not apply
to any document created using the fonts or their derivatives.
DEFINITIONS
"Font Software" refers to the set of files released by the Copyright
Holder(s) under this license and clearly marked as such. This may
include source files, build scripts and documentation.
"Reserved Font Name" refers to any names specified as such after the
copyright statement(s).
"Original Version" refers to the collection of Font Software components as
distributed by the Copyright Holder(s).
"Modified Version" refers to any derivative made by adding to, deleting,
or substituting -- in part or in whole -- any of the components of the
Original Version, by changing formats or by porting the Font Software to a
new environment.
"Author" refers to any designer, engineer, programmer, technical
writer or other person who contributed to the Font Software.
PERMISSION & CONDITIONS
Permission is hereby granted, free of charge, to any person obtaining
a copy of the Font Software, to use, study, copy, merge, embed, modify,
redistribute, and sell modified and unmodified copies of the Font
Software, subject to the following conditions:
1) Neither the Font Software nor any of its individual components,
in Original or Modified Versions, may be sold by itself.
2) Original or Modified Versions of the Font Software may be bundled,
redistributed and/or sold with any software, provided that each copy
contains the above copyright notice and this license. These can be
included either as stand-alone text files, human-readable headers or
in the appropriate machine-readable metadata fields within text or
binary files as long as those fields can be easily viewed by the user.
3) No Modified Version of the Font Software may use the Reserved Font
Name(s) unless explicit written permission is granted by the corresponding
Copyright Holder. This restriction only applies to the primary font name as
presented to the users.
4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font
Software shall not be used to promote, endorse or advertise any
Modified Version, except to acknowledge the contribution(s) of the
Copyright Holder(s) and the Author(s) or with their explicit written
permission.
5) The Font Software, modified or unmodified, in part or in whole,
must be distributed entirely under this license, and must not be
distributed under any other license. The requirement for fonts to
remain under this license does not apply to any document created
using the Font Software.
TERMINATION
This license becomes null and void if any of the above conditions are
not met.
DISCLAIMER
THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE
COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM
OTHER DEALINGS IN THE FONT SOFTWARE.

Binary file not shown.

Before

Width:  |  Height:  |  Size: 539 KiB

After

Width:  |  Height:  |  Size: 623 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 297 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 470 KiB

View File

@ -130,26 +130,30 @@ class CircuitBackground extends MovingObject {
current: WindowState.first,
);
windowA.changePriorityWithoutResorting(WINDOW_PRIORITY);
windowA.changePriorityWithoutResorting(WINDOW_PRIORITY);
setUp();
}
void setUp() {
windowA.current = WindowState.first;
windowB.current = WindowState.first;
gameRef.add(windowA);
gameRef.add(windowB);
// gameRef.add(windowA);
// gameRef.add(windowB);
background1Position = Vector2(0, 0);
background1Size = Vector2(
gameRef.size.y * (background.width / background.height),
gameRef.size.y);
gameRef.viewport.canvasSize.y * (background.width / background.height),
gameRef.viewport.canvasSize.y);
windowA.position = background1Position;
windowA.size = background1Size;
background2Position =
Vector2(background1Position.x + background1Size.x - 1, 0);
background2Size = Vector2(
gameRef.size.y * (background.width / background.height),
gameRef.size.y);
gameRef.viewport.canvasSize.y * (background.width / background.height),
gameRef.viewport.canvasSize.y);
windowB.position = background2Position;
windowB.size = background2Size;
}
@ -206,9 +210,13 @@ class CircuitBackground extends MovingObject {
void render(Canvas canvas) {
background1.render(canvas,
size: background1Size, position: background1Position);
// windowA.render(canvas);
canvas.save();
windowA.render(canvas);
canvas.restore();
background2.render(canvas,
size: background2Size, position: background2Position);
// windowB.render(canvas);
canvas.save();
windowB.render(canvas);
canvas.restore();
}
}

View File

@ -10,7 +10,7 @@ class Coin extends MovingObject {
SpriteAnimation normal = SpriteAnimation.fromFrameData(
coin,
SpriteAnimationData.sequenced(
amount: 10,
amount: 12,
stepTime: 0.1,
textureSize: Vector2(512, 512),
),

100
lib/firework.dart Normal file
View File

@ -0,0 +1,100 @@
import 'package:firo_runner/main.dart';
import 'package:flame/components.dart';
import 'package:flame/extensions.dart';
import 'package:flame/flame.dart';
enum FireworkState { normal }
class Firework extends Component {
MyGame gameRef;
late SpriteAnimationGroupComponent sprite1;
late SpriteAnimationGroupComponent sprite2;
Firework(this.gameRef);
double timeSinceFirework = 0;
String message = "";
Future load() async {
Image firework = await Flame.images.load("fireworks-frames.png");
SpriteAnimation normal = SpriteAnimation.fromFrameData(
firework,
SpriteAnimationData.sequenced(
amount: 9,
stepTime: 0.25,
textureSize: Vector2(512, 512),
loop: false,
),
);
sprite1 = SpriteAnimationGroupComponent(
animations: {
FireworkState.normal: normal,
},
current: FireworkState.normal,
);
sprite1.changePriorityWithoutResorting(FIREWORK_PRIORITY);
sprite1.update(100);
sprite1.size =
Vector2(gameRef.viewport.canvasSize.y, gameRef.viewport.canvasSize.y);
sprite1.position = Vector2(0, 0);
sprite2 = SpriteAnimationGroupComponent(
animations: {
FireworkState.normal: normal,
},
current: FireworkState.normal,
);
sprite2.changePriorityWithoutResorting(FIREWORK_PRIORITY);
sprite2.size =
Vector2(gameRef.viewport.canvasSize.y, gameRef.viewport.canvasSize.y);
sprite2.position =
Vector2(gameRef.viewport.canvasSize.x - sprite2.size.x, 0);
sprite2.update(100);
}
void setUp() {
message = "";
timeSinceFirework = 0;
gameRef.add(sprite1);
gameRef.add(sprite2);
}
@override
void update(double dt) {
if (!(sprite1.animation?.done() ?? false)) {
timeSinceFirework = 0;
} else {
timeSinceFirework += dt;
}
sprite1.update(dt);
sprite2.update(dt);
}
void renderText(Canvas canvas) {
sprite1.render(canvas);
sprite1.render(canvas);
if ((sprite1.animation?.done() ?? false) &&
timeSinceFirework < 1 &&
message != "") {
gameRef.fireworksPaint.render(
canvas,
message,
Vector2(
gameRef.size.x / 2 -
gameRef.fireworksPaint.measureTextWidth(message) / 2,
gameRef.size.y / 9 -
gameRef.fireworksPaint.measureTextHeight(message) / 2),
);
}
}
void reset() {
message = gameRef.gameState.numCoins.toString();
sprite1.animation!.reset();
sprite2.animation!.reset();
}
}

View File

@ -3,6 +3,7 @@ import 'dart:math';
import 'package:firo_runner/bug_holder.dart';
import 'package:firo_runner/circuit_background.dart';
import 'package:firo_runner/coin_holder.dart';
import 'package:firo_runner/firework.dart';
import 'package:firo_runner/game_state.dart';
import 'package:firo_runner/platform_holder.dart';
import 'package:firo_runner/wire.dart';
@ -10,7 +11,6 @@ import 'package:firo_runner/wire_holder.dart';
import 'package:flame/components.dart';
import 'package:flame/extensions.dart';
import 'package:flame/flame.dart';
import 'package:flame/game.dart' as flame;
import 'package:flame/game.dart';
import 'package:flame/gestures.dart';
import 'package:flame/keyboard.dart';
@ -32,10 +32,12 @@ const LEVEL6 = 50000000;
const LEVEL7 = 60000000;
const RUNNER_PRIORITY = 100;
const BUG_PRIORITY = 75;
const COIN_PRIORITY = 70;
const PLATFORM_PRIORITY = 50;
const WIRE_PRIORITY = 25;
const COIN_PRIORITY = 70;
const BUG_PRIORITY = 75;
const FIREWORK_PRIORITY = 15;
const WINDOW_PRIORITY = 10;
void main() async {
WidgetsFlutterBinding.ensureInitialized();
@ -46,8 +48,9 @@ void main() async {
}
class MyGame extends BaseGame with PanDetector, TapDetector, KeyboardEvents {
TextPaint textPaint = TextPaint(
config: const TextPaintConfig(fontSize: 48.0),
TextPaint fireworksPaint = TextPaint(
config: const TextPaintConfig(
fontSize: 48.0, fontFamily: 'Codystar', color: COLOR),
);
late CircuitBackground circuitBackground;
@ -55,6 +58,7 @@ class MyGame extends BaseGame with PanDetector, TapDetector, KeyboardEvents {
late CoinHolder coinHolder;
late WireHolder wireHolder;
late BugHolder bugHolder;
late Firework fireworks;
Random random = Random();
bool playingMusic = false;
@ -87,6 +91,8 @@ class MyGame extends BaseGame with PanDetector, TapDetector, KeyboardEvents {
await wireHolder.loadWires();
bugHolder = BugHolder();
await bugHolder.loadBugs();
fireworks = Firework(this);
await fireworks.load();
gameState = GameState();
@ -180,6 +186,7 @@ class MyGame extends BaseGame with PanDetector, TapDetector, KeyboardEvents {
void setUp() {
add(runner);
fireworks.setUp();
runner.sprite.clearEffects();
runner.sprite.current = RunnerState.run;
circuitBackground.setUp();
@ -202,9 +209,10 @@ class MyGame extends BaseGame with PanDetector, TapDetector, KeyboardEvents {
@override
void render(Canvas canvas) {
circuitBackground.render(canvas);
fireworks.renderText(canvas);
super.render(canvas);
final fpsCount = fps(1);
textPaint.render(
fireworksPaint.render(
canvas,
fpsCount.toString(),
Vector2(0, 0),
@ -213,6 +221,7 @@ class MyGame extends BaseGame with PanDetector, TapDetector, KeyboardEvents {
@override
void update(double dt) {
fireworks.update(dt);
platformHolder.removePast(this);
coinHolder.removePast(this);
wireHolder.removePast(this);

View File

@ -275,6 +275,9 @@ class Runner extends Component with HasGameRef<MyGame> {
for (int i = 0; i < coinLevel.length;) {
if (coinLevel[i].intersect(runnerRect) != "none") {
gameRef.gameState.numCoins++;
if (gameRef.gameState.numCoins % 5 == 0) {
gameRef.fireworks.reset();
}
gameRef.coinHolder.remove(coinLevel, i);
continue;
}
@ -376,9 +379,9 @@ class Runner extends Component with HasGameRef<MyGame> {
);
SpriteAnimation falling = await loadSpriteAnimation(
'hover-frames.png',
'fall-frames.png',
SpriteAnimationData.sequenced(
amount: 3,
amount: 7,
stepTime: 0.1,
textureSize: Vector2(512, 512),
),

View File

@ -52,33 +52,8 @@ flutter:
- assets/audio/
- assets/audio/sfx/
# To add assets to your application, add an assets section, like this:
# assets:
# - images/a_dot_burr.jpeg
# - images/a_dot_ham.jpeg
fonts:
- family: Codystar
fonts:
- asset: assets/fonts/Codystar-Regular.ttf
# An image asset can refer to one or more resolution-specific "variants", see
# https://flutter.dev/assets-and-images/#resolution-aware.
# For details regarding adding assets from package dependencies, see
# https://flutter.dev/assets-and-images/#from-packages
# To add custom fonts to your application, add a fonts section here,
# in this "flutter" section. Each entry in this list should have a
# "family" key with the font family name, and a "fonts" key with a
# list giving the asset and other descriptors for the font. For
# example:
# fonts:
# - family: Schyler
# fonts:
# - asset: fonts/Schyler-Regular.ttf
# - asset: fonts/Schyler-Italic.ttf
# style: italic
# - family: Trajan Pro
# fonts:
# - asset: fonts/TrajanPro.ttf
# - asset: fonts/TrajanPro_Bold.ttf
# weight: 700
#
# For details regarding fonts from package dependencies,
# see https://flutter.dev/custom-fonts/#from-packages