Skip to content

Commit

Permalink
implemented main menu
Browse files Browse the repository at this point in the history
  • Loading branch information
Mythical-Atlas committed May 23, 2020
1 parent 83fe49e commit cdf8099
Show file tree
Hide file tree
Showing 16 changed files with 254 additions and 7 deletions.
Binary file added Sonic Fan Game/assets/objectsounds/back.wav
Binary file not shown.
Binary file added Sonic Fan Game/assets/objectsounds/forward.wav
Binary file not shown.
Binary file added Sonic Fan Game/assets/objectsounds/move.wav
Binary file not shown.
Binary file added Sonic Fan Game/assets/objectsounds/title.wav
Binary file not shown.
Binary file not shown.
Binary file added Sonic Fan Game/assets/objectsprites/cloudLeft.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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 Sonic Fan Game/assets/objectsprites/fade.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 Sonic Fan Game/assets/objectsprites/start.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 Sonic Fan Game/assets/objectsprites/title.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
24 changes: 24 additions & 0 deletions Sonic Fan Game/src/main/Loader.java
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,12 @@ public class Loader {
public static ByteBuffer itemBox;
public static ByteBuffer ramp;

public static ByteBuffer fade;
public static ByteBuffer title;
public static ByteBuffer leftCloud;
public static ByteBuffer rightCloud;
public static ByteBuffer pressStart;

public static ByteBuffer[] spinnerAnim;
public static ByteBuffer[] explosionAnim;

Expand Down Expand Up @@ -136,6 +142,12 @@ public class Loader {
public static Clip springPoleSound;

public static Clip leaf1Music;
public static Clip titleScreenMusic;

public static Clip titleSound;
public static Clip forwardSound;
public static Clip backSound;
public static Clip moveSound;

public static void main(String[] args) {
get().init();
Expand All @@ -153,6 +165,12 @@ private void init() {
if(!loadedAssets) {
loadedAssets = true;

fade = loadImage("/objectsprites/fade.png");
title = loadImage("/objectsprites/title.png");
leftCloud = loadImage("/objectsprites/cloudLeft.png");
rightCloud = loadImage("/objectsprites/cloudRight.png");
pressStart = loadImage("/objectsprites/start.png");

testMap1 = new TiledJSON("/maps/testMap1.json").map[0];
testMap2 = new TiledJSON("/maps/testMap2.json").map[0];

Expand Down Expand Up @@ -215,8 +233,14 @@ private void init() {
voice1 = loadSound("/voiceclips/1.wav", -10.0f);
voiceGo = loadSound("/voiceclips/go.wav", -10.0f);

titleScreenMusic = loadSound("/objectsounds/titleScreen.wav", -20.0f);
leaf1Music = loadSound("/maps/leaf1.wav", -20.0f);

titleSound = loadSound("/objectsounds/title.wav", -10.0f);
forwardSound = loadSound("/objectsounds/forward.wav", -10.0f);
backSound = loadSound("/objectsounds/back.wav", -10.0f);
moveSound = loadSound("/objectsounds/move.wav", -10.0f);

ringSound = loadSound("/objectsounds/ring.wav", -10.0f);
springSound = loadSound("/objectsounds/spring.wav", -10.0f);
popSound = loadSound("/objectsounds/pop.wav", -10.0f);
Expand Down
13 changes: 11 additions & 2 deletions Sonic Fan Game/src/main/Window.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,18 @@
import java.nio.ByteBuffer;
import java.nio.IntBuffer;

import org.joml.Vector2f;
import org.lwjgl.*;
import org.lwjgl.glfw.*;
import org.lwjgl.opengl.*;
import org.lwjgl.system.*;

import rendering.Camera;
import rendering.Image;
import rendering.Shader;
import rendering.SpriteRenderer;
import scenes.MainScene;
import scenes.MenuScene;
import scenes.Scene;

public class Window {
Expand All @@ -40,6 +45,10 @@ public static Window get() {
public static void changeScene(int newScene) {
switch(newScene) {
case(0):
get().currentScene = new MenuScene();
get().currentScene.init();
break;
case(1):
get().currentScene = new MainScene();
get().currentScene.init();
break;
Expand Down Expand Up @@ -98,11 +107,11 @@ public void init() {

GL.createCapabilities();

changeScene(0);

initWidth = getWidth();
initHeight = getHeight();

changeScene(0);

glfwRestoreWindow(glfwWindow);
GLFWVidMode vidmode = glfwGetVideoMode(glfwGetPrimaryMonitor());
glfwSetWindowPos(glfwWindow, (vidmode.width() - getWindowWidth()) / 2, (vidmode.height() - getWindowHeight()) / 2);
Expand Down
5 changes: 1 addition & 4 deletions Sonic Fan Game/src/rendering/Camera.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,8 @@ public Camera(Vector2f position) {
}

public void adjustProjection() {
float width = 32.0f * 40.0f;
float height = 32.0f * 21.0f;

projectionMatrix.identity();
projectionMatrix.ortho(0.0f, Window.getWidth(), Window.getHeight(), 0.0f, 0.0f, 100.0f);
projectionMatrix.ortho(0.0f, Window.getInitWidth(), Window.getInitHeight(), 0.0f, 0.0f, 100.0f);
}

public Matrix4f getViewMatrix() {
Expand Down
19 changes: 19 additions & 0 deletions Sonic Fan Game/src/rendering/Image.java
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,25 @@ public void setColors(float[] colors) {
vertexArray[33] = colors[15];
}

public void setColor(float r, float g, float b, float a) {
vertexArray[ 3] = r;
vertexArray[ 4] = g;
vertexArray[ 5] = b;
vertexArray[ 6] = a;
vertexArray[12] = r;
vertexArray[13] = g;
vertexArray[14] = b;
vertexArray[15] = a;
vertexArray[21] = r;
vertexArray[22] = g;
vertexArray[23] = b;
vertexArray[24] = a;
vertexArray[30] = r;
vertexArray[31] = g;
vertexArray[32] = b;
vertexArray[33] = a;
}

public float[] getPositions() {
return(
new float[]{
Expand Down
6 changes: 5 additions & 1 deletion Sonic Fan Game/src/scenes/MainScene.java
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,11 @@ public void checkKeysPressed() {
toggle1 = false;
showTileMasks = !showTileMasks;
}
if(KeyListener.isKeyPressed(GLFW_KEY_ESCAPE)) {glfwSetWindowShouldClose(Window.getWindow(), true);}
if(KeyListener.isKeyPressed(GLFW_KEY_ESCAPE)) {
leaf1Music.stop();

Window.changeScene(0);
}
if(KeyListener.isKeyPressed(GLFW_KEY_BACKSPACE)) {reset();}
}
public void checkKeysReleased() {
Expand Down
194 changes: 194 additions & 0 deletions Sonic Fan Game/src/scenes/MenuScene.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,194 @@
package scenes;

import static java.lang.Math.*;
import static org.lwjgl.glfw.GLFW.*;
import static org.lwjgl.opengl.GL11.GL_COLOR_BUFFER_BIT;
import static org.lwjgl.opengl.GL11.glClear;
import static org.lwjgl.opengl.GL11.glClearColor;
import static org.lwjgl.opengl.GL33.*;
import static java.awt.event.KeyEvent.*;
import static functionholders.CollisionFunctions.*;
import static functionholders.DebugFunctions.*;
import static functionholders.ListFunctions.*;

import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.event.KeyEvent;
import java.awt.event.MouseEvent;
import java.nio.ByteBuffer;

import javax.sound.sampled.Clip;

import org.joml.Vector2f;

import badniks.Badnik;
import badniks.Spinner;
import datatypes.Shape;
import datatypes.State;
import datatypes.TiledJSON;
import datatypes.Tilemap;
import datatypes.Vector;
import main.KeyListener;
import main.Loader;
import main.Window;
import misc.Background;
import misc.HUD;
import objects.Item;
import objects.Player;
import objects.Ramp;
import objects.Ring;
import objects.Rotor;
import objects.Spring;
import objects.SpringPole;
import rendering.Camera;
import rendering.Image;
import rendering.Shader;
import rendering.SpriteRenderer;
import shapes.Arc;
import shapes.Circle;
import shapes.InverseArc;
import shapes.Rectangle;
import shapes.Triangle;

public class MenuScene extends Scene {
private final int SCALE = 2;

private Clip titleMusic;
private Clip sonicAdvance2;
private Clip forward;
private Clip back;
private Clip move;

private Shader shader;

private Image fade;
private Image leftCloud;
private Image rightCloud;
private Image title;
private Image start;

private int fadeTimer;
private int startTimer;

private boolean starting;

public void init() {
SpriteRenderer.reset();

shader = new Shader("/shaders/spriteBatch.glsl");
shader.compile();

camera = new Camera(new Vector2f());

titleMusic = Loader.titleScreenMusic;

sonicAdvance2 = Loader.titleSound;
forward = Loader.forwardSound;
back = Loader.backSound;
move = Loader.moveSound;

fade = new Image(Loader.fade);
title = new Image(Loader.title);
leftCloud = new Image(Loader.leftCloud);
rightCloud = new Image(Loader.rightCloud);
start = new Image(Loader.pressStart);

fadeTimer = 60;
startTimer = 0;
}

public void update(float dt) {
checkKeysPressed();
checkKeysReleased();

int screenWidth = Window.getWidth();
int screenHeight = Window.getHeight();
camera.position = new Vector2f(0, -(Window.getInitHeight() - Window.getHeight()));

glClearColor(0, 80.0f / 255.0f, 224.0f / 255.0f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT);

SpriteRenderer.reset();

leftCloud.draw(0, screenHeight - leftCloud.getHeight() * 2, 2, 2, shader, camera);
rightCloud.draw(screenWidth - rightCloud.getWidth() * 2, screenHeight - rightCloud.getHeight() * 2, 2, 2, shader, camera);

title.draw(screenWidth / 2 - title.getWidth(), screenHeight / 3 - title.getHeight(), 2, 2, shader, camera);

if(!starting && fadeTimer == 0) {
if(startTimer < 30) {start.draw(screenWidth / 2 - start.getWidth(), screenHeight / 3 * 2 - start.getHeight(), 2, 2, shader, camera);}
for(int f = 1; f < min(60.0f / (1.0f / dt), 5); f++) {
startTimer++;
if(startTimer == 60) {startTimer = 0;}
}
}
if(!starting && fadeTimer > 0) {
float fadeNum = fadeTimer / 60.0f;
double alpha = -pow(2, fadeNum) + 2;
fade.setColor(1, 1, 1, (float)(1.0f - alpha));
fade.draw(0, 0, screenWidth, screenHeight, shader, camera);

for(int f = 1; f < min(60.0f / (1.0f / dt), 5); f++) {
fadeTimer--;
if(fadeTimer <= 0) {
fadeTimer = 0;

titleMusic.stop();
titleMusic.flush();
titleMusic.setFramePosition(0);
titleMusic.start();

sonicAdvance2.stop();
sonicAdvance2.flush();
sonicAdvance2.setFramePosition(0);
sonicAdvance2.start();
}
}
}
if(starting && fadeTimer >= 0) {
if(startTimer >= 60) {
float fadeNum = fadeTimer / 60.0f;
double alpha = -pow(2, fadeNum) + 2;
fade.setColor(1, 1, 1, (float)(1.0f - alpha));
fade.draw(0, 0, screenWidth, screenHeight, shader, camera);

for(int f = 1; f < min(60.0f / (1.0f / dt), 5); f++) {
fadeTimer++;
if(fadeTimer >= 60) {
titleMusic.stop();
sonicAdvance2.stop();
forward.stop();
back.stop();
move.stop();

Window.changeScene(1);
}
}
}
else {
if(startTimer % 20 < 10) {start.draw(screenWidth / 2 - start.getWidth(), screenHeight / 3 * 2 - start.getHeight(), 2, 2, shader, camera);}
for(int f = 1; f < min(60.0f / (1.0f / dt), 5); f++) {startTimer++;}
}
}

SpriteRenderer.draw(shader, camera);
}

public void checkKeysPressed() {
if(KeyListener.isKeyPressed(GLFW_KEY_ESCAPE)) {if(fadeTimer == 0 && !starting) {glfwSetWindowShouldClose(Window.getWindow(), true);}}
if(KeyListener.isKeyPressed(GLFW_KEY_ENTER)) {
if(fadeTimer == 0 && !starting) {
starting = true;
startTimer = 0;
forward.stop();
forward.flush();
forward.setFramePosition(0);
forward.start();
}
}
}
public void checkKeysReleased() {
//if(KeyListener.isKeyPressed(GLFW_KEY_F1)) {toggle0 = true;}
//if(KeyListener.isKeyPressed(GLFW_KEY_F2)) {toggle1 = true;}
}
}

0 comments on commit cdf8099

Please sign in to comment.