제조공정
| × | 1 | ||||
| × | 1 | ||||
| × | 1 | ||||
| × | 1 | ||||
| × | 1 | ||||
| × | 1 | ||||
| × | 5 | ||||
| × | 10 | ||||
| × | 1 | ||||
| × | 1 |
저는 Arduino 스타터 키트의 MAXX7219 매트릭스 및 구성 요소의 "4 in 1" 세트인 Arduino UNO를 사용하여 이 게임을 만들었습니다.
코드는 제가 작성했으며 Max72xxPanel, Adafruit GFX 및 SPI 라이브러리를 사용했습니다.
한 번 해보고 UFO를 날려보세요! :-)
각 레벨에는 보스가 나타나기 전에 죽일 UFO의 목표 수가 있습니다.
게임에는 Atari 호환 9핀 조이스틱이 필요합니다. 따라서 주변에 오래된 것이 있으면 다시 넣어 사용할 수 있습니다. 아니면 직접 만들 수도 있습니다. 나는 이것을 향후 버전에서 핸드헬드로 만들기 위해 노력하고 있습니다.
섹션> <섹션 클래스="섹션 컨테이너 섹션 축소 가능" id="코드">
/*UFO 공격! - 저자 앤서니 클라크 *//*오픈 소스 예제 프로그램에서 일부 특정 코드 줄을 가져왔습니다. 주석에 레이블이 지정되어 있습니다.*/#include섹션>#include #include const int pinCS =10; // CS를 이 핀에 연결하고 DIN을 MOSI에 연결하고 CLK를 SCK에 연결합니다(cf http://arduino.cc/en/Reference/SPI )const int numberOfHorizontalDisplays =4;const int numberOfVerticalDisplays =1;Max72xxPanel matrix =Max72xxPanel(pinCS, [numberOfHorizontalDisplays, numberOfVerticalDisplays);// '배', 8x8pxconst unsigned char ship [] PROGMEM ={ 0x80, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0008픽셀 ]const,foMEM ={ 0x40, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};// '폭발', 8x8pxconst unsigned char 폭발;// 'Bouncer', 8x8pxconst unsigned char bounder [] PROGMEM ={ 0x60, 0xc0, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00};// 'unBoss1', 보스 [80MEM =unBoss1', ]signed8pxcons 0x24, 0x42, 0xff, 0x24, 0xff, 0x7e, 0x3c};// 'Faller', 8x8pxconst unsigned char faller [] PROGMEM ={ 0x80, 0xc0, 0xe0, 0x000, 0/0' 라이저', 8x8pxconst unsigned char 라이저 [] PROGMEM ={ 0xe0, 0xc0, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00};// 'LT', 8x8pxconst unsigned char LT [] PROGMEM ={ 0x78, 0xfc, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0808 레이저 ' [] PROGMEM ={ 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};// 'BossBoom', 8x8pxconst unsigned char bossBoom1 0xa5 0xa1 [] PROGMEM ={ 0x55a, 0x55a, Defining , 0x55};// 'BossBoom2', 8x8pxconst unsigned char bossBoom2 [] PROGMEM ={ 0x55, 0xaa, 0x45, 0x8a, 0x51, 0xa2, 0x55, 0xaa 변수 제어 조이스틱 시작 =게임 시작 pinint up =2;int down =3;int left =4;int right =5;int trigger =6;//Ticker 변수 제목..티커 예제에서 뻔뻔하게 훔쳤습니다. :PString tape ="UFO ATTACK! - 발사를 시작하려면 ";int wait =40; // 밀리초 단위sint spacer =1;int width =5 + spacer; // 글꼴 너비는 5픽셀입니다. // 선박 및 레이저 위치 변수int shipx =0;int shipy =0;int lasx;int lasy;//수명 카운터int 생활 =5;//레이저 존재 변수bool lasExist;//UFO 레이저 위치 변수int ufoLas1x;int ufoLas1y;int ufoLas2x;int ufoLas2y;int ufoLas3x;int ufoLas3x;int ufoLasufoLas;//UFO 레이저 존재 변수bool ufoLasExist1 =false;bool ufoLasExist2 =false;bool ufoLasExist3 =false;bool ufoLasExist4 =false;//UFO 레이저 선택 변수int 선택;int lastSelection;//보스 미니언 선택 변수int minionSelectionint;//UFO 위치 변수 ufo1x;int ufo1y;int ufo2x;int ufo2y;int ufo3x;int ufo3y;//경력 위치 변수int 경비자1x;int 경비1y;int 경비2x;int 경비2y;int 경비3x;int 경비3y;int 경비4x;int 경비원4y;/ faller1x;int faller1y;int faller2x;int faller2y;int faller3x;int faller3y;int faller4x;i riserynt faller4y;//하강 속도 변수int faller1Speedx;int faller1Speedy;int faller2Speedx;int faller2Speedy;int faller3Speedx;int faller3Speedy;int faller4Speedx;int faller4Speedy;int fallerxSpeedTarget =2;int fallerxSpeedTarget =2;;int 라이저2x;int 라이저2y;int 라이저3x;int 라이저3y;int 라이저4x;int 라이저4y;//라이저 속도 변수int 라이저1Speedx;int 라이저1Speedy;int 라이저2Speedx;int 라이저2Speedy;int 라이저3Speedx;int 라이저3Speedy/Speedx;int 라이저3Speedy;int 위치 변수int ltx;int lty;//LT 건강 변수int ltHealth =3;//LT 속도 변수int ltxSpeed =0;int ltxSpeedTarget =2;//보스 위치 변수int bossx =34;int bossy =0;//보스 이동 속도 변수int bossxSpeed =0;int bossySpeed =0;int bossxSpeedTarget =3;int bossySpeedTarget =1; //UFO 존재 변수bool ufo1Exist =false;bool ufo2Exist =false;bool ufo3Exist =false;//Bouncer 존재 변수bool bounder1Exist =false;bool bouncer2Exist =false;bool bounder3Exist =false;bool bounder4Exist =false;//Faller 존재 변수bool faller1 false;bool faller2Exist =false;bool faller3Exist =false;bool faller4Exist =false;//라이저 존재 변수bool riser1Exist =false;bool riser2Exist =false;bool riser3Exist =false;bool riser4Exist =false;//LT 존재 변수bool ltExist =false; //Boss1 존재 변수bool boss1Exist =false;//보스 건강 변수int bossHealth;//Bouncer top or bottom variableint bouncerOrigin;//Bouncer gap space variableint bouncerGap =6;//Bouncer 방향 변수bool bouncer1Direction;bool bounder2Direction;bool bouncer3Direction;bool bouncer;int 경비자1xSpeed;int 경비자2xSpeed;int 경비자3xSpeed;int 경비4xSpeed;int 경비1ySpeed;int 경비2ySpeed;int 경비3ySpeed;int 경비4ySpeed;int ySpe d =1;int xSpeed =2; // UFO 적의 스폰 타이머 및 스폰 시간 변수unsigned long startTime; // 타이머 변수 설정 unsigned long currentTime; unsigned long spawnTime =3000; //UFO의 스폰 타이머 // 경비원의 스폰 타이머 및 스폰 시간unsigned long startTime2;unsigned long currentTime2;unsigned long spawnTime2 =10000; // 경비원을 위한 스폰 타이머 // LT 미니 보스를 위한 스폰 타이머unsigned long startTime3;unsigned long currentTime3;unsigned long spawnTime3; //LT를 위한 스폰 타이머//UFO 레이저를 위한 스폰 타이머sunsigned long bossStartTime;unsigned long bossCurrentTime;unsigned long bossStartTime2;unsigned long bossCurrentTime2;unsigned long bossLaserTimer =1000;unsigned long bossMinionTimer =6000;//Spawn enabler 변수에 필요, 보스 battlebool spawnEnabled에 대한 스폰;//레벨 변수int levelNumber =1;//변수 변수int score =0;//레벨 진행 변수int kills;int killsTarget;//보스 전투 참여 변수bool bossBattleStarted =false;//플레이어 함선 충돌 감지 변수bool collisionDetection =true;//UFOLaser 4 선택을 위한 동전 뒤집기int coinFlip;//사운드 변수int buzzerPin =9;//보스 사이렌 변수float sinVal; // 사인 값을 저장할 변수 정의 int toneVal; // 사운드 주파수를 저장할 변수 정의 void setup() { //Serial.begin(9600); //사운드 핀 설정 pinMode(buzzerPin, OUTPUT); // 버저 핀을 출력 모드로 설정 // 스폰 타이머 설정 // 조이스틱 작동을 위한 핀 모드 설정 pinMode(up, INPUT_PULLUP); //UP 핀 pinMode(down, INPUT_PULLUP); //DOWN 핀 pinMode(왼쪽, INPUT_PULLUP); //LEFT 핀 pinMode(오른쪽, INPUT_PULLUP); //오른쪽 핀 pinMode(트리거, INPUT_PULLUP); //FIRE 핀 //LED 강도 설정 matrix.setIntensity(0);// 필요에 맞게 조정합니다. matrix.setPosition(0, 3, 0); // 첫 번째 디스플레이는 <0, 0>에 있습니다. matrix.setPosition(1, 2, 0); // 두 번째 디스플레이는 <1, 0>에 있습니다. matrix.setPosition(2, 1, 0); // 세 번째 디스플레이는 <2, 0>에 있습니다. matrix.setPosition(3, 0, 0); // 그리고 마지막 디스플레이는 <3, 0>// ... matrix.setRotation(0, 3); // 첫 번째 디스플레이는 거꾸로 된 위치입니다. matrix.setRotation(1, 3); matrix.setRotation(2, 3); matrix.setRotation(3, 3); // 마지막 디스플레이에 대한 동일한 유지 matrix.fillScreen(LOW);}void loop() { if (gameStart ==false) { Ticker(true); } SpawnTimer(); 조이스틱 컨트롤(); UfoControl(); 경비원 컨트롤(); 레이저 컨트롤(); 화면 제한(); 보스전(); 보스컨트롤(); UFOLaserControl(); LT컨트롤(); 폴러컨트롤(); 라이저 컨트롤(); 선박 충돌(); //Serial.println(ufoLas1x); matrix.write();//draw screen delay(50);//속도 지연 matrix.fillScreen(LOW);//화면 지우기, 매 프레임마다 수행되어야 합니다. }void Level(int level){ if (level ==1) { spawnEnabled =true; //스폰 생성 활성화 spawnTime =3000; //UFO의 스폰 타이머 spawnTime2 =10000000; // 경비원의 스폰 타이머는 너무 높게 설정되어 절대 나타나지 않습니다. spawnTime3 =10000000; //LT의 스폰 타이머가 너무 높게 설정되어 절대 나타나지 않습니다. killsTarget =10; //킬 타겟을 설정합니다. 목표에 도달하면 보스가 생성되어야 합니다. bossHealth =10; 보스 레이저 타이머 =1000; } if (레벨 ==2) { spawnEnabled =true; 스폰 시간 =3000; 스폰시간2 =8000; 스폰타임3 =10000000; killsTarget =20; 보스 건강 =15; 보스 레이저 타이머 =900; } if (레벨 ==3) { spawnEnabled =true; 스폰 시간 =2000; 스폰 시간2 =6000; 스폰시간3 =8000; killsTarget =30; 보스 건강 =20; 보스 레이저 타이머 =800; } if (레벨 ==4) { spawnEnabled =true; 스폰 시간 =2000; 스폰 시간2 =5000; 스폰시간3 =7000; killsTarget =40; 보스 건강 =25; 보스 레이저 타이머 =700; 보스미니온 타이머 =6000; } if (레벨 ==5) { spawnEnabled =true; 스폰 시간 =1800; 스폰 시간2 =4500; 스폰시간3 =6000; killsTarget =50; 보스 건강 =30; 보스 레이저 타이머 =600; 보스미니온 타이머 =5500; } if (레벨 ==6) { spawnEnabled =true; 스폰 시간 =2000; 스폰 시간2 =5000; 스폰시간3 =7000; killsTarget =60; 보스 건강 =35; 보스 레이저 타이머 =500; 보스미니온 타이머 =5000; } if (레벨 ==7) { spawnEnabled =true; 스폰 시간 =2000; 스폰 시간2 =5000; 스폰시간3 =7000; killsTarget =70; 보스 건강 =40; 보스 레이저 타이머 =400; 보스미니온 타이머 =4000; } if (레벨 ==8) { spawnEnabled =true; 스폰 시간 =2000; 스폰 시간2 =5000; 스폰시간3 =7000; killsTarget =80; 보스 건강 =45; 보스 레이저 타이머 =300; 보스미니온 타이머 =3000; } if (레벨 ==9) { spawnEnabled =true; 스폰 시간 =2000; 스폰 시간2 =5000; 스폰시간3 =7000; killsTarget =90; 보스 건강 =50; 보스 레이저 타이머 =200; 보스미니온 타이머 =2000; } if (레벨 ==10) { spawnEnabled =true; 스폰 시간 =2000; 스폰 시간2 =5000; 스폰시간3 =7000; killsTarget =100; 보스 건강 =55; 보스 레이저 타이머 =100; 보스미니온 타이머 =1000; } //레벨 10 달성 축하 메시지 추가 필요}void Ticker(bool resetKills) //Ticker 예제에서 뻔뻔하게 훔친 티커 코드. 제목 및 점수 및 게임 오버에 사용{ while (gameStart ==false) { for ( int i =0; i =0 &&letter>=0 ) { if ( letter 29) { shipx =29; } if (shipy <0) { shipy =0; } if (shipy> 6) { shipy =6; } if (lasExist ==true) //화면이 꺼지면 그리기를 멈추고 존재하지 않는 것으로 표시합니다. { if (lasx> 31) { lasExist=false; } if (레이시 <0) { 레이시 =0; } if (레이지> 7) { 레이지 =7; } } //UFO 레이저 화면 제한 제어 if (ufoLas1x <-2) { ufoLasExist1 =false; } if (ufoLas2x <-2) { ufoLasExist2 =거짓; } if (ufoLas3x <-2) { ufoLasExist3 =거짓; } if (ufoLas4x <-2) { ufoLasExist4 =거짓; } //UFO 화면 제한 컨트롤. UFO가 왼쪽을 벗어나면 오른쪽의 임의의 Y 좌표에서 자동으로 다시 생성됩니다. if (ufo1Exist ==true &&ufo1x <-3) { ufo1x =33; //UFO가 왼쪽에서 벗어나면 다시 오른쪽으로 이동합니다. ufo1y =random(0,7); // ufo의 겹침을 중지하려면 일종의 정렬 코드가 필요합니다. } if (ufo2Exist ==true &&ufo2x <-3) { ufo2x =33; // UFO가 왼쪽에서 벗어나면 다시 오른쪽으로 이동합니다. ufo2y =random(0,7); // ufo의 겹침을 중지하려면 일종의 정렬 코드가 필요합니다. } if (ufo3Exist ==true &&ufo3x <-3) { ufo3x =33; // UFO가 왼쪽에서 벗어나면 다시 오른쪽으로 이동합니다. ufo3y =random(0,7); // ufo의 겹침을 중지하려면 일종의 정렬 코드가 필요합니다. } //Bouncer 화면 제한 컨트롤. 경비원이 위 또는 아래를 치면 방향 변수가 변경됩니다. 왼쪽에서 벗어나면 존재에서 지워지고 나중에 리스폰됩니다. if (bouncer1Exist ==true &&bouncer1y> 5) { bounder1Direction =false; } else if (bouncer1Exist ==true &&bouncer1y <0) { bouncer1Direction =true; } if (bouncer2Exist ==true &&bouncer2y> 5) { bouncer2Direction =false; } else if (bouncer2Exist ==true &&bouncer2y <0) { bouncer2Direction =true; } if (bouncer3Exist ==true &&bouncer3y> 5) { bounder3Direction =false; } else if (bouncer3Exist ==true &&bouncer3y <0) { bouncer3Direction =true; } if (bouncer4Exist ==true &&bouncer4y> 5) { bounder4Direction =false; } else if (bouncer4Exist ==true &&bouncer4y <0) { bouncer4Direction =true; } // 경비원이 왼쪽에서 벗어나면 디스폰된 것으로 사라집니다. if (bouncer1x <0) { 경비원1Exist =false; } if (bouncer2x <0) { bounder2Exist =false; } if (bouncer3x <0) { bouncer3Exist =false; } if (bouncer4x <0) { bounder4Exist =false; } //LT 화면 제한 제어 if (ltExist ==true &<x <-6) { ltx =33; // LT가 왼쪽에서 벗어나면 다시 오른쪽으로 이동합니다. lty =random(0,6); } //라이저에 대한 화면 제한 제어 if (faller1Exist ==true &&faller1y> 7) { faller1Exist =false; } if (faller2Exist ==true &&faller2y> 7) { faller2Exist =false; } if (faller3Exist ==true &&faller3y> 7) { faller3Exist =false; } if (faller4Exist ==true &&faller4y> 7) { faller4Exist =false; } //Screen limit controls for Risers if (riser1Exist ==true &&riser1y <-2) { riser1Exist =false; } if (riser2Exist ==true &&riser2y <-2) { riser2Exist =false; } if (riser3Exist ==true &&riser3y <-2) { riser3Exist =false; } if (riser4Exist ==true &&riser4y <-2) { riser4Exist =false; } }void SpawnTimer(){ if (spawnEnabled ==true) { //Counting spawn timer currentTime =millis(); //get the current time in milliseconds currentTime2 =millis();//same again for second timer currentTime3 =millis();//and again if (currentTime - startTime>=spawnTime) //Uses the currentTime, startTime and spawnTime variables to spawn enemies on set times { //spawn UFO SpawnUFO(); //reset timer startTime =currentTime; //Saves the start time of the spawn so the if statement works } if (currentTime2 - startTime2>=spawnTime2) { //spawn bouncer squad SpawnBouncer(); //reset timer startTime2 =currentTime2; //Saves the start time of the spawn so the if statement works } if (currentTime3 - startTime3>=spawnTime3) { //spawn LT SpawnLT(); //reset timer startTime3 =currentTime3; //Saves the start time of the spawn so the if statement works } } }void SpawnUFO(){ if (ufo1Exist ==false) { ufo1x =32; //Spawn off the right side of the screen ufo1y =random(0,7); //Spawn at a random Y coord ufo1Exist =true; } else if (ufo2Exist ==false) { ufo2x =32; //Spawn off the right side of the screen ufo2y =random(0,7); //Spawn at a random Y coord ufo2Exist =true; } else if (ufo3Exist ==false) { ufo3x =32; //Spawn off the right side of the screen ufo3y =random(0,7); //Spawn at a random Y coord ufo3Exist =true; } }void UfoControl(){ //If the UFO exists then draw its bitmap if (ufo1Exist ==true) { ufo1x--; matrix.drawBitmap(ufo1x,ufo1y,ufo,3,2,1); } if (ufo2Exist ==true) { ufo2x--; matrix.drawBitmap(ufo2x,ufo2y,ufo,3,2,1); } if (ufo3Exist ==true) { ufo3x--; matrix.drawBitmap(ufo3x,ufo3y,ufo,3,2,1); }}void SpawnBouncer(){ if (bouncer1Exist ==false &&bouncer2Exist ==false &&bouncer3Exist ==false &&bouncer4Exist ==false) { bouncer1x =32; //Spawn off the right side of the screen bouncer2x =bouncer1x+bouncerGap;//spawn other bouncers spaced out on the x axis bouncer3x =bouncer2x+bouncerGap; bouncer4x =bouncer3x+bouncerGap; bouncerOrigin =random(0,2); if (bouncerOrigin =0) { bouncer1y =0; //Spawn at top of screen bouncer2y =1; bouncer3y =2; bouncer4y =3; } if (bouncerOrigin =1) { bouncer1y =7; //Spawn at bottom bouncer2y =6; bouncer3y =5; bouncer4y =4; } bouncer1Exist =true; bouncer2Exist =true; bouncer3Exist =true; bouncer4Exist =true; }}void BouncerControl(){ //Bouncer move across to the left and up or down depending opn direction variable. That variable is changed in ScreenLimit() if (bouncer1Exist ==true) //If bouncer exists then increment bouncer x and y counters. These are used to slow the movement. { bouncer1xSpeed++; bouncer1ySpeed++; if (bouncer1xSpeed> xSpeed) //When the counter goes above the speed value then IF statement executes { bouncer1x--; bouncer1xSpeed =0; } if (bouncer1Direction ==true) { if (bouncer1ySpeed> ySpeed) { bouncer1y++; bouncer1ySpeed =0; } } else if (bouncer1Direction ==false) { if (bouncer1ySpeed> ySpeed) { bouncer1y--; bouncer1ySpeed =0; } } matrix.drawBitmap(bouncer1x,bouncer1y,bouncer,2,3,1); } if (bouncer2Exist ==true) { bouncer2xSpeed++; bouncer2ySpeed++; if (bouncer2xSpeed> xSpeed) { bouncer2x--; bouncer2xSpeed =0; } if (bouncer2Direction ==true) { if (bouncer2ySpeed> ySpeed) { bouncer2y++; bouncer2ySpeed =0; } } else if (bouncer2Direction ==false) { if (bouncer2ySpeed> 2) { bouncer2y--; bouncer2ySpeed =0; } } matrix.drawBitmap(bouncer2x,bouncer2y,bouncer,2,3,1); } if (bouncer3Exist ==true) { bouncer3xSpeed++; bouncer3ySpeed++; if (bouncer3xSpeed> xSpeed) { bouncer3x--; bouncer3xSpeed =0; } if (bouncer3Direction ==true) { if (bouncer3ySpeed> ySpeed) { bouncer3y++; bouncer3ySpeed =0; } } else if (bouncer3Direction ==false) { if (bouncer3ySpeed> 2) { bouncer3y--; bouncer3ySpeed =0; } } matrix.drawBitmap(bouncer3x,bouncer3y,bouncer,2,3,1); } if (bouncer4Exist ==true) { bouncer4xSpeed++; bouncer4ySpeed++; if (bouncer4xSpeed> xSpeed) { bouncer4x--; bouncer4xSpeed =0; } if (bouncer4Direction ==true) { if (bouncer4ySpeed> 2) { bouncer4y++; bouncer4ySpeed =0; } } else if (bouncer4Direction ==false) { if (bouncer4ySpeed> ySpeed) { bouncer4y--; bouncer4ySpeed =0; } } matrix.drawBitmap(bouncer4x,bouncer4y,bouncer,2,3,1); }}void SpawnFaller(){ if (faller1Exist ==false &&faller2Exist ==false &&faller3Exist ==false &&faller4Exist ==false) { faller1x =15; //Spawn above the boss off the top of the screen faller2x =faller1x+bouncerGap;//spawn other bouncers spaced out on the x axis faller3x =faller2x+bouncerGap; faller4x =faller3x+bouncerGap; faller1y =-1; //Spawn at top of screen faller2y =-2; faller3y =-3; faller4y =-4; faller1Exist =true; faller2Exist =true; faller3Exist =true; faller4Exist =true; }}void FallerControl(){ //Fallers are spawned by the Boss during battle after level 4. Timer for spawning is in the BossControl function. //Control routines for faller 1 if (faller1Exist ==true) //If faller exists then increment fallerSpeed x and y counters. These are used to slow the movement. { faller1Speedx++; faller1Speedy++; if (faller1Speedx> fallerxSpeedTarget) //When the counter goes above the speed value then IF statement executes { faller1x--; faller1Speedx =0; } if (faller1Speedy> fallerySpeedTarget) { faller1y++; faller1Speedy =0; } matrix.drawBitmap(faller1x,faller1y,faller,3,3,1); }// Control routines for faller 2 if (faller2Exist ==true) //If faller exists then increment fallerSpeed x and y counters. These are used to slow the movement. { faller2Speedx++; faller2Speedy++; if (faller2Speedx> fallerxSpeedTarget) //When the counter goes above the speed value then IF statement executes { faller2x--; faller2Speedx =0; } if (faller2Speedy> fallerySpeedTarget) { faller2y++; faller2Speedy =0; } matrix.drawBitmap(faller2x,faller2y,faller,3,3,1); } // Control routines for faller 3 if (faller3Exist ==true) //If faller exists then increment fallerSpeed x and y counters. These are used to slow the movement. { faller3Speedx++; faller3Speedy++; if (faller3Speedx> fallerxSpeedTarget) //When the counter goes above the speed value then IF statement executes { faller3x--; faller3Speedx =0; } if (faller3Speedy> fallerySpeedTarget) { faller3y++; faller3Speedy =0; } matrix.drawBitmap(faller3x,faller3y,faller,3,3,1); } // Control routines for faller 4 if (faller4Exist ==true) //If faller exists then increment fallerSpeed x and y counters. These are used to slow the movement. { faller4Speedx++; faller4Speedy++; if (faller4Speedx> fallerxSpeedTarget) //When the counter goes above the speed value then IF statement executes { faller4x--; faller4Speedx =0; } if (faller4Speedy> fallerySpeedTarget) { faller4y++; faller4Speedy =0; } matrix.drawBitmap(faller4x,faller4y,faller,3,3,1); } }void SpawnRiser(){ if (riser1Exist ==false &&riser2Exist ==false &&riser3Exist ==false &&riser4Exist ==false) { riser1x =15; //Spawn above the boss off the top of the screen riser2x =riser1x+bouncerGap;//spawn other bouncers spaced out on the x axis riser3x =riser2x+bouncerGap; riser4x =riser3x+bouncerGap; riser1y =7; //Spawn at Bottom of screen riser2y =8; riser3y =9; riser4y =10; riser1Exist =true; riser2Exist =true; riser3Exist =true; riser4Exist =true; }}void RiserControl(){ //Risers are spawned by the Boss during battle after level 5. Timer for spawning is in the BossControl function. //Control routines for riser 1 if (riser1Exist ==true) //If riser exists then increment riserSpeed x and y counters. These are used to slow the movement. { riser1Speedx++; riser1Speedy++; if (riser1Speedx> fallerxSpeedTarget) //When the counter goes above the speed value then IF statement executes { riser1x--; riser1Speedx =0; } if (riser1Speedy> fallerySpeedTarget) { riser1y--; riser1Speedy =0; } matrix.drawBitmap(riser1x,riser1y,riser,3,3,1); } //Control routines for riser 2 if (riser2Exist ==true) //If riser exists then increment riserSpeed x and y counters. These are used to slow the movement. { riser2Speedx++; riser2Speedy++; if (riser2Speedx> fallerxSpeedTarget) //When the counter goes above the speed value then IF statement executes { riser2x--; riser2Speedx =0; } if (riser2Speedy> fallerySpeedTarget) { riser2y--; riser2Speedy =0; } matrix.drawBitmap(riser2x,riser2y,riser,3,3,1); } //Control routines for riser 3 if (riser3Exist ==true) //If riser exists then increment riserSpeed x and y counters. These are used to slow the movement. { riser3Speedx++; riser3Speedy++; if (riser3Speedx> fallerxSpeedTarget) //When the counter goes above the speed value then IF statement executes { riser3x--; riser3Speedx =0; } if (riser3Speedy> fallerySpeedTarget) { riser3y--; riser3Speedy =0; } matrix.drawBitmap(riser3x,riser3y,riser,3,3,1); } //Control routines for riser 4 if (riser4Exist ==true) //If riser exists then increment riserSpeed x and y counters. These are used to slow the movement. { riser4Speedx++; riser4Speedy++; if (riser4Speedx> fallerxSpeedTarget) //When the counter goes above the speed value then IF statement executes { riser4x--; riser4Speedx =0; } if (riser4Speedy> fallerySpeedTarget) { riser4y--; riser4Speedy =0; } matrix.drawBitmap(riser4x,riser4y,riser,3,3,1); }}void SpawnLT(){ if (ltExist ==false) { ltx =32; //Spawn off the right side of the screen lty =random(0,6); //Spawn at a random Y coord ltExist =true; }}void LTControl(){ //If the UFO exists then draw its bitmap if (ltExist ==true) { ltxSpeed++; if (ltxSpeed ==ltxSpeedTarget) { ltxSpeed =0; ltx--; } matrix.drawBitmap(ltx, lty, LT, 6, 3, 1); } if (ltHealth <=0) { ltExist =false; Boom(ltx,lty,false,3); //Calls Boom() function to add score. Kills are added manually below. kills=kills+3; ltHealth =3; }}void BossBattle()//Sounds the warning siren then spawns boss. Still need to finish movement{ if (kills> killsTarget &&bossBattleStarted ==false) { bossBattleStarted =true; spawnEnabled =false; //Turns off spawning for other UFO types for(int i =5; i> 0; i--) //Play alarm sound { for (int x =0; x <360; x++) // X from 0 degree->360 degree { sinVal =sin(x * (PI / 180)); // Calculate the sine of x toneVal =2000 + sinVal * 500; // Calculate sound frequency according to the sine of x tone(buzzerPin, toneVal); // Output sound frequency to buzzerPin delay(1); } } tone(buzzerPin, 0, 5); //This is to stop the tone sound. It sticks around otherwise. if (boss1Exist ==false) { matrix.drawBitmap(bossx, bossy, boss, 8 ,8 ,1); boss1Exist =true; bossStartTime =millis(); //Set start timer for boss weapons bossStartTime =millis(); //Set start timer for boss minions } }}void BossControl(){ if (boss1Exist ==true) { bossxSpeed++; if (bossxSpeed> bossxSpeedTarget &&bossx> 24) //When the counter goes above the speed value then IF statement executes { bossx--; //Move the boss x cords to the left bossxSpeed =0; } matrix.drawBitmap(bossx, bossy, boss, 8, 8, 1); //Draw the boss bitmap at the new coords if (bossx ==24) { //Counting shoot timer bossCurrentTime =millis(); //get the current time in milliseconds bossCurrentTime2 =millis(); if (bossCurrentTime - bossStartTime>=bossLaserTimer) //startTimer is set in BossBattle function { //shoot laser selection =random(1,5);//Select laser cannon at random while (selection ==lastSelection)//While loop to ensure that the same laser isnt fired twice in a row too quick. Prevents timing gaps { selection =random(1,5); } UFOLaserShoot(selection);//Call UFOLaserShoot function with cannon selection //reset timer bossStartTime =bossCurrentTime; //Saves the start time of the spawn so the if statement works } if (levelNumber>=4) { if (bossCurrentTime2 - bossStartTime2>=bossMinionTimer) //startTimer is set in BossBattle function { //Select minions and spawn them minionSelection =random(1,3); if (minionSelection ==1) { SpawnFaller(); } if (minionSelection ==2) { SpawnRiser(); } //reset timer bossStartTime2 =bossCurrentTime2; //Saves the start time of the spawn so the if statement works } } } //Boss health counter hits zero, trigger boss death and new level if (bossHealth <=0) { boss1Exist =false; //Boss no longer exists Boom(bossx,bossy,false,5);//Calls Boom() function to add score matrix.fillScreen(LOW); //Clear screen for (int i =5; i> 0; i--) { matrix.drawBitmap(bossx, bossy, bossBoom1 ,8 ,8, 1); //Boss explosion first frame tone(buzzerPin, 100,100); //Play sound delay(200); //Wait //matrix.fillScreen(LOW); //Clear screen matrix.drawBitmap(bossx, bossy, bossBoom2 ,8 ,8, 1); //Boss explosion second frame tone(buzzerPin, 200,100); //Play second sound delay(200); //Wait } tone(buzzerPin, 1, 1);//Stop beep bossx=39; //Move bossx back to 32 matrix.fillScreen(LOW); //clear the screen gameStart =false; //Mark game as stopped levelNumber++; //increment level if (levelNumber> 10) { GameOver(1); 반품; } tape ="Level "; //Prepare new tape for ticker function tape +=levelNumber; //Adding level number to ticker string tape +=" Score:"; tape +=score; ufoLasExist1 =false; ufoLasExist2 =false; ufoLasExist3 =false; ufoLasExist4 =false; faller1Exist =false; faller2Exist =false; faller3Exist =false; faller4Exist =false; riser1Exist =false; riser2Exist =false; riser3Exist =false; riser4Exist =false; ufoLas1x=bossx; ufoLas2x=bossx; ufoLas3x=bossx; ufoLas4x=bossx; Ticker(true); //Call ticker function to show score and new level } }}void UFOLaserShoot(int selection){ if (selection ==1) { if (ufoLasExist1 ==false)//Check to see if the UFO laser already exists { ufoLas1x=bossx+1; //spawn laser in the middle ufoLas1y=bossy+4; ufoLasExist1=true; tone(buzzerPin, 200,100);//play laser sound } } if (selection ==2) { if (ufoLasExist2 ==false) { ufoLas2x=bossx+2; //spawn laser at the top side ufoLas2y=bossy+1; ufoLasExist2=true; tone(buzzerPin, 300,100);//play laser sound } } if (selection ==3) { if (ufoLasExist3 ==false) { ufoLas3x=bossx+2; //spawn laser at the bottom side ufoLas3y=bossy+7; ufoLasExist3=true; tone(buzzerPin, 400,100);//play laser sound } } if (selection ==4) { if (ufoLasExist4 ==false)//Planning to make this one random { coinFlip =random(0,2); if (coinFlip ==0) { ufoLas4x=bossx+2; ufoLas4y=bossy+2; ufoLasExist4=true; tone(buzzerPin, 500,100);//play laser sound } if (coinFlip ==1) { ufoLas4x=bossx+2; ufoLas4y=bossy+6; ufoLasExist4=true; tone(buzzerPin, 500,100);//play laser sound } } } }void UFOLaserControl(){ if (ufoLasExist1 ==true) { ufoLas1x--; matrix.drawBitmap(ufoLas1x, ufoLas1y, ufoLaser, 2, 1, 1); } if (ufoLasExist2 ==true) { ufoLas2x--; matrix.drawBitmap(ufoLas2x, ufoLas2y, ufoLaser, 2, 1, 1); } if (ufoLasExist3 ==true) { ufoLas3x--; matrix.drawBitmap(ufoLas3x, ufoLas3y, ufoLaser, 2, 1, 1); } if (ufoLasExist4 ==true) { ufoLas4x--; matrix.drawBitmap(ufoLas4x, ufoLas4y, ufoLaser, 2, 1, 1); } }void ShipCollision(){ if (gameStart ==true &&collisionDetection ==true) { //Collision detection for line 0 of ship //Collision detection for UFO1. Dont need line 0 of UFO because line 0 of ship cannot touch it anyway. if (ufo1Exist ==true) { for (int a =0; a <2; a++) { if (shipx ==ufo1x+a &&shipy ==ufo1y+1) ///Line 1 { ShipHit(); } } //Collision detection for line 1 of ship.................. //Contains extra for loop to loop through all the ship line 1 pixels //Collision detection for UFO1 for (int b =0; b <1; b++) //Had b <2 and the collision detection worked but looked wonky when moving towards ufos { for (int a =0; a <2; a++) { if (shipx+b ==ufo1x+a &&shipy+1 ==ufo1y+1) //Line 1 { ShipHit(); } } for (int a =1; a <3; a++) { if (shipx+b ==ufo1x+a &&shipy+1 ==ufo1y) //Line 0 { ShipHit(); } } } } //Collision detection for line 0 of ship //collision detection for UFO2 if (ufo2Exist ==true) { for (int a =0; a <2; a++) { if (shipx ==ufo2x+a &&shipy ==ufo2y+1) ///Line 1 { ShipHit(); } } //Collision detection for line 1 of ship //Collision detection for UFO2 for (int b =0; b <1; b++) { for (int a =0; a <2; a++) { if (shipx+b ==ufo2x+a &&shipy+1 ==ufo2y+1) //Line 1 { ShipHit(); } } for (int a =1; a <3; a++) { if (shipx+b ==ufo2x+a &&shipy+1 ==ufo2y) //Line 0 { ShipHit(); } } } } //Collision detection for line 0 of ship //Collision detection for UFO3 if (ufo3Exist ==true) { for (int a =0; a <2; a++) { if (shipx ==ufo3x+a &&shipy ==ufo3y+1) ///Line 1 { ShipHit(); } } //Contains extra for loop to loop through all the ship line 1 pixels //Collision detection for UFO3 for (int b =0; b <1; b++) { for (int a =0; a <2; a++) { if (shipx+b ==ufo3x+a &&shipy+1 ==ufo3y+1) //Line 1 { ShipHit(); } } for (int a =1; a <3; a++) { if (shipx+b ==ufo3x+a &&shipy+1 ==ufo3y) //Line 0 { ShipHit(); } } } } //Collision detection for line 0 of ship //Collision detection for Bouncer1. Don't need line 0 and 1 becuase line 0 and 1 of bouncers and line 0 of ship never meet if (bouncer1Exist ==true) { for (int a =1; a <2; a++) { if (shipx ==bouncer1x+a &&shipy ==bouncer1y+2) //Line 2 { ShipHit(); } } //Collision detection for Bouncer1 and Line 1 of ship for (int b =0; b <1; b++) { for (int a =1; a <2; a++) { if (shipx+b ==bouncer1x+a &&shipy+1 ==bouncer1y) //Line 0 { ShipHit(); } } for (int a =0; a <2; a++) { if (shipx+b ==bouncer1x+a &&shipy+1 ==bouncer1y+1) //Line 1 { ShipHit(); } } for (int a =1; a <2; a++) { if (shipx+b ==bouncer1x+a &&shipy+1 ==bouncer1y+2) //Line 2 { ShipHit(); } } } } //Collision detection for line 0 of ship //Collision detection for Bouncer2. Don't need line 0 and 1 because line 0 and 1 of bouncers and line 0 of ship never meet if (bouncer2Exist ==true) { for (int a =1; a <2; a++) { if (shipx ==bouncer2x+a &&shipy ==bouncer2y+2) //Line 2 { ShipHit(); } } //Collision detection for Bouncer2 and Line 1 of ship for (int b =0; b <1; b++) { for (int a =1; a <2; a++) { if (shipx+b ==bouncer2x+a &&shipy+1 ==bouncer2y) //Line 0 { ShipHit(); } } for (int a =0; a <2; a++) { if (shipx+b ==bouncer2x+a &&shipy+1 ==bouncer2y+1) //Line 1 { ShipHit(); } } for (int a =1; a <2; a++) { if (shipx+b ==bouncer2x+a &&shipy+1 ==bouncer2y+2) //Line 2 { ShipHit(); } } } } //Collision detection for line 0 of ship //Collision detection for Bouncer3. Don't need line 0 and 1 becuase line 0 and 1 of bouncers and line 0 of ship never meet if (bouncer3Exist ==true) { for (int a =1; a <2; a++) { if (shipx ==bouncer3x+a &&shipy ==bouncer3y+2) //Line 2 { ShipHit(); } } //Collision detection for Bouncer3 and Line 1 of ship for (int b =0; b <1; b++) { for (int a =1; a <2; a++) { if (shipx+b ==bouncer3x+a &&shipy+1 ==bouncer3y) //Line 0 { ShipHit(); } } for (int a =0; a <2; a++) { if (shipx+b ==bouncer3x+a &&shipy+1 ==bouncer3y+1) //Line 1 { ShipHit(); } } for (int a =1; a <2; a++) { if (shipx+b ==bouncer3x+a &&shipy+1 ==bouncer3y+2) //Line 2 { ShipHit(); } } } } //Collision detection for line 0 of ship //Collision detection for Bouncer4. Don't need line 0 and 1 becuase line 0 and 1 of bouncers and line 0 of ship never meet if (bouncer4Exist ==true) { for (int a =1; a <2; a++) { if (shipx ==bouncer4x+a &&shipy ==bouncer4y+2) //Line 2 { ShipHit(); } } //Collision detection for Bouncer4 and Line 1 of ship for (int b =0; b <1; b++) { for (int a =1; a <2; a++) { if (shipx+b ==bouncer4x+a &&shipy+1 ==bouncer4y) //Line 0 { ShipHit(); } } for (int a =0; a <2; a++) { if (shipx+b ==bouncer4x+a &&shipy+1 ==bouncer4y+1) //Line 1 { ShipHit(); } } for (int a =1; a <2; a++) { if (shipx+b ==bouncer4x+a &&shipy+1 ==bouncer4y+2) //Line 2 { ShipHit(); } } } } //Dont need collision detection for lines 0 and 1 of LT and line 0 of ship because they cant touch anyway//Collision detection routines for LT if (ltExist ==true) { for (int a =2; a <4; a++) //Line 2 { if (shipx ==ltx+a &&shipy ==lty+2) { ShipHit(); } } //Collision detection routines for LT and Ship line 1 for (int b =0; b <2; b++) { for (int a =1; a <4; a++) //Top line 0 { if (shipx+b ==ltx+a &&shipy+1 ==lty) { ShipHit(); } } for (int a =0; a <5; a++) //Line 1 { if (shipx+b ==ltx+a &&shipy+1 ==lty+1) { ShipHit(); } } for (int a =2; a <4; a++) //Line 2 { if (shipx+b ==ltx+a &&shipy+1 ==lty+2) { ShipHit(); } } } } //Dont need collision detection between line 0 of ship and line 0 and 1 of fallers because they will never touch//Collision detection for Faller 1 if (faller1Exist ==true) { for (int a =0; a <3; a++) //Line 2 { if (shipx ==faller1x+a &&shipy ==faller1y+2) //Checks to see if laser coords match bouncer bitmap coords, including the pixels just behind them. { ShipHit(); } } //Collision detection for Faller 1 and ship line 1 for (int b =0; b <1; b++) { for (int a =0; a <2; a++) //Top Line 0 { if (shipx+b ==faller1x+a &&shipy+1 ==faller1y) { ShipHit(); } } for (int a =0; a <3; a++) //Line 1 { if (shipx+b ==faller1x+a &&shipy+1 ==faller1y+1) { ShipHit(); } } for (int a =0; a <3; a++) //Line 2 { if (shipx+b ==faller1x+a &&shipy+1 ==faller1y+2) { ShipHit(); } } } } //Dont need collision detection between line 0 of ship and line 0 and 1 of fallers because they will never touch //Collision detection for Faller 2 if (faller2Exist ==true) { for (int a =0; a <3; a++) //Line 2 { if (shipx ==faller2x+a &&shipy ==faller2y+2) //Checks to see if laser coords match bouncer bitmap coords, including the pixels just behind them. { ShipHit(); } } //Collision detection for Faller 2 and ship line 1 for (int b =0; b <1; b++) { for (int a =0; a <2; a++) //Top Line 0 { if (shipx+b ==faller2x+a &&shipy+1 ==faller2y) { ShipHit(); } } for (int a =0; a <3; a++) //Line 1 { if (shipx+b ==faller2x+a &&shipy+1 ==faller2y+1) { ShipHit(); } } for (int a =0; a <3; a++) //Line 2 { if (shipx+b ==faller2x+a &&shipy+1 ==faller2y+2) { ShipHit(); } } } } //Dont need collision detection between line 0 of ship and line 0 and 1 of fallers because they will never touch //Collision detection for Faller 3 if (faller3Exist ==true) { for (int a =0; a <3; a++) //Line 2 { if (shipx ==faller3x+a &&shipy ==faller3y+2) //Checks to see if laser coords match bouncer bitmap coords, including the pixels just behind them. { ShipHit(); } } //Collision detection for Faller 3 and ship line 1 for (int b =0; b <1; b++) { for (int a =0; a <2; a++) //Top Line 0 { if (shipx+b ==faller3x+a &&shipy+1 ==faller3y) { ShipHit(); } } for (int a =0; a <3; a++) //Line 1 { if (shipx+b ==faller3x+a &&shipy+1 ==faller3y+1) { ShipHit(); } } for (int a =0; a <3; a++) //Line 2 { if (shipx+b ==faller3x+a &&shipy+1 ==faller3y+2) { ShipHit(); } } } } //Dont need collision detection between line 0 of ship and line 0 and 1 of fallers because they will never touch //Collision detection for Faller 4 if (faller4Exist ==true) { for (int a =0; a <3; a++) //Line 2 { if (shipx ==faller4x+a &&shipy ==faller4y+2) //Checks to see if laser coords match bouncer bitmap coords, including the pixels just behind them. { ShipHit(); } } //Collision detection for Faller 4 and ship line 1 for (int b =0; b <1; b++) { for (int a =0; a <2; a++) //Top Line 0 { if (shipx+b ==faller4x+a &&shipy+1 ==faller4y) { ShipHit(); } } for (int a =0; a <3; a++) //Line 1 { if (shipx+b ==faller4x+a &&shipy+1 ==faller4y+1) { ShipHit(); } } for (int a =0; a <3; a++) //Line 2 { if (shipx+b ==faller4x+a &&shipy+1 ==faller4y+2) { ShipHit(); } } } } //Dont need collision detection between line 0 of ship and lines 0 and 1 of risers because they'll never touch //Collision detection for Riser 1 if (riser1Exist ==true) { for (int a =0; a <1; a++) //Line 2 { if (shipx ==riser1x+a &&shipy ==riser1y+2) //Checks to see if laser coords match bouncer bitmap coords, including the pixels just behind them. { ShipHit(); } } //Collision detection for Riser 1 and Ship line 1 for (int b =0; b <1; b++) { for (int a =0; a <3; a++) //Top Line 0 { if (shipx+b ==riser1x+a &&shipy+1 ==riser1y) { ShipHit(); } } for (int a =0; a <2; a++) //Line 1 { if (shipx+b ==riser1x+0 &&shipy+1 ==riser1y+1) { ShipHit(); } } for (int a =0; a <1; a++) //Line 2 { if (shipx+b ==riser1x+a &&shipy+1 ==riser1y+2) { ShipHit(); } } } } //Dont need collision detection between line 0 of ship and lines 0 and 1 of risers because they'll never touch //Collision detection for Riser 2 if (riser2Exist ==true) { for (int a =0; a <1; a++) //Line 2 { if (shipx ==riser2x+a &&shipy ==riser2y+2) //Checks to see if laser coords match bouncer bitmap coords, including the pixels just behind them. { ShipHit(); } } //Collision detection for Riser 2 and Ship line 1 for (int b =0; b <1; b++) { for (int a =0; a <3; a++) //Top Line 0 { if (shipx+b ==riser2x+a &&shipy+1 ==riser2y) { ShipHit(); } } for (int a =0; a <2; a++) //Line 1 { if (shipx+b ==riser2x+0 &&shipy+1 ==riser2y+1) { ShipHit(); } } for (int a =0; a <1; a++) //Line 2 { if (shipx+b ==riser2x+a &&shipy+1 ==riser2y+2) { ShipHit(); } } } } //Dont need collision detection between line 0 of ship and lines 0 and 1 of risers because they'll never touch //Collision detection for Riser 3 if (riser3Exist ==true) { for (int a =0; a <1; a++) //Line 2 { if (shipx ==riser3x+a &&shipy ==riser3y+2) //Checks to see if laser coords match bouncer bitmap coords, including the pixels just behind them. { ShipHit(); } } //Collision detection for Riser 3 and Ship line 1 for (int b =0; b <1; b++) { for (int a =0; a <3; a++) //Top Line 0 { if (shipx+b ==riser3x+a &&shipy+1 ==riser3y) { ShipHit(); } } for (int a =0; a <2; a++) //Line 1 { if (shipx+b ==riser3x+0 &&shipy+1 ==riser3y+1) { ShipHit(); } } for (int a =0; a <1; a++) //Line 2 { if (shipx+b ==riser3x+a &&shipy+1 ==riser3y+2) { ShipHit(); } } } } //Dont need collision detection between line 0 of ship and lines 0 and 1 of risers because they'll never touch //Collision detection for Riser 4 if (riser4Exist ==true) { for (int a =0; a <1; a++) //Line 2 { if (shipx ==riser4x+a &&shipy ==riser4y+2) //Checks to see if laser coords match bouncer bitmap coords, including the pixels just behind them. { ShipHit(); } } //Collision detection for Riser 4 and Ship line 1 for (int b =0; b <1; b++) { for (int a =0; a <3; a++) //Top Line 0 { if (shipx+b ==riser4x+a &&shipy+1 ==riser4y) { ShipHit(); } } for (int a =0; a <2; a++) //Line 1 { if (shipx+b ==riser4x+0 &&shipy+1 ==riser4y+1) { ShipHit(); } } for (int a =0; a <1; a++) //Line 2 { if (shipx+b ==riser4x+a &&shipy+1 ==riser4y+2) { ShipHit(); } } } } //No collision detection for line 0 of ship and boss because they'll never touch anyway. //Collision detection for Boss abd Ship line 1 if (boss1Exist ==true) { for (int b =0; b <1; b++) { for (int a =3; a <5; a++ ) //Top line 0 { if (shipx+b ==bossx+a &&shipy+1 ==bossy) { ShipHit(); } } for (int a =2; a <5; a++) //Line 1 { if (shipx+b ==bossx+a &&shipy+1 ==bossy+1) { ShipHit(); } } for (int a =1; a <6; a++) //Line 2 { if (shipx+b ==bossx+a &&shipy+1 ==bossy+2) { ShipHit(); } } for (int a =0; a <7; a++) //Line 3 { if (shipx+b ==bossx+a &&shipy+1 ==bossy+3) { ShipHit(); } } for (int a =2; a <6; a++) //Line 4 { if (shipx+b ==bossx+a &&shipy+1 ==bossy+4) { ShipHit(); } } for (int a =0; a <7; a++) //Line 5 { if (shipx+b ==bossx+a &&shipy+1 ==bossy+5) { ShipHit(); } } for (int a =1; a <6; a++) //Line 6 { if (shipx+b ==bossx+a &&shipy+1 ==bossy+6) { ShipHit(); } } for (int a =2; a <5; a++) //Line 7 { if (shipx+b ==bossx+a &&shipy+1 ==bossy+7) { ShipHit(); } } } } //Collision detection for UFO Lasers. They only have line 0 if (ufoLasExist1 ==true) { for (int a =0; a <1; a++) { if (shipx ==ufoLas1x+a &&shipy ==ufoLas1y) ///Line 0 { ShipHit(); } } for (int b =0; b <1; b++) { for (int a =0; a <1; a++) { if (shipx+b ==ufoLas1x+a &&shipy+1 ==ufoLas1y) ///Line 1 { ShipHit(); } } } } //Collision detection for UFO Lasers. They only have line 0 if (ufoLasExist2 ==true) { for (int a =0; a <1; a++) { if (shipx ==ufoLas2x+a &&shipy ==ufoLas2y) ///Line 0 { ShipHit(); } } for (int b =0; b <1; b++) { for (int a =0; a <1; a++) { if (shipx+b ==ufoLas2x+a &&shipy+1 ==ufoLas2y) ///Line 1 { ShipHit(); } } } } //Collision detection for UFO Lasers. They only have line 0 if (ufoLasExist3 ==true) { for (int a =0; a <1; a++) { if (shipx ==ufoLas3x+a &&shipy ==ufoLas3y) ///Line 0 { ShipHit(); } } for (int b =0; b <1; b++) { for (int a =0; a <1; a++) { if (shipx+b ==ufoLas3x+a &&shipy+1 ==ufoLas3y) ///Line 1 { ShipHit(); } } } } //Collision detection for UFO Lasers. They only have line 0 if (ufoLasExist4 ==true) { for (int a =0; a <1; a++) { if (shipx ==ufoLas4x+a &&shipy ==ufoLas4y) ///Line 0 { ShipHit(); } } for (int b =0; b <1; b++) { for (int a =0; a <1; a++) { if (shipx+b ==ufoLas4x+a &&shipy+1 ==ufoLas4y) ///Line 1 { ShipHit(); } } } } }}void GameOver(int gameStatus){ spawnEnabled =false; if (gameStatus ==0) //Game over due to death { tape ="Game Over :( Your score was "; tape +=score; // Ticker(true); tape ="UFO ATTACK! - Press fire to start "; lives =5; score =0; levelNumber =1; } else if (gameStatus ==1)//Game over due to winning level 10 { tape ="Congratulations! You defeated the alien invasion :) Your total score was "; tape +=score; //Ticker(true); lives =5; score =0; levelNumber =1; } else if (gameStatus ==2)//Life lost { tape ="Ship destroyed! "; tape +="Lives left:"; tape +=lives; } ufo1Exist =false; ufo2Exist =false; ufo3Exist =false; bouncer1Exist =false; bouncer2Exist =false; bouncer3Exist =false; bouncer4Exist =false; faller1Exist =false; faller2Exist =false; faller3Exist =false; faller4Exist =false; riser1Exist =false; riser2Exist =false; riser3Exist =false; riser4Exist =false; ltExist =false; boss1Exist =false; gameStart =false; ufoLasExist1 =false; ufoLasExist2 =false; ufoLasExist3 =false; ufoLasExist4 =false; ufoLas1x =34; ufoLas1y =34; ufoLas2x =34; ufoLas2y =34; ufoLas3x =34; ufoLas3y =34; ufoLas4x =34; ufoLas4y =34; ufo1x =34; ufo2x =34; ufo3x =34; bouncer1x =34; bouncer2x =34; bouncer3x =34; bouncer4x =34; faller1x =34; faller2x =34; faller3x =34; faller4x =34; riser1x =34; riser2x =34; riser3x =34; riser4x =34; ltx =34; bossx =34; shipx =0; shipy =3; lasExist =false; if (gameStatus ==2){ Ticker(false);}else if (gameStatus ==0 || gameStatus ==1){ Ticker(true);}}void ShipHit(){ lives--; for (int i =5000; i> 1; i =i-5) { tone(buzzerPin, i, 1); delay(1); } if (lives> 0) { GameOver(2); } else if (lives <=0) { GameOver(0); }}
제조공정
구성품 및 소모품 초음파 센서 - HC-SR04(일반) × 2 Arduino Nano R3 × 1 포토 저항기 × 1 Maxim 통합 8x8 LED 매트릭스 MAX7219 × 2 납땜 브레드보드 절반 크기 × 1 점퍼 와이어(일반) × 1 저항 330옴 × 1 앱 및 온라인 서비스 Arduino IDE 이 프로젝트 정보 저는 8x8 매트릭스 LED와
구성품 및 소모품 Arduino Nano R3 × 1 회전 전위차계(일반) × 7 SparkFun 푸시버튼 스위치 12mm × 7 MIDI 포트 × 1 저항 221옴 × 4 LED(일반) × 2 이 프로젝트 정보 2019년 3월 11일 업데이트 안녕하세요, 저는 아르페지에이터를 위한 새 펌웨어를 만들었습니다. 소스 코드가 완전히 다시 작성되었습니다. 이제 모듈식 구조를 통해 Arduino뿐만