Visual Scripting
Examples from openprocessing.org
These are a few examples that I found on www.openprocessing.org that can help me come up with an idea as to what I am going to create.
float posx = width/2; |
float posy = height/2; |
float velx = 5; |
float vely = 2; |
float pad_height = 10; |
float pad_width = 70; |
int score = 0; |
int level = 1; |
int moveArea = 30; |
void setup(){ |
size(500,500); |
background(0); |
} |
void draw(){ |
background(0); |
posx += velx; |
posy += vely; |
fill(0,200,0); |
rect(posx,posy,30,30); |
fill(255); |
rect(mouseX,height-pad_height,pad_width,pad_height); |
textSize(30); |
textAlign(CENTER); |
fill(255); |
text("Games played: " + score,width/2,height/4); |
fill(255); |
text("Level " + level + "/5", width/2,height/2); |
//stroke(255); |
//line(0,height-moveArea,width,height-moveArea); |
|
if (posx>=width-30){ |
velx = -velx; |
} |
else if (posx<=0){ |
velx = +-velx; |
} |
else if (posy>=(height-30)-pad_height && posx>=mouseX && |
posx<mouseX + pad_width){ |
vely = -vely; |
} |
else if (posy>=height - 30){ |
posx = width/2; |
posy = height/2; |
score += 1; |
velx = 5; |
vely = 2; |
level = 1; |
} |
else if (posy<=0){ |
vely = +-vely * 1.2; |
} |
|
if (vely>=3){ |
level = 2; |
} |
else if (vely>=4){ |
level = 3; |
} |
else if (vely>=5){ |
level = 4; |
} |
else if (vely>=7){ |
level = 5; |
} |
|
} |
My Idea
My idea is to make a game that people of all ages can play. The objective of the game is you control a square with your mouse and you try to avoid the constant falling circles while trying to gain as high as score as possible. If the square you are controlling touches a circle then you lose a life. You have 3 lives in total so when they all run out it's game over and you have to start again.
My Code
import fisica.*;
import ddf.minim.*;
Minim minim;
AudioPlayer player;
//ControlP5 cp5;
FWorld world;
FBox box;
//Button newButton;
float x, y;
boolean gameInPlay = true;
int lives = 3;
float boxX, boxY;
float circle1X, circle1Y;
float circle2X, circle2Y;
int score = 0;
void setup()
{
size(600,650); // setting the size of the canvas
smooth();
//cp5 = new ControlP5(this);
//cp5.addButton("Start")
//.setValue(0)
//.setPosition(100, 100)
//.setSize(200,100)
//;
minim = new Minim(this);
player = minim.loadFile("action.wav"); // loads the sound file
Fisica.init(this);
world = new FWorld(); // creating a new world
world.setGravity(0, 200); // speed at which the circles fall
frameRate(20); // how many circles fall every second
world = new FWorld();
box = new FBox(25, 25); // the size of the box
box.setNoStroke(); // amount of border on the shapes
box.setFill(253, 0, 0); // the colour of the box
box.setPosition(mouseX, height - 40); // position of the box (follows the mouse)
box.setStatic(true); // keeps the box set so it doesn't rotate when hit
world.add(box); // adding a new world
}
void draw()
{
if (gameInPlay == true) // if the game is in play then it must do everything in the curly brackets
{
fill(0); // background colour
noStroke(); // amount of border on the shapes
rect(0, 0, width, height); // position of the rectangle
textSize(30); // size of the text
fill(255); // colour of the text
text("Score: " + score + "\n" +// The position where the "Score" text is placed
"Lives: " + lives, 10, 30); // The position where the "Lives" text is placed
if ((frameCount % 2) ==0) // how many frames per second
{
FCircle circle = new FCircle(random(10,50)); // sets the size of the circles
circle.setNoStroke(); // sets the amount of border on the outline of the shpes
circle.setFill(255); // sets the colour of the circles
circle.setPosition(random(0+10, width-10), 0); // sets the postion from where the circles begin to fall
circle.setVelocity(0, 500); // speed at which the circles fall
circle.setDamping(0.6);
world.add(circle);
}
box.setPosition(mouseX, height - 40); // sets the position of the square
if (dist(boxX, boxY, circle1X, circle1Y, circle2X, circle2Y)<1) // when the circles dont touch the box score is gained
{
score++; // score is gained
}
// when the amount of lives hit 0 its game over
if(lives<0)
{
gameInPlay = false;
}
}
else
{
fill(253, 0, 0); // colour of the text
textSize(80); // size of the text
text("Game Over!", 60, 300); // what the text says and the postion of it
}
// if the amount of lives hits 0 then its game over
if(lives<0)
{
gameInPlay = false;
}
if ( player.isPlaying() )
{
text("Sound On", 450, 30 ); // where the "sound on" text is displayed
}
else
{
text("Sound Off", 450, 30 ); // where the "sound off" text is displayed
}
world.draw();
world.step();
}
void contactStarted(FContact c)
{
FCircle circle1 = new FCircle(10);
FCircle circle2 = new FCircle(10);
if (!c.getBody1().isStatic()) //
{
circle1 = (FCircle)c.getBody1(); //
}
if (!c.getBody2().isStatic()) //
{
circle2 = (FCircle)c.getBody2(); //
}
if (c.contains(circle1, box)) // if circle 1 touches the box
{
// when contact is made lives are lost
println("contact box circle1");
lives--;
}
if (c.contains(circle2, box)) // if circle 2 touches the box
{
// when contact is made lives are lost
println("contact box circle2");
lives--;
}
if(lives<0)
{
gameInPlay = false;
}
}
void keyPressed()
{
if ( player.isPlaying() ) // playes the sound when any key is pressed
{
player.pause(); // pauses the sound when any key is pressed
}
else if (player.position() == player.length() )
{
player.rewind();
player.play();
}
else
{
player.play(); // plays the sound
}
// resets the game when it's "Game Over"
if (!gameInPlay)
{
if (key == 'r' || key == 'R')
{
gameInPlay = true;
lives = 3;
score = 0;
}
}
}
Testing/Improvements
When I gave my game to someone so they could try it out, some of the feedback that I got was really useful. One piece of feedback that I found really useful was "you either need a bigger quantity of circles or you need to make them fall faster" With that in mind I increased the framerate of the circles from "8" to "2" By doing this it gave me a greater quantity of circles falling from the top of the screen and they were doing it at a faster rate as well.
Another point that I found useful was to add some sound to the game to make it more interesting to play. I feel that this was a good point because music can make things more fun and interesting. It took me a while to find the right music for my game because I had to find the right genre that best fitted the style of game I had created.
To begin with my game only had 1 life. A suggestion that I had was to add more lives to the game so people who were playing it had more of a chance when playing it and wouldn't get frustrated when playing it, especially after I had put the framerate of the circles up to make it harder for people.
A reset button was also another suggestion because otherwise would keep having to exiting the application and running it again every time they wanted to play them game. So with the addition of a reset button, after the game has ended players can reset the game by pressing the "R" key so it saves them loading the application up each time they want to try it.
Terms
Void Setup - This feature is used to setup something. For example if you wanted a square at a certain point in the application in your code you would tell processing where to draw it once not over and over again, this would most likely crash the application. if you wanted to continually draw a square you would put it in draw.
Void Draw - If you want something in your code to be draw over and over again this is where you will write the code. For example, if you wanted circles to randomly fall from the top of the screen throughout your application you would put it in draw.
Button -
Boolean - Boolean values can be used to control statements e.g. true and false.
boolean a = false;
if (!a) {
rect(30, 20, 50, 50);
}
a = true;
if (a) {
line(20, 10, 90, 80);
line(20, 80, 90, 10);
}
Float - Converts an "int" or a "string" to its floating point representation.
Int - Datatype for integers are numbers without decimal points. They can be as large as "2,147,483,647" and as low as "-2,147,483,648" and are stored in 32 bit information.
int a;
a = 23; int b = -256; int c = a + b;
Loop - By default, processing loops through the draw function that i mentioned above. This can be stopped with "noLoop();"
Contact - If two arrays touch they get separated .
Expand - Increases the size of an array's, by default it doubles the size.
Else - Extends the if structure so two lines of code can be used.
line(20, i, 90, i);
line(20, i, 90, i);
} else {
line(0, i, 100, i);
If - Allows the system to choose between two different lines of code.
frameRate- The number of frames per second.
frameRate(20); // how many circles fall every second
Ellipse - Draws an oval onto the screen.
Line - Draws a line onto the screen.
Rect - Draws a rectangle onto the screen.
strokeWeight - Sets the width for borders of shapes and lines.
mouseClicked - An action will take place after the mouse is pressed and then released.
mousePressed - An action will take place each time the mouse is clicked.
mouseX - Sets the mouse's "X" axis.
mouseY - Sets the mouse's "Y" axis.
keyPressed - An action will take place when a designated key is pressed.
Background - Sets the background colour for the application by entering an "RGB" value.
Fill - This function allows you to fill shapes by entering an "RGB" value.
noStroke - Disables drawing the outline of shapes.
loadImage - Loads an image that you have saved on your desktop.
Tint - Adds tint to an image by entering a value between 1-100.
Text - Allows you to add text to your application.
Random - Generates random numbers each time the function is called upon.