Code
/*
ArkanDroid
This game is a combination of space shooter and block & paddle games.
You need to shoot the mothership in the center of the screen, before one of her bullets gets you.
However, to get to her, you need to first go through her minions - the ArcAngels.
The ArcAngels will disappear when shot - but only temporarily - they will be back in times that are
inversely propotional to their size.
Use the mouse to control your ship and the left click to shoot.
*/
Wheel w;
Vector bricks[]; //an array of bricks for each ring
Vehicle v;
float angle; //wheel rotation
boolean gameOver;
BFont b;
int numRings = 3;
float angleStep; //rotation increment which is taken from between min and max speed
int maxSpeed = 4; //max and min speeds of wheel rotation
int minSpeed = 1;
boolean bulletPresent; //elements for enemy bullet
float eBulletx;
float eBullety;
float eAngle;
float eVelocity;
int starX[]; //background starfield
int starY[];
void setup()
{
size(600,600);
framerate(24);
noStroke();
starX = new int[100]; //create the starfield points
starY = new int[100];
for(int i=0;i<100;i++){
starX[i] = (int)random(600);
starY[i] = (int)random(600);
}
w = new Wheel();
v = new Vehicle();
angle = 1;
angleStep = random(minSpeed,maxSpeed);
gameOver = false;
b = loadFont("Futura-Heavy.vlw.gz");
bulletPresent = false; //default for enemy bullet
}
void loop()
{
background(0);
ellipseMode(CENTER_DIAMETER);
rectMode(CENTER_DIAMETER);
fill(255);
for(int i=0;i<100;i++) //starfield
{
ellipse(starX[i],starY[i],2,2);
}
fill(255,0,0);
if(!gameOver) // mothership
{
ellipse(300,300,20,20);
beginShape(QUADS);
vertex(300, 295);
vertex(300, 305);
vertex(280, 305);
vertex(280, 300);
vertex(300, 295);
vertex(320, 300);
vertex(320, 305);
vertex(300, 305);
endShape();
}
if(sqrt(sq(v.b.x-300)+sq(v.b.y-300)) < 30) //hit condition for mothership
{
gameOver=true;
}
if(gameOver)
{
textFont(b,30);
textMode(ALIGN_CENTER);
strokeWeight(10);
if(numRings<5)
{
text("Impressive! Press 'n' to advance",290,520);
}
else
{
text("The End. To play again, press 'n'",280,520);
}
}
v.draw();
v.x = mouseX;
if(!v.triggered) //conditions to shoot bullet - possible only when there is no other bullet on screen
{
v.b.x = mouseX;
}
v.checkBullet();
try
{ // index out of bounds exception
w.draw();
}
catch(ArrayIndexOutOfBoundsException e)
{
println("Exception");
}
if((int)(random(1,40))==3) // wheel changes speed and direction
{
angleStep = -angleStep*random(minSpeed,maxSpeed)/abs(angleStep);
}
if(!gameOver)
{
if((int)(random(1,20))==3) // enemy bullet
{
shootEnemyBullet();
}
if(bulletPresent){
drawEnemyBullet();
updateEnemyBullet();
checkEnemyHit();
}
angle+=angleStep;
angle = angle%360;
if(angle<0)
angle+=360;
}
if(numRings>5) // end game and restart
{
numRings=3;
setup();
}
}
void shootEnemyBullet()
{
if(bulletPresent ==false){
bulletPresent = true;
eBulletx = 300;
eBullety = 300;
eAngle = atan2(585-300,v.x-300); // between enemy and player
eVelocity = random(4,15);
}
}
void updateEnemyBullet(){
eBulletx += eVelocity*cos(eAngle);
eBullety += eVelocity*sin(eAngle);
if(eBulletx>600 || eBullety>600) // if buller passes 600, set default
{
bulletPresent = false;
}
}
void drawEnemyBullet(){
fill(255);
ellipse(eBulletx,eBullety,10,10);
}
void checkEnemyHit()
{
if((abs(eBulletx-v.x)<=35)&&(abs(eBullety-585)<=7)) //condition for enemy bullet to hit player
{
gameOver = true;
gameOver=false;
setup();
}
}
class Wheel
{
Wheel()
{
int numberBricks;
bricks = new Vector[numRings]; //each ring has a unique vector of bricks
for(int i=0; i<numRings; i++)
{
numberBricks = (int)random(8,12);
float angleBias = random(360);
float sumAngle=0; //the sum of the brick angles
float brickAngle;
bricks[i] = new Vector();
Brick b;
float[] r = new float[numberBricks];
float r_sum = 0; // sum of random nos tht make numberBricks - causes the variation in brick distribution
for(int j=0; j<numberBricks;j++)
{
r[j] = random(0.1,1); //the random angle of the brick
r_sum+=r[j];
}
for(int j=0;j<numberBricks;j++) //this loop will create 'numberBricks' bricks that add up to 360 degrees
{
brickAngle = (360.0*r[j]/r_sum); // calculates the individual brick angles for each brick
b = new Brick(angleBias+sumAngle,angleBias+sumAngle+brickAngle,i);
bricks[i].add(b);
//make a brick from sumAngle to sumAngle+brickAngle and add it to bricks[i]
sumAngle += brickAngle;
}
}
}
void draw()
{
int l;
Brick b;
for(int i=0;i<numRings;i++)
{
l = bricks[i].size();
for(int j=0;j<l;j++)
{
b = (Brick)(bricks[i].get(j));
if(b.visible)
{
b.draw();
}
else
{
b.count();
if(b.countValue > 200+(100-1.8*(b.angleTwo - b.angleOne))) //the timer for brick reappearance is set based on brick size
{
b.stopWatch();
}
bricks[i].removeElementAt(j); // need to remove and insert so that the vector is updated with the new visible value
bricks[i].insertElementAt(b,j);
}
if(b.collisionCheck() && b.visible) //if collision and the brick is visible
{
b.visible = false;
bricks[i].removeElementAt(j);
bricks[i].insertElementAt(b,j);
v.resetBullet();
j = l;
}
}
}
}
}
class Brick
{
float angleOne;
float angleTwo;
int ringIndex; //position of the ring
color c;
boolean visible;
int countValue;
Brick(float angleOne,float angleTwo,int ringIndex)
{
this.angleOne = angleOne;
this.angleTwo = angleTwo;
this.ringIndex = ringIndex;
this.c = color((int)random(255),(int)random(255),(int)random(255));
this.visible = true;
this.countValue = 0;
}
void draw()
{
fill(c);
sector(300,300,angle+angleOne,angle+angleTwo,(30*(ringIndex+1)),(30*(ringIndex+2))); //triangle formula tht draws the brick sector
noFill();
}
void count()
{
countValue++;
}
void stopWatch() //resets brick and timer to default values
{
visible = true;
countValue = 0;
}
boolean collisionCheck()
{
float bulletAngle;
float radius;
float x1 = v.b.x;
float y1 = v.b.y;
radius = sqrt(sq(x1-300)+sq(y1-300));
bulletAngle = 180*atan2(300-y1,x1-300)/PI;
bulletAngle = bulletAngle%360;
if(bulletAngle < 0)
{
bulletAngle += 360;
}
//condition to chk for collision of bullet with brick
if((bulletAngle>=int((angle+angleOne)%360)) && (bulletAngle<=int((angle+angleOne)%360)+angleTwo-angleOne) && (radius>=(30*(ringIndex+1))) && (radius<=(30*(ringIndex+2))))
{
return true;
}
else
{
return false;
}
}
}
class Vehicle
{
int x;
color c;
Bullet b; //from the Bullet class, used in the Shoot method
boolean triggered;
Vehicle()
{
this.x = 300;
this.c = color(255,255,0);
this.triggered = false;
this.b = new Bullet(x+30);
}
void draw()
{
fill(c); // player vehicle
beginShape(QUADS);
vertex(x-5,575);
vertex(x+5,575);
vertex(x+10,590);
vertex(x-10,590);
endShape();
rect(x,585,60,5);
noFill();
}
void moveRight()
{
x=x+5;
if(x>585)
{
x=585;
}
if(!triggered) // bullet origin
{
b.x = x;
}
}
void moveLeft()
{
x=x-5;
if(x<15)
{
x=15;
}
if(!triggered) // bullet origin
{
b.x = x;
}
}
void checkBullet()
{
if(triggered==true)
{
b.draw();
b.move();
}
if(b.y<0)
{
triggered=false;
b = new Bullet(x+15);
}
}
void resetBullet()
{
triggered = false;
b = new Bullet(x+15);
}
}
class Bullet
{
int x;
int y;
color c;
Bullet(int x)
{
this.x = mouseX;
this.y = 585;
this.c = color(255,0,0);
}
void draw()
{
fill(c);
ellipse(x,y,10,10);
noFill();
move();
}
void move()
{
if(numRings<=4) // setting the bullet to go faster makes it skip over the sector
{
y-=12;
}
else
{
y-=15;
}
}
}
void keyPressed()
{
if(gameOver)
{
if(key == 'n')
{
gameOver = false;
numRings++;
setup();
}
}
}
void mousePressed()
{
if(!gameOver)
{
v.triggered = true;
}
}
void sector(int x, int y, float begin, float end, int radius1, int radius2) //function to draw the sector
{
if (begin > end) {
float temp = begin;
begin = end;
end = temp;
}
int x1,y1,x2,y2,x3,y3;
float dt1 = (end-begin)/6;
float dt = PI*dt1/180.0;
float t;
for(float t1 = begin; t1<end; t1+=dt1)
{
t = radians(t1);
x1 = x+(int)((radius1+2)*cos(t));
y1 = y-(int)((radius1+2)*sin(t));
x2 = x+(int)((radius2-2)*cos(t));
y2 = y-(int)((radius2-2)*sin(t));
x3 = x+(int)((radius1+2)*cos(t+dt));
y3 = y-(int)((radius1+2)*sin(t+dt));
triangle(x1,y1,x2,y2,x3,y3);
x1 = x+(int)((radius2-2)*cos(t+dt));
y1 = y-(int)((radius2-2)*sin(t+dt));
triangle(x1,y1,x2,y2,x3,y3);
}
}
Project 6: Create a simple game.
Statement:While computer-based interactive games (a.k.a. video games) have been a pop-cultural force since the arcade scene of the late 1970s and early 1980s, in recent years video games have been recognized as a major emerging art form, poised to have as much cultural impact on the 21st century as cinema did on the 20th. The game industry is making Hollywood-sized amounts of money, with designers of the most popular games achieving a geeky sort of celebrity. Museums and galleries are offering exhibitions of “art games”, computer-scientists are beginning to treat games as technical objects worthy of serious attention, and in humanities departments around the world, games studies is a hot new topic. In short, something is going on, even if we don't yet know what it is or how to talk about it. What kind of game would you create? Create a simple game.
Simple Game : ArkanDroid