Skip to content

Commit

Permalink
Add enemies
Browse files Browse the repository at this point in the history
  • Loading branch information
srikavin committed Jan 9, 2020
1 parent 2e963f4 commit ad29a81
Show file tree
Hide file tree
Showing 13 changed files with 441 additions and 42 deletions.
67 changes: 47 additions & 20 deletions core/src/me/srikavin/fbla/game/FBLAGame.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import com.artemis.managers.TagManager
import com.badlogic.gdx.ApplicationAdapter
import com.badlogic.gdx.Gdx
import com.badlogic.gdx.assets.AssetManager
import com.badlogic.gdx.assets.loaders.FileHandleResolver
import com.badlogic.gdx.assets.loaders.SkinLoader
import com.badlogic.gdx.assets.loaders.resolvers.InternalFileHandleResolver
import com.badlogic.gdx.graphics.GL20
Expand All @@ -15,6 +16,8 @@ import com.badlogic.gdx.graphics.g2d.BitmapFont
import com.badlogic.gdx.graphics.g2d.SpriteBatch
import com.badlogic.gdx.graphics.g2d.TextureRegion
import com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGenerator
import com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGeneratorLoader
import com.badlogic.gdx.graphics.g2d.freetype.FreetypeFontLoader
import com.badlogic.gdx.maps.tiled.TiledMap
import com.badlogic.gdx.maps.tiled.TmxMapLoader
import com.badlogic.gdx.math.Vector2
Expand All @@ -25,6 +28,7 @@ import com.badlogic.gdx.utils.ObjectMap
import com.badlogic.gdx.utils.viewport.ExtendViewport
import com.badlogic.gdx.utils.viewport.FitViewport
import ktx.actors.onClick
import ktx.assets.disposeSafely
import me.srikavin.fbla.game.Scene.PLAYING
import me.srikavin.fbla.game.Scene.TITLE
import me.srikavin.fbla.game.ecs.system.*
Expand All @@ -35,16 +39,19 @@ const val cameraScale = 45f

enum class Scene {
PLAYING,
TITLE
TITLE,
LOADING
}

class FBLAGame : ApplicationAdapter() {
lateinit var camera: OrthographicCamera
lateinit var world: World
lateinit var batch: SpriteBatch
lateinit var skin: Skin
var assetManager = AssetManager()
lateinit var splashImage: Texture

var scene: Scene = TITLE
private var scene: Scene = Scene.LOADING

override fun resize(width: Int, height: Int) {
if (scene == PLAYING) {
Expand All @@ -53,7 +60,7 @@ class FBLAGame : ApplicationAdapter() {

camera.zoom = 1f
camera.update()
} else {
} else if (scene == TITLE) {
stageBg.viewport.update(width, height)
}
}
Expand All @@ -64,7 +71,6 @@ class FBLAGame : ApplicationAdapter() {
camera.position.y = cameraScale * (9f / 16f) * 0.75f

val physicsWorld = com.badlogic.gdx.physics.box2d.World(Vector2(0f, -23f), true)
batch = SpriteBatch()

val stage = Stage(ExtendViewport(640f, 480f))
val root = Table(skin)
Expand Down Expand Up @@ -108,29 +114,40 @@ class FBLAGame : ApplicationAdapter() {
.register(listenerManager)

world = World(config)
mapLoader.loadMap(world, "assets/maps/level2.tmx")
mapLoader.loadMap(world, "assets/maps/level1.tmx")
}

private lateinit var titleBg: TextureRegion
private lateinit var stageBg: Stage

override fun create() {
val assetManager = AssetManager()
assetManager.setLoader(TiledMap::class.java, TmxMapLoader(InternalFileHandleResolver()))
batch = SpriteBatch()
splashImage = Texture(Gdx.files.internal("assets/graphics/titlelogo.png"))

// Load necessary resources asynchronously
val resolver: FileHandleResolver = InternalFileHandleResolver()
assetManager.setLoader(TiledMap::class.java, TmxMapLoader(resolver))
assetManager.setLoader(FreeTypeFontGenerator::class.java, FreeTypeFontGeneratorLoader(resolver))
assetManager.setLoader(BitmapFont::class.java, ".ttf", FreetypeFontLoader(resolver))

val generator = FreeTypeFontGenerator(Gdx.files.internal("assets/fonts/Kenney Pixel.ttf"))
val parameter = FreeTypeFontGenerator.FreeTypeFontParameter()
parameter.size = 48
val font12: BitmapFont = generator.generateFont(parameter)
val parameter = FreetypeFontLoader.FreeTypeFontLoaderParameter()
parameter.fontParameters.size = 48
parameter.fontFileName = "assets/fonts/Kenney Pixel.ttf"
assetManager.load("KenneyPixel48.ttf", BitmapFont::class.java, parameter)
val font = assetManager.finishLoadingAsset<BitmapFont>("KenneyPixel48.ttf")

val fontMap = ObjectMap<String, Any>()
fontMap.put("KenneyPixel", font12)
generator.dispose()
fontMap.put("KenneyPixel", font)

assetManager.load("assets/skin/skin.json", Skin::class.java, SkinLoader.SkinParameter(fontMap))
assetManager.finishLoading()
}

fun afterLoad() {
skin = assetManager.get<Skin>("assets/skin/skin.json")
skin.add("KenneyPixel", assetManager.get("KenneyPixel48.ttf"))
}

fun initTitleScreen() {
camera = OrthographicCamera(cameraScale, cameraScale * (9f / 16f))
titleBg = TextureRegion(Texture(Gdx.files.internal("assets/graphics/homescreen.png")))

Expand Down Expand Up @@ -198,7 +215,6 @@ class FBLAGame : ApplicationAdapter() {
vertGroup.addActor(instructions)
vertGroup.addActor(exit)
Gdx.input.inputProcessor = stageBg

scene = TITLE
}

Expand All @@ -210,19 +226,30 @@ class FBLAGame : ApplicationAdapter() {
}
TITLE -> {
Gdx.gl.glClearColor(0f, 0f, 0f, 1f)
Gdx.gl.glClear(
GL20.GL_COLOR_BUFFER_BIT
or GL20.GL_DEPTH_BUFFER_BIT
or (if (Gdx.graphics.bufferFormat.coverageSampling) GL20.GL_COVERAGE_BUFFER_BIT_NV else 0)
)
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT or GL20.GL_DEPTH_BUFFER_BIT)

stageBg.act()
stageBg.draw()
}
Scene.LOADING -> {
// Render splash image
Gdx.gl.glClearColor(20f, 20f, 20f, 1f)
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT or GL20.GL_DEPTH_BUFFER_BIT)
batch.begin()
batch.draw(splashImage, (Gdx.graphics.width / 2f) - 128f, (Gdx.graphics.height / 2f) - 182f,
256f, 264f)
batch.end()
// Continue loading resources
if (assetManager.update()) {
afterLoad()
initTitleScreen()
}
}
}
}

