This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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( |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class GameManager : MonoBehaviour | |
{ | |
public static GameManager instance = null; | |
void Awake() | |
{ | |
//Check if instance already exists | |
if (instance == null) | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// this needs to go into the ship's AI script | |
public integer numFramesBetweenAICall; | |
integer currentFrame; | |
void Awake() | |
{ | |
numFramesBetweenAICall = 5; | |
currentFrame = 0; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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) ); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//initialise this variable | |
shootingRangeDeg = 5f; | |
if( atan2 * mathf.Rad2Deb < shootingRangeDeg ) | |
fire(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(), |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) = { |
OlderNewer