Breakout prototype made with Dreemchest

Read all posts about "" game

This prototype comes directly from Dmitry Sovetov, the brain behind Dreemchest. It’s a breakout prototype ready to be published as a standalone Windows/Mac game or as an Android/iOS game.

All starts from the visual editor

Then it’s just a matter of writing some lines of code, for the main class:

class "App"( StageObjectContainer )

function App:main()
	local w = Stage.getWidth()
	local h = Stage.getHeight()
	
	Physics.setGravity( 0, 0 )
	
	-- Horizontal walls
	self:createWall( w * 0.5, 0, w, 5 )
	self:createWall( w * 0.5, h, w, 5 )
	
	-- Vertical walls
	self:createWall( 0, h * 0.5, 5, h )
	self:createWall( w, h * 0.5, 5, h )
end

function App:createWall( x, y, w, h )
	local wall 	 = Graphics.new()
	wall.x		 = x
	wall.y 		 = y
	wall.visible = false
	wall:setAsRectangle( w, h )
	wall:physicalize( { static = true } )
	
	self:attach( wall )
end

for the ball:

class "Ball"( Graphics )

function Ball:Ball()
	self.texture = 'bmpBall1'
	
	self:physicalize( { radius = self.width * 0.5 } )
	self.physicalBody:setLinearVelocity( math.random() * 10 - 10, math.random() * 10 - 10 )
	
	self:attachListener( Event.Update, self )
end

function Ball:onUpdate( e )
	local body  = self.physicalBody
	local vel	= body.linearVelocity
	local speed = math.abs( vel.x ) + math.abs( vel.y )

	if speed <= 0.5 then
		speed = 0.5
	end

	if speed < 5 then
		local rescale 	= 5 / speed
		body:setLinearVelocity( vel.x * rescale, vel.y * rescale )
	end
end

the block:

class "Block"( bmpBox )

function Block:Block()
	self:physicalize( { static = true } )
	self:attachListener( CollisionEvent.Begin, self )
end

function Block:onCollisionBegin( e )
	self:release()
end

and obviously the pad:

class "Pad"( bmpPad )

function Pad:Pad()
	self:physicalize( { shape = 'shPad', kinematic = true } )
	Stage.attachListener( TapEvent.Move, self )
end

function Pad:onTapMove( e )
	self.x = e.x
end

That’s 72 lines of code, and you’re ready to run your mobile breakout, thanks to Dreemchest power.

Download the project source.

Get the most popular Phaser 3 book

Through 202 pages, 32 source code examples and an Android Studio project you will learn how to build cross platform HTML5 games and create a complete game along the way.

Get the book

214 GAME PROTOTYPES EXPLAINED WITH SOURCE CODE
// 1+2=3
// 100 rounds
// 10000000
// 2 Cars
// 2048
// A Blocky Christmas
// A Jumping Block
// A Life of Logic
// Angry Birds
// Angry Birds Space
// Artillery
// Astro-PANIC!
// Avoider
// Back to Square One
// Ball Game
// Ball vs Ball
// Ball: Revamped
// Balloon Invasion
// BallPusher
// Ballz
// Bar Balance
// Bejeweled
// Biggification
// Block it
// Blockage
// Bloons
// Boids
// Bombuzal
// Boom Dots
// Bouncing Ball
// Bouncing Ball 2
// Bouncy Light
// BoxHead
// Breakout
// Bricks
// Bubble Chaos
// Bubbles 2
// Card Game
// Castle Ramble
// Chronotron
// Circle Chain
// Circle Path
// Circle Race
// Circular endless runner
// Cirplosion
// CLOCKS - The Game
// Color Hit
// Color Jump
// ColorFill
// Columns
// Concentration
// Crossy Road
// Crush the Castle
// Cube Jump
// CubesOut
// Dash N Blast
// Dashy Panda
// Deflection
// Diamond Digger Saga
// Don't touch the spikes
// Dots
// Down The Mountain
// Drag and Match
// Draw Game
// Drop Wizard
// DROP'd
// Dudeski
// Dungeon Raid
// Educational Game
// Elasticity
// Endless Runner
// Erase Box
// Eskiv
// Farm Heroes Saga
// Filler
// Flappy Bird
// Fling
// Flipping Legend
// Floaty Light
// Fuse Ballz
// GearTaker
// Gem Sweeper
// Globe
// Goat Rider
// Gold Miner
// Grindstone
// GuessNext
// Helicopter
// Hero Emblems
// Hero Slide
// Hexagonal Tiles
// HookPod
// Hop Hop Hop Underwater
// Horizontal Endless Runner
// Hundreds
// Hungry Hero
// Hurry it's Christmas
// InkTd
// Iromeku
// Jet Set Willy
// Jigsaw Game
// Knife Hit
// Knightfall
// Legends of Runeterra
// Lep's World
// Line Rider
// Lumines
// Magick
// MagOrMin
// Mass Attack
// Math Game
// Maze
// Meeblings
// Memdot
// Metro Siberia Underground
// Mike Dangers
// Mikey Hooks
// Nano War
// Nodes
// o:anquan
// One Button Game
// One Tap RPG
// Ononmin
// Pacco
// Perfect Square!
// Perfectionism
// Phyballs
// Pixel Purge
// PixelField
// Planet Revenge
// Plants Vs Zombies
// Platform
// Platform game
// Plus+Plus
// Pocket Snap
// Poker
// Pool
// Pop the Lock
// Pop to Save
// Poux
// Pudi
// Pumpkin Story
// Puppet Bird
// Pyramids of Ra
// qomp
// Quick Switch
// Racing
// Radical
// Rebuild Chile
// Renju
// Rise Above
// Risky Road
// Roguelike
// Roly Poly
// Run Around
// Rush Hour
// SameGame
// SamePhysics
// Save the Totem
// Security
// Serious Scramblers
// Shrink it
// Sling
// Slingy
// Snowflakes
// Sokoban
// Space Checkers
// Space is Key
// Spellfall
// Spinny Gun
// Splitter
// Spring Ninja
// Sproing
// Stabilize!
// Stack
// Stick Hero
// String Avoider
// Stringy
// Sudoku
// Super Mario Bros
// Surfingers
// Survival Horror
// Talesworth Adventure
// Tetris
// The Impossible Line
// The Moops - Combos of Joy
// The Next Arrow
// Threes
// Tic Tac Toe
// Timberman
// Tiny Wings
// Tipsy Tower
// Toony
// Totem Destroyer
// Tower Defense
// Trick Shot
// Tunnelball
// Turn
// Turnellio
// TwinSpin
// vvvvvv
// Warp Shift
// Way of an Idea
// Whack a Creep
// Wheel of Fortune
// Where's my Water
// Wish Upon a Star
// Word Game
// Wordle
// Worms
// Yanga
// Yeah Bunny
// Zhed
// zNumbers