Skip to content

Commit

Permalink
Merge pull request #10 from MutantPiggieGolem1/menu
Browse files Browse the repository at this point in the history
yay
  • Loading branch information
MutantPiggieGolem1 authored May 28, 2022
2 parents e0ceb29 + 8026aee commit f4c04f4
Show file tree
Hide file tree
Showing 100 changed files with 938 additions and 510 deletions.
4 changes: 2 additions & 2 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
"type": "java",
"name": "Launch",
"request": "launch",
"mainClass": "hugoneseven.App",
"projectName": "hugoneseven",
"mainClass": "hugone.App",
"projectName": "hugone",
"console": "internalConsole"
}
]
Expand Down
20 changes: 20 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"version": "2.0.0",
"tasks": [
{
"type": "java",
"mainClass": "hugone.App",
"targetPath": "${workspaceFolder}/${workspaceFolderBasename}.jar",
"elements": [
"${compileOutput}",
"${dependencies}"
],
"problemMatcher": [],
"label": "java: exportjar:hugone",
"group": {
"kind": "build",
"isDefault": true
}
}
]
}
3 changes: 2 additions & 1 deletion META-INF/MANIFEST.mf
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
Main-Class: hugoneseven.App
Class-Path: .
Main-Class: hugone.App
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# Hugone Seven
# Hugone
An undertale-style horror game designed with rhythm battles
Commissioned.
#### Commissioned.
39 changes: 25 additions & 14 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>hugone</groupId>
<artifactId>hugone</artifactId>
<version>ALPHA</version>
<version>0.5-ALPHA</version>

<name>hugone</name>
<!-- <url>http://www.example.com</url> -->
Expand All @@ -18,22 +18,11 @@
</properties>

<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20211205</version>
</dependency>
<dependency>
<groupId>javax.media</groupId>
<artifactId>jmf</artifactId>
<version>2.1.1e</version>
</dependency>
</dependencies>

<build>
Expand All @@ -60,14 +49,36 @@
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<version>3.0.2</version>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<mainClass>hugone.App</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<mainClass>hugoneseven.App</mainClass>
<mainClass>hugone.App</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
<executions>
<execution>
<id>make-assembly</id> <!-- this is used for inheritance merges -->
<phase>package</phase> <!-- bind to the packaging phase -->
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-install-plugin</artifactId>
Expand Down
89 changes: 89 additions & 0 deletions src/main/java/hugone/App.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
package hugone;

import java.awt.Graphics2D;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

import javax.swing.JFrame;

import hugone.Constants.Feature;
import hugone.Constants.GameState;
import hugone.util.Utils;

class App {
public static java.util.HashMap<String,Object> shit = new java.util.HashMap<String,Object>(); // stores temporary vars to be relayed to main file

public static Story story;
public static Player player;
public static GameState gamestate;

public static final JFrame f = new JFrame("Hugone - Alpha Version");
private static final ScheduledExecutorService executor = Executors.newScheduledThreadPool(1);

public static void main(String[] args) {
try {
story = new Story("story.json");
story.init();
} catch (Exception e) {
throw new RuntimeException("Couldn't initalize story.\nDetais: " + e.toString());
}
player = story.player;
gamestate = story.currentState();

DrawingCanvas dc = new DrawingCanvas(f);
f.setIconImage(Utils.ICONIMG);
f.setFocusable(true);
f.setResizable(false);
f.setUndecorated(false);
f.setExtendedState(JFrame.MAXIMIZED_BOTH);
f.add(dc);
f.addKeyListener(player);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

// Game Loop begins
executor.scheduleAtFixedRate(() -> {
try {
Feature cur = story.getCurrent();
if (cur.update())
story.next(); // on completion, advance story
cur = story.getCurrent();
switch (story.currentState()) {
case MENU:
Menu m = (Menu) cur;
m.update();
break;
case CUTSCENE:
break;
case EXPLORATION:
Area a = (Area) cur;
if(!a.renderingDialogue()) {
player.moveLoop();
a.checkInteracts(player);
}
break;
case BATTLE:
Battle b = (Battle) cur;
b.beat();
break;
}
} catch (Exception e) {
e.printStackTrace();
System.exit(0);
}
}, 0, (long) (1000 / Constants.TPS), TimeUnit.MILLISECONDS);

f.setVisible(true);
f.requestFocus();
dc.startDraw();
f.setEnabled(true);
}

public static void render(Graphics2D g) {
story.getCurrent().render(g);
}

public static void postRender(Graphics2D g) {
g.drawString(String.valueOf(Utils.fps()), 0, 0);
}
}
Original file line number Diff line number Diff line change
@@ -1,37 +1,35 @@
package hugoneseven;
package hugone;

