‹ All courses

How to Write a Platformer Game in Java

Build a side-scrolling game in Java across 14 video lectures, with slides and labs.

In this short video series course, we will learn how to write a platformer (or side-scrolling) game like Super Mario. We will write this game from scratch with very basic algebra without relying on any physics engine!

Below are all of the resources including video lectures, code, and labs. I created this curriculum for my AP Computer Science A course during the current school closures due to the coronavirus. Subscribe to my channel.

If you teach AP Computer Science A and would like solutions, feel free to contact me directly.

1) Game PreviewYoutube

A preview of the platformer game that we will write.

2) Introduction to ProcessingYoutube

A quick introduction to Processing, a software sketchbook that allows us to easily create animations/games with simple Java code.

SlidesPPT
Bouncing Ball LabFriendly VersionMore Challenging VersionGiven a ball PNG image, simulate a ball bouncing on the screen.

3) Creating the Sprite ClassYoutube

Making our game object-oriented by creating the Sprite class, which is the superclass of all of our game objects.

SlidesPPT
Sprite Class LabFriendly VersionMore Challenging VersionImplement the Sprite class. This is the base class for all game objects.

4) Controlling a Sprite Using the KeyboardYoutube

Controlling our player using the keyboard.

SlidesPPT
Controlling A Sprite Using Keyboard LabFriendly VersionMore Challenging VersionControl a sprite with the keyboard.

5) Creating the Game Map by Using a CSV FileYoutube

Create a game map or level stage using a comma-separated values (CSV) file.

SlidesPPT
Design CSV Game/Stage Map LabZIPNo coding lab. Read code and modify CSV file to create a stage map.

6) Collision DetectionYoutube

Detecting collision between sprites. We'll implement the checkCollision method which returns true if two sprites collide and the checkCollisionList method which returns the collision list between a sprite and a list of sprites.

SlidesPPT
Collect Coins LabFriendly VersionMore Challenging VersionTank moves around on the screen and collect coins. Coin counter is display and updated on the screen.

7) Resolving Platform Collisions Part 1Youtube

Understanding the math behind resolving platform collisions. This is the most important algorithm in writing this game.

SlidesPPT

8) Resolving Platform Collisions Part 2Youtube

Implement the code to resolve platform collisions.

SlidesPPT
Resolving Platform Collisions LabZIPAdd gravity and resolve platform collisions. This is the most important algorithm in the game.

9) Add JumpingYoutube

Add in jumping ability to the player.

SlidesPPT
Jumping LabZIPAdd jumping feature to our game. You'll need your solution from the previous Resolving Platform Collisions Lab.

10) ScrollingYoutube

Add scrolling to the game.

SlidesPPT
Platformer Scrolling LabZIPImplement scrolling for the platformer game.
(Optional) Scrolling LabFriendly VersionMore Challenging VersionImplement scrolling. Draw left/right/top/bottom boundaries to visualize scrolling.

11) Animating the Sprite(uses inheritance)Youtube

Create AnimatedSprite class for simple animated Sprites. AnimatedSprite inherits from the Sprite class.

SlidesPPT
Animated Sprites LabFriendly VersionMore Challenging VersionAnimate the coins from the previous Collect Coins lab.

12) Creating Enemies(uses inheritance)Youtube

Creating animated enemies by inheriting from the AnimatedSprite class.

SlidesPPT
Create Enemies LabFriendly VersionMore Challenging VersionCreate an ArrayList of Enemy objects using CSV file. Each enemy has a different walk length between its left and right boundaries.

13) Animating the Player(uses inheritance)Youtube

Create Player class which inherits from the AnimatedSprite class to animate the player.

SlidesPPT
Animating the Player LabFriendly VersionMore Challenging VersionAnimate a simple version of the player to walk left and right. No jumping or platform collisions.

14) Finish Up GameYoutube

Finish up the game by adding game over screen and restart feature.

SlidesPPT

This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.