For my senior capstone, I decided to create an Asteroid game using what I learned in Computer Science Engineering class, from online and my mentor Joseph Kopena. Unfortunately, in order for my game to be played I would have to upload the entire file, not just the code itself and I'm not sure how to do that. So instead I decided to upload a video of me playing the game. To prove that it is a game that I created on my laptop I will how myself opening the file and showing my name on the top right corner on my laptop.
My Senior Capstone
Friday, May 22, 2015
Asteroid Game! Capstone Project
For my senior capstone, I decided to create an Asteroid game using what I learned in Computer Science Engineering class, from online and my mentor Joseph Kopena. Unfortunately, in order for my game to be played I would have to upload the entire file, not just the code itself and I'm not sure how to do that. So instead I decided to upload a video of me playing the game. To prove that it is a game that I created on my laptop I will how myself opening the file and showing my name on the top right corner on my laptop.
Thursday, May 21, 2015
Ping Pong Final
On May 21, 2015 I had assignment due where I had to add more functionality to a Ping Pong game code that my teacher had taught the class. Below is my new and improved code. I will be including this game in my Capstone Presentation. My code is down below.
PFont f;
int x, y, w, h, maxSpeedX, maxSpeedY;
int paddleX, paddleY, paddleW, paddleH, paddleS;
int paddleX2, paddleY2;
int scorePlayer1 = 0;
int scorePlayer2 = 0;
int winner = 7;
int s1 = 4; // controls speed for ball
int s2 = 4; // controls speed for ball
boolean up, down;
boolean up2, down2;
color color1 = (#FF2600);
color color2 = (#FEFF00);
void setup() {
size(600, 600);
background(0);
frameRate(60);
x = width/2;
y = height/2;
w = 50;
h = 50;
maxSpeedX = s1;
maxSpeedY = s2;
f = loadFont("ArialRoundedMTBold-48.vlw");
textFont(f, 25);
textAlign(CENTER, CENTER);
rectMode(CENTER);
paddleX = 25;
paddleY = height/2;
paddleX2 = width - 25;
paddleY2 = height/2;
paddleW = 25;
paddleH = 125;
paddleS = 6;
}
void draw() {
background(0);
drawBall();
moveBall();
bounceBall();
drawPaddle();
movePaddle();
stopPaddle();
touchBallPaddle();
keepscore();
gameOver();
text("Ping Pong Time", 300,25);
}
// begining of drawBall
void drawBall() {
stroke(#00FFDB);
strokeWeight(4);
fill(random(255), random(234), random(213));
ellipse(x, y, w, h); // ellipse(w,h,x,y) check it out!//
}
// end of drawBall
//Begining of moveBall
void moveBall() {
x = x + maxSpeedX;
y = y + maxSpeedY;
}
// end of moveBall
//begining of bounceBall
void bounceBall() {
if (x > width - w/2) {
setup();
maxSpeedX = -maxSpeedX;
scorePlayer1 = scorePlayer1 + 1;
} else if (x < 0 + w/2) {
setup();
maxSpeedX = +maxSpeedX;
scorePlayer2 = scorePlayer2 + 1;
}
if (y > height - h/2) {
maxSpeedY = -maxSpeedY;
} else if (y < 0 + h/2) {
maxSpeedY = -maxSpeedY;
}
}
// end of bounceBall
//beinging of paddle
void drawPaddle() {
stroke(#0A0A0A);
fill(color1);
rect(paddleX, paddleY, paddleW, paddleH);
stroke(#0A0A0A);
fill(color2);
rect(paddleX2, paddleY2, paddleW, paddleH);
}
// end of paddle
//begining of movePaddle
void movePaddle() {
if (up) {
paddleY = paddleY - paddleS;
}
if (down) {
paddleY = paddleY + paddleS;
}
if (up2) {
paddleY2 = paddleY2 - paddleS;
}
if (down2) {
paddleY2 = paddleY2 + paddleS;
}
}
// end of movePaddle
//begining os stopPaddle
void stopPaddle() {
if (paddleY - paddleH/2 < 0) {
paddleY = paddleY + paddleS;
}
if (paddleY + paddleH/2 > height) {
paddleY = paddleY - paddleS;
}
if (paddleY2 - paddleH/2 < 0) {
paddleY2 = paddleY2 + paddleS;
}
if (paddleY2 + paddleH/2 > height) {
paddleY2 = paddleY2 - paddleS;
}
}
// end of stopPaddle
//begining of touchBallPaddle
void touchBallPaddle() {
if (x - w/2 < paddleX + paddleW/2 && y - h/2 < paddleY + paddleH/2 && y + h/2 > paddleY - paddleH/2 ) {
if (maxSpeedX < 0) {
maxSpeedX = -maxSpeedX;
}
}
//right collision
else if (x + w/2 > paddleX2 - paddleW/2 && y - h/2 < paddleY2 + paddleH/2 && y + h/2 > paddleY2 - paddleH/2 ) {
if (maxSpeedX > 0) {
maxSpeedX = -maxSpeedX;
}
}
}
// end of of touchBallPaddle
// begining of keepScore
void keepscore() {
fill(#DE8BFF);
text(scorePlayer1, 100, 50);
text(scorePlayer2, width-100, 50);
}
//end of keepScore
// begining of gameOver
void gameOver() {
if (scorePlayer1 == winner) {
gameDone(" Player 1 wins!", color1);
}
if (scorePlayer2 == winner) {
gameDone(" Player 2 wins!", color2 );
}
}
// end of gameOver
//begining of gameDone
void gameDone(String text, color c) {
maxSpeedX = 0;
maxSpeedY = 0;
fill(random(100), random(150), random(200));
text(" Game OVER", width/2, height/3 - 40);
text("Click here to play again!", width/2, height/3+40);
fill(c);
text(text, width/2, height/3);
if (mousePressed) {
scorePlayer1 = 0;
scorePlayer2 = 0;
maxSpeedX = s1;
maxSpeedY = s2;
}
}
// end of gameDone
//begining of keyPressed
void keyPressed() {
if (key == 'w' || key == 'W') {
up = true;
}
if (key == 's' || key == 'S') {
down = true;
}
if (keyCode == UP) {
up2 = true;
}
if (keyCode == DOWN) {
down2 = true;
}
}
// end of keyPressed
// begining of keyRealsed
void keyReleased() {
if (key == 'w' || key == 'W') {
up = false;
}
if (key == 's' || key == 'S') {
down = false;
}
if (keyCode == UP) {
up2 = false;
}
if (keyCode == DOWN) {
down2 = false;
}
}
// end of keyrealsed
Tuesday, May 12, 2015
Ping Pong 3(In class)
For the last few weeks in CSE we've been learning how to create a Ping Pong game. Below is the code taught to the class by Mr. Miles.
// create paddle
// create the ball
// update the screen every few milliseconds with position
// start in 1D
/* things that you can do:
ball/paddle goes off the screen, comes out the other side
paddles can't go off the screen
score - the game ends when you reach a certain amount?
balls/paddles speed up as the game goes on
balls added as game goes on
incorporate top and bottom
more than 2 players
make it pretty/add music
balls can run into each other
title screen/winning screen
create a computer opponent
fix any bugs
*/
float paddle1Y;
float paddle2Y;
float maxSpeed;
boolean[] paddleControl;
//Ball ball1;
//Ball ball2;
// Ball[] ballArray;
ArrayList<Ball> myList;
void setup() {
size(600, 600);
background(#000000);
smooth();
frameRate(30); // draw() 30 times/seconds
paddle1Y = height/2 - 40;
paddle2Y = height/2 - 40;
maxSpeed = 5;
paddleControl = new boolean[4];
//ball1 = new Ball(50, 100);
//ball2 = new Ball(50, 50, 25, 10, color(0, 0, 255));
// println(ball1.getDiameter());
// ballArray = new Ball[5];
myList = new ArrayList<Ball>();
myList.add(new Ball());
for (int i = 0; i < paddleControl.length; i++) {
paddleControl[i] = false;
} // end of for
// for(int i = 0; i < ballArray.length; i++){
// ballArray[i] = new Ball();
// } // end of for
} // end of setup
void draw() {
background(#000000);
fill(255, 0, 0);
// move paddles
if(paddleControl[0]){
paddle1Y -= maxSpeed;
}
if(paddleControl[1]){
paddle1Y += maxSpeed;
}
if(paddleControl[2]){
paddle2Y -= maxSpeed;
}
if(paddleControl[3]){
paddle2Y += maxSpeed;
}
// draw player 1
rect(10, paddle1Y, 10, 80);
// draw player 2
rect(width - 20, paddle2Y, 10, 80);
//ball1.update();
//ball2.update();
//println(ballArray.length);
// for(int i = 0; i < ballArray.length; i++){
// ballArray[i].update();
// }
// update balls
for(int i = 0; i < myList.size(); i++){
// Ball temp = myList.get(i);
// temp.update();
myList.get(i).update();
} // end of update loop
} // end of draw
void keyPressed() {
if (key == 'w' || key == 'W') {
paddleControl[0] = true;
}
if (key == 's' || key == 'S') {
paddleControl[1] = true;
}
if (keyCode == UP) {
paddleControl[2] = true;
}
if (keyCode == DOWN) {
paddleControl[3] = true;
}
if(key == ' '){
myList.add(new Ball());
}
} // end of keyPressed
void keyReleased(){
if (key == 'w' || key == 'W') {
paddleControl[0] = false;
}
if (key == 's' || key == 'S') {
paddleControl[1] = false;
}
if (keyCode == UP) {
paddleControl[2] = false;
}
if (keyCode == DOWN) {
paddleControl[3] = false;
}
} // end of keyReleased
Subscribe to:
Posts (Atom)