Is this OOP?
Posted: Mon Dec 28, 2015 8:56 pm
I have always struggled with understanding what OOP is, which probably sounds silly to a lot of veteran programmers. I first started coding trying to learn C++ many years ago and I never got to fully understanding the language, then(still a long time ago) I took a class in Visual Basic but only learned how to make simple apps like a calculator for instance. Doing these things I never really understood OOP even though I used objects in my code. I've watched videos trying to explain it as well and I feel like most programmers make it hard to explain because they explain it in a way that makes sense to a programmer but is confusing to someone new to coding...
On to my question! Flash forward to today and I'm neck deep into programming a platformer in Love2D, I just got back into programming about a month ago and I'm having a lot of fun this time thanks to Lua and Love2D. But when you do this with tables:
Is that OOP? To me it looks like what I think OOP is... but like I said the definition of OOP is confusing to me. I mean here you are creating an object of the type 'zapBullet' and you can create as many of them as you'd like. Is that right?
I've also heard that Lua is a 'prototype' language and that's different than what C++ is, but don't really understand what that means either.
On to my question! Flash forward to today and I'm neck deep into programming a platformer in Love2D, I just got back into programming about a month ago and I'm having a lot of fun this time thanks to Lua and Love2D. But when you do this with tables:
Code: Select all
local isDown = love.keyboard.isDown
if isDown('f') and playerStats.weaponEquip == 0 and sprite.zapperGun.canShoot == true then
--create zapper shot
local body = love.physics.newBody(world, sprite.body:getX(), sprite.body:getY(), 'dynamic')
local shape = love.physics.newRectangleShape(7, 7, 13, 13, 0)
local fixture = love.physics.newFixture(body, shape)
table.insert(sprite.zapperGun.zapBullet, {body = body, shape = shape, fixture = fixture:setSensor(true), body:setBullet(true), speedSet = false})
sprite.zapperGun.zapSound:play()
sprite.zapperGun.canShoot = false
sprite.zapperGun.canShootTimer = sprite.zapperGun.canShootTimerMax
end
I've also heard that Lua is a 'prototype' language and that's different than what C++ is, but don't really understand what that means either.