Last active
August 4, 2020 22:28
-
-
Save 133794m3r/7d2d96c0032840f3d255685e739c2f10 to your computer and use it in GitHub Desktop.
key_lock_spanwer
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
--to be at the head of the function. | |
-- so that I can make sure that I'm not respawning something over something that already exists. | |
local object_position = {} | |
for x=0,width do | |
object_position[x] = false | |
ground_x[x] = true | |
coin_x[x] = false | |
end | |
--each time an object is chosen to be shown. change object_position[x] to be true. | |
local x = width | |
x = width | |
local lock | |
local lock_x = 0 | |
while not locked_block_spawned do | |
x = math.random(width) - 1 | |
if (not object_position[x]) and (not object_position[x-1]) and (not object_position[x+1]) | |
and (ground_x[x-1] and ground_x[x] and ground_x[x+1]) and not coin_x[x] then | |
lock_x = x | |
lock = GameObject{ | |
texture = 'locks', | |
x = x * TILE_SIZE, | |
y = 1 * TILE_SIZE, | |
width = 16, | |
height = 16, | |
frame = LOCKS[math.random(4)], | |
collidable = true, | |
consumable = true, | |
solid = true, | |
hit = false, | |
onCollide = function(obj,player) | |
if not obj.hit and player.key == true then | |
gSounds['pickup']:play() | |
LevelMaker.addFlagGoal(player) | |
--obj.hit = true | |
local direction = false | |
print('l',love.keyboard.isDown('left')) | |
print('r',love.keyboard.isDown('right')) | |
if love.keyboard.isDown('left') then | |
direction = 'left' | |
elseif love.keyboard.isDown('right') then | |
direction = 'right' | |
end | |
player.x,player.y = player:findGround(player,direction) | |
player.key = nil | |
player.stateData.pole_spawned = true | |
return true | |
end | |
end, | |
onConsume = function(ob) | |
end | |
} | |
locked_block_spawned = true | |
end | |
end | |
table.insert(objects,lock) | |
local key = {} | |
if x <= width /2 then | |
width = width - x | |
else | |
width = width - 1 | |
end | |
local y = 0 | |
while not key_spawned do | |
y = math.random(2) | |
x = math.random(width) | |
if not object_position[x] and not(x >= lock_x -15 and x <= lock_x + 15 ) and not coin_x[x] then | |
key = GameObject{ | |
texture = 'locks', | |
x = x * TILE_SIZE, | |
y = y * TILE_SIZE, | |
width = 16, | |
height = 16, | |
frame = KEYS[math.random(4)], | |
collidable = false, | |
consumable = true, | |
solid = false, | |
-- gem has its own function to add to the player's score | |
onConsume = function(player, object) | |
gSounds['pickup']:play() | |
print('player_key',object.frame) | |
player.stateData.key_color = object.frame | |
player.key = true | |
end | |
} | |
key_spawned = true | |
end | |
end | |
table.insert(objects, key) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment