Skip to content

Instantly share code, notes, and snippets.

View Henry-E's full-sized avatar
😃

Henry-E

😃
View GitHub Profile
//All this should be in the GameManager Script
// initialise the list
public List<Transform> asteroids;
//this function will all you to use the ship's transform and the asteroid list to find the closest asteroid
void SortCharactersByDistance(Transform myTransform, List<Transform> characterList)
{
characterList.Sort (delegate(Transform t1, Transform t2){
return Vector3.Distance(t1.position, myTransform.position).CompareTo(
public class GameManager : MonoBehaviour
{
public static GameManager instance = null;
void Awake()
{
//Check if instance already exists
if (instance == null)
// this needs to go into the ship's AI script
public integer numFramesBetweenAICall;
integer currentFrame;
void Awake()
{
numFramesBetweenAICall = 5;
currentFrame = 0;
}
// this needs to go into the asteroid's update function.
// It might be prudent to store the gameHeight and gameWidth variables
// in the GameManager script and assign them to variables in this
// script on awake.
// I'm neglecting to add any initialisation here but I'm sure you know what to do
aWidth = GameManager.instance.gameWidth
aHeight = GameManager.instance.gameHeight
// inside the update function
// outside of the class, below "Using UnityEngine"
using Random = UnityEngine.Random;
// make sure to initialise this properly
fudgeFactor = 30;
// inside the update function
atan2 = Mathf.Atan2 (v_diff.y, v_diff.x);
Quaternion newAngle = Quaternion.Euler (0f, 0f, atan2 * Mathf.Rad2Deg + Random.Range( - fudgeFactor, fudgeFactor) );
//initialise this variable
shootingRangeDeg = 5f;
if( atan2 * mathf.Rad2Deb < shootingRangeDeg )
fire();
// all this code needs to go in the loop which initialises the asteroids
bool isStillCheckingLocation = true;
while(isStillCheckingLocation)
{
asteroidStartLocation = new Vector2 (UnityEngine.Random.Range (0, gameWidth),
UnityEngine.Random.Range (0, gameHeight));
// we need to make sure the asteroids are not spawned too close to the player
if( (asteroidStartLocation.x < gameWidth * 0.4f || asteroidStartLocation.x > gameWidth * 0.6f) &&
(asteroidStartLocation.y < gameHeight * 0.4f || asteroidStartLocation.y > gameHeight * 0.6f) )
isStillCheckingLocation = false;
#!/bin/bash
# make it easier to request interactive jobs
int ()
{
# there's issues with getopts working in functions if OPTIND isn't reset
# every time the function is called
local OPTIND;
# should we use gpu queue, defaults to cpu
@Henry-E
Henry-E / proxy_transfer.rs
Last active May 4, 2022 00:13
Very hacky PCA CPI
pub fn proxy_transfer(ctx: Context<ProxyTransfer>, amount: u64, nonce: u8) -> ProgramResult {
token::transfer(ctx.accounts.into(), amount)?;
// let seeds = &[TEST_SEED.as_bytes(), &[nonce]];
let seeds: &[&[u8]] = &[ctx.accounts.authority.to_account_info().key.as_ref(), &[nonce]];
let signer = &[&seeds[..]];
// let cpi_ctx = CpiContext::from(&*ctx.accounts).with_signer(signer);
let cpi_ctx = CpiContext::new_with_signer(
ctx.accounts.token_program.clone(),
@Henry-E
Henry-E / lib.rs
Created July 12, 2021 14:43
Serum New Order CPI
const BASE: u128 = 1_000_000
// Assumes limit price and coin amount have 6 decimals and the u64 int contains all decimal places
fn new_order(
&self,
side: Side,
limit_price: u64,
coin_amount: u64,
order_type: OrderType,
) -> ProgramResult {
let (price_lots, coin_lots, pc_lot_size) = {