NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io

import 'package:flame/game.dart';
import 'package:flame/gestures.dart';
import 'package:flutter/material.dart';

void main() {
runApp(GameWidget());
}

class GameWidget extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'My Game',
home: GameScreen(),
);
}
}

class GameScreen extends StatefulWidget {
@override
_GameScreenState createState() => _GameScreenState();
}

class _GameScreenState extends State<GameScreen>
with
SingleTickerProviderStateMixin,
TickerProviderStateMixin,
GestureRecognizerMixin {
Size screenSize;
double tileSize;
int score = 0;
bool gameOver = false;

AnimationController controller;
Animation<double> animation;

void _initializeGame() {
score = 0;
gameOver = false;
}

void _incrementScore() {
setState(() {
score++;
});
}

void _gameOver() {
gameOver = true;
controller.stop();
}

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

controller = AnimationController(
duration: const Duration(seconds: 1),
vsync: this,
);

animation = Tween<double>(begin: 0, end: 1).animate(controller)
..addListener(() {
setState(() {});
});

controller.repeat();
}

@override
void dispose() {
controller.dispose();
super.dispose();
}

@override
void resize(Size size) {
screenSize = size;
tileSize = screenSize.width / 9;
super.resize(size);
}

@override
void onTapDown(TapDownDetails details) {
if (gameOver) {
_initializeGame();
} else {
_incrementScore();
}
}

@override
void onTapUp(TapUpDetails details) {}

@override
void onTapCancel() {}

@override
void onLongPress() {}

@override
void onLongPressMoveUpdate(LongPressMoveUpdateDetails details) {}

@override
void onLongPressUp() {}

@override
Widget build(BuildContext context) {
return Scaffold(
body: GestureDetector(
onTapDown: onTapDown,
onTapUp: onTapUp,
onTapCancel: onTapCancel,
onLongPress: onLongPress,
onLongPressMoveUpdate: onLongPressMoveUpdate,
onLongPressUp: onLongPressUp,
child: Container(
decoration: BoxDecoration(
gradient: LinearGradient(
begin: Alignment.topLeft,
end: Alignment.bottomRight,
colors: [
Colors.blueGrey[800],
Colors.blueGrey[900],
],
),
),
child: Stack(
children: <Widget>[
Positioned(
top: 0,
left: 0,
right: 0,
bottom: 0,
child: AnimatedBuilder(
animation: animation,
builder: (BuildContext context, Widget child) {
return CustomPaint(
size: screenSize,
painter: BackgroundPainter(
animationValue: animation.value,
),
);
},
),
),
Positioned(
top: tileSize,
left: tileSize,
child: Text(
'Score: $score',
style: TextStyle(
fontSize: 24,
color: Colors.white,
),
),
),
gameOver
? Positioned.fill(
child: Center(
child: Text(
'Game Over',
style: TextStyle(
fontSize: 48,
color: Colors.white,
fontWeight: FontWeight.bold,
),
),
),
)
: Positioned(
top: tileSize * 2,
left: tileSize * 2,
child: Player(
onGameover: _gameOver,
),
),
],
),
),
),
);
}
}

class BackgroundPainter extends CustomPainter {
final double animationValue;

BackgroundPainter({this.animationValue});

@override
void paint(Canvas canvas, Size size) {
Paint paint = Paint()
..color = Colors.white.withOpacity(animationValue)
..style = PaintingStyle.fill;
canvas.drawRect(
Rect.fromLTWH(0, 0, size.width, size.height),
paint,
);
}

@override
bool shouldRepaint(BackgroundPainter oldDelegate) {
return oldDelegate.animationValue != animationValue;
}
}

class Player extends StatefulWidget {
final VoidCallback onGameover;

Player({this.onGameover});

@override
_PlayerState createState() => _PlayerState();
}

class _PlayerState extends State<Player> {
Offset position = Offset.zero;
double speed = 150;

@override
void initState() {
super.initState();
position = Offset(0, 0);
start();
}

void start() async {
while (true) {
await Future.delayed(Duration(milliseconds: 50));
setState(() {
position += Offset(speed * 0.05, speed * 0.05);
if (position.dx > 9 || position.dy > 16) {
widget.onGameover();
}
});
}
}

@override
Widget build(BuildContext context) {
return Container(
width: 50,
height: 50,
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(10),
),
child: Stack(
children: <Widget>[
Positioned(
left: 0,
right: 0,
top: 0,
bottom: 0,
child: Icon(
Icons.airplanemode_active,
size: 32,
),
),
],
),
);
}
}
     
 
what is notes.io
 

Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...

With notes.io;

  • * You can take a note from anywhere and any device with internet connection.
  • * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
  • * You can quickly share your contents without website, blog and e-mail.
  • * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
  • * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.

Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.

Easy: Notes.io doesn’t require installation. Just write and share note!

Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )

Free: Notes.io works for 12 years and has been free since the day it was started.


You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;


Email: [email protected]

Twitter: http://twitter.com/notesio

Instagram: http://instagram.com/notes.io

Facebook: http://facebook.com/notesio



Regards;
Notes.io Team

     
 
Shortened Note Link
 
 
Looding Image
 
     
 
Long File
 
 

For written notes was greater than 18KB Unable to shorten.

To be smaller than 18KB, please organize your notes, or sign in.