Skip to content

Instantly share code, notes, and snippets.

View OutlawGameTools's full-sized avatar

J. A. Whye OutlawGameTools

View GitHub Profile
@OutlawGameTools
OutlawGameTools / Missile.js
Created April 4, 2015 05:39
CS109 - Attach to the rocket to allow firing, exploding, and resetting.
#pragma strict
public var xSpeed : int;
public var ySpeed : int;
public var randomX : boolean = false;
public var minXSpeed : int = 100;
public var maxXSpeed : int = 200;
public var randomY : boolean = false;
@OutlawGameTools
OutlawGameTools / getneighbors.lua
Created April 9, 2015 09:43
Pass in an index into a 2-dimensional square grid and get back a table containing the index of all neighbor squares.
--==============================================================
-- pass in a lily pad number and get back a
-- table containing all the neighbors for
-- that lily pad.
local numCols = 11
local numRows = 7
local function getNeighbors(padNum)
@OutlawGameTools
OutlawGameTools / Accelerate.js
Created April 23, 2015 05:11
CS109 - Add force to a game object when mouse button is pressed; stop adding when button is up.
#pragma strict
public var rocket : GameObject; // object to push
public var xSpeed : float = 0; // horizontal speed
public var ySpeed : float = 400; // vertical speed
private var rb2D : Rigidbody2D;
function Start ()
{
@OutlawGameTools
OutlawGameTools / GoToSceneButton.cs
Created September 5, 2015 03:52
Use on a UI button click event to go to another scene.
using UnityEngine;
using System.Collections;
public class GoToSceneButton : MonoBehaviour {
public void GoToScene(string sceneName)
{
Application.LoadLevel (sceneName);
}
@OutlawGameTools
OutlawGameTools / DriftingText.cs
Created September 5, 2015 03:58
Used with DOTween to make message, scores, etc., float up (or down) and fade out.
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
using DG.Tweening;
public class DriftingText : MonoBehaviour {
public GameObject canvas;
public GameObject textPrefab;
public float driftTime = 1f;
@OutlawGameTools
OutlawGameTools / DragWithMouse.cs
Created November 21, 2015 02:40
Drag a 2D game object using the mouse. Game Object must have a Collider2D component.
using UnityEngine;
using System.Collections;
public class DragWithMouse : MonoBehaviour {
private Vector3 offset;
void OnMouseDown () {
Vector3 mousePos = new Vector3(Input.mousePosition.x, Input.mousePosition.y, 0);
offset = transform.position - Camera.main.ScreenToWorldPoint(mousePos);
using UnityEngine;
using System.Collections;
public class SpawnAnimal : MonoBehaviour {
public GameObject animalPrefab;
public Sprite[] animalSprites;
public void MakeRandomAnimal()
{
@OutlawGameTools
OutlawGameTools / Animal.cs
Created November 21, 2015 02:48
Attached to an animal prefab. For the "Many Game Objects from One Prefab and an Array of Sprites" tutorial.
using UnityEngine;
using System.Collections;
public class Animal : MonoBehaviour {
private Vector2 origPos;
public string animalName;
public bool returnToOrigin = false;
void Start () {
@OutlawGameTools
OutlawGameTools / ScreenCoords.lua
Created January 4, 2016 11:56
Corona SDK. Local vars that hold the most commonly used screen coordinates.
-- most commonly used screen coordinates
local centerX = display.contentCenterX
local centerY = display.contentCenterY
local screenLeft = display.screenOriginX
local screenWidth = display.viewableContentWidth - screenLeft * 2
local screenRight = screenLeft + screenWidth
local screenTop = display.screenOriginY
local screenHeight = display.viewableContentHeight - screenTop * 2
local screenBottom = screenTop + screenHeight
local screenTopSB = screenTop + display.topStatusBarContentHeight -- when status bar is showing
@OutlawGameTools
OutlawGameTools / StringExplode.lua
Created January 4, 2016 12:00
Corona SDK. Use like split -- pass in divider character and a string and get back a table/array holding each piece between the dividers.
-- works like PHP explode() function
function explode(div,str) -- credit: http://richard.warburton.it
if (div=='') then return false end
local pos,arr = 0,{}
-- for each divider found
for st,sp in function() return string.find(str,div,pos,true) end do
table.insert(arr,string.sub(str,pos,st-1)) -- Attach chars left of current divider
pos = sp + 1 -- Jump past current divider
end
table.insert(arr,string.sub(str,pos)) -- Attach chars right of last divider