Skip to content

Commit

Permalink
Added credits screen
Browse files Browse the repository at this point in the history
- Added credits as option in menu
- Included attribution and notice for music
- Wrote tests
  • Loading branch information
uoy-jb2501 committed May 2, 2022
1 parent b65d1cf commit 20bbb1a
Show file tree
Hide file tree
Showing 10 changed files with 309 additions and 3 deletions.
5 changes: 5 additions & 0 deletions core/assets/audio/music/credits-attibution.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Title: Wings Of Liberty
By: EvgenyBardyuzha
Website: https://pixabay.com/

Music was listed under Royalty Free
Binary file added core/assets/audio/music/credits.mp3
Binary file not shown.
Binary file added core/assets/mario/shard-software-logo4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
70 changes: 70 additions & 0 deletions core/assets/ui/credits.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
-= Developers =-

-= Assessment 2 =-
-= Team 29 "Shard Software" =-
James Burnell
Hector Woods
Ben Faulkner

-= Assessment 1 =-
-= Team 28 "Mario" =-
Annabeth Singleton
Joseph Frankland
Leif Kemp
Hugo Kwok
Saj Hoque
Lucy Li


-= Website =-
www.mario.shardsoftware.tk

Jensen Bradshaw
James Burnell


-= Audio =-

Powerup SoundFX by 15.ai
Based on characters from "TF2"

Credits Music - "Wings Of Liberty"
By EvgenyBardyuzha
pixabay.com



-= Graphics =-
Original Assets By

Annabeth Singleton
Leif Kemp
James Burnell


-= Shard Software Logo =-

James Burnell


-= Software Used =-

libGDX - Java Game Engine
Blender - Shard Software Logo
Eclipse & IntelliJ - Code Development
Audacity - Audio Development







Produced For The University of York
As Part of Engineering 1






149 changes: 149 additions & 0 deletions core/src/main/java/io/github/annabeths/GameScreens/CreditScreen.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
package io.github.annabeths.GameScreens;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Input.Keys;
import com.badlogic.gdx.Screen;
import com.badlogic.gdx.audio.Music;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.math.MathUtils;
import com.badlogic.gdx.scenes.scene2d.Stage;
import com.badlogic.gdx.scenes.scene2d.ui.Image;
import com.badlogic.gdx.scenes.scene2d.ui.Label;
import com.badlogic.gdx.scenes.scene2d.ui.Label.LabelStyle;
import com.badlogic.gdx.utils.Align;
import com.badlogic.gdx.utils.ScreenUtils;
import com.badlogic.gdx.utils.viewport.FillViewport;

import io.github.annabeths.GeneralControl.ResourceManager;
import io.github.annabeths.GeneralControl.eng1game;

/**
* A screen to display credits for the game
*
* @since Assessment 2
* @author James Burnell
*/
public class CreditScreen implements Screen {

private eng1game game;
private String creditText;
/** How fast the credits scroll in px/sec */
private float scrollSpeed = 100;

public Stage stage;
public LabelStyle lblStyle;
public Label label;
public Image shardLogo;
public Image marioLogo;

public Music music;
/** How long the music will fade out in seconds */
public static final float MUSIC_FADE_TIME = 4f;

public CreditScreen(eng1game game) {
this.game = game;

creditText = Gdx.files.internal("ui/credits.txt").readString();

lblStyle = new LabelStyle();
lblStyle.font = ResourceManager.debugFont;
lblStyle.fontColor = Color.WHITE;

music = Gdx.audio.newMusic(Gdx.files.internal("audio/music/credits.mp3"));

label = new Label(creditText, lblStyle);
label.setAlignment(Align.center);
label.setFontScale(1f);
label.setHeight(label.getPrefHeight());
label.setPosition(0, -label.getPrefHeight() - 100);

shardLogo = new Image(ResourceManager.getTexture("mario/shard-software-logo4.png"));
shardLogo.setScale(0.5f);

marioLogo = new Image(ResourceManager.getTexture("mario/full.png"));
}

@Override
public void show() {
stage = new Stage(new FillViewport(1280, 720));

label.setWidth(stage.getWidth());
stage.addActor(label);

shardLogo.setPosition((stage.getWidth() - shardLogo.getWidth() * 0.5f) / 2,
label.getY() - shardLogo.getHeight() * 0.5f);
stage.addActor(shardLogo);

marioLogo.setPosition((stage.getWidth() - marioLogo.getWidth()) / 2,
shardLogo.getY() - marioLogo.getHeight());
stage.addActor(marioLogo);

music.play();
}

@Override
public void render(float delta) {
ScreenUtils.clear(Color.BLACK);

// skip credits
if (Gdx.input.isKeyJustPressed(Keys.ESCAPE)) {
returnToMenu();
}

// scroll text and images up
float scrollAmount = scrollSpeed * delta;
label.moveBy(0, scrollAmount);
shardLogo.moveBy(0, scrollAmount);
marioLogo.moveBy(0, scrollAmount);

// go to the menu if the credits are over
if (marioLogo.getY(Align.bottom) > stage.getHeight()) {
returnToMenu();
}

music.setVolume(MathUtils.clamp(timeLeft() / MUSIC_FADE_TIME, 0, 1));

stage.draw();
}

public void returnToMenu() {
game.gotoScreen(Screens.menuScreen);
music.stop();
music.dispose();
}

/**
* How long is left in the credits before they end
*
* @return the time left in seconds
*/
public float timeLeft() {
return (stage.getHeight() - marioLogo.getY(Align.bottom)) / scrollSpeed;
}

@Override
public void resize(int width, int height) {
stage.getViewport().update(width, height, true);
}

@Override
public void pause() {

}

@Override
public void resume() {

}

@Override
public void hide() {

}

@Override
public void dispose() {

}

}
7 changes: 6 additions & 1 deletion core/src/main/java/io/github/annabeths/GameScreens/Menu.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,10 @@ public void show() {
// layouts can be used to manage text to allow it to be centered
menuTextLayout = new GlyphLayout();
menuTextLayout.setText(font,
"press ENTER to PLAY\npress I to toggle INSTRUCTIONS\npress ESCAPE to QUIT");
"press ENTER to PLAY\n"
+ "press I to toggle INSTRUCTIONS\n"
+ "press C for credits\n"
+ "press ESCAPE to QUIT");
instructions = ResourceManager.getTexture("ui/instructions.png");
// create example HUD
hud = new HUD(GameController.getMockForHUD());
Expand All @@ -65,6 +68,8 @@ public void render(float delta) {
}
} else if (Gdx.input.isKeyJustPressed(Keys.ESCAPE)) {
Gdx.app.exit();
} else if (Gdx.input.isKeyJustPressed(Keys.C)) {
game.gotoScreen(Screens.credits);
}

