F-111 Simulation Code

Because I didn’t attach any audio files here, if you’re running the code you’ll have to delete anything that references audio or replace it with something, making sure the files are in the same location as this file.

//F-111 sim full demo

//Brian Franceschi

//Music credit to https://www.youtube.com/watch?v=R7p5kWPl7Xw

int xspacing = 1;
int w;
float planeheight = 300;
int i;
int beamheight;
int directionY = 5;
int dieDirectionY = 2;
int dieX = 375;
int dieY = 490;
float alpha = 0.0;
float amplitude = 158.0;
float period = 500.0;
float dx;
float[] yvalues;
float altitudeUp = 1.0075;
float altitudeDown = 1;
int points = 0;

//timer code
int actualSecs;
int actualMins;
int startSec = 0;
int startMin = 0;
int scrnSecs;
int scrnMins=0;
int restartSecs=0;
int restartMins=0;

import ddf.minim.*;

AudioPlayer player;
AudioPlayer player2;
Minim minim;//audio context

void setup() {
size(1080,720);
w = width+200;
dx = (TWO_PI / period) * xspacing;
beamheight = 300;
yvalues = new float[w/xspacing];
frameRate(220);
minim = new Minim(this);
player = minim.loadFile(“F-111 sim 2.mp3”, 2048);
player2 = minim.loadFile(“explosion.mp3”, 2048);
player.play();
PFont font;
}

void draw() {
background(0);
fill(250,100,100);
text(“OFF”, 70, 90);

//Timer: turns to night every 10 seconds
actualSecs = millis()/1000;
actualMins = millis() /1000 / 60;
scrnSecs = actualSecs – restartSecs;
scrnMins = actualMins – restartMins;

if (keyPressed == true){
if (key ==’a’){
restartSecs = actualSecs;
scrnSecs = startSec;
restartMins = actualMins;
scrnMins = startMin;
}
}
if (actualSecs % 60 == 0) {
restartSecs = actualSecs;
scrnSecs = startSec;
}

println(scrnSecs);
println(scrnMins);

textAlign(LEFT);
fill(255);
text(“Time:”,856,85);
text(nf(scrnMins, 2) + ” : ” + nf(scrnSecs, 2), 932, 85);

//TFR Zone
stroke(10,40,180,255);
strokeWeight(80);
line(0,280,width,280);
fill(0,0,0);
noStroke();
rect(275,250,150,20,3);
rect(340,250,20,65,3);

rect(435,250,150,20,3);
rect(435,250,20,65,3);
rect(435,280,110,20,3);

rect(595,250,150,20,3,10,3,3);
rect(595,267,150,20,3,3,10,3);
rect(595,250,20,65,3);
rect(700,250,20,65,3);
fill(10,40,180,255);
rect(615,269,115,8,3,10,10,3);
stroke(255,255,255);
fill(255,255,255);

//Scoring points. More points if you go lower
text(“Score: “+points,850,50);
points=points+1;
if((planeheight>250) && (planeheight<800)){
points=points+5;
player.play();
player2.rewind();
}

stroke(0);
calcWave();
renderWave();

//Setting the death sensor
//original: if(dieY > 510 || dieY < 200){
if(dieY > 510 || dieY < 200){
dieDirectionY = -1 * dieDirectionY;
}

dieY = dieY + dieDirectionY;

//Ceiling:
stroke(59,200,111,230);
strokeWeight(7);
line(0,110,1080,110);

//Death by ceiling:
if (planeheight < 110){
planeheight=planeheight+10000;
background(0,0,0);
textAlign(CENTER);
text(“you died.”,width/2,300);
points=points-1;
text(“Score: “+points,width/2,400);
textAlign(BASELINE);
player.pause();
player.rewind();
player2.play();
player2.rewind();
}
endShape();

fill(255,255,255);
noStroke();

ellipse(dieX,dieY,1,1);
//front radar (TFR):
fill(230,60,60,100);
beginShape();
vertex(405,planeheight);
vertex(850,-50+beamheight);
vertex(850,0+beamheight);
vertex(405,planeheight);
endShape();

//bottom radar (LARA):
beginShape();
noStroke();
vertex(380, planeheight);
vertex(350, planeheight+160);
vertex(410, planeheight+160);
vertex(380,planeheight);
endShape();
stroke(230,60,60,100);
strokeWeight(3);
line(320,planeheight+40,440,planeheight+40);
noStroke();
//F-111:
fill(200,200,200);
ellipse(370,planeheight,65,10);
beginShape();
vertex(342,planeheight);
vertex(330,planeheight-14);
vertex(345,planeheight-16);
vertex(372,planeheight);
endShape();
fill(255,255,255);
ellipse(375,planeheight+1,30,5);
//Description/labels:
textSize(25);
fill(255,255,255);
text(“F-111 Terrain Following Radar System”, 10, 30);
text(“ride control: Hard”, 10, 60);
text(“TFR: “, 10, 90);

//Manual up:
if (keyPressed == true) {
if(key== ‘w’){
planeheight = planeheight-altitudeUp*2;
}

//Manual down:
if(key==’s’){
planeheight = planeheight+altitudeDown*3;
}

//TFC on:
if(key==’d’){
if (yvalues[1000]>1) {
planeheight = planeheight-altitudeUp;
fill(0,0,0);
rect(70,70,70,25);
fill(100,255,100);
text(“ON!”, 70, 90);
}
else { planeheight = planeheight+altitudeDown;}
fill(0,0,0);
rect(70,70,70,25);
fill(100,255,100);
text(“ON!”, 70, 90);

}
}
else { planeheight = planeheight+altitudeDown;}

if(beamheight > 500 || beamheight < 200){
directionY = -1 * directionY;
}
beamheight = beamheight + directionY;

//Death by mountains:
if (dieY < planeheight){
planeheight=planeheight+10000;
background(0,0,0);
textAlign(CENTER);
text(“you died.”,width/2,300);
points=points-1;
text(“Score: “+points,width/2,400);
textAlign(BASELINE);
player.pause();
player.rewind();
player2.play();
}
else{
player.play();
}

//Reset game
if (key==’a’){
planeheight=180;
points=0;
player.play();
}

//Nighttime:
if(scrnSecs > 9 && scrnSecs < 20 || scrnSecs > 29 && scrnSecs < 40 || scrnSecs > 49 && scrnSecs < 60){

fill(0,0,0,255);
rect(0,105,1200,1200);
fill(255,255,255);

if (dieY < planeheight){
planeheight=planeheight+10000;
background(0,0,0);
textAlign(CENTER);
text(“you died.”,width/2,300);
text(“Score: “+points,width/2,400);

textAlign(BASELINE);
player.pause();
player.rewind();
player2.play();
}
}
//Wave creation. Basic sine wave ellipses originally from Daniel Shiffman:
//https://processing.org/examples/sinewave.html
}
void calcWave() {
alpha += 0.02;
float x = alpha;
for (int i = 0; i < yvalues.length; i++) {
yvalues[i] = sin(x)*amplitude;
x+=dx;
}

}

void renderWave() {
noStroke();
fill(59,200,111);
for (int x = 0; x < yvalues.length; x++) {
ellipse(x*xspacing, height/2-yvalues[x], 10, 10);
}

}