Friday, April 10, 2015

The game of Dot Matrix

Introduction

This page is the source code page for the game of Dot Matrix. Please visit my gaming blog for a brief explanation of the source code.

Required

You will need DotMatrix.java and match3_sheet_0.png

Optional

epic_loop.wav and twoTone2.wav for sound support.

Compile and Run

javac DotMatrix.java
java DotMatrix


Source Code

Sunday, April 5, 2015

Simple Wave File Player

Introduction

This post presents a simple Wave File Player written in Java, using the sampled sound API. Since we are not using JavaFX, it will not support the mp3 format.

Import

We will be using API from the javax.sound.sampled package. Hence we make the following imports at the beginning of the program.
import javax.sound.sampled.AudioFormat;
import javax.sound.sampled.AudioInputStream;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.Clip;
import javax.sound.sampled.DataLine;


Progress bar

We will use a JSlider as a progress bar. The scale are from 0 to 10000, which is simple to represent 0 to 100% with two decimal place. To update the progress, the following method will be invoked by a Swing Timer on every 30ms.

Sample Wave File

  epic_loop.wav : Orchestral Adventure by RevampedPRO, CC BY 3.0 license 
                  http://opengameart.org/content/orchestral-adventure 

  twoTone2.wav : "63 Digital sound effects" by Kenney, CC0 license, 
    http://opengameart.org/content/63-digital-sound-effects-lasers-phasers-space-etc
The wave files are inside a github project. Follow the following link to download the project as a zip file.
https://github.com/macteki/WavePlayer

Source Code

Saturday, March 14, 2015

The game of Color Matrix



Attribution

We are using the artwork from the following source:

MATCH 3 by Buch/CC0
We just need a single file (match3_sheet_0.png) provided by Buch:
match3_sheet_0

Explanation

For a brief explanation of the source code, please visit Teach Yourself Java Programming in 21 Games

Compile and run

You will need the following files :
match3_sheet_0.png
ColorMatrix.java    
Board.java
Cell.java
BlockSprite.java
BlockType.java
Sprite.java
Token.java

To compile:
  javac *.java
To run
  java ColorMatrix
match3_sheet_0.png can be downloaded in opengameart.org

Alternatively, you may just right click the image in the attribution section and download it.

Source Code


ColorMatrix.java
Board.java Cell.java
BlockSprite.java
BlockType.java
Sprite.java
Token.java

Saturday, February 28, 2015

Moving Objects and Sprite Manager - Part 10

This is part 10 of the series. You are suggested to read the whole series from the beginning. You may find the whole series in the Featured page.


The Game of Space Invader

For a brief explanation of the source code, please visit Teach Yourself Java Programming in 21 Games

Attribution

"Space Ship Shooter Pixel Art Assets" by ansimuz / CC0
You may download the file space_shooter_pack.zip at opengameart.org.
Alternatively, you may download an unmodified version of the zip file here.

Compile and Run

You will need Scroller.java, Sprite.java, ShipSprite.java, EnemySprite.java, FireboltSprite.java, ExplosionSprite.java, LaserSprite.java and space_shooter_pack.zip Place everything in the same folder and type:
javac *.java
java Scroller


Scroller.java



EnemySprite.java



FireboltSprite.java



ExplosionSprite.java

LaserSprite.java



ShipSprite.java



Sprite.java

Moving Objects and Sprite Manager - Part 9

This is part 9 of the series. You are suggested to read the whole series from the beginning. You may find the whole series in the Featured page.


A sprite in a scrolling background

For a brief explanation of the source code, please visit Teach Yourself Java Programming in 21 Games

Compile and Run

You will need Scroller.java, Sprite.java, ShipSprite.java and space_shooter_pack.zip Place everything in the same folder and type:
javac *.java
java Scroller


You may download the file space_shooter_pack.zip at opengameart.org.
Alternatively, you may download an unmodified version of the zip file here.

The Java source file are listed below.

Scroller.java



ShipSprite.java



Sprite.java

This is the same as the file Sprite.java in "Moving Objects and Sprite Manager Part 6".

Friday, February 27, 2015

Moving Objects and Sprite Manager - Part 8

This is part 8 of the series. You are suggested to read the whole series from the beginning. You may find the whole series in the Featured page.


Scrolling Background

We will use a looping background created by ansimuz.

You may find the original collection at :
http://opengameart.org/content/space-ship-shooter-pixel-art-assets

The author release the file under the CC0 license. In summary, the license allow you to use it in your own game, even for commercial purpose.

You may download the file space_shooter_pack.zip

We will use the file desert-backgorund-looped.png inside the zip file.

This is a looping background. That means if we cut the bottom row of the image, and then paste it to the top, we still have a continuous image. Hence the scrolling is as simple as: Note that we are using the same technique in Optimized flood filler to access the pixel array of the image. This is much faster than the getPixel() and setPixel() API.


Reading image from zip file

We will read directly from the zip file so that we don't need to uncompress the file to the harddrive. The source code for reading zip file is defined in readZipImage() in the demonstration. The reason to read directly from zip file is that we may redistribute other people artwork in an unmodified form. This typically fulfill most of the license requirement in http://opengameart.org.

Important
There are many free artworks available in opengameart.org. However, you must read the license of the individual entry before using it. Not every entry is released under CC0. Different authors may submit their work under different licenses. For example, many licenses require you to attribute the original author. Just like what I am doing below :



You may have a look at Best Practices for attribution


Demonstration

You will need Scroller.java and space_shhoter_pack.zip in the same folder.

Compile and run

javac Scroller.java
java Scroller