supplierdeeply

Shapes: a little rpg game in LUA (Development Thread)

  • 9 Replies
  • 1253 Views
*

Offline otosclerosi

  • *
  • 22
  • Canon IXUS160 with CHDK 1.5
Shapes: a little rpg game in LUA (Development Thread)
« on: 03 / December / 2016, 11:32:31 »
Advertisements
As i said in the other post...
i'm currently developing a little rpg game following the hack n slash style in LUA, using drawings libraries...
the goal is to create something simple and funny like a game i don't remember the name which i used to play on linux...
here i'll post the sources and the update of the developing...
currently, i only set up the enviroment and put the bases to continue it, just for sharing the results...here is the code, it should work on every camera with a 360x240 minimum gui...

What is there by now:
- A red spot (named "peter") moveable
- A room without sense (i mean, it's a try for the walls)
- A little console

I'll obviously go on coding and post here the results
Now i'm posting because i would like to know if you guys have any ideas especially regarding the story and the things to implement in a game like that
I imagine the following things:
- Items & Inventory
- Weapons (ranged and melee)
- Lvling system
- Obviously mobs (aggro and peaceful) & related combat system
- Many levels
- Spells

Ty for the attention :)
Can a kangaroo jump higher than a house?
Of course, a house doesn’t jump at all.

*

Offline otosclerosi

  • *
  • 22
  • Canon IXUS160 with CHDK 1.5
Re: Shapes: a little rpg game in LUA (Development Thread)
« Reply #1 on: 04 / December / 2016, 05:42:24 »
A sort of GUI, do you think the code is clear enough?
Can a kangaroo jump higher than a house?
Of course, a house doesn’t jump at all.

*

Offline reyalp

  • ******
  • 10944
Re: Shapes: a little rpg game in LUA (Development Thread)
« Reply #2 on: 04 / December / 2016, 18:03:48 »
Very cool to see someone do this with Lua, nicely done :D

On D10, I got a "not enough memory" error trying to run it. Free memory is ~500k (free_block_max_size = 558016)

On elph130, it runs (free_block_max_size = 1864024)

From a quick look, I'm guessing this is mostly the "world" array. There's probably more efficient ways to represent this, but it's up to you whether you feel the need to have it run on lower memory cameras.

On exiting, I saw
"SHAPES.LUA:382: attempt to concatenate global 'choiche'"

Quote
A sort of GUI, do you think the code is clear enough?
Some general comments below. These are just my suggestions as someone who has written a relatively large amount of Lua code (e.g. https://app.assembla.com/spaces/chdkptp/subversion/source/HEAD/trunk/lua, http://chdk.wikia.com/wiki/User:ReyalP#My_scripts) not a criticism of what you have done so far.

Use local variables as much as possible, especially inside functions. They are faster, more memory efficient, and make the code easier to follow. For things that have to be global, I suggest at grouping them in to tables (e.g. player.name, player.health player.x etc) for clarity.

For things like monsters, items, weapons and so on, I would probably try to use an object-oriented-ish approach, where there is a standard set of methods/values for e.g. all weapons and the different ones just override as needed.

There are various ways to do OOP-ish code in Lua (google will find some articles), but one pattern I use a lot is something I call extend_table in chdkptp (somewhat inspired by jquery $.extend) https://app.assembla.com/spaces/chdkptp/subversion/source/HEAD/trunk/lua/rlibs.lua#ln255  (https://app.assembla.com/spaces/chdkptp/subversion/source/HEAD/trunk/lua/util.lua#ln170 in PC side code)

With this, you can do things like
Code: [Select]
function create_monster(options)
  local monster=extend_table({},monster_base_methods) -- create a basic monster
  extend_table(monster,options) -- set specific values / override methods
  ... do other initialization...
  return monster
end
...
my_monster = create_monster{
 name="Bob",
 health=100,
 weapon=create_weapon{name="Bludgeon of Bobbing", damage=10},
 function attack(self,target) -- override standard attack method
  self:yell("Bob is angry!")
  return monster_base_methods.attack(self,target) -- do standard attack
 end,
}
Don't forget what the H stands for.

*

Offline otosclerosi

  • *
  • 22
  • Canon IXUS160 with CHDK 1.5
Re: Shapes: a little rpg game in LUA (Development Thread)
« Reply #3 on: 05 / December / 2016, 03:56:55 »
ty for your reply!  :D

i appreciate a lot your comments and advices, the memory fact is something i didn't think about, in fact i should have tought that a camera has not a lot of ram :P
i'll work to use more local variables than global, and i will try to represent the world in a different way, i mean, there must be another way and if you have an idea it would be very very good...
and..regarding the oop, that's what i was thinking about

honestly i didn't understand very well the extend_table, i mean, your example is clear but the function itself is not clear to me, but i know that's because i just started with LUA and i don't code anything since at least 3 years (except for silly c code), by now i was thinking something like

Code: [Select]
monster = {}
monster.__index = monster

function monster.create(name,hp,str,wp)
local mob={}
setmetatable(mob,monster)
mob.name=name
mob.hp=hp
mob.str=str
mob.wp=wp
mob.dmg="0"
return mob
end

function monster:attacking(target)
self.dmg=self.str*self.wp
message=self.name.." attacked and dealt "..self.dmg.." damages to "..target
return message
end

aggro=monster.create("Bob",100,20,3)
print(aggro:attacking("peter"))

which is basic but (by now) working

last but not least:
Quote
"SHAPES.LUA:382: attempt to concatenate global 'choiche'"

this is weird to me, never happened, but i know the menu code is not optimized so it will probably go away automatically when i'll start optimizing code :)

ty for your attenction, we were talking about you in the other post i made and you just spawned here ahah!  :D
Can a kangaroo jump higher than a house?
Of course, a house doesn’t jump at all.


*

Offline reyalp

  • ******
  • 10944
Re: Shapes: a little rpg game in LUA (Development Thread)
« Reply #4 on: 05 / December / 2016, 13:11:18 »
ty for your reply!  :D

i appreciate a lot your comments and advices, the memory fact is something i didn't think about, in fact i should have tought that a camera has not a lot of ram :P
The cameras themselves have quite a bit of RAM (32 to 512 MB for supported cams) but usually only 300 KB - 3 MB is available to CHDK. The amount available to CHDK doesn't really depend on how much the camera has total, it depends on how much is "left over" in the Canon firmware and how the port is configured. You can use get_meminfo to find out how much is available to CHDK.

The Lua collectgarbage function can be used to see how much Lua is using, and manage garbage collection.

Quote
honestly i didn't understand very well the extend_table, i mean, your example is clear but the function itself is not clear to me
extend_table(dst,src) just copies the values from table src into dst. Functions in Lua are just values, so they get copied like anything else. Anything that already exists and doesn't have a value in src is unchanged.

Using metatables like your example is the more traditional way in Lua. Both methods have pros and cons but mostly it's a matter of you prefer.
Don't forget what the H stands for.

*

Offline otosclerosi

  • *
  • 22
  • Canon IXUS160 with CHDK 1.5
Re: Shapes: a little rpg game in LUA (Development Thread)
« Reply #5 on: 05 / December / 2016, 14:12:23 »
mmmh i think using oop is way more efficent regarding the ram usage, cause each variable of the object is local...
i get
Code: [Select]
attempt to concatenate global 'choiche'" also in some menu voices, so it's probably something wrong about the choiche variable usage and modification

i'll post an updated code tomorrow :)
Can a kangaroo jump higher than a house?
Of course, a house doesn’t jump at all.

*

Offline otosclerosi

  • *
  • 22
  • Canon IXUS160 with CHDK 1.5
Re: Shapes: a little rpg game in LUA (Development Thread)
« Reply #6 on: 06 / December / 2016, 09:28:11 »
Just uploaded the new code!
Inventory, item management, oop code, found item management test, classes...
something new :)
also reduced world array to usable cells, maybe solved the mem problems..

