Skip to content

Commit

Permalink
Make the project working again
Browse files Browse the repository at this point in the history
  • Loading branch information
sunboyy committed Jul 5, 2023
1 parent 509093a commit 9ca2fd4
Show file tree
Hide file tree
Showing 3 changed files with 101 additions and 49 deletions.
Binary file removed Project_2017_CP_Story.jar
Binary file not shown.
94 changes: 59 additions & 35 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,35 +1,59 @@
# Instruction

1. Using a git command to clone this repository to your computer.
2. Open Eclipse and then "import existing project" from the cloned folder (In Step 1) into your Eclipse workspace.
3. Rename your Eclipse Java project: **`2110215_Project_2017_{GroupName}`**.
- Example: If your group name is **`Rockman`**, your project name should be **`2110215_Project_2017_Rockman`**.
4. Implement your project.
- You should create a commit when you finish each function of your project.
- Don't wait until you finish the whole project to create a commit.
5. Export your project into a runnable jar file named **`Project_2017_{GroupName}.jar`**
- Example: If your group name is **`Rockman`**, your jar name should be **`Project_2017_Rockman.jar`**.
- Your jar file must include all your resources (images or audios) and it must be runnable from anywhere.
6. Create a PDF document of your project and put it at the root directory.
- Your document should contain:
- Brief introduction about your project.
- User Manual (How to use your program or How to play if your project is a game).
- Implementation Detail (UML class diagram and description of all classes and methods you implemented)
- The document of each lab or exercise is a great example of how your document should look like.
7. Ensure that you push all commits of your project within **14 December 2017**.
- To sum up, this repository should contain:
- All your codes.
- Runnable jar file.
- PDF Document.
- An image of the UML class diagram.
8. **On your presentation day (15 December 2017)**, bring a printed version of your document and your own laptop for showing a demo of your project.
- **You only have 5 minutes for showing a demo of your project. So make sure that your laptop is ready for presentation beforehand.**

# Support

* If you need any kind of help or advice about your project
1. You can meet and ask TAs directly at Lab Game 18th floor Engineering 4 Building (Charoenvidsavakham) every Friday between 1pm and 4pm.
- Please make an appointment if you want to meet at some other time.
2. You can ask in channel #project of our Slack.
- If you have never joined our Slack before, go to https://goo.gl/FmKbMY.
- Otherwise, go to https://progmeth2017.slack.com and sign in with your account.
# CP Story

CP Story is a final project of the Programming Methodology class 2017 at Chulalongkorn University, learning about object-oriented programming. It is a game inspired by MapleStory but was modified to have characters, monsters, scenes, and skills related to Computer Engineering and Chulalongkorn University.

## How to run the code on Eclipse

Since this project was initially developed without a package manager, external libraries must be imported manually.

1. Download [JavaFX SDK 17](https://gluonhq.com/products/javafx/) and extract the downloaded ZIP file.
2. Open Eclipse settings, go to `Java` > `Build Path` > `User Libraries` and create new `JavaFX 17` library
3. Add all 8 External JARs from the downloaded JavaFX SDK to the `JavaFX 17` user library.
4. Open the project on Eclipse, right click on the root directory, go to `Build Path` > `Add Libraries`, select `User Library` and select `JavaFX 17`
5. Open `src/main/Main.java` and click Run. This should not be working yet.
6. Click dropdown next to the Run button and open Run Configurations, select Arguments tab, type the following to VM arguments text field, and uncheck `Use the -XstartOnFirstThread...` option.

```
--module-path <JAVAFX_SDK_DIR>/lib --add-modules=javafx.controls,javafx.media
```

7. Click Run again, the game should now be working.

## How to run the JAR file

The JAR file is provided in the [Releases](https://github.com/sunboyy/cp-story/releases) page on GitHub. Download the latest version before continuing.

Because JavaFX library is not embedded in the JAR file, you still need to download the JavaFX SDK library like in the previous section. After having the JavaFX library downloaded and unzipped, execute this command in the terminal window to start the game.

```
java --module-path <JAVAFX_SDK_DIR>/lib \
--add-modules=javafx.controls,javafx.media \
-jar cpstory.jar
```

## Contributors

Thanks all these people to make this project happen!

<table>
<tbody>
<tr>
<td align="center" width="50%">
<a href="https://github.com/sunboyy">
<img src="https://avatars.githubusercontent.com/u/22892266?v=4?s=100" width="100px;" alt="sunboyy"/><br />
<sub><b>sunboyy</b></sub>
</a>
</td>
<td align="center" width="50%">
<a href="https://github.com/npmoewii">
<img src="https://avatars.githubusercontent.com/u/22891156?v=4?s=100" width="100px;" alt="npmoewii"/><br />
<sub><b>npmoewii</b></sub>
</a>
</td>
</tr>
</tbody>
</table>

## Original code

You can find the original code of this project when it was submitted in branch [final](https://github.com/sunboyy/cp-story/tree/final).
56 changes: 42 additions & 14 deletions src/particle/DisplayName.java
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
package particle;

import com.sun.javafx.tk.FontLoader;
import com.sun.javafx.tk.Toolkit;

import controller.GameManager;
import javafx.geometry.Dimension2D;
import javafx.geometry.VPos;
import javafx.scene.canvas.GraphicsContext;
import javafx.scene.paint.Color;
import javafx.scene.text.Font;
import javafx.scene.text.FontWeight;
import javafx.scene.text.Text;
import javafx.scene.text.TextAlignment;
import model.DamageableEntity;
import model.player.Player;

public class DisplayName implements IParticle {

public static final Font NAME_FONT = Font.font("Arial", FontWeight.BOLD, 12);
public static final double PADDING = 4;

private DamageableEntity entity;
private int visibleTick = 180;
Expand All @@ -28,23 +28,51 @@ public DisplayName(DamageableEntity entity) {
public void render(GraphicsContext gc) {
if (!isVisible() && !(entity instanceof Player)) return;

double mapX = GameManager.getInstance().getCurrentMap().getX();
double mapY = GameManager.getInstance().getCurrentMap().getY();
double centerX = entity.getX() + entity.getWidth() / 2;
String text = String.format("Lv. %d: %s", entity.getLevel(), entity.getName());
FontLoader fontLoader = Toolkit.getToolkit().getFontLoader();
double textWidth = fontLoader.computeStringWidth(text, NAME_FONT);
double textHeight = fontLoader.getFontMetrics(NAME_FONT).getLineHeight();
Dimension2D textSize = calculateTextSize(text);

renderBackground(gc, textSize);
renderText(gc, text, textSize);

visibleTick++;
}

private Dimension2D calculateTextSize(String textValue) {
Text text = new Text(textValue);
text.setFont(NAME_FONT);
return new Dimension2D(text.getLayoutBounds().getWidth(), text.getLayoutBounds().getHeight());
}

private void renderBackground(GraphicsContext gc, Dimension2D textSize) {
double mapOffsetX = GameManager.getInstance().getCurrentMap().getX();
double entityCenterX = entity.getX() + entity.getWidth() / 2;
double topLeftX = entityCenterX - textSize.getWidth() / 2 - PADDING - mapOffsetX;

double mapOffsetY = GameManager.getInstance().getCurrentMap().getY();
double topLeftY = entity.getY() + entity.getHeight() - mapOffsetY;

double width = textSize.getWidth() + PADDING * 2;
double height = textSize.getHeight() + PADDING * 2;

gc.setFill(Color.BLACK);
gc.setGlobalAlpha(0.6);
gc.fillRoundRect(topLeftX, topLeftY, width, height, 8, 8);
}

private void renderText(GraphicsContext gc, String textValue, Dimension2D textSize) {
double mapOffsetX = GameManager.getInstance().getCurrentMap().getX();
double entityCenterX = entity.getX() + entity.getWidth() / 2;
double x = entityCenterX - mapOffsetX;

double mapOffsetY = GameManager.getInstance().getCurrentMap().getY();
double y = entity.getY() + entity.getHeight() + PADDING - mapOffsetY;

gc.setTextAlign(TextAlignment.CENTER);
gc.setTextBaseline(VPos.TOP);
gc.setFill(Color.BLACK);
gc.setFont(NAME_FONT);
gc.setGlobalAlpha(0.6);
gc.fillRoundRect(centerX-textWidth/2-4-mapX, entity.getY()+entity.getHeight()-mapY, textWidth+8, textHeight+8, 8, 8);
gc.setGlobalAlpha(1);
gc.setFill(Color.WHITE);
gc.fillText(text, centerX-mapX, entity.getY()+entity.getHeight()+4-mapY);
visibleTick++;
gc.fillText(textValue, x, y);
}

public boolean isVisible() {
Expand Down

0 comments on commit 9ca2fd4

Please sign in to comment.