Commit 55f09740 authored by a.guest's avatar a.guest

Asteroid rendered

Comments added
Worksheet 01 added (not completed)
parent f8188b8c
package spaceshooter01; package spaceshooter01;
import processing.core.PApplet; import processing.core.PApplet;
import processing.core.PImage;
public class SpaceShooter01 extends PApplet { public class SpaceShooter01 extends PApplet {
enemyObject asteroid; // object used to define an asteroid
// settings() method is run when the application starts
// It is used to set the application settings
public void settings() { public void settings() {
size(500, 500); size(500, 500); // Sets the size of the window
} }
// setup() method is called once, after the settings() method
// setup() is used to create objects and carry out any preparations for running the application
public void setup() public void setup()
{ {
int i=0; asteroid = new enemyObject(this); // Creates a new object of the enemyObject type called asteroid
} }
// The draw() method is run and as soon as it completes it is run again.
// This continues until the application ends
// The method is poorly named because it does more than simply draw to the screen
// It needs to carry out three main functions
// 1 - Process input from the mouse and keyboard
// 2 - Update all the objects in the application
// 3 - Render (draw) to the screen
// I've added methods for each of these functions and changed the draw() method
// to call these three new methods in order.
// You *shouldn't* need to ever change the draw() method
// Method to handle keyboard and mouse input
public void handleInput() public void handleInput()
{ {
} }
// update() handles updating all the objects in the application
// More accurately it tells all the objects in the application to update themselves,
// passing on any information they need to do that
public void update() public void update()
{ {
asteroid.update(); // calls the asteroid's update() method
} }
// render() handles the drawing of objects to the screen
// again it mostly does this by telling all the objects to draw themselves
public void render() public void render()
{ {
background(64); background(0); // sets the windows background to black
ellipse(mouseX, mouseY, 20, 20);
asteroid.render(); // calls the asteroid's render() method to draw it
} }
// draw() method described above. Called constantly byh processing
// You shouldn't need to change this
public void draw(){ public void draw(){
handleInput(); handleInput();
update(); update();
render(); render();
} }
// main() method is the starting point of any Java application
// In this case it starts the processing applet
// this calls settings() followed by setup(), then begins repeatedly calling draw.
public static void main(String[] passedArgs) { public static void main(String[] passedArgs) {
String[] appletArgs = new String[] { "spaceshooter01.SpaceShooter01" }; String[] appletArgs = new String[] { "spaceshooter01.SpaceShooter01" };
PApplet.main(appletArgs); PApplet.main(appletArgs);
......
package spaceshooter01; package spaceshooter01;
public class enemyObject { import processing.core.PApplet;
import processing.core.PImage;
public enemyObject() public class enemyObject {
PApplet papplet; // Handle for processing methods
PImage sprite; // object to hold an image
// Constructor method for enemyObject
public enemyObject(PApplet papp)
{ {
papplet = papp; // required to use processing methods here
sprite = papp.loadImage("asteroid.png"); // loads the image from the data folder
sprite.resize(64, 0); // resizes the image to (x,y) dimensions. Note that if either x or y is
// zero then the image will be resized and maintain aspect ratio
} }
// Method to handle keyboard and mouse input
// Not used yet!
public void handleInput() public void handleInput()
{ {
} }
// Method to handle updates to the enemyObject
public void update() public void update()
{ {
} }
// Method to draw the enemyObject
public void render() public void render()
{ {
papplet.image(sprite,100,100); // Draws image at position 100,100
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment