int time = 0; //system time (<2000)
int theScore = -1; //total score (increse/decrese)
int big_time = 0; //control the duration of SPAN
int base_h = 5; //horizental position (mostleft point)
int fallObj1_h = 2;
int fallObj2_h = 6;
int fallObj1_v = 3;
int fallObj2_v = -3;
int envObj_v = 3;
int biggerObj_h;
int biggerObj_v;
int bulletObj_h;
int bulletObj_v =12; // vertical position of bullet is always 12
int rseed = 98; //used for generating random numer
int bb = 2987;
int mm = 987;
int p;
int i;
int BIGTIME = 0; // flag when to fall the bigger objects
int SPAN = 0; //horizental span (0:normal?1:bigger)
int LR = 0; //flag for location of environmental object
int HIT_ENV = 0; //flag of detecting of environment object
int HIT_OBJ = 0; //flag of detecting of falling objects
int HIT_BULLET = 0; //flag of detecting of collision between bullet
of
single point target
int HIT_BULLET_2 = 0; //flag of detecting of collision between bullet
of
double point target
int BIGOBJ = 0;
int LOSE = 0;
int LOSE_2 = 0;
int PIN_ON = 0;
int BULLET = 0; //flag for shotting. 0:no bullet?1:yes bullet
int TYPE1 = 0;
int TYPE2 = 0; // 0 is dot, 1 is two dots, 2 is helping guy
// use to detect whether it is first time
int counter = 1;
// random function used to generate random number
// from 0 -- 10
int Random() {
int bl = (rseed * bb + 1);
rseed = (bl % mm);
return (rseed % 10);
}
int TypeRandom() {
int temp = Random();
int type = 0;
if(temp < 5) type = 0;
if((temp > 5)&&(temp < 8)) type = 1;
if((temp > 8)&&(temp < 10)) type = 2;
//else type = 0;
return type;
}
// base object used for shoting the falling object
void Base() {
line(base_h,13,(base_h+2+SPAN),13); // base part
line((base_h+1),12,(base_h+1+SPAN),12); // top part used to shot
}
// falling objects
// 1. at any given time, there are two falling objects
// 2. two types of objects: single point | double points
void FallObj(int x, int y, int TYPE) {
stroke(2);
// single point first
if(TYPE == 0) point(x,y);
// double points
if(TYPE == 1){
point(x,y);
point(x+1,y);
}
// drop the helping guy
if(TYPE == 2)
{
point(x,y);
point(x+1,y);
point(x,y+1);
point(x+1,y+1);
}
stroke(1);
}
void Shot() {
// when the base is normal
if(SPAN == 0)
{
point(bulletObj_h, bulletObj_v);
}
// when the base is in bigger mode
if(SPAN == 1)
{
point(bulletObj_h, bulletObj_v);
point((bulletObj_h+1), bulletObj_v);
}
}
// used to detect whether bullet hits the falling object
void ShotDetect(int bullet_h, int bullet_v) {
// CASE1: single point object
if(SPAN == 0)
{
if(TYPE1 == 0 || TYPE2 == 0)
{
if(bullet_h == fallObj1_h)
{
if(bullet_v == fallObj1_v || bullet_v ==
fallObj1_v+1) HIT_BULLET = 1;
else HIT_BULLET = 0;
}
else if(bullet_h == fallObj2_h)
{
if(bullet_v == fallObj2_v || bullet_v ==
fallObj2_v+1) HIT_BULLET = 1;
else HIT_BULLET = 0;
}
else HIT_BULLET = 0;
}
if(TYPE1 == 1 || TYPE2 == 1)
{}
}
if(SPAN == 1)
{
if(TYPE1 == 0 || TYPE2 == 0)
{
if(bullet_h == fallObj1_h || bullet_h+1 == fallObj1_h)
{
if(bullet_v == fallObj1_v || bullet_v ==
fallObj1_v+1) HIT_BULLET = 1;
else HIT_BULLET = 0;
}
else if(bullet_h == fallObj2_h || bullet_h+1 == fallObj2_h)
{
if(bullet_v == fallObj2_v || bullet_v ==
fallObj2_v+1) HIT_BULLET = 1;
else HIT_BULLET = 0;
}
else HIT_BULLET = 0;
}
if(TYPE1 == 1 || TYPE2 == 1)
{
if(bullet_h == fallObj1_h && bullet_h+1 == fallObj1_h+1)
{
if(bullet_v == fallObj1_v || bullet_v ==
fallObj1_v+1) HIT_BULLET_2 = 1;
else HIT_BULLET_2 = 0;
}
else if(bullet_h == fallObj2_h && bullet_h+1 == fallObj2_h+1)
{
if(bullet_v == fallObj2_v || bullet_v ==
fallObj2_v+1) HIT_BULLET_2 = 1;
else HIT_BULLET_2 = 0;
}
else HIT_BULLET_2 = 0;
}
}
}
// used to detect whether base hits bigger objects
void BigDetect(int obj_h, int obj_v) {
if(obj_h == base_h+1 && obj_v == 11) SPAN = 1;
if(obj_h+1 == base_h+1 && obj_v == 11) SPAN = 1;
//else SPAN = 0;
}
void ExplosionShot() {
if(HIT_BULLET == 1)
{
circle(bulletObj_h,bulletObj_v,1);
pause(20);
circle(bulletObj_h,bulletObj_v,2);
}
if(HIT_BULLET_2 == 1)
{
circle(bulletObj_h,bulletObj_v,1);
pause(20);
circle(bulletObj_h,bulletObj_v,2);
pause(20);
circle(bulletObj_h,bulletObj_v,3);
}
HIT_BULLET = 0;
HIT_BULLET_2 = 0;
}
void HitFallDetect() {
if(SPAN == 0)
{
if(fallObj1_v == 12)
{
if(base_h == fallObj1_h || base_h+1 == fallObj1_h || base_h+2 ==
fallObj1_h) LOSE = 1;
else LOSE = 0;
}else LOSE = 0;
if(fallObj2_v == 12)
{
if(base_h == fallObj2_h || base_h+1 == fallObj2_h || base_h+2 ==
fallObj2_h) LOSE = 1;
else LOSE = 0;
}
else LOSE = 0;
}
if(SPAN == 1)
{}
}
void Score() {
point(theScore,0);
if(theScore > 0) line(0,0,(theScore-1),0);
if(theScore == 10){
line(0,0,9,0);
point((theScore-10),1);
line(0,1,(theScore-10),1);
}
//if(theScore < -1) theScore = 1;
}
int ii = 14;
void ShowLose(){
// draw lost on screen
canvas(0);
theScore = -1;
while(true){
line(3,3,3,8);
line(4,3,4,8);
line(3,8,7,8);
line(3,9,7,9);
if(@1 == 1) {
theScore = -1;
return;
}
pause(20);
canvas(0);
}
//pause(20000);
}
void ShowWin(){
// draw win
while(true){
line(0,3,1,8);
line(1,3,2,8);
line(2,8,4,3);
line(3,8,5,3);
line(5,3,6,8);
line(6,3,7,8);
line(6,8,9,3);
line(7,8,10,3);
if(@1 == 1) {
theScore = -1;
return;
}
pause(20);
canvas(0);
}
}
// Render() render the screen
void Render(){
// reduce the speed of falling targets
if(time%2 == 0)
{
fallObj1_v++;
fallObj2_v++;
FallObj(fallObj1_h, fallObj1_v, TYPE1);
if(fallObj2_v > 3) FallObj(fallObj2_h, fallObj2_v, TYPE2);
// falling object 1 hits the bottom
if(fallObj1_v == 12)
{
if(base_h == fallObj1_h || base_h+1 == fallObj1_h || base_h+2 ==
fallObj1_h) LOSE = 1;
else LOSE = 0;
fallObj1_v = 3;
fallObj1_h = Random();
TYPE1 = TypeRandom();
}
// falling object 2 hits the bottom
if(fallObj2_v == 12)
{
if(base_h == fallObj2_h || base_h+1 == fallObj2_h || base_h+2 ==
fallObj2_h) LOSE = 1;
else LOSE = 0;
fallObj2_v = 3;
fallObj2_h = Random();
TYPE2 = TypeRandom();
}
}
ShotDetect(bulletObj_h, bulletObj_v);
if((TYPE1 == 2 || TYPE2 == 2)&&SPAN != 1) {
BigDetect(fallObj1_h, fallObj1_v);
BigDetect(fallObj2_h, fallObj2_v);
}
// listen to input pin 3 (shotting)
if(PIN_ON == 1){
// use to detect whether it is first time
if(counter == 1) bulletObj_h = base_h+1;
// call shot function here
Shot();
if(bulletObj_v == 3){
bulletObj_h = base_h+1;
bulletObj_v = 12;
}
if(HIT_BULLET == 0 || HIT_BULLET_2 == 0) bulletObj_v--; //flag of
detecting of collision between bullet of single point target)
if(HIT_BULLET == 1 || HIT_BULLET_2 == 1){
pause(50);
ExplosionShot(); // call explosionShot function
bulletObj_h = base_h+1;
bulletObj_v = 12;
fallObj1_h = Random();
fallObj2_h = Random();
// add score
theScore++;
}
if(HIT_BULLET_2 == 1) theScore = theScore + 2;
counter++;
}
// render base object
//Base();
// tracking vars.
//debug("bulletObj_v is "+bulletObj_v);
//debug("fallObj1_v is "+fallObj1_v);
//debug("bulletObj_h is "+bulletObj_h);
//debug("fallObj1_h is "+fallObj1_h);
//debug("HIT_BULLET is "+HIT_BULLET+"\n");
//debug("bulletObj_v is "+bulletObj_v);
//debug("fallObj2_v is "+fallObj2_v);
//debug("bulletObj_h is "+bulletObj_h);
//debug("fallObj2_h is "+fallObj2_h);
//debug("HIT_BULLET is "+HIT_BULLET+"\n");
//debug("BASE_H is " + base_h);
//debug("TYPE1 is "+TYPE1);
//debug("TYPE2 is "+TYPE2);
//debug("the score is "+theScore);
//pause(20);
//debug("base_h+1 is "+(base_h+1));
//debug("base_v is "+base_v);
//debug("SPAN is "+SPAN);
//debug("LOSE is "+LOSE);
debug("the score is "+theScore);
// debug("\n");
}
void FirstBegin(){
int ii =20;
while(true)
{
// n
point(3, ii);
point(3, ii+1);
point(3, ii+2);
point(4, ii+1);
point(5, ii);
point(5, ii+1);
point(5, ii+2);
// y
point(3, ii+4);
point(4, ii+5);
point(4, ii+6);
point(5, ii+4);
// l
point(3, ii+8);
point(3, ii+9);
point(3, ii+10);
point(4, ii+10);
point(5, ii+10);
// o
point(3, ii+12);
point(4, ii+12);
point(5, ii+12);
point(3, ii+13);
point(5, ii+13);
point(3, ii+14);
point(4, ii+14);
point(5, ii+14);
// n
point(3, ii+16);
point(3, ii+17);
point(3, ii+18);
point(4, ii+17);
point(5, ii+16);
point(5, ii+17);
point(5, ii+18);
pause(5);
canvas(0);
if(@1 == 1) return;
if(ii == -20)
{
int iii;
for(iii = 0; iii< 10; iii++)
{
circle(4,7,iii);
pause(iii*2);
}
ii = 20;
}
debug(i);
ii--;
}
}
void Begin(){
int ii =20;
while(true)
{
// n
point(3, ii);
point(3, ii+1);
point(3, ii+2);
point(4, ii+1);
point(5, ii);
point(5, ii+1);
point(5, ii+2);
// y
point(3, ii+4);
point(4, ii+5);
point(4, ii+6);
point(5, ii+4);
// l
point(3, ii+8);
point(3, ii+9);
point(3, ii+10);
point(4, ii+10);
point(5, ii+10);
// o
point(3, ii+12);
point(4, ii+12);
point(5, ii+12);
point(3, ii+13);
point(5, ii+13);
point(3, ii+14);
point(4, ii+14);
point(5, ii+14);
// n
point(3, ii+16);
point(3, ii+17);
point(3, ii+18);
point(4, ii+17);
point(5, ii+16);
point(5, ii+17);
point(5, ii+18);
pause(5);
canvas(0);
if(@1 == 0) return;
if(ii == -20)
{
int iii;
for(iii = 0; iii< 10; iii++)
{
circle(4,7,iii);
pause(iii*2);
}
ii = 20;
}
debug(i);
ii--;
}
}
int done;
FirstBegin();
while (true) {
time = 0;
done = 0;
while(time < 500 && done == 0){
if(@0 == 1) PIN_ON = 1;
if(@0 == 0) PIN_ON = 0;
if(LOSE == 1)
{
theScore--;
LOSE = 0;
}
Score(); // show the score
//if(theScore < 0) Lose(); // call lose function
Base();
line(0,3,9,3); // set the top bar
p = #0/3; // control falling speed
i = #1; // control movement
base_h = i/11-1;
Render();
// set the big duration time to 500.
if(SPAN == 1) big_time = big_time + p;
if(big_time > 5500)
{
SPAN = 0;
big_time = 0;
}
pause(p);
time = time + p;
if(theScore == -5) {
done = 1;
}
canvas(0); // refresh the screen
}
if (theScore > -5)
ShowWin();
else
ShowLose();
Begin();
}
[download]
|