ps. i'll use more local variables when the code will be at least alpha, and i'll know what to use :)
Can a kangaroo jump higher than a house?
Of course, a house doesn’t jump at all.

*

Offline otosclerosi

  • *
  • 22
  • Canon IXUS160 with CHDK 1.5
Re: Shapes: a little rpg game in LUA (Development Thread)
« Reply #7 on: 09 / December / 2016, 12:39:27 »
Level 1 (alpha, obviously) completed!
Try it and let me know! (if you manage to complete it, obviously!  8) )
Known problems:
- Screen flickering a lot (don't know if this is avoidable, it's due to draw.redraw() & overdraw() )

What to know before playing:
- It's better to play in playback mode with a black photo displaying (due to flickering)
- Passcode not yet implemented in a useful way (only 1 level!)
- Guide is not implemented
- "Menu" open inventory
- "zoom_in" use items, "zoom_out" use specials (not useful by now)
- "Half_shoot" shoot arrows (if a bow is equipped)
- Tip: pay attention to the console messages and to the little spots...
- Melee attack monsters by walking on them (don't try to do that with a bow or bare hands!)
- The cake isn't a lie, it restores hp!
- If any message reporting "DAFUQ" appears, it means that you discovered an exception

Let me know :) any comment will be appreciated

Can a kangaroo jump higher than a house?
Of course, a house doesn’t jump at all.


*

Offline reyalp

  • ******
  • 10944
Re: Shapes: a little rpg game in LUA (Development Thread)
« Reply #8 on: 11 / December / 2016, 18:30:11 »
Coming along nicely.

One bug: When shooting the bow, sometimes the script errors "shapes.lua:1027: attempt to index field '?' (a nil value)"

This seems to happen if you are pointed off the edge of the map.

A few other comments:
* Holding down keys to move would be nice. You can use is_pressed to check if a key is down rather than using clicks, but some additional work may be needed to allow moving one click at a time when desired.
* It would be nice if the "peter is at..." messages didn't immediately hide other messages.
* When you are at the name prompt it's not really clear what the keys do.
* Still get out of memory on d10.
Don't forget what the H stands for.

*

Offline otosclerosi

  • *
  • 22
  • Canon IXUS160 with CHDK 1.5
Re: Shapes: a little rpg game in LUA (Development Thread)
« Reply #9 on: 12 / December / 2016, 02:33:58 »
Thanks for your review :)
so...
Yep, the arrow problem is probably because i didn't set the arrow to stop when reaching x=0 or y=0, and that arrow tries to escape from the screen..i'll solve it immediatly
probably the message "peter is at.." will be completely removed 'cause it's a little annoying, i'll put a X*Y box somewhere else
and the memory...it'll be a really big problem to deal with. I tried to use local variables (not enough, i can do better) and to reduce the world matrix size to walkable size (235x175), but i'll have to work harder with it

i'll post a new test as soon as possible :)
Can a kangaroo jump higher than a house?
Of course, a house doesn’t jump at all.

 

Related Topics