Write a game.
This is a very open-ended assignment. I'll just put down a few rules.
readme.txt
file. Then get the absolute minimum to work. Then, if there is any time
left, work on adding all those missing features to your game--but be
sure to keep a working copy of your game at every step.You will need a void setup() method. Here's where you set the size of the window, call frameRate, and do any other necessary initializations.
You will need a void draw() method. This method will be
automatically called some number of times a second, as set by the frame
rate. All drawing must be done in the draw method, or in methods called (directly or indirectly) from the draw method--drawing commands anywhere else probably won't do anything. Start with a call to background, otherwise your drawings will "pile up" on top of one another.
You can tell where the mouse (pointer) is by accessing the predefined mouseX and mouseY integer variables.
You can tell if a key has been pressed by checking the keyPressed boolean variable; the key variable holds the most recently pressed key. If key == CODED, it's a special key, like an arrow key, and the keyCode variable holds the numeric code for it.
You can write a function void keyPressed() that will be automatically called each time a key is pressed. Remember that keys repeat if you hold them down for too long.
Processing isn't going to automatically remember what you did. Anything you want to keep from one frame to the next, you have to explicitly save in something that will be redrawn next time.
The following code has samples of everything you are likely to need.
import java.awt.Point; import java.util.ArrayList; ArrayListMy DodgeEm game is a simple example you might also get some ideas from. Movement of my ball uses "easing," and if you want to do that, here's how.points = new ArrayList (); String keys = ""; void setup() { size(300, 300); } void draw() { background(255 - mouseX, 127, 255 - mouseY); putTextAtTop(); drawAllTheOldPoints(); if (mousePressed) { makeAnotherPoint(); } if (keyPressed && key == CODED) { drawATemporaryLine(); } } void keyPressed() { if (key != CODED) { keys += key; } } void putTextAtTop() { fill(0); text("mouseX = " + mouseX + ", mouseY = " + mouseY, 20, 20); text(keys, 20, 35); fill(100, 200, 255); } void drawAllTheOldPoints() { for (Point p : points) { ellipse(p.x, p.y, 10, 10); } } void makeAnotherPoint() { fill(255, 0, 0); ellipse(mouseX, mouseY, 10, 10); points.add(new Point(mouseX, mouseY)); } void drawATemporaryLine() { if (keyCode == LEFT) { line (mouseX - 100, mouseY, mouseX, mouseY); } else if (keyCode == RIGHT) { line (mouseX, mouseY, mouseX + 100, mouseY); } else if (keyCode == UP) { line (mouseX, mouseY, mouseX, mouseY - 100); } else if (keyCode == DOWN) { line (mouseX, mouseY, mouseX, mouseY + 100); } else { text(keyCode, mouseX, mouseY); } }
Your program should work. Zip your file or files together with a readme.txt file for your description of the minimum and desired game features, and anything else you want to say about the program.