Make signs work

master
John 2022-06-19 17:31:08 -07:00
parent 07e56c49cf
commit edc1376084
7 changed files with 81 additions and 3 deletions

5
saves/Level1-signs.txt Normal file
View File

@ -0,0 +1,5 @@
200 350 This is a sign
300 400 This is also a sign
/
300 200 This is a different sign
400 250 sign sign sign sign

5
saves/Level2-signs.txt Normal file
View File

@ -0,0 +1,5 @@
200 350 This is a sign
300 400 This is also a sign
/
300 200 This is a different sign
400 250 sign sign sign sign

5
saves/Level3-signs.txt Normal file
View File

@ -0,0 +1,5 @@
200 350 This is a sign
300 400 This is also a sign
/
300 200 This is a different sign
400 250 sign sign sign sign

View File

@ -14,6 +14,7 @@ import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
import java.io.Serializable;
import java.lang.reflect.Array;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
@ -31,6 +32,12 @@ public class GamePanel extends JPanel implements Runnable, KeyListener, Serializ
public static final int GAME_HEIGHT = 630;
public static final int fireballSpeed = 5;
public static Font tutorialFont = new Font(Font.MONOSPACED, Font.BOLD, 36);
public static Font loreFont = new Font(Font.MONOSPACED, Font.ITALIC + Font.BOLD, 36);
public static Color tutorialColor = Color.darkGray;
public static Color loreColor = Color.lightGray;
public int bombCount;
public transient JPanel gameFrame;
@ -85,6 +92,8 @@ public class GamePanel extends JPanel implements Runnable, KeyListener, Serializ
public String lastText;
public boolean isContinue;
public boolean isRunning;
public ArrayList<WallSign> tutorialSign = new ArrayList<WallSign>();
public ArrayList<WallSign> loreSign = new ArrayList<WallSign>();
public GamePanel(JPanel gameFrame) throws IOException, SpriteException, UnsupportedAudioFileException, LineUnavailableException {
@ -249,10 +258,21 @@ public class GamePanel extends JPanel implements Runnable, KeyListener, Serializ
//call the draw methods in each class to update positions as things move
public void draw(Graphics g, int playerFrame, int enemyFrame) throws IOException, UnsupportedAudioFileException, LineUnavailableException {
Color oldColor = g.getColor();
Font oldFont = g.getFont();
background.draw(g);
cloudOneBackground.draw(g);
cloudTwoBackground.draw(g);
cloudThreeBackground.draw(g);
for (WallSign w: tutorialSign) {
w.draw(g, tutorialColor);
}
for (WallSign w: loreSign) {
w.draw(g, loreColor);
}
// reset graphics color to black and font to system default
g.setColor(oldColor);
g.setFont(oldFont);
if (isPaused || isDialogue) {
// set player frame to 0 to prevent frame from changing when player moves
playerFrame = 0;
@ -323,8 +343,7 @@ public class GamePanel extends JPanel implements Runnable, KeyListener, Serializ
g.drawImage(getImage(filePath),x*Tile.length - (GamePanel.GAME_WIDTH/2)-camera.x,(int)y,Tile.length,Tile.length,null);
}
// g.drawString(camera.x+" "+((camera.x+GAME_WIDTH)/Tile.length)+" "+player.leftMouseDown,100,100);
// g.drawString(camera.x+" "+((player.mouseX+camera.x+GAME_WIDTH/2)/Tile.length)+" "+player.leftMouseDown,100,200);
g.drawString(camera.x+" "+player.y,100,100);
g.drawImage(bomb.image,20,20,35,35,null);
g.drawString("X"+LevelManager.bombs,60,40);
if (isPaused) {
@ -431,7 +450,7 @@ public class GamePanel extends JPanel implements Runnable, KeyListener, Serializ
double delta = 0;
long now;
int fireballCounter = 0;
while(isRunning){ //this is the infinite game loop
while(isRunning){ //this is the game loop, terminates on game restart to prevent race conditions
now = System.nanoTime();
delta = delta + (now-lastTime)/ns;
lastTime = now;

View File

@ -1,6 +1,7 @@
import javax.imageio.ImageIO;
import javax.sound.sampled.LineUnavailableException;
import javax.sound.sampled.UnsupportedAudioFileException;
import java.awt.*;
import java.io.IOException;
import java.io.Serializable;
import java.util.ArrayList;
@ -50,6 +51,18 @@ public class LevelManager implements Serializable {
GameFrame.game.dialogueMenu.frameCounter = 0;
GameFrame.game.isDialogue = true;
}
// temporary boolean, so only declared here
boolean stillTutorial = true;
for (String[] sA: MapReader.inputSign(filePath)) {
if (sA[0].contains("/")) {
stillTutorial = false;
} else if (stillTutorial) {
System.out.println("" + sA[0] + sA[1]);
GameFrame.game.tutorialSign.add(new WallSign(Integer.parseInt(sA[0]), Integer.parseInt(sA[1]), GamePanel.tutorialFont, sA[2]));
} else {
GameFrame.game.loreSign.add(new WallSign(Integer.parseInt(sA[0]), Integer.parseInt(sA[1]), GamePanel.loreFont, sA[2]));
}
}
} catch (IOException | SpriteException | UnsupportedAudioFileException | LineUnavailableException e) {
throw new RuntimeException(e);
}

View File

@ -1,6 +1,7 @@
import javax.sound.sampled.LineUnavailableException;
import javax.sound.sampled.UnsupportedAudioFileException;
import java.io.*;
import java.util.ArrayList;
import java.util.Arrays;
public class MapReader implements Serializable {
@ -128,6 +129,16 @@ public class MapReader implements Serializable {
return FileManager.readFile(filePath).split("\n");
}
public static ArrayList<String[]> inputSign(String signFilePath) throws IOException {
String filePath = signFilePath.replace(".txt", "-signs.txt");
String[] temporaryStringArray = FileManager.readFile(filePath).split("\n");
ArrayList<String[]> returnArray = new ArrayList<String[]>();
for (String s: temporaryStringArray) {
returnArray.add(s.split(" ", 3));
}
return returnArray;
}
public static void newTile(String filePath) throws IOException, SpriteException {
GameFrame.game.map[x][y]=(new SingleTile(TileX,TileY, new BufferedImageWrapper((filePath))));
}

20
src/WallSign.java Normal file
View File

@ -0,0 +1,20 @@
import java.awt.*;
import java.io.Serializable;
public class WallSign extends TextBox implements Serializable {
public WallSign(int x, int y, Font font, String text) {
super(0, 0, 0, 0, font, text, null);
this.newX = x;
this.y = y;
}
// TODO: flip
public void draw(Graphics g, Color textColor) {
int oldX = this.newX;
newX -= GameFrame.game.camera.x;
super.draw(g, new Color(0, 0, 0, 0), textColor);
newX = oldX;
System.out.println();
}
}