Skip to content

Instantly share code, notes, and snippets.

View jrenner's full-sized avatar

Jon Renner jrenner

  • Minneapolis, Minnesota, USA
View GitHub Profile
@jrenner
jrenner / astar.java
Created June 14, 2014 08:53
Libgdx A* A Star path finding example
package org.jrenner.tac.ai;
import com.badlogic.gdx.math.Vector3;
import com.badlogic.gdx.utils.Array;
import com.badlogic.gdx.utils.BinaryHeap;
import com.badlogic.gdx.utils.DelayedRemovalArray;
import com.badlogic.gdx.utils.GdxRuntimeException;
import com.badlogic.gdx.utils.ObjectFloatMap;
import com.badlogic.gdx.utils.ObjectMap;
import com.badlogic.gdx.utils.ObjectSet;
@jrenner
jrenner / heightmap.java
Created August 30, 2014 03:55
HeightMap.java
package org.jrenner.tac;
import com.badlogic.gdx.files.FileHandle;
import com.badlogic.gdx.graphics.Pixmap;
import com.badlogic.gdx.math.Vector3;
import com.badlogic.gdx.utils.GdxRuntimeException;
import org.jrenner.tac.utils.Tools;
/** Heightmap (heightfield) implementation with adjustable height/width scaling and iterative smoothing
* @author jrenner */
@jrenner
jrenner / box2d_air_resistance.java
Last active January 14, 2022 04:30
box2d air resistance
float dragForce;
Vector2 appliedDrag = new Vector2();
float dragAngle;
float p, A, Cd, v; // elements of the formula see wikipedia entry for Drag (physics)
/*
ρ is the density of the fluid,
v is the speed of the object relative to the fluid,
A is the cross-sectional area
Cd is the drag coefficient – a dimensionless number.
sample drag co-efficients (http://en.wikipedia.org/wiki/Drag_coefficient)
@jrenner
jrenner / generate.java
Last active January 7, 2016 00:10
font-generation-libgdx
private static void generateFonts() {
// if fonts are already generated, just load from file
Preferences fontPrefs = Gdx.app.getPreferences("org.jrenner.superior.font");
int displayWidth = fontPrefs.getInteger("display-width", 0);
int displayHeight = fontPrefs.getInteger("display-height", 0);
boolean loaded = false;
if (displayWidth != Gdx.graphics.getWidth() || displayHeight != Gdx.graphics.getHeight()) {
Tools.log.debug("Screen size change detected, regenerating fonts");
} else {
try {
fun main(args: Array<String>) {
val arr = array("cats", "dogs")
for (i in 0..10) {
println(arr.random())
}
// this version works fine
fun <T> Array<T>.random() : T {
val rand = Random()
return this.get(rand.nextInt(this.size))
float frameTime = dt;
if (frameTime > 0.5f) {
frameTime = 0.5f;
}
accumulatedDT += frameTime;
while (accumulatedDT >= Physics.TIME_STEP) {
frame++;
tick();
Physics.runPhysics();
//System.out.printf("ran physics - accum: %.3f\n", accumulatedDT);
@jrenner
jrenner / headless-test-libgdx
Created December 14, 2013 01:57
LwjglHeadlessApplication test server
package com.example.libgdx.skeleton;
import com.badlogic.gdx.ApplicationAdapter;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Net;
import com.badlogic.gdx.math.MathUtils;
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.net.ServerSocket;
import com.badlogic.gdx.net.Socket;
import com.badlogic.gdx.physics.box2d.Body;
float frameTime = dt;
if (frameTime > 0.5f) {
frameTime = 0.5f;
}
accumulatedDT += frameTime;
while (accumulatedDT >= Physics.TIME_STEP) {
frame++;
tick();
Physics.runPhysics();
//System.out.printf("ran physics - accum: %.3f\n", accumulatedDT);
@jrenner
jrenner / box2dproper.java
Created November 14, 2013 02:18
box2d working properly
package com.example.libgdx.skeleton;
import com.badlogic.gdx.ApplicationListener;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.GL10;
import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.math.Matrix4;
import com.badlogic.gdx.math.Rectangle;
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.physics.box2d.*;
@jrenner
jrenner / Desktop.java
Created September 10, 2013 14:04
a desktop launching class for libgdx with convenient screen size options, good for debugging
import com.badlogic.gdx.backends.lwjgl.LwjglApplication;
import com.badlogic.gdx.backends.lwjgl.LwjglApplicationConfiguration;
public class DesktopStarter {
private static final short FULLSCREEN = 0;
private static final short GALAXY_S3 = 1;
private static final short NEXUS_ONE = 2;
private static final short EVO3D = 3;
private static final short BIG_WINDOW = 4;
private static final short SMALL_PHONE = 5;