// do draws
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@

/** All the screens the game can switch to */
public enum Screens {
splashScreen, menuScreen, gameScreen, gameOverScreen, gameWinScreen, gameDifScreen
splashScreen, menuScreen, gameScreen, gameOverScreen, gameWinScreen, gameDifScreen, credits
}
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ public static void init(AssetManager assetMan) {
for (PowerupType p : PowerupType.values()) {
loadTexture(p.getTexture());
}
/* Other Textures */
loadTexture("mario/shard-software-logo4.png");
loadTexture("mario/full.png");

assets.finishLoading();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;

import io.github.annabeths.GameScreens.CreditScreen;
import io.github.annabeths.GameScreens.GameController;
import io.github.annabeths.GameScreens.GameDifScreen;
import io.github.annabeths.GameScreens.GameOverScreen;
import io.github.annabeths.GameScreens.GameWinScreen;
import io.github.annabeths.GameScreens.Menu;
import io.github.annabeths.GameScreens.Screens;
import io.github.annabeths.GameScreens.Splash;
import io.github.annabeths.GameScreens.GameDifScreen;

/** @tt.updated Assessment 2 */
public class eng1game extends Game {
Expand Down Expand Up @@ -102,6 +103,9 @@ public void gotoScreen(Screens s) {
GameDifScreen gameDifScreen = new GameDifScreen(this);
setScreen(gameDifScreen);
break;
case credits:
setScreen(new CreditScreen(this));
break;
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package io.github.annabeths.GameScreens;

import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.ArgumentMatchers.*;
import static org.mockito.Mockito.*;

import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import com.badlogic.gdx.Files;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Input.Keys;
import com.badlogic.gdx.scenes.scene2d.Stage;
import com.badlogic.gdx.scenes.scene2d.ui.Image;

import io.github.annabeths.GeneralControl.TestHelper;
import io.github.annabeths.GeneralControl.eng1game;

public class CreditScreenTest {

CreditScreen cs;

@BeforeAll
public static void init() {
TestHelper.setupEnv();
Gdx.files = mock(Files.class, withSettings().defaultAnswer(RETURNS_MOCKS));
}

@BeforeEach
public void setup() {
cs = mock(CreditScreen.class, withSettings().useConstructor(mock(eng1game.class))
.defaultAnswer(CALLS_REAL_METHODS));
cs.stage = mock(Stage.class, withSettings().defaultAnswer(RETURNS_DEEP_STUBS));
when(cs.stage.getHeight()).thenReturn(720f);
}

@Test
public void testRender() {
assertDoesNotThrow(() -> cs.render(1f));
}

@Test
public void testEscReturnToMenu() {
when(Gdx.input.isKeyJustPressed(Keys.ESCAPE)).thenReturn(false);
cs.render(1f);
verify(cs, never()).returnToMenu();

when(Gdx.input.isKeyJustPressed(Keys.ESCAPE)).thenReturn(true);
cs.render(1f);
verify(cs, times(1)).returnToMenu();
}

@Test
public void testEndReturnToMenu() {
cs.marioLogo = mock(Image.class);
when(cs.marioLogo.getY(anyInt())).thenReturn(725f);

cs.render(1f);
verify(cs, times(1)).returnToMenu();
}

@Test
public void testResize() {
cs.resize(100, 100);

verify(cs.stage.getViewport(), times(1)).update(eq(100), eq(100), eq(true));
}

}

0 comments on commit 20bbb1a

Please sign in to comment.