Skip to content

Instantly share code, notes, and snippets.

View tedigc's full-sized avatar

ted tedigc

View GitHub Profile
@tedigc
tedigc / Animation.java
Last active September 20, 2016 19:03
Used for animated sprites in libGDX, but could easily be changed for some other framework.
import com.badlogic.gdx.graphics.g2d.Sprite;
/**
* @author tedigc
* @since 8-04-2016
*/
public class Animation {
private Sprite[] frames;
private int currentFrame;
@tedigc
tedigc / Pair.java
Last active September 20, 2016 14:58
ImmutablePair stolen from GitHub, stored here for convenience.
public class Pair<L,R> {
private final L left;
private final R right;
public Pair(L left, R right) {
this.left = left;
this.right = right;
}
@tedigc
tedigc / SpriteSheet.java
Created September 12, 2016 20:57
Easily reference individual sprites from a spritesheet.
import com.badlogic.gdx.assets.AssetManager;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
/**
* @author brokenbeach
* @since 12/09/2016
*/
public class SpriteSheet {
@tedigc
tedigc / frag.glsl
Last active September 10, 2017 19:48
default shader programs for libGDX
#ifdef GL_ES
precision mediump float;
#endif
varying vec4 v_color;
varying vec2 v_texCoords;
uniform sampler2D u_texture;
uniform mat4 u_projTrans;
void main() {
@tedigc
tedigc / Timer.java
Last active September 15, 2017 01:20
A simple Timer for libGDX projects
public class Timer {
private int delay;
private int elapsed;
private boolean running;
public Timer(int delay, boolean running) {
this.delay = delay;
this.running = running;
@tedigc
tedigc / opencv link commands
Created September 22, 2016 20:20
opencv's python port is a pain in the ass to get working. These are the commands needed to link to opencv on OSX.
@tedigc
tedigc / randomConvexPolygon()
Last active December 18, 2016 15:22
Generate a random convex polygon by dividing a circle's circumference into regions and connecting points randomly selected from each region.
/**
* Generate a random convex polygon by dividing a circle's circumference into regions and connecting points
* randomly selected from each region.
*
* @param nPoints the number of points the polygon will have
* @param radius the radius of the circle used to generate the polygon
*/
protected void defineHitbox(int nPoints, float radius) {
// calculate the size of the arc regions around the circle
@tedigc
tedigc / Palette.java
Last active September 15, 2017 01:05
All of the colours from @ENDESGA's edg32 palette, in order of hue
import com.badlogic.gdx.graphics.Color;
/**
* All of the colours from @ENDESGA's edg32 palette, in order of hue
*/
public class Palette {
static final public Color WHITE = define(255, 255, 255);
static final public Color PINE = define(116, 63, 57);
static final public Color TETANUS = define(190, 74, 47);
@tedigc
tedigc / line(v1, v1)
Created September 16, 2017 15:44
calculate a line of points between two vectors
static public ArrayList<Vector2> line(Vector2 v1, Vector2 v2) {
int x = (int) v1.x;
int y = (int) v1.y;
int x2 = (int) v2.x;
int y2 = (int) v2.y;
ArrayList<Vector2> result = new ArrayList<Vector2>();
int w = x2 - x ;
int h = y2 - y ;
@tedigc
tedigc / HtmlLauncher.java
Last active December 26, 2017 23:54
A not-ugly HTML launcher and loading screen for libGDX
package com.halfcut.galaxygarden.client;
import com.badlogic.gdx.ApplicationListener;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.backends.gwt.GwtApplication;
import com.badlogic.gdx.backends.gwt.GwtApplicationConfiguration;
import com.badlogic.gdx.backends.gwt.preloader.Preloader;
import com.badlogic.gdx.graphics.Pixmap;
import com.google.gwt.canvas.client.Canvas;
import com.google.gwt.canvas.dom.client.Context2d;