games50 / zelda Goto Github PK
View Code? Open in Web Editor NEWLecture examples for Lecture 5: Legend of Zelda
Lecture examples for Lecture 5: Legend of Zelda
hey everyone,
I'm currently working on the assignment for Zelda remake. I've got everything working fine but im stuck on how to get the pots to disappear after your throw them. I have been trying to add a table.remove(self.objects, k) in the room:update(dt) section of the logic. below is my latest attempt:
(you can skip down to SEE BELOW FOR MY ATTEMPT)
function Room:update(dt)
-- don't update anything if we are sliding to another room (we have offsets)
if self.adjacentOffsetX ~= 0 or self.adjacentOffsetY ~= 0 then return end
self.player:update(dt)
for i = #self.entities, 1, -1 do
local entity = self.entities[i]
-- if entity is dead, skip the next code block
if not entity.dead then
-- if entity has been just defeated
if entity.health <= 0 then
-- mark entity as dead
entity.dead = true
-- spawn a heart with 10% probability
if math.random(10) <= 7 then
self:spawnHeart(entity.x, entity.y)
end
-- if entity has not been defeated yet
else
entity:processAI({room = self}, dt)
entity:update(dt)
end
-- collision between the player and entities in the room
if self.player:collides(entity) and not self.player.invulnerable then
gSounds['hit-player']:play()
self.player:damage(1)
self.player:goInvulnerable(1.5)
if self.player.health == 0 then
gStateMachine:change('game-over')
end
end
end
end
----------------- SEE BELOW FOR MY ATTEMPT
for k, object in pairs(self.objects) do
object:update(dt)
local distance = 3*16
-- trigger collision callback on object
if self.player:collides(object) then
if object.type == 'heart' then
Event.dispatch('heartCollected')
end
object:onCollide()
if object.consumable then
table.remove(self.objects, k)
end
end
if object.type == 'pot' and object.state == 'thrown' then
-- wall collision check
if self:wallsCollideWith(object) then
table.remove(self.objects, k)
end
-- for each entity (enemy)
for i = #self.entities, 1, -1 do
local entity = self.entities[i]
-- if entity is dead, skip the next code block
if not entity.dead then
if entity:collides(object) then
-- pot collided with enemy, so deal damage
entity:damage(1)
-- and destroy the pot, removing it from the objects table
table.remove(self.objects, k)
end
end
end
if object.type == 'pot' and object.state == 'idle' and distance == true then
table.remove(self.objects, k)
end
end
end
Timer.update(dt)
end
any advice would be extremely helpful. Im sure im missing something small but i've spent the whole day trying to do this one part of the assignment :((((
Hey I was currently going through the zelda code and when I run it without making any changes I got this stencil error
Error
src/world/Room.lua:214: Drawing to the stencil buffer with a Canvas active requires either stencil=true or a custom stencil-type Canvas to be used, in setCanvas.
Traceback
[C]: in function 'stencil'
src/world/Room.lua:214: in function 'render'
src/world/Dungeon.lua:152: in function 'render'
src/states/game/PlayState.lua:51: in function 'render'
src/StateMachine.lua:27: in function 'render'
main.lua:58: in function 'draw'
[C]: in function 'xpcall'
Error
src/Dependencies.lua:68: bad argument #2 to 'newSource' (string expected, got no value
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.