15 årig scout, tycker om nyheter, politik och datorer (FOSS)

  • 8 Posts
  • 228 Comments
Joined 1 year ago
cake
Cake day: September 20th, 2023

help-circle


















  • nice game! although I feel like some of the setups in tumbling ballistic are impossible to beat, although there just random. Anyways, here’s my very messy code:

    // Arguments:
    let {x_position, altitude, angle, userStore} = arguments[0];
    
    let target_angle = 0
    let x_thrust = 0
    
    ///////////////
    // Side slip //
    ///////////////
    
    let half = 159
    let ms = 400
    let target_speed = ((half - x_position) / half) * ms
    
    if (altitude < 150 || target_speed < 0.1 * ms)
      target_speed = 0
    
    if (!("px" in userStore)) {
      userStore.px = x_position
    }
    let dx = userStore.px - x_position
    userStore.px = x_position
    let xs = dx * 60 + target_speed
    let axs = xs > 0 ? xs : -xs
    
    target_angle = axs < 90 ? xs : 90 * (xs / axs)
    x_thrust = (axs / 90) * (target_angle  > 0 ? target_angle : -target_angle) * 1
    if (x_thrust > 1) {
      x_thrust = 1
    }
    x_thrust = x_thrust * ((target_angle  > 0 ? target_angle : -target_angle) / 90)
    
    let atas = altitude < 150 ? altitude / 150 : 1
    target_angle *= atas
    
    let ad = target_angle - angle
    let aad = ad > 0 ? ad : -ad
    
    let aa = angle > 0 ? angle : -angle
    
    let xtc90 = altitude < 500 ? (altitude / 500) * 30 : 30
    
    if (aa > 90 + xtc90 || aad > 45 || altitude < 200) {
      x_thrust = 0
    }
    
    //////////////
    // Altitude //
    //////////////
    
    if (!("da" in userStore)) {
      userStore.da = 0;
    }
    if (!("pa" in userStore)) {
      userStore.pa = altitude;
    }
    
    userStore.da = userStore.pa - altitude
    userStore.pa = altitude
    let as = userStore.da * 60
    
    let tas = altitude / 1.35 + 0.2
    let thrust = 0
    if (as > tas) {
      thrust = 1
    }
    let acb = 200 + (as > 250 ? 100 : 0)
    let angle_cutoff = altitude < acb ? 89 * (as / 200) : 35
    if (angle_cutoff > 89) angle_cutoff = 89
    if ((angle > 0 ? angle : -angle) > angle_cutoff) {
      thrust = 0
    }
    
    thrust += x_thrust
    if (thrust > 1) {
      thrust = 1
    }
    
    //////////////
    // Rotation //
    //////////////
    
    if (!("dr" in userStore)) {
      userStore.dr = 0;
    }
    if (!("pr" in userStore)) {
      userStore.pr = angle;
    }
    
    userStore.dr = userStore.pr - angle
    userStore.pr = angle
    let rs = userStore.dr * 60
    let ars = rs > 0 ? rs : -rs
    let rsrtm = 0.02
    let rt = (-(angle - target_angle) / 360) * 10 + rs * rsrtm
    
    let ardmc = 50
    if (ars < 30) ardmc = 0
    
    let rd = angle - target_angle
    let ard = (rd > 0 ? rs : -rd) + rs * ardmc
    
    let ard180_1 = 180 - (angle > 0 ? angle : -angle)
    let ard180_2 = 180 - (target_angle > 0 ? target_angle : -target_angle)
    let ard180 = ard180_1 + ard180_2 - rs * ardmc
    
    if (((target_angle > 0) != (angle > 0)) && ard180 < ard && false) {
      rt -= rs * rsrtm
      rt = -rt 
    }
    
    if (rt > 1) rt = 1;
    else if (rt < -1) rt = -1;
    
    // Return:
    return { rotThrust:rt, aftThrust:thrust,userStore:userStore };