Created
June 6, 2013 03:31
-
-
Save prophetgoddess/5719123 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
ROT = require("/src/rot") | |
require("camera") | |
require("randomlua") | |
cameraX = 0 | |
cameraY = 0 | |
p = false | |
Eupdate = false | |
statscalc = 0 | |
floorMade = 0 | |
game = 1 | |
floorNumber = 1 | |
enemyNumber = floorNumber * 2 | |
enemies = {} | |
drawExit = true | |
newLevel = false | |
playerClass = nil | |
gameOver = false | |
retryButtonInit = false | |
function calbak(x, y, val) --calbaks initialize various aspects of the game. this one sets the map size. | |
map[x..','..y]=val | |
end | |
function lightCalbak(fov, x, y) | |
local key=x..','..y | |
if map[key] then | |
return map[key]==0 | |
end | |
return false | |
end | |
function computeCalbak(x, y, r, v) | |
local key =x..','..y | |
if not map[key] then return end | |
field[key]=1 | |
seen[key]=1 | |
end | |
function placePlayer() --exactly what it says on the tin. | |
local key =nil | |
local char='#' | |
local rng=ROT.RNG.Twister:new() -- initialize a mersenne twister | |
rng:randomseed() | |
while true do | |
key=rng:random(1,f:getWidth())..','..rng:random(1,f:getHeight()) --randomly picks a coordinate between 1 and the max width and height for the map | |
if map[key]==0 then --if the space that the key chose is free.... | |
local pos = key:split(',') | |
player.x, player.y=tonumber(pos[1]), tonumber(pos[2]) | |
f:write('@', player.x, player.y) --set the player's position to the aforementioned random coordinates that have free space. | |
break | |
end | |
end | |
end | |
function playerStats() | |
player.str = playerClass.strength | |
player.dex = playerClass.dexterity | |
player.int = playerClass.intelligence | |
player.con = playerClass.constitution | |
player.faith = playerClass.faith | |
player.hitDice = playerClass.hitDice | |
player.damageDice = playerClass.damageDice | |
player.health = math.random(1, player.hitDice) + player.con | |
player.mana = math.random(1, 10) + player.int | |
player.ac = math.random(1,player.dex) + player.dex | |
end | |
function love.load() | |
require("loveframes") | |
require("32log") | |
gameOverScreen = love.graphics.newImage("/sprites/gameOver.png") | |
loveframes.load() | |
draw = true | |
f =ROT.Display(70, 35) --initialize the display and such | |
map={} | |
field={} | |
seen={} | |
seenColor={r=100, g=100, b=100, a=255} | |
fieldColor={r=225, g=225, b=225, a=255} | |
fieldbg={r=50, g=50, b=50, a=255} | |
update=false | |
player={x=1, y=1, class=nil, health=nil, mana = nil, str=nil, dex=nil, int=nil, con=nil, faith=nil, hitDice = nil, damageDice = nil, ac=nil} | |
exit={x=1, y=1} | |
--class initialization | |
fighter = { | |
strength = math.random(3, 5); | |
dexterity = math.random(1, 3); | |
intelligence = math.random(1, 2); | |
constitution = math.random(3, 5); | |
faith = math.random(1, 2); | |
hitDice = 6; | |
damageDice = 6; | |
sprite = "/sprites/fighter.png"; | |
} | |
class "ranger"{ | |
strength = math.random(1, 2); | |
dexterity = math.random(3, 5); | |
intelligence = math.random(3, 5); | |
constitution = math.random(1, 3); | |
faith = math.random(1, 2); | |
sprite = "/sprites/ranger.png"; | |
} | |
rangerInst = ranger:new() | |
class "mage"{ | |
strength = math.random(1, 2); | |
dexterity = math.random(1, 3); | |
intelligence = math.random(3, 5); | |
constitution = math.random( 1, 2); | |
faith = math.random(1, 3); | |
sprite = "/sprites/mage.png" | |
} | |
mageInst = mage:new() | |
class "cleric"{ | |
strength = math.random(1, 3); | |
dexterity = math.random(1, 2); | |
intelligence = math.random(3, 5); | |
constitution = math.random(1, 3); | |
faith = math.random(3, 5); | |
} | |
clericInst = cleric:new() | |
--buttons for selecting classes | |
-- if game == 0 then | |
-- fighterButton = loveframes.Create("button") | |
-- fighterButton:SetPos(300, 600) | |
-- fighterButton:SetText("Fighter") | |
-- fighterButton.OnClick = function(object) | |
-- playerClass = fighterInst | |
-- game = true | |
-- end | |
-- rangerButton = loveframes.Create("button") | |
-- rangerButton:SetPos(400, 600) | |
-- rangerButton:SetText("Ranger") | |
-- rangerButton.OnClick = function(object) | |
-- playerClass = rangerInst | |
-- game = true | |
-- end | |
-- mageButton = loveframes.Create("button") | |
-- mageButton:SetPos(500, 600) | |
-- mageButton:SetText("Mage") | |
-- mageButton.OnClick = function(object) | |
-- playerClass = mageInst | |
-- game = true | |
-- end | |
-- clericButton = loveframes.Create("button") | |
-- clericButton:SetPos(600, 600) | |
-- clericButton:SetText("Cleric") | |
-- clericButton.OnClick = function(object) | |
-- playerClass = clericInst | |
-- game = true | |
-- end | |
-- end | |
playerClass = fighter | |
initialize() | |
end | |
function initialize() --initialization function for fov and uni, placing players | |
print("Thing done.") | |
draw = true | |
enemies = {} | |
player = {x=1, y=1, class=nil, health=nil, mana = nil, str=nil, dex=nil, int=nil, con=nil, faith=nil, hitDice = nil, damageDice = nil, ac=nil} | |
map={} | |
field={} | |
seen={} | |
uni=ROT.Map.Uniform:new(70, 35) | |
uni:create(calbak) | |
fov=ROT.FOV.Precise:new(lightCalbak)--, {topology=4}) | |
placePlayer() | |
playerStats() | |
fov:compute(player.x, player.y, 10, computeCalbak) | |
gameOver = false | |
end | |
function love.update(dt) | |
if newLevel then | |
newLevel = false | |
initialize() | |
end | |
if not gameOver then | |
f:clear() -- clear the map to recalculate fov and such | |
for x=1,f:getWidth() do -- for each coordinate in the grid | |
for y=1,f:getHeight() do | |
local key=x..','..y | |
if seen[key] then --check if the tile that we're currently checking has been seen | |
char=key==player.x..','..player.y and '@' or map[key]==0 and '.' or map[key]==1 and '#' --checks the properties of the seen key and then chooses the character based on that | |
f:write(char, x, y, field[key] and fieldColor or seenColor, field[key] and fieldbg or nil) --write the characters and comput FOV | |
end | |
end | |
end | |
enemyDraw() | |
baseDamage() | |
enemyBehaviour() | |
exitDraw() | |
descend() | |
end | |
end | |
function love.draw() | |
f:draw(0, 0) | |
if gameOver then | |
f:clear() | |
initialize() | |
end | |
loveframes.draw() | |
end | |
function love.mousepressed(button, x, y) | |
loveframes.mousepressed(x,y,button) | |
end | |
function love.mousereleased(button, x, y) | |
loveframes.mousereleased(x,y,button) | |
end | |
function love.keypressed(key) | |
--updates the position of the player depending on what button or press | |
local newPos={0,0} | |
if key =='s' then | |
newPos={ 0, 1} | |
elseif key=='a' then | |
newPos={-1, 0} | |
elseif key=='d' then | |
newPos={ 1, 0} | |
elseif key=='w' then | |
newPos={ 0,-1} | |
elseif key=="p" then | |
gameOver = true | |
end | |
--change the player's x and y coord based on the above | |
if newPos~={0,0} then | |
update=true | |
updateD=true | |
Eupdate = true | |
local newx = player.x+newPos[1] | |
local newy = player.y+newPos[2] | |
if map[newx..','..newy]==0 then | |
field={} | |
player.x=newx | |
player.y=newy | |
fov:compute(player.x, player.y, 10, computeCalbak) | |
end | |
end | |
loveframes.keypressed(key, unicode) | |
end | |
function love.keyreleased(key) | |
loveframes.keyreleased(key) | |
end | |
function love.focus(f) | |
end | |
function love.quit() | |
end | |
function abilityUse(user,target,ability) | |
dist = math.sqrt((user.x - target.x)^2 + (user.y - target.y)^2) | |
if dist < ability.range then | |
allclear = true | |
else | |
allclear = false | |
end | |
if allclear then | |
if target =="none" then | |
ability.use() | |
else | |
ability.use(target) | |
end | |
end | |
end | |
function enemyDraw() | |
if draw then | |
for i=0,enemyNumber do | |
while true do | |
local x=math.random(1,25) | |
local y=math.random(1,25) | |
local key=x..','..y | |
if map[key] == 0 then | |
enemies[i] = {} | |
enemies[i][1] = x | |
enemies[i][2] = y | |
getMonsterType(floorNumber, i) | |
f:write('X',x,y) | |
break | |
end | |
end | |
end | |
draw = false | |
else | |
for i=0,enemyNumber do | |
local x=enemies[i][1] | |
local y=enemies[i][2] | |
local key = x..','..y | |
if seen[key] then | |
if enemies[i][3].alive then | |
f:write('X',x,y) | |
end | |
end | |
end | |
end | |
end | |
function exitDraw() | |
if drawExit then | |
print("drawexit") | |
while true do | |
exit.x = math.random(10, 50) | |
exit.y = math.random(10, 50) | |
local exitkey = exit.x..','..exit.y | |
if map[exitkey] == 0 then | |
f:write('$',exit.x,exit.y) | |
drawExit = false | |
break | |
end | |
end | |
else | |
local exitkey=exit.x..','..exit.y | |
if seen[exitkey] then | |
f:write('$',exit.x,exit.y) | |
end | |
end | |
end | |
function getMonsterType(floor, j) | |
lo = {rat={name="rat", health=5, mana=0, dmg=1, ac=5, alive=true}, snake={name="snake", health=8, mana=0,dmg=2,ac=3,alive=true}} | |
if floor == 1 then | |
local i = math.random(0,1) | |
if i == 0 then | |
monsterType=lo.rat | |
print(monsterType.name) | |
table.insert(enemies[j], monsterType) | |
elseif i == 1 then | |
monsterType=lo.snake | |
print(monsterType.name) | |
table.insert(enemies[j], monsterType) | |
end | |
end | |
end | |
function enemyBehaviour() | |
if update then | |
for i=0,enemyNumber do | |
while true do | |
nx=math.random(-1,1) | |
ny=math.random(-1,1) | |
xy=math.random(0,1) | |
if xy == 0 then | |
local x = enemies[i][1] + nx | |
local y = enemies[i][2] | |
key=x..','..y | |
if map[key] == 0 then | |
enemies[i][1] = x | |
break | |
end | |
elseif xy==1 then | |
local x = enemies[i][1] | |
local y = enemies[i][2] + ny | |
key=x..','..y | |
if map[key] == 0 then | |
enemies[i][2]=enemies[i][2] + ny | |
break | |
end | |
end | |
end | |
end | |
update = false | |
end | |
end | |
function baseDamage() | |
if updateD then | |
for i=0,enemyNumber do | |
local ex = enemies[i][1] | |
local ey = enemies[i][2] | |
local px = player.x | |
local py = player.y | |
local ekey = ex..','..ey | |
local pkey = px..','..py | |
if ekey == pkey then | |
local playerDamage = math.random(1, player.damageDice) | |
local enemyDamage = math.random(1, enemies[i][3].dmg) | |
local playerHitRoll = math.random(1,20) | |
local enemyHitRoll = math.random(1, 20) | |
local playerHit = playerHitRoll + player.dex | |
local enemyHit = math.random(1,20) | |
if playerHitRoll == 20 then | |
playerDamage = playerDamage * 2 | |
print("You got a Critical Hit!") | |
end | |
if enemyHitRoll == 20 then | |
enemyDamage = enemyDamage * 2 | |
print("The enemy got a Critical Hit!") | |
end | |
if playerHit >= enemies[i][3].ac then | |
enemies[i][3].health = enemies[i][3].health - playerDamage | |
print("You did "..playerDamage.." points of damage!") | |
else | |
print("You missed!") | |
end | |
if enemyHit >= player.ac then | |
player.health = player.health - enemyDamage | |
print("The enemy did "..enemyDamage.." points of damage!") | |
print("Your health is now at "..player.health) | |
else | |
print("The enemy missed!") | |
end | |
end | |
if enemies[i][3].health <= 0 and enemies[i][3].alive then | |
enemies[i][3].alive = false | |
print("You killed an enemy!") | |
end | |
end | |
if player.health <= 0 then | |
gameOver = true | |
end | |
updateD = false | |
end | |
end | |
function descend() | |
if Eupdate then | |
local ex = exit.x | |
local ey = exit.y | |
local px = player.x | |
local py = player.y | |
local ekey = ex..','..ey | |
local pkey = px..','..py | |
-- if ekey == pkey then | |
--newLevel = true | |
-- end | |
Eupdate = false | |
end | |
end | |
function loot() | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment