Skip to content

Instantly share code, notes, and snippets.

View dwaard's full-sized avatar

Daan de Waard dwaard

  • HZ University of Applied Sciences
  • Str:omsund, Sweden
View GitHub Profile
@dwaard
dwaard / GameLoop.ts
Last active November 18, 2021 14:01
A basic Game Loop
import Game from './Game.js';
/**
* Represents a basic Game Loop based on `requestAnimationFrame()`.
*
* The implementation of this class depends on another class: `Game`. This
* means that, if you use this class, you need to either have a `Game` class
* that exactly implements the three methods `processInput()`, `update(elapsed)`
* and `render()` or change the code in the `step()` method of this class so it
* represents your own game methods.
@dwaard
dwaard / MouseListener.ts
Last active January 12, 2022 08:51
Example implementation of a class that listens to MouseEvents and holds the state of the mouse.
/**
* Listens to mouse events within the window and document and holds the current
* mouse state like position, buttons and whether or not the mouse is within the
* browser window.
*
* @author BugSlayer
*/
export default class MouseListener {
/*
* THESE ARE CONSTANTS THAT DEFINE THE DIFFERENT BUTTON STATES
@dwaard
dwaard / prices.html
Last active October 19, 2021 08:11
An html document used for some assignments based on a Bootstrap example
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="">
<meta name="author" content="Mark Otto, Jacob Thornton, and Bootstrap contributors">
<meta name="generator" content="Hugo 0.88.1">
<title>Pricing example · Bootstrap v5.1</title>
@dwaard
dwaard / 9ball.js
Created September 20, 2021 15:06
Pseudo code solution for the 9 ball problem
// Divide balls a - i into THREE groups.
// Use two of them to weigh on the scales, ignore the third
if (abc < ghi) {
// a, b or c must be lighter
// Take any two of these to compare, ignore the third
if ( a < c ) {
console.log("a is lighter");
} else if ( a == c ) {
console.log("b is lighter");
} else {
@dwaard
dwaard / HZ-HBOICT-PHPcs.yml
Created July 7, 2021 07:12
GitHub action for HZ-HBOICT Laravel projects
name: "HZ-HBOICT Laravel Style Check"
on:
pull_request:
paths:
- "**.php"
- "phpcs.xml"
- ".github/workflows/HZ-HBOICT-PHPcs.yml"
jobs:
@dwaard
dwaard / phpcs.xml
Last active April 11, 2024 12:25
PHP_CodeSniffer ruleset for HZ-HBOICT Laravel projects
<?xml version="1.0"?>
<!--
VERSION: 2.0
PHP_CodeSniffer ruleset tailored for HZ-HBOICT Laravel projects. This file defines
which files to check and what to check in each file. This will provide feedback to
students about their code quality.
This configuration is used in a GitHub action.
==================================
DO NOT CHANGE OR DELETE THIS FILE!
@dwaard
dwaard / notifications.blade.php
Created December 18, 2020 13:17
Bulma components for standard Laravel messages
@if (session('status')) {{-- status messages are for auth and password messages --}}
<div class="notification is-success">
<button class="delete"></button>
{{ session('status') }}
</div>
@endif
@if(session('info'))
<div class="notification is-info">
<button class="delete"></button>
{{ session('info') }}
@dwaard
dwaard / tasks.json
Created November 25, 2020 07:06
.vscode tasks for installing and building HZ Typescript projects
{
"version": "2.0.0",
"tasks": [
{
"type": "shell",
"command": "docker run --rm -it -v ${PWD}:/app -w=\"/app\" node:latest npm install",
"group": "build",
"problemMatcher": [],
"label": "npm: install (Docker)",
"detail": "install dependencies from package",
@dwaard
dwaard / GameLoop.ts
Created November 9, 2020 14:26
Example of an implementation of a Game Loop design pattern with "play catch up".
/**
* This class implements a game loop using the "Play catch up" method. It will
* update the game using a fixed time step because that makes everything simpler
* and more stable for physics and AI. But it will allow flexibility in when we
* render in order to free up some processor time.
*
* It goes like this: A certain amount of real time has elapsed since the last
* turn of the game loop. This is how much game time we need to simulate for the
* game’s “now” to catch up with the player’s. We do that using a series of
* fixed time steps.
@dwaard
dwaard / KeyListener.ts
Last active November 18, 2021 15:23
Example implementation of a class that listens to KeyboardEvents and holds the state of the keyboard.
/**
* This class handles the keyboard events. It knows the last known state of its
* keys
*
* Some parts of this class are pretty complex, but the class itself is fairly
* easy to use. You just instantiate one object in your game and us the method
* `isKeyDown()` to check if a specific key is currently pressed down by the
* user.
*
* NOTE: It is known that the MouseEvent.keyCode property is deprecated, which