import java.awt.Graphics2D;
import java.awt.Point;
import java.awt.Rectangle;
import java.awt.event.KeyEvent;
import java.awt.Dimension;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import hugoneseven.Constants.Feature;
import hugoneseven.Constants.InteractableObject;
import hugoneseven.Constants.KeyPress;
import hugoneseven.Constants.RenderState;
import hugoneseven.util.Audio;
import hugoneseven.util.Image;
import hugoneseven.util.Utils;
import hugone.Constants.Feature;
import hugone.Constants.InteractableObject;
import hugone.Constants.KeyPress;
import hugone.Constants.RenderState;
import hugone.util.Audio;
import hugone.util.Image;
import hugone.util.Utils;

@SuppressWarnings("unused")
class Area implements Feature {
class Area implements Feature { // TODO: Allow audio overlap
private final String id;
private final Image image;
private ArrayList<Furniture> furniture = new ArrayList<Furniture>();
private RenderState renderstate;
private ArrayList<String> find;
private Dialogues dialogue;
private Audio music;
private int[] dimensions = new int[2];
private int[] borders = new int[2];
private Point startloc = new Point();
private Rectangle dimensions;
private Point startloc;
private boolean exit = false;

public Area(String id) throws JSONException {
JSONObject data = App.story.data.getJSONObject("areas").getJSONObject(id);
Expand All @@ -40,12 +38,9 @@ public Area(String id) throws JSONException {

this.id = id;
this.image = new Image(data.getString("image"));
this.dimensions[0] = dims.getJSONArray(1).getInt(0);
this.dimensions[1] = dims.getJSONArray(1).getInt(1);
this.borders[0] = dims.getJSONArray(0).getInt(0);
this.borders[1] = dims.getJSONArray(0).getInt(1);
this.startloc.setLocation(start.getInt(0), start.getInt(1));;
this.image.scaleToWidth(this.dimensions[0]);
this.dimensions = new Rectangle(dims.getJSONArray(0).getInt(0),dims.getJSONArray(0).getInt(1),dims.getJSONArray(1).getInt(0),dims.getJSONArray(1).getInt(1));
this.startloc = new Point(start.getInt(0), start.getInt(1));;
this.image.scaleToWidth(this.dimensions.width);
// misc vars
this.find = Utils.toArray(data.getJSONArray("find"));

Expand All @@ -63,6 +58,9 @@ public Area(String id) throws JSONException {
Furniture furni = new Furniture(furn, this);
this.furniture.add(furni);
}

JSONObject exitdata = data.getJSONObject("exit");
this.furniture.add(new Exit(exitdata, this));
}

public void init() {
Expand All @@ -75,21 +73,37 @@ public ArrayList<Furniture> getFurniture() {
return this.furniture;
}

public ArrayList<String> getFind() {
return this.find;
}

public void exit() {
this.exit = true;
}

public boolean update() {
if (this.music!=null && !this.music.isPlaying()) this.music.play();
return App.player.inventory.containsAll(find) && this.renderstate.equals(RenderState.DEFAULT); // all required items, and not rendering dialogue
if (this.music!=null) {
if (this.music.isPlaying()) {
if (this.renderingDialogue()) this.music.pause();
} else {
if (!this.renderingDialogue()) this.music.play();
}
}
return this.exit && this.renderstate.equals(RenderState.DEFAULT); // all required items, and not rendering dialogue
}

public void setDialogue(Dialogues dg) {
this.dialogue = dg;
this.renderstate = RenderState.DIALOGUE;
App.player.stopMovement();
}

public void render(Graphics2D g) {
this.image.draw(0, 0, g);
for (Furniture furniture : this.furniture) {
furniture.render(g);
}
App.player.render(g);
if (this.renderstate.equals(RenderState.DIALOGUE)) {
if (this.dialogue.update() || App.player.spaceDown()) {
this.renderstate = RenderState.DEFAULT; // once done / skipped, return to normal state
Expand All @@ -108,24 +122,28 @@ public void checkInteracts(Player p) {
});
}

public boolean collideFurniture(Point coords) {
public boolean collideFurniture(Rectangle r) {
for (Furniture f : this.furniture) {
if (f.collidesWith(coords)) {
if (f.collidesWith(r)) {
return true;
}
}
return false;
}

public boolean checkCollisions(Point coords) {
return coords.x < this.borders[0] || coords.y < this.borders[1]
|| coords.x > this.dimensions[0]|| coords.y > this.dimensions[1]
|| this.collideFurniture(coords);
public boolean collidesWith(Rectangle r) { // true if collision
return !this.dimensions.contains(r) || this.collideFurniture(r);
}

public boolean renderingDialogue() {
return this.renderstate.equals(RenderState.DIALOGUE);
}

public void reccieveKeyPress(KeyEvent e, KeyPress p) {}

@Override
public void close() {
if (this.music != null) this.music.reset();

}
}
Loading

0 comments on commit f4c04f4

Please sign in to comment.