override fun dispose() {
assetManager.disposeSafely()
world.dispose()
}
}
8 changes: 6 additions & 2 deletions core/src/me/srikavin/fbla/game/dialogue/DialogueManager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,15 @@ class DialogueManager(private val stage: Stage, skin: Skin) {
"job_interview" to DialogueJobInterview(),
"speech" to DialogueSpeech(),
"letter_rec" to DialogueLetterRec(),
"fbla_knowledge" to QuizFBLAKnowledge()
"fbla_knowledge" to QuizFBLAKnowledge(),
"animal" to DialogueAnimal(),
"brochure" to DialogueBrochure(),
"social_media" to DialogueSocialMedia(),
"blog" to DialogueBlog()
)

/**
* Gets the [DialogueCallable] associated with the given name
* Gets the [DialogueCallable] associated with a given name
*
* @param name The name of the Dialogue Callable to lookup
*/
Expand Down
78 changes: 78 additions & 0 deletions core/src/me/srikavin/fbla/game/dialogue/callable/DialogueAnimal.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
package me.srikavin.fbla.game.dialogue.callable

import me.srikavin.fbla.game.dialogue.DialogueCallable

class DialogueAnimal : DialogueCallable() {

override fun run() {
say("Do you like animals?")
var index = getResponse(listOf("Kind of", "They're lovely", "I hate them"))

if (index == 0) {
updateScore(0)
}
if (index == 1) {
updateScore(1)
}
if (index == 2) {
updateScore(-1)
}
say("How much experience do you have with them?")
index = getResponse(listOf("Enough", "None"))

if (index == 0) {
updateScore(1)
}
if (index == 1) {
updateScore(-1)
}

say("Why do you want to work with them?")
index = getResponse(listOf("It's a passion of mine", "To further my progress in my award.", "No clue, I was told to show up here"))

if (index == 0) {
updateScore(1)
}
if (index == 1) {
updateScore(0)
}
if (index == 2) {
updateScore(-1)
}

say("Which animals would you like to work with?")
index = getResponse(listOf("Cats", "Dogs", "Horses"))

if (index == 0) {
updateScore(1)
}
if (index == 1) {
updateScore(1)
}
if (index == 2) {
updateScore(1)
}

say("Hope you have fun!")
index = getResponse(listOf("Sure", "I will!", "I wish I would."))

if (index == 0) {
updateScore(0)
}
if (index == 1) {
updateScore(1)
}
if (index == 2) {
updateScore(-1)
}


val score = getScore()
if (score > 0) {
say("You've completed your volunteering!")
}
if (score <= 0) {
say("They kicked you out.")
}
}
}
79 changes: 79 additions & 0 deletions core/src/me/srikavin/fbla/game/dialogue/callable/DialogueBlog.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
package me.srikavin.fbla.game.dialogue.callable

import me.srikavin.fbla.game.dialogue.DialogueCallable

class DialogueBlog : DialogueCallable() {

override fun run() {
say("Title?")
var index = getResponse(listOf("The adventures of FBLA", "Business Achievement Award ultimate guide", "Funny blog"))

if (index == 0) {
updateScore(0)
}
if (index == 1) {
updateScore(1)
}
if (index == 2) {
updateScore(-1)
}

say("Format?")
index = getResponse(listOf("Organized", "Thrown Together"))

if (index == 0) {
updateScore(1)
}
if (index == 1) {
updateScore(-1)
}

say("Topic?")
index = getResponse(listOf("BAA Award", "Every-day life of FBLA president", "Memes"))

if (index == 0) {
updateScore(1)
}
if (index == 1) {
updateScore(0)
}
if (index == 2) {
updateScore(-1)
}

say("Color scheme?")
index = getResponse(listOf("Green and purple", "Gold and blue", "Orange and yellow"))

if (index == 0) {
updateScore(-1)
}
if (index == 1) {
updateScore(1)
}
if (index == 2) {
updateScore(-1)
}

say("Ads?")
index = getResponse(listOf("Sometimes", "No", "Yes"))

if (index == 0) {
updateScore(0)
}
if (index == 1) {
updateScore(1)
}
if (index == 2) {
updateScore(-1)
}


val score = getScore()
if (score > 0) {
say("You've successfully created a blog!")
}
if (score <= 0) {
say("Time to start over!")
}
}
}
Loading

0 comments on commit ad29a81

Please sign in to comment.