-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
203 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
Bunny = {} | ||
Bunny.__index = Bunny | ||
|
||
local random = math.random | ||
|
||
function Bunny:create(texture) | ||
local r = {} | ||
setmetatable(r, Bunny) | ||
r.x = 0 | ||
r.y = 0 | ||
|
||
r.texture = texture | ||
r.speedX = random() * 10 | ||
r.speedY = random() * 10 - 5 | ||
|
||
r.scale = 0.5 + random() * 0.5 | ||
r.w = r.scale * texture.w | ||
r.h = r.scale * texture.h | ||
|
||
return r | ||
end | ||
|
||
function Bunny:processPhysics(bunny) | ||
local x = bunny.x + bunny.speedX | ||
local y = bunny.y + bunny.speedY | ||
local speedX = bunny.speedX | ||
local speedY = bunny.speedY + gravity | ||
local w = bunny.w | ||
local h = bunny.h | ||
|
||
if x > maxX - w then | ||
speedX = speedX * -1 | ||
x = maxX - w | ||
elseif x < minX then | ||
speedX = speedX * -1 | ||
x = minX | ||
end | ||
|
||
if y > maxY - h then | ||
speedY = speedY * -0.85 | ||
y = maxY - h | ||
if random() > 0.5 then | ||
speedY = speedY - random() * 6 | ||
end | ||
elseif y < minY then | ||
speedY = 0 | ||
y = minY | ||
end | ||
|
||
bunny.x = x | ||
bunny.y = y | ||
bunny.speedX = speedX | ||
bunny.speedY = speedY | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
require("Assets/Scripts/Rect") | ||
require("Assets/Scripts/Bunny") | ||
require('Assets/Scripts/buttonsCommon') | ||
|
||
width = 480 | ||
height = 272 | ||
|
||
wabbitTexture = nil | ||
|
||
bunnys = {} | ||
gravity = 0.5 --1.5 | ||
|
||
maxX = width | ||
minX = 0 | ||
maxY = height | ||
minY = 0 | ||
|
||
startBunnyCount = 2 | ||
isAdding = false | ||
count = 0 | ||
|
||
amount = 10 | ||
|
||
bgColor = pge.gfx.createcolor(255, 255, 255) | ||
font = pge.font.load("Assets/Fonts/arialbd.ttf", 12, PGE_VRAM) | ||
|
||
fontFGColor = pge.gfx.createcolor(0, 255, 255) | ||
fontBGColor = pge.gfx.createcolor(16, 92, 182) | ||
|
||
bunnyTextures = nil | ||
currentTexture = nil | ||
bunnyType = nil | ||
|
||
function spawnBunny() | ||
local bunny = Bunny:create(currentTexture) | ||
table.insert(bunnys, bunny) | ||
count = count + 1 | ||
end | ||
|
||
function onReady() | ||
wabbitTexture = pge.texture.load("Assets/Sprites/bunnys.png", PGE_VRAM) | ||
|
||
bunnyTextures = { | ||
Rect:create(2, 47, 26, 37), | ||
Rect:create(2, 86, 26, 37), | ||
Rect:create(2, 125, 26, 37), | ||
Rect:create(2, 164, 26, 37), | ||
Rect:create(2, 2, 26, 37) | ||
} | ||
|
||
bunnyType = 2 | ||
currentTexture = bunnyTextures[bunnyType] | ||
|
||
for i = 1, startBunnyCount do | ||
spawnBunny() | ||
end | ||
end | ||
|
||
|
||
function onTouchStart() | ||
isAdding = true; | ||
end | ||
|
||
function onTouchEnd() | ||
bunnyType = bunnyType + 1 | ||
bunnyType = (bunnyType % 5) + 1; | ||
currentTexture = bunnyTextures[bunnyType]; | ||
|
||
isAdding = false; | ||
end | ||
|
||
|
||
|
||
local fpsTimer = pge.timer.create() | ||
local FPS = 60 | ||
|
||
onReady() | ||
while true do | ||
pge.controls.update() | ||
pge.gfx.startdrawing() | ||
pge.gfx.clearscreen(bgColor) | ||
|
||
if pge.controls.pressed(PGE_CTRL_CROSS) then | ||
onTouchStart() | ||
end | ||
if pge.controls.released(PGE_CTRL_CROSS) then | ||
onTouchEnd() | ||
end | ||
|
||
if isAdding then | ||
-- add 10 at a time :) | ||
if count < 200000 then | ||
for i = 0, amount do | ||
spawnBunny() | ||
end | ||
end | ||
end | ||
|
||
wabbitTexture:activate() | ||
for i = 1, count do | ||
local bunny = bunnys[i] | ||
Bunny:processPhysics(bunny) | ||
local tex = bunny.texture | ||
wabbitTexture:draw( | ||
bunny.x, bunny.y, bunny.w, bunny.h, | ||
tex.x, tex.y, tex.w, tex.h) | ||
end | ||
|
||
pge.timer.update(fpsTimer) | ||
FPS = math.floor(1 / pge.timer.getdelta(fpsTimer)) | ||
|
||
pge.gfx.drawrect(0, 0, 90, 30, fontBGColor) | ||
font:activate() | ||
font:print(2, 2, fontFGColor, FPS .. " FPS")--, fontFGColor, fontBGColor) | ||
font:print(2, 16, fontFGColor, count .. " BUNNIES")--, fontFGColor, fontBGColor) | ||
|
||
pge.gfx.enddrawing() | ||
pge.gfx.swapbuffers() | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
Rect = {} | ||
Rect.__index = Rect | ||
|
||
function Rect:create(x,y,w,h) | ||
local r = {} | ||
setmetatable(r, Rect) | ||
r.x = x | ||
r.y = y | ||
r.w = w | ||
r.h = h | ||
return r | ||
end |
11 changes: 11 additions & 0 deletions
11
bunnyMarkPhoenixGameEngine/Assets/Scripts/buttonsCommon.lua
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
function press(button) | ||
return buttons.pressed(buttons[button]) | ||
end | ||
|
||
function held(button) | ||
return buttons.held(buttons[button]) | ||
end | ||
|
||
function release(button) | ||
return buttons.released(buttons[button]) | ||
end |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
dofile("Assets/Scripts/Main.lua") |