• Docs
  • Install
  • Follow @cosplayengine
  • v.0.9.5
  • GitHub
  • Watch
  • Examples
  1. Home
  2. Examples

Examples

  • Introduction
  • Install
  • ASCII Games
  • Demos
  • Examples
  • Macarena
  • Pong
  • Snake
  • Bird
  • Developer Guide
  • Quick Game 🏃
  • Key Concepts
  • Game Structure
  • Scenes & Objects
  • Log & Debugging
  • Pixels & Colors
  • Images
  • Keyboard Input
  • Sprite Animation
  • Shaders
  • Particle Effects
  • Fonts
  • Canvas Drawing
  • Text Input
  • Camera Tracking
  • Tile Mapping
  • Audio
  • Video
  • UI Toolkit
  • Build & Run

Built-In Games

CosPlay comes with a number of built-in ready to play games:

  • Pong
  • Snake
  • Bird
  • Macarena

Examples

CosPlay also comes with many examples for each functional area. The source code for these examples is shipped with the project (see org.cosplay.examples package) and can be also found on GitHub.

If you have CosPlay project in IDE you can review the source code and run each example right from IDE. Each example is a simple Scala application with the main(...) method. The easiest way to run examples from the command line is to use SBT or Maven. First, clone and build the CosPlay Git repository (this needs to be done only once):

Maven
                    # One-time Git clone & build:
                    $ git clone https://github.com/nivanov/cosplay.git
                    $ cd cosplay
                    $ sbt package
                
                    # One-time Git clone & build:
                    $ git clone https://github.com/nivanov/cosplay.git
                    $ cd cosplay
                    $ mvn package
                

SBT & Maven

CosPlay comes with support for both SBT and Maven builds. Running examples and built-in games via SBT will automatically use terminal emulator since both SBT and CosPlay use JLine library and SBT therefor uses Java process fork to launch the examples and games. If you want to run directly in the terminal console using pure text-mode - use Maven method instead.

Assuming you are in cosplay folder use the following table to run examples:

ExampleRun & Code
Animation

CPAnimationExample.scala

Maven
                                # Will launch using terminal emulator.
                                $ sbt "project cosplay; runMain org.cosplay.examples.animation.CPAnimationExample"
                            
                                # Will launch in the same terminal console.
                                $ mvn -f modules/cosplay exec:java -P ex:animation
                            
Camera

CPCameraExample.scala

Maven
                                # Will launch using terminal emulator.
                                $ sbt "project cosplay; runMain org.cosplay.examples.camera.CPCameraExample"
                            
                                # Will launch in the same terminal console.
                                $ mvn -f modules/cosplay exec:java -P ex:camera
                            
Image Formats

CPImageFormatsExample.scala

Maven
                                # Will launch using terminal emulator.
                                $ sbt "project cosplay; runMain org.cosplay.examples.image.CPImageFormatsExample"
                            
                                # Will launch in the same terminal console.
                                $ mvn -f modules/cosplay exec:java -P ex:image_formats
                            
Image Carousel

CPImageCarouselExample.scala

Maven
                                # Will launch using terminal emulator.
                                $ sbt "project cosplay; runMain org.cosplay.examples.image.CPImageCarouselExample"
                            
                                # Will launch in the same terminal console.
                                $ mvn -f modules/cosplay exec:java -P ex:image_carousel
                            
Fonts

CPFontsExample.scala

Maven
                                # Will launch using terminal emulator.
                                $ sbt "project cosplay; runMain org.cosplay.examples.fonts.CPFontsExample"
                            
                                # Will launch in the same terminal console.
                                $ mvn -f modules/cosplay exec:java -P ex:fonts
                            
Particle Effects

CPParticleExample.scala

Maven
                                # Will launch using terminal emulator.
                                $ sbt "project cosplay; runMain org.cosplay.examples.particle.CPParticleExample"
                            
                                # Will launch in the same terminal console.
                                $ mvn -f modules/cosplay exec:java -P ex:particle
                            
Shaders

CPShaderExample.scala

Maven
                                # Will launch using terminal emulator.
                                $ sbt "project cosplay; runMain org.cosplay.examples.shader.CPShaderExample"
                            
                                # Will launch in the same terminal console.
                                $ mvn -f modules/cosplay exec:java -P ex:shader
                            
Slide Shaders

CPSlideShaderExample.scala

Maven
                                # Will launch using terminal emulator.
                                $ sbt "project cosplay; runMain org.cosplay.examples.shader.CPSlideShaderExample"
                            
                                # Will launch in the same terminal console.
                                $ mvn -f modules/cosplay exec:java -P ex:slide_shader
                            
Text Input

CPTextInputExample.scala

Maven
                                # Will launch using terminal emulator.
                                $ sbt "project cosplay; runMain org.cosplay.examples.textinput.CPTextInputExample"
                            
                                # Will launch in the same terminal console.
                                $ mvn -f modules/cosplay exec:java -P ex:textinput
                            
Tile Mapping

CPTileMapperExample.scala

Maven
                                # Will launch using terminal emulator.
                                $ sbt "project cosplay; runMain org.cosplay.examples.tilemapper.CPTileMapperExample"
                            
                                # Will launch in the same terminal console.
                                $ mvn -f modules/cosplay exec:java -P ex:tilemapper
                            
Sound

CPSoundExample.scala

Maven
                                # Will launch using terminal emulator.
                                $ sbt "project cosplay; runMain org.cosplay.examples.sound.CPSoundExample"
                            
                                # Will launch in the same terminal console.
                                $ mvn -f modules/cosplay exec:java -P ex:sound
                            
Video

CPVideoExample.scala

Maven
                                # Will launch using terminal emulator.
                                $ sbt "project cosplay; runMain org.cosplay.examples.video.CPVideoExample"
                            
                                # Will launch in the same terminal console.
                                $ mvn -f modules/cosplay exec:java -P ex:video
                            
Sprite Layout

CPLayoutExample.scala

Maven
                                # Will launch using terminal emulator.
                                $ sbt "project cosplay; runMain org.cosplay.examples.layout.CPLayoutExample"
                            
                                # Will launch in the same terminal console.
                                $ mvn -f modules/cosplay exec:java -P ex:layout
                            
Dialog Support

CPDialogExample.scala

Maven
                                # Will launch using terminal emulator.
                                $ sbt "project cosplay; runMain org.cosplay.examples.dialog.CPDialogExample"
                            
                                # Will launch in the same terminal console.
                                $ mvn -f modules/cosplay exec:java -P ex:dialog
                            
ListBox

CPListBoxExample.scala

Maven
                                # Will launch using terminal emulator.
                                $ sbt "project cosplay; runMain org.cosplay.examples.listbox.CPListBoxExample"
                            
                                # Will launch in the same terminal console.
                                $ mvn -f modules/cosplay exec:java -P ex:listbox
                            
  • On This Page
  • Examples
  • Quick Links
  • Discord
  • Stack Overflow
  • GitHub
  • @cosplayengine
  • YouTube
  • API
Copyright © 2023 Rowan Games, Inc. Privacy • Docs release: 0.9.5 Latest: