Skip to content

Commit

Permalink
Merge pull request #7 from ImXico/0.3.0
Browse files Browse the repository at this point in the history
v0.3.0 - Addition of profiler module and small updates
  • Loading branch information
ImXico authored Aug 28, 2018
2 parents 31ce0de + a927460 commit 74161e6
Show file tree
Hide file tree
Showing 28 changed files with 201 additions and 158 deletions.
60 changes: 36 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,28 +1,46 @@
![Cyberpunk logo](https://github.com/ImXico/Cyberpunk/blob/master/logo.png?raw=true)

[![Build Status](https://travis-ci.org/ImXico/Cyberpunk.svg?branch=master)](https://travis-ci.org/ImXico/Cyberpunk)
[![libGDX](https://img.shields.io/badge/libgdx-1.9.8-red.svg)](http://libgdx.badlogicgames.com)
[![kotlin](https://img.shields.io/badge/kotlin-1.2.41-orange.svg)](https://kotlinlang.org)
[![JitPack](https://jitpack.io/v/ImXico/Cyberpunk.svg)](https://jitpack.io/#ImXico/Cyberpunk)
[![License](https://img.shields.io/badge/license-MIT-green.svg)](https://github.com/ImXico/HandyGDX/blob/master/LICENSE.md)
<br>
<p align="center">
<img src="https://github.com/ImXico/Cyberpunk/blob/master/logo.png?raw=true" alt="Cyberpunk Logo"/>
</p>

<p align="center">
<a href="https://travis-ci.org/ImXico/Cyberpunk">
<img src="https://travis-ci.org/ImXico/Cyberpunk.svg?branch=master">
</a>

<a href="https://jitpack.io/#ImXico/Cyberpunk">
<img src="https://jitpack.io/v/ImXico/Cyberpunk.svg">
</a>

<a href="http://libgdx.badlogicgames.com">
<img src="https://img.shields.io/badge/libgdx-1.9.8-red.svg">
</a>

<a href="https://kotlinlang.org">
<img src="https://img.shields.io/badge/kotlin-1.2.51-orange.svg">
</a>

<a href="https://github.com/ImXico/Cyberpunk/blob/master/LICENSE.md">
<img src="https://img.shields.io/badge/license-MIT-green.svg">
</a>
</p>

## Introduction

Cyberpunk is a collection of independent, modular, pure-Kotlin libraries to use on top of [libGDX](http://libgdx.badlogicgames.com/), tailored with Java interoperability in mind. By offering various utilities and boilerplates, it aims to speed up development and ease the making of prototypes, making it a great fit for game jams!

## Modules

Cyberpunk is all about small, independent modules. Because of the Gradle integration, you can import *just* the modules that you need. To properly serve that purpose, every single module is totally independent from all others.

Here are the **current** modules (each one has a *README.md* file):
Cyberpunk is all about small, independent modules. Because of the Gradle integration, you can import *just* the modules that you need. To properly serve that purpose, every single module is totally independent from all others:

- [audio](https://github.com/ImXico/Cyberpunk/tree/master/audio): Music/Sound asset management and various utilities.
- [camera](https://github.com/ImXico/Cyberpunk/tree/master/camera): Various camera styles on the go.
- [core](https://github.com/ImXico/Cyberpunk/tree/master/core): States, state management and transitions. Get up and running quickly!
- [image](https://github.com/ImXico/Cyberpunk/tree/master/image): Image asset management and various utilities.
- [physics](https://github.com/ImXico/Cyberpunk/tree/master/physics): Friendly and practical Box2D constructs.
- [text](https://github.com/ImXico/Cyberpunk/tree/master/text): Text positioning helpers.
| Module | Description |
| ------ | ----------- |
| [audio](https://github.com/ImXico/Cyberpunk/tree/master/audio) | Music/Sound asset management and various utilities. |
| [camera](https://github.com/ImXico/Cyberpunk/tree/master/camera) | Various camera styles on the go.
| [core](https://github.com/ImXico/Cyberpunk/tree/master/core) | State management and transitions - get up and running quickly! |
| [image](https://github.com/ImXico/Cyberpunk/tree/master/image) | Image asset management and various utilities. |
| [profiler](https://github.com/ImXico/Cyberpunk/tree/master/profiler) | Wrappers around libGDX profiling utilities. |
| [physics](https://github.com/ImXico/Cyberpunk/tree/master/physics) | Friendly and practical Box2D constructs. |
| [text](https://github.com/ImXico/Cyberpunk/tree/master/text) | Text positioning helpers. |

## Usage

Expand All @@ -47,13 +65,7 @@ Replace `$module` with the name of the desired library (see above). Likewise, `$

## What About libKTX?

Hey, [libKTX](https://github.com/libktx/ktx) is an awesome project! If you're already a libKTX user and you're happy with it, you should definitely stick with it. Same thing would apply if you were to start a larger, *pure Kotlin* project. It provides an *incredible* range of utilities, and makes full use of Kotlin's awesome features!

That being said, if you're looking for a smoother Java interop or are carrying out a game jam, give Cyberpunk a try!

## Report Issues

Something not working quite as expected? Do you need a feature that has not been implemented yet? Feel free to report bugs, fix them, suggest enhancements, add functionality and point out any mistakes!
Hey, [libKTX](https://github.com/libktx/ktx) is an awesome project, and I recommend it for larger Kotlin projects. It provides an *incredible* range of features, all very high quality. That being said, If you're looking for a smoother Java interoperability or are carrying out a game jam, give Cyberpunk a try!

## License

Expand Down
16 changes: 3 additions & 13 deletions audio/src/main/kotlin/cyberpunk/audio/MusicManager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ object MusicManager {

/**
* Creates and loads a [Music] object onto the [tracks] structure.
*
* @param trackName key that will identify this track in the map.
* @param path track's path inside the assets folder.
*/
Expand All @@ -29,7 +28,6 @@ object MusicManager {
* If no volume is specified (the second parameter), then the sound will be played with
* the default volume, 1f.
* Contrarily to the sound instances, this action doesn't return an unique id.
*
* @param trackName key that identifies the track in the map.
* @param volume audio volume; ranges between [0, 1] and it's optional.
* @throws AudioAssetNotFoundException
Expand All @@ -45,7 +43,6 @@ object MusicManager {

/**
* Pauses the given track's playback.
*
* @param trackName key that identifies the track in the map.
* @throws AudioAssetNotFoundException
*/
Expand All @@ -56,7 +53,6 @@ object MusicManager {

/**
* Stops the given track's playback.
*
* @param trackName key that identifies the track in the map.
* @throws AudioAssetNotFoundException
*/
Expand All @@ -67,7 +63,6 @@ object MusicManager {

/**
* Repeats the given track's playback until [stop] is called.
*
* @param trackName key that identifies the track in the map.
* @throws AudioAssetNotFoundException
*/
Expand All @@ -79,8 +74,7 @@ object MusicManager {
}

/**
* Whether or not the given track is playing.
*
* Checks whether or not the given track is playing.
* @param trackName key that identifies the track in the map.
* @return whether or not the given track is playing.
* @throws AudioAssetNotFoundException
Expand All @@ -91,8 +85,7 @@ object MusicManager {
tracks[trackName]?.isPlaying ?: throw AudioAssetNotFoundException("$trackName not found.")

/**
* Whether or not the given track is looping.
*
* Checks whether or not the given track is looping.
* @param trackName key that identifies the track in the map.
* @return whether or not the given track is looping.
* @throws AudioAssetNotFoundException
Expand All @@ -104,7 +97,6 @@ object MusicManager {

/**
* Gets this track's current position in seconds.
*
* @param trackName key that identifies the track in the map.
* @return this track's current position in seconds.
* @throws AudioAssetNotFoundException
Expand All @@ -116,7 +108,6 @@ object MusicManager {

/**
* Sets this track's current position in seconds.
*
* @param trackName key that identifies the track in the map.
* @param position target position in seconds.
* @throws AudioAssetNotFoundException
Expand All @@ -129,9 +120,8 @@ object MusicManager {
}

/**
* Release resources, once you don't need the [Music] anymore.
* Releases resources held by the [Music] instances.
* Accessing the sound after you disposed of it will result in undefined errors.
*
* @param trackName key that identifies the track in the map.
* @throws AudioAssetNotFoundException
*/
Expand Down
9 changes: 1 addition & 8 deletions audio/src/main/kotlin/cyberpunk/audio/SoundManager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ object SoundManager {

/**
* Creates and loads a [Sound] onto the [sounds] structure.
*
* @param soundName key that will identify this sound in the map.
* @param path sounds's path inside the assets folder.
*/
Expand All @@ -27,7 +26,6 @@ object SoundManager {
* Plays the given sound, if present in the [sounds] map.
* If no volume is specified (the second parameter), then the sound will be played with
* the default volume, 1f.
*
* @param soundName key that identifies the sound in the map.
* @param volume audio volume; ranges between [0, 1] and it's optional.
* @param pitch the pitch multiplier; ranges between [0.5 (slower), 2.0 (faster)] and it's optional.
Expand All @@ -47,7 +45,6 @@ object SoundManager {
* Plays the given sound, if present in the [sounds] map.
* If no volume is specified (the second parameter), then the sound will be played with
* the default volume, 1f.
*
* @param soundName key that identifies the sound in the map.
* @param volume audio volume; ranges between [0, 1] and it's optional.
* @param pitch the pitch multiplier; ranges between [0.5 (slower), 2.0 (faster)] and it's optional.
Expand All @@ -66,7 +63,6 @@ object SoundManager {
/**
* Stops all instances of the sound identified by the given [soundName].
* If the instance doesn't exist, this method has no effect.
*
* @param soundName key that identifies the sound in the map.
* @throws AudioAssetNotFoundException
*/
Expand All @@ -78,7 +74,6 @@ object SoundManager {
/**
* Pauses all instances of the sound identified by the given [soundName].
* If the instance doesn't exist, this method has no effect.
*
* @param soundName key that identifies the sound in the map.
* @throws AudioAssetNotFoundException
*/
Expand All @@ -90,7 +85,6 @@ object SoundManager {
/**
* Resumes all instances of the sound identified by the given [soundName].
* If the instance doesn't exist, this method has no effect.
*
* @param soundName key that identifies the sound in the map.
* @throws AudioAssetNotFoundException
*/
Expand All @@ -100,9 +94,8 @@ object SoundManager {
sounds[soundName]?.resume() ?: throw AudioAssetNotFoundException("$soundName not found.")

/**
* Release resources, once you don't need the [Sound] anymore.
* Releases resources held by the [Sound] instances.
* Accessing the sound after you disposed of it will result in undefined errors.
*
* @param soundName key that identifies the sound in the map.
* @throws AudioAssetNotFoundException
*/
Expand Down
8 changes: 1 addition & 7 deletions camera/src/main/kotlin/cyberpunk/camera/CameraStyles.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import com.badlogic.gdx.math.Vector3

/**
* Centers the [Camera] in the middle of the screen, fiven the world coordinates.
*
* @param worldWidth width of the world (world coordinates).
* @param worldHeight height of the world (world coordinates).
*/
Expand All @@ -20,7 +19,6 @@ fun Camera.center(worldWidth: Int, worldHeight: Int) {
/**
* The [Camera] will follow the target coordinates rigidly.
* Not suitable for all cases, as it may cause a very rough motion.
*
* @param targetPosition position of the target, where the camera will be also positioned to.
*/
fun Camera.lockOn(targetPosition: Vector2) {
Expand All @@ -31,7 +29,6 @@ fun Camera.lockOn(targetPosition: Vector2) {
/**
* The [Camera] will rigidly follow the [targetPosition] horizontally, but will be
* offset vertically by a [yOffset].
*
* @param targetPosition position of the target, where the camera will be also positioned to (horizontally).
* @param yOffset camera's Y offset, relatively to the [targetPosition] Y.
*/
Expand All @@ -43,7 +40,6 @@ fun Camera.lockOnX(targetPosition: Vector2, yOffset: Float) {
/**
* The [Camera] will rigidly follow the [targetPosition] vertically, but will be
* offset horizontally by a [xOffset].
*
* @param targetPosition position of the target, where the camera will be also positioned to (horizontally).
* @param xOffset camera's X offset, relatively to the [targetPosition] X.
*/
Expand All @@ -54,9 +50,8 @@ fun Camera.lockOnY(targetPosition: Vector2, xOffset: Float) {

/**
* The [Camera] will follow a [targetPosition] with a smooth linear interpolation, based on a [lerp] amount.
* The lower the lerp amount, the smoother - and thus slower - the following motion.
* The lower that interpolation amount, the smoother - and thus slower - the following motion.
* The camera can also be offset by an [xOffset] and [yOffset] amounts, but that's optional.
*
* @param targetPosition position of the target that the camera will be set on.
* @param lerp defines how smoothly the camera follows; ]0 (slowest), 1 (fastest)].
* @param xOffset camera's X offset, relatively to the [targetPosition] X.
Expand All @@ -73,7 +68,6 @@ fun Camera.lerpTo(targetPosition: Vector2, lerp: Float, xOffset: Float = 0f, yOf
/**
* Sets the [Camera] position to the given one and updates it.
* Won't be called explicitly anywhere besides this class.
*
* @param newPosition new [Vector3] position for the camera.
*/
private fun Camera.refresh(newPosition: Vector3) {
Expand Down
18 changes: 18 additions & 0 deletions core/src/main/kotlin/cyberpunk/core/Graphics.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
@file:JvmName("Graphics")

package cyberpunk.core

import com.badlogic.gdx.Gdx
import com.badlogic.gdx.graphics.GL20

/**
* Clears the frame and depth buffers with the selected color.
* @param red red color value.
* @param green green color value.
* @param blue blue color value.
* @param alpha optional color alpha value.
*/
fun clearScreen(red: Float, green: Float, blue: Float, alpha: Float = 1f) {
Gdx.gl.glClearColor(red, green, blue, alpha)
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT or GL20.GL_DEPTH_BUFFER_BIT)
}
5 changes: 0 additions & 5 deletions core/src/main/kotlin/cyberpunk/core/state/State.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,13 @@ interface State : InputProcessor {
/**
* Updates the state.
* This is called every frame.
*
* @param delta time elapsed since the last call to this method.
*/
fun update(delta: Float)

/**
* Renders the state.
* This is also called every frame, always after [State.update].
*
* @param batch [Batch] used to render the state.
*/
fun render(batch: Batch)
Expand All @@ -44,15 +42,13 @@ interface State : InputProcessor {

/**
* Resizes the state and any of its components.
*
* @param width new width.
* @param height new height.
*/
fun resize(width: Int, height: Int)

/**
* Unprojects screen coordinates into world coordinates.
*
* @param screenX X in screen coordinates.
* @param screenY Y in screen coordinates.
* @return world coordinates.
Expand All @@ -61,7 +57,6 @@ interface State : InputProcessor {

/**
* Unprojects screen coordinates into world coordinates.
*
* @param screenCoordinates (X, Y) screen coordinates.
* @return world coordinates.
*/
Expand Down
27 changes: 14 additions & 13 deletions core/src/main/kotlin/cyberpunk/core/state/StateAdapter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,30 @@ import com.badlogic.gdx.math.Vector2

abstract class StateAdapter(protected val stateManager: StateManager) : State {

/* State methods that absolutely must be overridden. */

/**
* State methods that absolutely must be overridden.
*/
override abstract fun update(delta: Float)
override abstract fun render(batch: Batch)
override abstract fun dispose()

/* State methods that may or may not be overridden. */

/**
* State methods that may or may not be overridden (no-op implementation).
*/
override fun resize(width: Int, height: Int) = Unit
override fun hide() = Unit
override fun pause() = Unit
override fun resume() = Unit

/* State input conversion methods - should not be overridden. */

override fun unproject(screenCoordinates: Vector2) =
stateManager.viewport.unproject(screenCoordinates)

override fun unproject(screenX: Float, screenY: Float) =
this.unproject(Vector2(screenX, screenY))

/* InputProcessor methods that may or may not be overridden. */
/**
* State input conversion methods with default implementation.
*/
override fun unproject(screenCoordinates: Vector2) = stateManager.viewport.unproject(screenCoordinates)
override fun unproject(screenX: Float, screenY: Float) = this.unproject(Vector2(screenX, screenY))

/**
* InputProcessor methods that may or may not be overridden.
*/
override fun keyDown(keycode: Int) = false
override fun keyUp(keycode: Int) = false
override fun keyTyped(character: Char) = false
Expand Down
Loading

0 comments on commit 74161e6

Please sign in to comment.