Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Final Pull Request #47

Merged
merged 40 commits into from
Jul 29, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
ceff0d1
lab2
ethanyuwang Jul 1, 2016
a5dbe71
Update M16_lab02.md
kyokotake Jul 1, 2016
b38bb76
visible selections for backgrounds
ethanyuwang Jul 8, 2016
e58e998
Merge branch 'master' of https://github.com/ethanyuwang/cs56-games-co…
ethanyuwang Jul 8, 2016
fa39279
added image
kyokotake Jul 8, 2016
1ea1130
show total score at the end of game
ethanyuwang Jul 8, 2016
d754c4f
high score class added, not incoperated into the game yet
ethanyuwang Jul 13, 2016
63dcc54
working on high score
ethanyuwang Jul 13, 2016
50f436f
Update CountryRunnerTitleScreen.java
ethanyuwang Jul 13, 2016
8027ed3
Update ScoreSystem.java
ethanyuwang Jul 13, 2016
466bb2d
update high scores
ethanyuwang Jul 13, 2016
ca856fe
Update CountryRunnerJPanel.java
ethanyuwang Jul 13, 2016
95dec86
High scores function added
Jul 13, 2016
7611282
New background
Jul 13, 2016
2fd3132
latest
Jul 15, 2016
14a216c
latest working code
Jul 15, 2016
1b452b5
Scrolling background added, better backgrounds for scrolling
ethanyuwang Jul 15, 2016
df691f6
Add files via upload
kyokotake Jul 26, 2016
f9cece5
Delete mario copy.png
kyokotake Jul 26, 2016
f09ba23
uniformed title screen and game over screen, 50pts? two new avatars, …
Jul 26, 2016
d871302
Merge branch 'master' of https://github.com/ethanyuwang/cs56-games-co…
Jul 26, 2016
db541c0
Difficulties, new obstacles work in progress
Jul 27, 2016
6309fac
finished three levels of difficulties, two new obstacles
Jul 27, 2016
992e616
score system can save name and difficulty
Jul 28, 2016
e364b3b
Delete SpriteTest.java
ethanyuwang Jul 28, 2016
d5a3546
Deleted high score
kyokotake Jul 28, 2016
da778a3
Delete backgroundmaple.jpg
ethanyuwang Jul 28, 2016
a67461d
Delete backgroundmaple.png
ethanyuwang Jul 28, 2016
e1dcb48
Delete backgroundmaple.jpg.
ethanyuwang Jul 28, 2016
6015f1b
Delete backgroundmaple.odg
ethanyuwang Jul 28, 2016
cfee2b8
Delete 600x400maplebackground.jpg
ethanyuwang Jul 28, 2016
8f7b49d
Update HighScores
ethanyuwang Jul 28, 2016
d196f0e
Score system bug fix
Jul 28, 2016
a38d8c0
Merge branch 'master' of https://github.com/ethanyuwang/cs56-games-co…
Jul 28, 2016
523eed4
occurance of obstalced randomlized
Jul 28, 2016
09056d0
Update README.md
kyokotake Jul 29, 2016
392b731
Create M16_lab08.md
kyokotake Jul 29, 2016
79a768c
Future improvements
kyokotake Jul 29, 2016
8437ec0
furture changes
kyokotake Jul 29, 2016
0b79552
Future improvements
kyokotake Jul 29, 2016
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions M16_lab02.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
a. This is a game where the object is to jump over obstacles.

b. As a user I can press play so that I can play the game. As a user I can play the game by jumping over objects. As a user I can press Instructions so that I can see the instructions.

c. This software runs, but does not fulfill all functions in the descriptions. The game starts with a title screen and lets user to select play, high score, instructions, and choose background. When the game plays, two types of obstacles will move towards the user’s character. Uparrow key is used to jump over the obstacles. Choose Background changes the game’s background.

d. As a user I can press Choose Background so that I can see a list of backgrounds and choose one for the game’s background. As a user I can press High Scores so that I can see the most recent high scores. As a user I can press play game so that I can choose which level of difficulty I want play the game at.

e. The current readme covers most of information of this game. However, some of the functionalities are actually missing in the game, which should have been commented.

f. The build.xml file does not have any old legacy JWS stuff that needs to be removed and there are not any targets that need descriptions.

g. Yes the issues are enough for earning 1000 points. The first issue is that the background won’t scroll as it should be, also there no other background objects at different depth to show the game environment better.

