Skip to content

Instantly share code, notes, and snippets.

@Tom-Ski
Tom-Ski / WeldTest.java
Created April 18, 2014 12:30
Box2d Application
package me.tomski.blobrun.desktop;
import com.badlogic.gdx.ApplicationListener;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.InputProcessor;
import com.badlogic.gdx.backends.lwjgl.LwjglApplication;
import com.badlogic.gdx.backends.lwjgl.LwjglApplicationConfiguration;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.OrthographicCamera;
@Tom-Ski
Tom-Ski / WeldTest.java
Created April 15, 2014 06:25
Weld Joint Test
package me.tomski.blobrun.desktop;
import com.badlogic.gdx.ApplicationListener;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.InputProcessor;
import com.badlogic.gdx.backends.lwjgl.LwjglApplication;
import com.badlogic.gdx.backends.lwjgl.LwjglApplicationConfiguration;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.math.Vector2;
@Tom-Ski
Tom-Ski / SleekCanvas.java
Created April 4, 2014 23:42
Move JFrame
addMouseListener(new MouseAdapter() {
public void mousePressed(MouseEvent e) {
point.x = e.getX();
point.y = e.getY();
}
});
addMouseMotionListener(new MouseMotionAdapter() {
public void mouseDragged(MouseEvent e) {
Point p = getLocation();
setLocation(p.x + e.getX() - point.x, p.y + e.getY() - point.y);
addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
Runtime.getRuntime().addShutdownHook(new Thread() {
public void run() {
Runtime.getRuntime().halt(0);
}
});
Gdx.app.exit();
}
private static class TomUtils {
public Vector2 youCantMakeMeDivideWhenNormalizing(Vector2 vec) {
float invMag = (vec.x * vec.x) + (vec.y * vec.y);
float invSq = suckItMaximtwo(invMag);
return vec.scl(invSq);
}
private float suckItMaximtwo(float invMag) {
float half = 0.5f * invMag;
@Tom-Ski
Tom-Ski / SkeletonRenderer.java
Last active August 29, 2015 13:56
headbang
public void draw (PolygonSpriteBatch batch, Skeleton skeleton) {
boolean premultipliedAlpha = this.premultipliedAlpha;
int srcFunc = premultipliedAlpha ? GL11.GL_ONE : GL11.GL_SRC_ALPHA;
batch.setBlendFunction(srcFunc, GL11.GL_ONE_MINUS_SRC_ALPHA);
boolean additive = false;
float[] vertices;
short[] triangles;
Texture texture;
@Tom-Ski
Tom-Ski / SkeletonTest.java
Created February 18, 2014 00:37
Skeleton attachments
/******************************************************************************
* Spine Runtimes Software License
* Version 2
*
* Copyright (c) 2013, Esoteric Software
* All rights reserved.
*
* You are granted a perpetual, non-exclusive, non-sublicensable and
* non-transferable license to install, execute and perform the Spine Runtimes
* Software (the "Software") solely for internal use. Without the written
@Tom-Ski
Tom-Ski / Box2DExample.java
Created February 15, 2014 04:07
This stuff
AtlasAttachmentLoader atlasLoader = new AtlasAttachmentLoader(atlas) {
public RegionAttachment newRegionAttachment (Skin skin, String name, String path) {
Box2dAttachment attachment = new Box2dAttachment(name);
AtlasRegion region = atlas.findRegion(attachment.getName());
if (region == null) throw new RuntimeException("Region not found in atlas: " + attachment);
attachment.setRegion(region);
return attachment;
}
};
SkeletonJson json = new SkeletonJson(atlasLoader);
@Tom-Ski
Tom-Ski / secretstuff.java
Created February 15, 2014 01:37
maximtwo is my hero
protected void loadFixtures(TiledMap map, World world) {
MapLayer fixturesLayer = map.getLayers().get("fixtures");
Array<PolylineMapObject> fixtures = fixturesLayer.getObjects().getByType(PolylineMapObject.class);
BodyDef bd = new BodyDef();
bd.type = BodyType.StaticBody;
groundBody = world.createBody(bd);
groundBody.setUserData(-1);
@Tom-Ski
Tom-Ski / build.gradle
Created February 14, 2014 17:17
Hoop Jumping
// called every time gradle gets executed, takes the native dependencies of
// the natives configuration, and extracts them to the proper libs/ folders
// so they get packed with the APK.
task copyAndroidNatives() {
file("libs/armeabi/").mkdirs();
file("libs/armeabi-v7a/").mkdirs();
configurations.natives.files.each { jar ->
def outputDir = null
if (jar.name.endsWith("natives-armeabi-v7a.jar")) outputDir = file("libs/armeabi-v7a")