Skip to content

Instantly share code, notes, and snippets.

View AlabasterAxe's full-sized avatar
🍊
<= Look at this Orange

Matthew Keller AlabasterAxe

🍊
<= Look at this Orange
View GitHub Profile
@AlabasterAxe
AlabasterAxe / open-electron-shared-worker.js
Created March 23, 2022 20:41
Inspect Electron Shared Worker
const { webContents } = require('electron')
let rendererContents = webContents.getAllWebContents().find((x)=>x.getAllSharedWorkers().length > 0);
let sharedWorkerId = rendererContents.getAllSharedWorkers()[0].id;
rendererContents.inspectSharedWorkerById(sharedWorkerId);
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
import 'common.dart';
class ExplorePage extends StatefulWidget {
const ExplorePage({Key key}) : super(key: key);
@override
_ExplorePageState createState() => _ExplorePageState();
AnimatedBuilder(
animation: cardSwipeAnimationController,
builder: (context, snapshot) {
Offset translateOffset = Offset.fromDirection(direction, cardAnimationController.value);
return Transform.translate(
offset: Offset(translateOffset.dx, 0),
child: Card(
child: Center(
child: Text("${widget.displayNumber}",
@AlabasterAxe
AlabasterAxe / dino.dart
Created November 10, 2020 00:26
dinosaur's frame advancing logic
frame = (elapsedTime.inMilliseconds / 100).floor() % 2 + 3
@AlabasterAxe
AlabasterAxe / cloud.dart
Created November 10, 2020 00:18
Adding Parallax to the clouds for the Flutter Dino game.
@override
Rect getRect(Size screenSize, double runDistance) {
return Rect.fromLTWH(
(location.dx - runDistance) WORLD_TO_PIXEL_RATIO / 5,
2 / 7 screenSize.height - cloud.imageHeight - location.dy,
cloud.imageWidth.toDouble(),
cloud.imageHeight.toDouble());
}
@AlabasterAxe
AlabasterAxe / main.dart
Created November 10, 2020 00:17
Adding the ground to the GameObject rendering loop
for (GameObject object in [...ground, ...obstacles, dino]) {
children.add(
AnimatedBuilder(
animation: worldController,
builder: (context, child) {
Rect objectRect = object.getRect(screenSize, runDistance);
return Positioned(
top: objectRect.top,
left: objectRect.left,
width: objectRect.width,
@AlabasterAxe
AlabasterAxe / main.dart
Created November 10, 2020 00:16
maintaining the infinite ground
if (groundlet.getRect(screenSize, runDistance).right < 0) {
setState(() {
ground.remove(groundlet);
ground.add(Ground(
worldLocation: Offset(
ground.last.worldLocation.dx +
groundSprite.imageWidth / WORLD_TO_PIXEL_RATIO,
0)));
});
}
@AlabasterAxe
AlabasterAxe / main.dart
Created November 10, 2020 00:15
Initialize the ground objects for Flutter Dino Game
ground = [
Ground(location: Offset(0, 0)),
Ground(
location: Offset(groundSprite.imageWidth / WORLD_TO_PIXEL_RATIO, 0))
];
@AlabasterAxe
AlabasterAxe / ground.dart
Created November 10, 2020 00:15
Implementation of the ground for Flutter Dino Game
Sprite groundSprite = Sprite()
..imagePath = "assets/images/ground.png"
..imageWidth = 2399
..imageHeight = 24;
class Ground extends GameObject {
// this is a logical location which is translated to pixel coordinates
final Offset location;
Ground({this.location});
@override