h. Modify the game over screen to show the final score of the game just played. (link: https://github.com/ethanyuwang/cs56-games-country-runner.git) Background does not scroll. (https://github.com/UCSB-CS56-Projects/cs56-games-country-runner/issues/43) Game is too difficult for new beginners. (https://github.com/UCSB-CS56-Projects/cs56-games-country-runner/issues/44)
Present list of options to change the background to. (https://github.com/ethanyuwang/cs56-games-country-runner.git)

i. The code is divided into sections for different functionalities of the game, and also different objects/characters. Classes and their methods are organized clear and how they are related can be understood easily. The code overall is precise and well-structured to understand.I would have a very precise description for each file at the very top, and a line or two to explain each class and their methods, to have other programmers to understand the source code easier.

j. Currently there are JUnit tests to test the Sprites, however expand the coverage we can add more tests for each of the method in the classes.
9 changes: 9 additions & 0 deletions M16_lab08.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#Karli Yokotake, Yuxiang (Ethan) Wang

* Issue #48: Game playing character boundary. 100pts Link:https://github.com/UCSB-CS56-Projects/cs56-games-country-runner/issues/48
* Issue #49: Add layered background. 200pts?
Link: https://github.com/UCSB-CS56-Projects/cs56-games-country-runner/issues/49
* Issue #30: Add shooting feature. 250pts?
Link: https://github.com/UCSB-CS56-Projects/cs56-games-country-runner/issues/30
* Issue #50: Handle zero score. 75pts?
Link: https://github.com/UCSB-CS56-Projects/cs56-games-country-runner/issues/50
18 changes: 12 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ project history
```
W14 | andrewberls 4pm | thetomcraig, sdrhoads | Running game with obstacles.
W16 | omeed 5pm |Dongyang Li, Yueyang Li| Running game with obstacles.
M16 | |Karli Yokotake, Yuxiang (Ethan) Wang | Running game with obstacles.
```

#Game Description
Expand All @@ -18,15 +19,19 @@ Country Runner is an "avoid-the-obstacles" sidescroller game. Ride your piggy th

Use the <b>UP</b> and <b>DOWN</b> arrow keys to cycle through your options. Press <b>RIGHT</b> to select.
Select <b>Play</b> to start the game.
Select <b>High Scores</b> to display user high scores.
Select <b>Instructions</b> to learn how to play.
(The HighScores will be displayed on Title Page)
Select <b>Choose Difficulty</b> choose the difficulty of the game.
Select <b>Choose Avatar</b> to choose an avatar to pay.
Select <b>Choose Background</b> to choose a background for the game.
(The HighScores will be displayed on a pop up on Title Page)


##Instuctions

Avoid all obstacles that come into the screen. Could be a stationary scarecrow, or a dashing sheep. Some crows could be overhead so time your jumps carefully.

Press the <b>UP</b> arrow key to jump
Avoid all obstacles that come into the screen. Could be a stationary scarecrow, or a dashing sheep.
Some crows could be overhead so time your jumps carefully.
Press the Up arrow key to jump, Left/Right arrow keys to move forward or backward.

--------------------------
#Developer Notes
Expand Down Expand Up @@ -55,13 +60,14 @@ Type `ant -p` to view the currently available tasks you can perform.


##<i>Ideas Future Versions of Country Runner</i>
Prevent the add score button from showing up on the game over screen when the score is 0.

Apply a scoring system to the game. Your score increases the farther you get without colliding with an obstacle. Keep a record of scores so that Highecores can be displayed on the Title Screen.
Set a boundary that prevents the player from moving of the screen.

Runner jumps longer by holding down the <b>UP</b> button. Quickly tapping the <b>UP</b> button will result in shorter jumps.

Layer the background to create depth. Layering wil consist of of several backgrounds (some of which have transparent parts) that each scroll slightly faster then one behind it.

##<i>W16 Final Remarks</i>

This is a game that we control a character to move and jump to avoid obstacles and get scores. Once the character collides with obstacles, game is over. The Gui.java is to create the window. The JPanel and title screen classes are used to draw image in different states of the game. Runner, Sheep and Snail classes which extends Sprite class will create and handle the state and behavior of the objects in the game. Runner object is the main character. Sheep and Snail objects are the obstacle objects. For future development of this legacy project, developer could implement the highest score record which can be showed in the title screen by clicking the "highest score" button. Also, developer can add shoot method to let the main character or obstacles shoot. Furthermore, developers also can make moving background which makes the game look more comfortable. For the opportunity of refactoring the project, future developers can move the action listeners out and create a InputHandler class to handle user inputs.
This is a game that we control a character to move and jump to avoid obstacles and get scores. Once the character collides with obstacles, game is over. The Gui.java is to create the window. The JPanel and title screen classes are used to draw image in different states of the game. Runner, Sheep and Snail classes which extends Sprite class will create and handle the state and behavior of the objects in the game. Runner object is the main character. Sheep, Snail, Racoon, and Panda objects are the obstacle objects. For future development of this legacy project, developer could prevent the player from moving off screen. Also, developer can add shoot method to let the main character or obstacles shoot. Furthermore, developers also can make a layered background which makes the game look more comfortable. For the opportunity of refactoring the project, future developers can move the action listeners out and create a InputHandler class to handle user inputs.
2 changes: 2 additions & 0 deletions data/HighScores
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ETHAN 99 Difficulty: Hard
Karli 80 Difficulty: Hard
Binary file removed res/600x400maplebackground.jpg
Binary file not shown.
Binary file added res/Cowboy.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added res/Cowgirl.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added res/Gameover.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added res/Pumpkin Head.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed res/background.jpg
Binary file not shown.
Binary file modified res/background1.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added res/background2.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added res/background3.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed res/backgroundmaple.jpg
Binary file not shown.
Binary file removed res/backgroundmaple.jpg.
Binary file not shown.
Binary file removed res/backgroundmaple.odg
Binary file not shown.
Binary file removed res/backgroundmaple.png
Binary file not shown.
Binary file modified res/newbackground.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added res/pandaSheet.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added res/raccoonSheet.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
77 changes: 77 additions & 0 deletions src/edu/ucsb/cs56/projects/games/country_runner/Background.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
package edu.ucsb.cs56.projects.games.country_runner;
import java.awt.Graphics;
import java.awt.image.BufferedImage;
import java.io.File;
import javax.imageio.ImageIO;


public class Background {
private BufferedImage image;

private int x;
private int y;

public Background(String imageName) {
this(0,0,imageName);
}

public Background(int x, int y, String imageName) {
this.x = x;
this.y = y;

// Try to open the image file background.png
try {
image = ImageIO.read(new File(imageName));
}
catch (Exception e) { System.out.println(e); }

}

/**
* Method that draws the image onto the Graphics object passed
* @param window
*/
public void draw(Graphics window) {

// Draw the image onto the Graphics reference
window.drawImage(image, getX(), getY(), image.getWidth(), image.getHeight(), null);

// Move the x position right for next time
this.x += 2;

// Check to see if the image has gone off stage right
if (this.x >= image.getWidth()) {

// If it has, line it back up so that its right edge is
// lined up to the left side of the other background image
this.x = this.x - image.getWidth() * 2;
}

}

public void setX(int x) {
this.x = x;
}
public int getX() {
return this.x;
}
public int getY() {
return this.y;
}
public int getImageWidth() {
return image.getWidth();
}

public static String[] loadBackgrounds() {
//Load background images
String[] backgrounds = new String[3];
for (int i=1; i<=backgrounds.length; i++) {
String imagePath = "res/background";
imagePath += i;
imagePath += ".jpg";
backgrounds[i-1] = imagePath;
}
return backgrounds;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.awt.image.BufferedImage;


/** CountryRunnerJPanel
Expand All @@ -32,12 +33,19 @@ public class CountryRunnerJPanel extends JPanel implements Runnable
Thread mainThread;
Thread musicThread;

//Background
private Background backOne;
private Background backTwo;
private BufferedImage back;

//The runner and the sheep, there
//is only one sheep right now, may want
//to add more in the future.
Runner runner = new Runner();
Sheep sheep = new Sheep();
Snail snail = new Snail();
Runner runner = new Runner(CountryRunnerTitleScreen.avatar);
Sheep sheep = new Sheep(CountryRunnerTitleScreen.difficulty);
Snail snail = new Snail(CountryRunnerTitleScreen.difficulty);
Raccoon raccoon = new Raccoon(CountryRunnerTitleScreen.difficulty);
Panda panda = new Panda(CountryRunnerTitleScreen.difficulty);

//Score Overlay
JLabel scoreLabel;
Expand Down Expand Up @@ -65,7 +73,16 @@ public CountryRunnerJPanel()
this.runnerHasCollided = false;
this.score = 0;

//The thrad gets started once and its run method is the main game loop

//background
//Load background images
String[] backgrounds = Background.loadBackgrounds();

//String imageName = "background.png";
backOne = new Background(backgrounds[CountryRunnerTitleScreen.changeBackground-1]);
backTwo = new Background(backOne.getImageWidth(), 0, backgrounds[CountryRunnerTitleScreen.changeBackground-1]);

//The thrad gets started once and its run method is the main game loop
this.mainThread = new Thread(this);
this.musicThread = new Thread(new BackgroundMusic());
mainThread.start();
Expand Down Expand Up @@ -167,7 +184,7 @@ public void run()
}

//update scores
score = sheep.getScore() + snail.getScore();
score = sheep.getScore() + snail.getScore() + raccoon.getScore() + panda.getScore();

//Every iteration of the main loop, we want
//to call this to redraw all of the images
Expand All @@ -176,7 +193,7 @@ public void run()
//Sleep the main thread so its doesn't update everything super quickly
try
{
mainThread.sleep(85);
mainThread.sleep(65);
}
catch(Exception e){}

Expand All @@ -192,36 +209,28 @@ public void paintComponent(Graphics g)
{
//Draw the background
g2 = (Graphics2D) g;

Image image = new ImageIcon("res/background1.jpg").getImage();


Image image1 = new ImageIcon("res/background.jpg").getImage();



Image heaven = new ImageIcon("res/heaven.jpg").getImage();
if(CountryRunnerTitleScreen.changeBackground == true){
g.drawImage(image1, 0, 0, this);

}
else{
g.drawImage(image, 0, 0, this);
}

scrollingBackground(g);

//Update the sprites' positions
runner.updateCurrentPosition();
sheep.updateCurrentPosition();
snail.updateCurrentPosition();
raccoon.updateCurrentPosition();
panda.updateCurrentPosition();

//Collision check, did the runner hit anything?
//If so, the game is over
if (this.runnerHasCollided(snail, sheep, runner)) // need to add snail to this later
if (this.runnerHasCollided(panda, raccoon, snail, sheep, runner)) // need to add snail to this later
{
// can add death animation here

this.gameIsRunning = false;
AudioPlayer.player.stop(BackgroundMusic.song);
CountryRunnerGui.setCurrentPanelTo(new GameOverJPanel());

CountryRunnerGui.setCurrentPanelTo(new GameOverJPanel(score));
}

else
Expand All @@ -234,9 +243,13 @@ public void paintComponent(Graphics g)
runner.updateCurrentImage();
sheep.updateCurrentImage();
snail.updateCurrentImage();
raccoon.updateCurrentImage();
panda.updateCurrentImage();
g2.drawImage(sheep.getCurrentImage(), (int)sheep.getX(), (int)sheep.getY(), null);
g2.drawImage(runner.getCurrentImage(), (int)runner.getX(), (int)runner.getY(), null);
g2.drawImage(snail.getCurrentImage(), (int)snail.getX(), (int)snail.getY(), null);
g2.drawImage(raccoon.getCurrentImage(), (int)raccoon.getX(), (int)raccoon.getY(), null);
g2.drawImage(panda.getCurrentImage(), (int)panda.getX(), (int)panda.getY(), null);

scoreLabel.setText("Score: " + Integer.toString(score));

Expand All @@ -246,11 +259,12 @@ public void paintComponent(Graphics g)

/** runnerHasCollided
* Determines if the runner hits the sheep object
*need much better organization
* @param c sheep object
* @param r runner object
* @return boolean true if there is a runnerHasCollided, false if not
*/
public boolean runnerHasCollided(Snail s, Sheep c, Runner r) // need to add snail to this function too
public boolean runnerHasCollided(Panda p, Raccoon a, Snail s, Sheep c, Runner r) // need to add snail to this function too
{
if ((r.getY() + r.getHeight()) >= c.getY())
{
Expand All @@ -262,7 +276,34 @@ public boolean runnerHasCollided(Snail s, Sheep c, Runner r) // need to add snai
if ((s.getX()+40>r.getX()) && ((s.getX()-20) <r.getX()))
return true;
}
if ((r.getY() + r.getHeight()) >= a.getY())
{
if ((a.getX()+40>r.getX()) && ((a.getX()-20) <r.getX()))
return true;
}
if((r.getY() + r.getHeight()) >= p.getY())
{
if ((p.getX()+40>r.getX()) && ((p.getX()-20) <r.getX()))
return true;
}

return false;
}

public void scrollingBackground(Graphics g)
{
if (back == null)
back = (BufferedImage)(createImage(getWidth(), getHeight()));

// Create a buffer to draw to
Graphics buffer = back.createGraphics();

// Put the two copies of the background image onto the buffer
backOne.draw(buffer);
backTwo.draw(buffer);

// Draw the image onto the window
g.drawImage(back, 0, 0, this);
}

}//JPanel
Loading