<?xml version="1.0"?>
<?xml-stylesheet type="text/css" href="http://oxeyegames.com/wiki/skins/common/feed.css?270"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
		<id>http://oxeyegames.com/wiki/index.php?action=history&amp;feed=atom&amp;title=SimpleBreak</id>
		<title>SimpleBreak - Revision history</title>
		<link rel="self" type="application/atom+xml" href="http://oxeyegames.com/wiki/index.php?action=history&amp;feed=atom&amp;title=SimpleBreak"/>
		<link rel="alternate" type="text/html" href="http://oxeyegames.com/wiki/index.php?title=SimpleBreak&amp;action=history"/>
		<updated>2026-04-11T17:27:28Z</updated>
		<subtitle>Revision history for this page on the wiki</subtitle>
		<generator>MediaWiki 1.16.0</generator>

	<entry>
		<id>http://oxeyegames.com/wiki/index.php?title=SimpleBreak&amp;diff=376&amp;oldid=prev</id>
		<title>Jeb: Created page with '== Description ==  SimpleBreak is a very simple break-out game. Rendering is done with only rectangles, and all input is done with the mouse. A couple of sfxr sound effects have ...'</title>
		<link rel="alternate" type="text/html" href="http://oxeyegames.com/wiki/index.php?title=SimpleBreak&amp;diff=376&amp;oldid=prev"/>
				<updated>2010-02-06T14:22:19Z</updated>
		
		<summary type="html">&lt;p&gt;Created page with &amp;#39;== Description ==  SimpleBreak is a very simple break-out game. Rendering is done with only rectangles, and all input is done with the mouse. A couple of sfxr sound effects have ...&amp;#39;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;== Description ==&lt;br /&gt;
