Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
S
SpaceShooter-02
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
a.guest
SpaceShooter-02
Commits
aee389c8
Commit
aee389c8
authored
Jul 30, 2019
by
a.guest
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added code to complete week 01 tasks
parent
ad2ba6f3
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
22 additions
and
6 deletions
+22
-6
.gitignore
bin/.gitignore
+1
-0
SpaceShooter.class
bin/spaceshooter/SpaceShooter.class
+0
-0
enemyObject.class
bin/spaceshooter/enemyObject.class
+0
-0
SpaceShooter.java
src/spaceshooter/SpaceShooter.java
+5
-3
enemyObject.java
src/spaceshooter/enemyObject.java
+16
-3
No files found.
bin/.gitignore
0 → 100644
View file @
aee389c8
/spaceshooter/
bin/spaceshooter/SpaceShooter.class
View file @
aee389c8
No preview for this file type
bin/spaceshooter/enemyObject.class
View file @
aee389c8
No preview for this file type
src/spaceshooter/SpaceShooter.java
View file @
aee389c8
...
@@ -23,6 +23,8 @@ public class SpaceShooter extends PApplet {
...
@@ -23,6 +23,8 @@ public class SpaceShooter extends PApplet {
}
}
// The draw() method is run and as soon as it completes it is run again.
// The draw() method is run and as soon as it completes it is run again.
// This continues until the application ends
// This continues until the application ends
// The method is poorly named because it does more than simply draw to the screen
// The method is poorly named because it does more than simply draw to the screen
...
@@ -34,6 +36,8 @@ public class SpaceShooter extends PApplet {
...
@@ -34,6 +36,8 @@ public class SpaceShooter extends PApplet {
// to call these three new methods in order.
// to call these three new methods in order.
// You *shouldn't* need to ever change the draw() method
// You *shouldn't* need to ever change the draw() method
// Method to handle keyboard and mouse input
// Method to handle keyboard and mouse input
public
void
handleInput
()
public
void
handleInput
()
...
@@ -55,9 +59,7 @@ public class SpaceShooter extends PApplet {
...
@@ -55,9 +59,7 @@ public class SpaceShooter extends PApplet {
{
{
background
(
0
);
// sets the windows background to black
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
}
}
...
...
src/spaceshooter/enemyObject.java
View file @
aee389c8
...
@@ -2,17 +2,23 @@ package spaceshooter;
...
@@ -2,17 +2,23 @@ package spaceshooter;
import
processing.core.PApplet
;
import
processing.core.PApplet
;
import
processing.core.PImage
;
import
processing.core.PImage
;
import
java.util.Random
;
public
class
enemyObject
{
public
class
enemyObject
{
PApplet
papplet
;
// Handle for processing methods
PApplet
papplet
;
// Handle for processing methods
PImage
sprite
;
// object to hold an image
PImage
sprite
;
// object to hold an image
int
xPosition
=
230
;
int
yPosition
=
50
;
int
speed
=
5
;
Random
rand
=
new
Random
();
float
counter
=
0
f
;
// Constructor method for enemyObject
// Constructor method for enemyObject
public
enemyObject
(
PApplet
papp
)
public
enemyObject
(
PApplet
papp
)
{
{
papplet
=
papp
;
// required to use processing methods here
papplet
=
papp
;
// required to use processing methods here
sprite
=
papp
.
loadImage
(
"asteroid.png"
);
// loads the image from the data folder
sprite
=
papp
let
.
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
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
// zero then the image will be resized and maintain aspect ratio
}
}
...
@@ -27,13 +33,20 @@ public class enemyObject {
...
@@ -27,13 +33,20 @@ public class enemyObject {
// Method to handle updates to the enemyObject
// Method to handle updates to the enemyObject
public
void
update
()
public
void
update
()
{
{
yPosition
=
yPosition
+
speed
;
if
(
yPosition
>
500
)
{
yPosition
=
-
100
;
xPosition
=
50
+
rand
.
nextInt
(
400
);
}
counter
++;
}
}
// Method to draw the enemyObject
// Method to draw the enemyObject
public
void
render
()
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
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment