-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathARDroneZeroP.pde
97 lines (87 loc) · 2.32 KB
/
ARDroneZeroP.pde
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
/*
* ARDroneZeroP - Processing game for Parrot ARDrone 2.0
* ---------------------------------------------------------
* The MIT Licence
* Copyright (c) 2014 Luiz Gustavo M. Sampaio
* https://github.com/lgmsampaio/ARDroneZeroP
*
* Collaborators:
* - Luiz Gustavo Moreira Sampaio - [email protected]
* - Kazuki Sakai
* - Shinichi Tamura
* - Koudai Fujii
* With the kind consultancy of Christopher Michael Yap
* and the supervision of professor Shigeru Kashihara.
*
* Strongly based on:
* - ODC - Open Drone Control
* http://www.opendronecontrol.org/
* - NyAR4psg - NyARTookit for Processing
* http://nyatla.jp/nyartoolkit/wp/?page_id=357
*/
import java.io.*;
Drone drone;
GameComponent game;
Enemies enemies;
void setup(){
// setup canvas
size(640, 480, P3D);
frameRate(20);
// setup components
enemies = new Enemies(this);
game = new GameComponent();
drone = new Drone();
}
void draw(){
// update drone and game state
drone.update();
game.update();
// game state is strongly depend on drone's state
// - no video -> drone is not ready yet (CASE 1)
// - landed -> game is over (CASE 2)
if( drone.isVideoAvailable() ){
// Display the video
set(0, 0, drone.getVideo());
if (game.isOnGoing()) {
if(drone.isJustLanded()){ // CASE 1
game.end(); // -> end the game
} else {
// This is normal case.
// Shoot the enemy and reflect the score
int earned_score = enemies.update(drone.getVideo(), game.circle);
enemies.display();
game.scoreUp(earned_score);
}
}
} else { // CASE 2
game.abort(); // -> cannot start the game
}
if (game.isReady()) {
enemies.refresh();// reset the enemies' state
}
// Display the game controller
game.display();
// Display the battery state
drone.displayBattery();
}
void keyPressed(){
if(keyCode == ESC) {//Emergency quit
drone.land();
}
game.keyPressed(keyCode);
if (game.isReady() || game.isOnGoing()) {
drone.keyPressed(keyCode);
}
if (game.isOnGoing()) {
enemies.keyPressed(keyCode);
}
}
void keyReleased(){
game.keyReleased(keyCode);
if (game.isReady() || game.isOnGoing()) {
drone.keyReleased(keyCode);
}
if (game.isOnGoing()) {
enemies.keyReleased(keyCode);
}
}