
Create a survival game in JavaScript with Phaser 3, featuring mining, foraging, and monster combat, and learn tile maps with Tiled, spawn points, and modern JavaScript features.
set up visual studio code, install the live server extension to run html pages locally, and download the map editor from map editor dot org to build maps.
IMPORTANT!!!
Due to changes in the matter physics plugin, you will need to make the follwoing changes:
In survival-game.js add .default to the end of the plugin line:
plugins: { scene: [ { plugin: PhaserMatterCollisionPlugin.default, key: 'matterCollision', mapping: 'matterCollision' } ] }
In index.html use the latest version of phaser by changing the phaser script line src to:
src="https://cdn.jsdelivr.net/npm/phaser@3.55.2/dist/phaser.js"
In this video we start off in Visual Studio Code and create our project folder that will contain our game.
We use the Terminal in VS Code to do this but if you are using Windows you may run in to problems changing to another drive since I use:
cd /d
To change to the D drive
However I can do this since I am using 'bash' as my terminal shell, for a standard Windows command shell or powershell you will need to use:
d:
To change to the D drive
If you want to use bash in windows there are various options but the simplest is probably to install Git for Windows since you will probably want to use / learn git if you are a web developer.
https://gitforwindows.org/
Set up a Phaser 3 main scene with preload, create, and update, add a matter sprite player, use WASD for movement, and normalize velocity to keep constant speed on diagonals.
Source 16x16 sprites from a free npc pack, use atlas packer to create an atlas, preload images, and add the townsfolk female sprite with idle and walking frames.
Refactor the player into a class extending Phaser Matter Sprite, encapsulating movement, input, and animation. Use a static preload method to set up textures and frames and tidy main scene.
Implement a well-rounded player by adding a circular collider and a larger circular sensor, forming a compound body for harvesting rocks and trees.
Create a 16 by 16 orthogonal map in tiled with a 32-pixel RPG nature tile set, save as map.json, then load it into Phaser 3 to render a static layer.
Use the stamp tool to add water tiles and refine edges for a cleaner look, then create a second layer to add variety and save the map in Phaser 3.
Create colliders on edge tiles in Phaser 3 using a collides property in Tiled, enable collisions with layer.setCollisionByProperty, and size colliders to fit edges so players can walk safely.
Build a resources atlas with trees, bushes, and rocks from tiled maps, export images, load into Phaser 3, place a tree and rock, and set them non-static.
Explore creating a pickaxe weapon in Phaser 3 by loading a sprite sheet, positioning the weapon with an origin, and swinging in an arc via mouse input with flip logic.
Use a sensor circle around the player to interact only with nearby rocks, trees, and bushes, building an array of touched objects for mining later.
Define a drops property on rocks, trees, and bushes as an array of item indices. Spawn drop items at the hit location with a class, enabling collision and pickup sounds.
Create forest themed enemies for a Phaser 3 survival game by using atlas packer to build an enemy atlas from assets and set up bear, wolf, and dog walk animations.
Learn how to place enemies in a Phaser 3 survival game by creating an enemies layer, defining bear and wolf enemies, their drops, health, loading sounds, and debugging idle frames.
Add sensors and a circular collider to enemies to detect and attack the player with a timed loop, flip sprites by velocity, map animations to each enemy, and handle death.
Override the on death method to display a death sprite, stop animations, set the corpse texture, and destroy the weapon, ensuring no movement or flipping while dead.
Turn off debugging to reveal a polished survival game where the character walks, chops trees, mines rocks, forages, and collects items as enemies chase and kill.
Fix the out-of-range bear damage bug, implement a smooth camera follow with bounds, and resolve tile bleeding by using tile extruder to produce a power-of-two 512x512 tileset.
If you need to practise your javascript...
If you want to learn some new ES6 stuff...
If you have ever wanted to create a survival game...
Then this course is for you!
You will get experience using:
ES6
Classes
Arrays
Objects
Functions
Phaser 3
Tiled
Animation
Spritesheets
Creating a survival game is fun and a great way to learn some Javascript and Phaser fundamentals.
The game includes:
Animations
Basic Enemy AI
Audio
Mouse & Keyboard Input Handling
Advanced Matter Physics
Full source code is included.
I hope you enjoy the course!
About me
I've been developing games using Unity3D for over 7 years now. I currently have ten games published on the Android app store. My first game I ever wrote, 'Isle Survive', has had over 1 million downloads and an average rating of 4 out of 5. I have also written numerous Unity plugins to enable adding features to mobile games like advertising banners and 'In-App' purchasing.
Account packages, haulage systems, mainframe processors, websites... I've done all sorts of programming but now I try to write games and it is so much more fun!
I still remember how excited I was, getting my ZX81 and writing my first few lines of BASIC. Yes I'm that old...
I love how the barrier of entry to game development has been lowered these past few years. I'm sure this has a lot to do with the current indie game explosion and I'm very excited for the future.
Why not join my discord server and say hello?!