Log In  


Cart #46096 | 2017-11-10 | Code ▽ | Embed ▽ | No License
2

HMS Repulse's short sharp mission is to repel mines in the unstable asteroid field. Use the ships repulse beam to repel gold explosives converting them to green energy. Then shoot these green orbs to recover energy. Every missed mine depletes your red energy orbs.

[First attempt at anything playable, would dearly appreciate if someone can help me apply and understand functions in tables, and meta-tables to improve the code. I have a few power ups in mind, but really the game is to see if you can last 60 seconds. Please provide me with game feedback, although the difficulty should be easy to adjust in _init().]

2


To reduce code duplication, I restructured my code in this cart to be more object-oriented. I used functions in tables and metatables to create an inheritance hierarchy for my actors. Taking a look at that might answer your questions. If not, I'd be happy to clarify. If you don't have a lot of overlap between actors that approach is probably overkill though.

There's two things that stood out to me while playing.

I got blown up unexpectedly a lot. I suspect this is because it can be hard to distinguish deadly asteroids from harmless asteroid particles and background stars.

It was also confusing that your bullets pass through asteroids. This resulted in me thinking they were harmless and then I would die. Some sort of collision effect would help communicate that they're dangerous.


Good game idea and the game feels to be in a pretty good shape already. Survived 81 seconds after few tries under 60 seconds. Difficulty feels about right to me.

I'll explain the table functions (or methods) in a nutshell here:

-- You can create functions in tables for example like this:
t = {}
function t:sum(a, b)
    return a + b
end

-- The ":" syntax is equal to writing it like this:
function t.sum(self, a, b)
    return a + b
end

-- And that in turn is equal to writing it like this:
t.sum = function(self, a, b)
    return a + b
end

-- You can then call the function like this:
t:foo(1, 2)
-- which is equal to this:
t.foo(t, 1, 2)

-- Again, the ":" syntax just means it passes the "self" argument automatically to the function
-- which is a reference to the table that the function is a member of.
-- For example:
t = {}
t.v = 4
function t:foo()
    return self.v -- returns the value of t.v
end

You can omit the "self" variable and create the function using regular "." syntax too, if you don't have any use for "self" inside the function.

Also don't forget anonymous tables and functions, they are very useful when returning them from functions. For example return {a=1, b=2}.
Here is some more reading material about functions: https://www.lua.org/pil/5.html
This section covers object-oriented programming: https://www.lua.org/pil/16.html

Regarding metatables, did you read the metatable section of the Pico-8 manual? It starts at line 1569, and has a good example of using metatables to "overload" the add operator.

You can find the Lua 5.0 programming manual entry about metatables here: https://www.lua.org/pil/13.html

And here is the reference manual for the version of Lua that Pico-8 uses, listing metatable functions (or metamethods) that you can use: https://www.lua.org/manual/5.2/manual.html#2.4

Hopefully this is helpful.


Thank you both. That is a month of working through for me. I'll tweak the game play and work on your code advice. And then I will be a heretic and convert to TIC-80 and then Swift IOS. Why ? Well, how else is an old man to learn.
Thanks again.


note that "self" is only a keyword because it can be omitted in a function definition:

function score:add(v)
 self.value += v
end

I tend to use this form instead:

function score.add(m, v)
  m.value += v
end

works the same

score:add(100) -- same as score.add(score,100)

but saves a lot of characters if you use "self" a lot and the char limit is near.
that's less readable oop-wise though.



[Please log in to post a comment]