/** * Mind-controlled Lunar/Apian Lander! * This can be controlled by the keyboard. Next steps is to build the EEG sensors... watch this space! * * Uses collision detection by Ricardo Sanchez, from the book Mathematics and Physics for Programers by D. Kodicek * */ PVector startPoint, endPoint; float gravity; boolean isMouseDragged, isMouseStageEnabled; Landscape landscape; Lander lander; Boolean bGameOver = false; Boolean bGameChoice = false; int iGameSkin = 2; PImage piLander1, piLander2; ImageButton btn1, btn2; void setup() { size(800, 600); smooth(); background(0); noLoop(); gravity = 0.01; isMouseDragged = false; // to control draw temp wall during creation isMouseStageEnabled = true; // to control if the canvas can recive mouse events piLander1 = loadImage("images/lander"+1+".png"); piLander2 = loadImage("images/lander"+2+".png"); ShowChoiceScreen(); } void ShowChoiceScreen(){ bGameChoice = true; background(0); btn1 = new GameSkinButton("images/button"+1+".jpg", "images/button"+1+"-over.jpg", "images/button"+1+".jpg", 300, 250, 1); btn2 = new GameSkinButton("images/button"+2+".jpg", "images/button"+2+"-over.jpg", "images/button"+2+".jpg", 600, 250, 2); btn1.x = width/2 - btn1.currentimage.width - 10; btn2.x = width/2 + 10; PFont endFont = createFont("Arial", 32); textFont(endFont); textAlign(CENTER); text("CHOOSE YOUR STYLE!" , width/2, 64); endFont = createFont("Arial", 14); textFont(endFont); text("Mind Controls: Think UP to fly, RELAX to land." , width/2, 450); text("Goal: Land on the pad/flower in the centre of the screen, avoiding everything else." , width/2, 470); text("Keyboard Controls: Just press any key to fly, release to land." , width/2, 490); text("Tip: Don't land too hard!" , width/2, 510); loop(); } void StartGame(int skin){ iGameSkin = skin; bGameOver = false; bGameChoice = false; landscape = new Landscape(); lander = new Lander(); loop(); } void StopGame(boolean bWon, String sMessage){ bGameOver = true; noLoop(); PFont endFont = createFont("Arial", 32); textFont(endFont); textAlign(CENTER); text(sMessage, width/2, 32); text("PRESS ENTER TO PLAY AGAIN" , width/2, 64); } void draw() { //background(0); noStroke(); if(bGameChoice){ btn1.draw(); btn2.draw(); } else { // the background landscape and landing structures landscape.draw(); if(bGameOver){ } else { lander.draw(); // draw a grey line to show the placement of the about-to-be-creaetd wall if (isMouseDragged && startPoint != null) { stroke(200); line(startPoint.x, startPoint.y, mouseX, mouseY); fill(180); ellipse(startPoint.x, startPoint.y, 8, 8); fill(180); ellipse(mouseX, mouseY, 8, 8); } // note this will be replaced by the BCI input if (keyPressed) { // thrust lander.thrust(); } } } } void keyPressed(){ if(bGameChoice){ if (key == '1' || key == '2' ) { println(key); iGameSkin = key - '0'; StartGame(iGameSkin); } } if(bGameOver){ if (( keyCode == ENTER || keyCode == RETURN ) ) { ShowChoiceScreen(); } } } /* // sets wall starting point on mouse press // mouse events can be local to the circle button class, // I will look in to that, to see if is possible void mousePressed() { for (int n = 0; n < landscape.walls.size(); n++) { Wall w = (Wall)landscape.walls.get(n); if (w.startPointButton.press() || w.endPointButton.press()) isMouseStageEnabled = false; } if (isMouseStageEnabled == true) { isMouseDragged = true; // sets start point of a the new wall startPoint = new PVector(mouseX, mouseY); } } // update tempWall endpoint void mouseDragged() { // check is click event is on the stage or any wall start/end points if (!isMouseStageEnabled) { for (int n = 0; n < landscape.walls.size(); n++) { Wall w = (Wall)landscape.walls.get(n); if (w.startPointButton.press()) { w.setStartPoint(new PVector(mouseX, mouseY)); w.startPointButton.x = mouseX; w.startPointButton.y = mouseY; } if (w.endPointButton.press()) { w.setEndPoint(new PVector(mouseX, mouseY)); w.endPointButton.x = mouseX; w.endPointButton.y = mouseY; } } } } // sets endpoints on mouse release, and create a wall void mouseReleased() { for (int n = 0; n < landscape.walls.size(); n++) { Wall w = (Wall)landscape.walls.get(n); w.startPointButton.release(); w.endPointButton.release(); } if (isMouseStageEnabled == true) { isMouseDragged = false; // sets end point of the new wall endPoint = new PVector(mouseX, mouseY); landscape.createWall(startPoint, endPoint, true); } isMouseStageEnabled = true; } */