&lt;br /&gt;
SimpleBreak is a very simple break-out game. Rendering is done with only rectangles, and all input is done with the mouse. A couple of sfxr sound effects have been added for some extra punch :)&lt;br /&gt;
&lt;br /&gt;
http://www.oxeyegames.com/files/dm_examples/simplebreak/simplebreak.jpg&lt;br /&gt;
&lt;br /&gt;
Development time of this example was roughly one hour.&lt;br /&gt;
&lt;br /&gt;
Download all files here: [http://www.oxeyegames.com/files/dm_examples/simplebreak/simplebreak.zip simplebreak.zip]&lt;br /&gt;
&lt;br /&gt;
== Assets ==&lt;br /&gt;
&lt;br /&gt;
=== Files ===&lt;br /&gt;
&lt;br /&gt;
* [http://www.oxeyegames.com/files/dm_examples/simplebreak/main.lua main.lua]&lt;br /&gt;
* [http://www.oxeyegames.com/files/dm_examples/simplebreak/font.fnt font.fnt]&lt;br /&gt;
* [http://www.oxeyegames.com/files/dm_examples/simplebreak/bounce.wav bounce.wav]&lt;br /&gt;
* [http://www.oxeyegames.com/files/dm_examples/simplebreak/break.wav break.wav]&lt;br /&gt;
* [http://www.oxeyegames.com/files/dm_examples/simplebreak/hit.wav hit.wav]&lt;br /&gt;
&lt;br /&gt;
=== main.lua ===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
math.randomseed( os.time() )&lt;br /&gt;
&lt;br /&gt;
local gameData = { destructionCounter = 0, }&lt;br /&gt;
local gameField = {}&lt;br /&gt;
local player = { x = 0, y = 0, width = 100, height = 20, momentum = {}, momentumUpdate = 0 }&lt;br /&gt;
local maxMomentum, momentumTime = 8, .05&lt;br /&gt;
local balls = {}&lt;br /&gt;
&lt;br /&gt;
local tileColors = {&lt;br /&gt;
	{ a = 255, r = 160, g = 120, b = 120 },&lt;br /&gt;
	{ a = 255, r = 180, g = 160, b = 130 },&lt;br /&gt;
	{ a = 255, r = 240, g = 230, b = 160 },&lt;br /&gt;
	{ a = 255, r = 240, g = 235, b = 220 },&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
local function addBall()&lt;br /&gt;
&lt;br /&gt;
	local ball = { x = 0, y = 0, width = 10, height = 10, dx = 0, dy = 0, momentum = {}, momentumUpdate = 0, state = &amp;quot;locked&amp;quot; }&lt;br /&gt;
	table.insert(balls, ball)&lt;br /&gt;
	&lt;br /&gt;
	return ball&lt;br /&gt;
&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
local function addTile(x, y, width, height, hits)&lt;br /&gt;
&lt;br /&gt;
	local tile = {x = x, y = y, width = width, height = height, hits = hits}&lt;br /&gt;
	table.insert(gameField, tile)&lt;br /&gt;
	&lt;br /&gt;
	return tile&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
local function createLevel()&lt;br /&gt;
&lt;br /&gt;
	gameField = {} -- clear old set&lt;br /&gt;
	&lt;br /&gt;
	local w,h = video.getScreenSize()&lt;br /&gt;
	local currentY = math.random(0, 5)&lt;br /&gt;
	&lt;br /&gt;
	while currentY &amp;lt; h / 2 do&lt;br /&gt;
	&lt;br /&gt;
		local tileHeight = math.random(30, 50)&lt;br /&gt;
		local currentX = math.random(0, 10)&lt;br /&gt;
		&lt;br /&gt;
		while currentX &amp;lt; w do&lt;br /&gt;
		&lt;br /&gt;
			local tileWidth = math.random(40, 80)&lt;br /&gt;
			if tileWidth + currentX &amp;gt; w then&lt;br /&gt;
				tileWidth = w - currentX&lt;br /&gt;
			end&lt;br /&gt;
			if tileWidth &amp;gt; 10 then&lt;br /&gt;
				addTile(currentX, currentY, tileWidth, tileHeight, math.random(1, 4))&lt;br /&gt;
			end&lt;br /&gt;
			&lt;br /&gt;
			currentX = currentX + tileWidth + math.random(3, 4)&lt;br /&gt;
		end&lt;br /&gt;
		&lt;br /&gt;
		currentY = currentY + tileHeight + math.random(3, 4)&lt;br /&gt;
	end&lt;br /&gt;
	&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
--[[&lt;br /&gt;
	INIT METHOD&lt;br /&gt;
]]&lt;br /&gt;
local function mainInit()&lt;br /&gt;
&lt;br /&gt;
	createLevel()&lt;br /&gt;
	addBall()&lt;br /&gt;
&lt;br /&gt;
end&lt;br /&gt;
hook.add(&amp;quot;gameInit&amp;quot;, mainInit)&lt;br /&gt;
&lt;br /&gt;
local function updateMomentum(object, time)&lt;br /&gt;
	object.momentumUpdate = object.momentumUpdate + time&lt;br /&gt;
	if object.momentumUpdate &amp;gt; momentumTime then&lt;br /&gt;
		object.momentumUpdate = object.momentumUpdate - momentumTime&lt;br /&gt;
		&lt;br /&gt;
		table.insert(object.momentum, {x = object.x, y = object.y} )&lt;br /&gt;
		while #object.momentum &amp;gt; maxMomentum do&lt;br /&gt;
			table.remove(object.momentum, 1)&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
--[[&lt;br /&gt;
	UPDATE METHOD&lt;br /&gt;
]]&lt;br /&gt;
local function mainUpdate(time)&lt;br /&gt;
	if time &amp;gt; .06 then&lt;br /&gt;
		time = .06&lt;br /&gt;
	end&lt;br /&gt;
	&lt;br /&gt;
	local w, h = video.getScreenSize()&lt;br /&gt;
	&lt;br /&gt;
	-- update momentum&lt;br /&gt;
	updateMomentum(player, time)&lt;br /&gt;
	for index, ball in ipairs(balls) do&lt;br /&gt;
		updateMomentum(ball, time)&lt;br /&gt;
	end&lt;br /&gt;
	&lt;br /&gt;
	-- update player position&lt;br /&gt;
	local mx, my = daisy.getMousePosition()&lt;br /&gt;
	player.x = mx - player.width / 2&lt;br /&gt;
	if player.x &amp;lt; 0 then&lt;br /&gt;
		player.x = 0&lt;br /&gt;
	elseif player.x + player.width &amp;gt; w then&lt;br /&gt;
		player.x = w - player.width&lt;br /&gt;
	end&lt;br /&gt;
	player.y = h - player.height - 10&lt;br /&gt;
	&lt;br /&gt;
	-- update balls&lt;br /&gt;
	for ballIndex, ball in ipairs(balls) do&lt;br /&gt;
		if ball.state == &amp;quot;locked&amp;quot; then&lt;br /&gt;
			ball.x = player.x + (player.width - ball.width) / 2&lt;br /&gt;
			ball.y = player.y - ball.height&lt;br /&gt;
			&lt;br /&gt;
			if daisy.isMouseButtonPressed(0) then&lt;br /&gt;
				ball.state = &amp;quot;action&amp;quot;&lt;br /&gt;
				&lt;br /&gt;
				ball.dx, ball.dy = 0, -250&lt;br /&gt;
			end&lt;br /&gt;
			&lt;br /&gt;
		elseif ball.state == &amp;quot;action&amp;quot; then&lt;br /&gt;
			ball.x, ball.y = ball.x + ball.dx * time, ball.y + ball.dy * time&lt;br /&gt;
			&lt;br /&gt;
			if ball.x + ball.width &amp;gt; w then&lt;br /&gt;
				ball.dx = -ball.dx&lt;br /&gt;
				ball.x = w - ball.width&lt;br /&gt;
			elseif ball.x &amp;lt; 0 then&lt;br /&gt;
				ball.dx = -ball.dx&lt;br /&gt;
				ball.x = 0&lt;br /&gt;
			end&lt;br /&gt;
			if ball.y &amp;lt; 0 then&lt;br /&gt;
				ball.dy = -ball.dy&lt;br /&gt;
				ball.y = 0&lt;br /&gt;
			end&lt;br /&gt;
			&lt;br /&gt;
			for index, tile in ipairs(gameField) do&lt;br /&gt;
				if ball.x + ball.width &amp;gt;= tile.x and ball.x &amp;lt;= tile.x + tile.width and&lt;br /&gt;
					ball.y + ball.height &amp;gt;= tile.y and ball.y &amp;lt;= tile.y + tile.height then&lt;br /&gt;
					&lt;br /&gt;
					if tile.hits &amp;gt; 1 then&lt;br /&gt;
						tile.hits = tile.hits - 1&lt;br /&gt;
						&lt;br /&gt;
						if ball.y &amp;lt; tile.y or ball.y + ball.height &amp;gt; tile.y + tile.height then&lt;br /&gt;
							ball.dy = -ball.dy&lt;br /&gt;
						end&lt;br /&gt;
						if ball.x &amp;lt; tile.x or ball.x + ball.width &amp;gt; tile.x + tile.width then&lt;br /&gt;
							ball.dx = -ball.dx&lt;br /&gt;
						end&lt;br /&gt;
						audio.playSound(&amp;quot;hit.wav&amp;quot;)&lt;br /&gt;
					&lt;br /&gt;
					else&lt;br /&gt;
						table.remove(gameField, index)&lt;br /&gt;
						audio.playSound(&amp;quot;break.wav&amp;quot;)&lt;br /&gt;
						&lt;br /&gt;
						gameData.destructionCounter = gameData.destructionCounter + 1&lt;br /&gt;
						if gameData.destructionCounter % 10 == 0 then&lt;br /&gt;
							addBall()&lt;br /&gt;
						end&lt;br /&gt;
					end&lt;br /&gt;
					break -- only allow one tile collision per update&lt;br /&gt;
					&lt;br /&gt;
				end&lt;br /&gt;
			end&lt;br /&gt;
			&lt;br /&gt;
			if ball.x + ball.width &amp;gt;= player.x and ball.x &amp;lt;= player.x + player.width and&lt;br /&gt;
				ball.y + ball.height &amp;gt;= player.y and ball.y &amp;lt;= player.y + player.height then&lt;br /&gt;
				&lt;br /&gt;
				if ball.dy &amp;gt; 0 then&lt;br /&gt;
					ball.dy = -(ball.dy + 1)&lt;br /&gt;
					audio.playSound(&amp;quot;bounce.wav&amp;quot;)&lt;br /&gt;
				end&lt;br /&gt;
				ball.dx = ((ball.x + ball.width / 2) - (player.x + player.width / 2)) * 3&lt;br /&gt;
				&lt;br /&gt;
			end&lt;br /&gt;
			&lt;br /&gt;
			if ball.y &amp;gt; h then&lt;br /&gt;
				-- note, removing stuff inside a loop will mess up the loop index, so this is not best practise&lt;br /&gt;
				table.remove(balls, ballIndex)&lt;br /&gt;
			end&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
	&lt;br /&gt;
end&lt;br /&gt;
hook.add(&amp;quot;frameUpdate&amp;quot;, mainUpdate)&lt;br /&gt;
&lt;br /&gt;
--[[&lt;br /&gt;
	RENDER METHOD&lt;br /&gt;
]]&lt;br /&gt;
local function mainRender()&lt;br /&gt;
&lt;br /&gt;
	local w,h = video.getScreenSize()&lt;br /&gt;
	&lt;br /&gt;
	video.renderRectangle(0, 0, w, h, 255, 40, 60, 80)&lt;br /&gt;
&lt;br /&gt;
	for index, tile in ipairs(gameField) do&lt;br /&gt;
		local color = tileColors[tile.hits]&lt;br /&gt;
		video.renderRectangle(tile.x, tile.y, tile.width, tile.height, color.a, color.r, color.g, color.b)&lt;br /&gt;
	end&lt;br /&gt;
	&lt;br /&gt;
	-- render player&lt;br /&gt;
	local intensity = 1&lt;br /&gt;
	for i=#player.momentum, 1, -1 do&lt;br /&gt;
		intensity = intensity * .8&lt;br /&gt;
		local a, r, g, b = math.floor(intensity * 255), 255, 255, 255&lt;br /&gt;
		video.renderRectangle(player.momentum[i].x, player.y, player.width, player.height, a, r, g, b)&lt;br /&gt;
	end&lt;br /&gt;
	video.renderRectangle(player.x, player.y, player.width, player.height, 255, 255, 255, 255)&lt;br /&gt;
	&lt;br /&gt;
	-- render balls&lt;br /&gt;
	for index, ball in ipairs(balls) do&lt;br /&gt;
		local intensity = 1&lt;br /&gt;
		for i=#ball.momentum, 1, -1 do&lt;br /&gt;
			intensity = intensity * .8&lt;br /&gt;
			local a, r, g, b = math.floor(intensity * 255), 230, 80, 20&lt;br /&gt;
			video.renderRectangle(ball.momentum[i].x, ball.momentum[i].y, ball.width, ball.height, a, r, g, b)&lt;br /&gt;
		end&lt;br /&gt;
		video.renderRectangle(ball.x, ball.y, ball.width, ball.height, 255, 230, 80, 20)&lt;br /&gt;
	end&lt;br /&gt;
	&lt;br /&gt;
	if #gameField == 0 then&lt;br /&gt;
		video.renderText(&amp;quot;VICTORY! - Press Ctrl+R to play again&amp;quot;, w / 2, h - 100, 1)&lt;br /&gt;
	elseif #balls == 0 then&lt;br /&gt;
		video.renderText(&amp;quot;GAME OVER - Press Ctrl+R to try again&amp;quot;, w / 2, h - 100, 1)&lt;br /&gt;
	end&lt;br /&gt;
	&lt;br /&gt;
	&lt;br /&gt;
end&lt;br /&gt;
hook.add(&amp;quot;frameRender&amp;quot;, mainRender)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[Category:Daisymoon]]&lt;/div&gt;</summary>
		<author><name>Jeb</name></author>	</entry>

	</feed>