Commit aee389c8 authored by a.guest's avatar a.guest

Added code to complete week 01 tasks

parent ad2ba6f3
/spaceshooter/
......@@ -23,6 +23,8 @@ public class SpaceShooter extends PApplet {
}
// 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
......@@ -34,6 +36,8 @@ public class SpaceShooter extends PApplet {
// 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()
......@@ -55,9 +59,7 @@ public class SpaceShooter extends PApplet {
{
background(0); // sets the windows background to black
asteroid.render(); // calls the asteroid's render() method to draw it
asteroid.render(); // calls the asteroid's render() method to draw it
}
......
......@@ -2,17 +2,23 @@ package spaceshooter;
import processing.core.PApplet;
import processing.core.PImage;
import java.util.Random;
public class enemyObject {
PApplet papplet; // Handle for processing methods
PImage sprite; // object to hold an image
int xPosition = 230;
int yPosition = 50;
int speed = 5;
Random rand = new Random();
float counter=0f;
// 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 = papplet.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
}
......@@ -27,13 +33,20 @@ public class enemyObject {
// Method to handle updates to the enemyObject
public void update()
{
yPosition = yPosition + speed;
if (yPosition>500)
{
yPosition = -100;
xPosition = 50 + rand.nextInt(400);
}
counter++;
}
// Method to draw the enemyObject
public void render()
{
papplet.image(sprite,200,200); // Draws image at position 100,100
papplet.image(sprite, xPosition, yPosition); // 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