RafaelOliveira / Plume

2D game engine for Kha
MIT License
6 stars 2 forks source link

Any demos/showcases? #1

Open Sondro opened 7 years ago

Sondro commented 7 years ago

Hey I've been working all week on the Sdg Tiled showcase and added

Anyways, I just found this engine.

The code looks a lot cleaner on this--what is Plume exactly vs Sdg?

Should I migrate my code over--do you have an example/showcase to get me started? It looks like it's using tmx (which is my main requirement).

Thanks.

RafaelOliveira commented 7 years ago

Hi, thanks for using Sdg, it's good to know someone is using it. Sdg was my first attempt to make a game engine. It's very inspired in HaxeFlixel and HaxePunk (specially HaxePunk). I'm developing a game for mobile browsers with Sdg that I'm planning to sell licenses. Now, with time something started to bother me. Everything is based in objects and if you just want to draw a rectangle on screen you still need to created a Object for it. It's like a waste of resources. Thats why I created Plume. In Plume there isn't a Object class, and the class State (like Screen in Sdg) doesn't have a list of objects, and also doesn't have a list of layers. In the render function in State you have access to Kha.g2 and can draw things manually. So the engine is more directed to classes that render things directly instead of objects. I'm porting the graphic classes from Sdg to Plume, and also adding helper classes, like FormatTmx, it's class with some functions that I use all the time with the lib haxe-format-tiled (like get tiled objects from the layers and create differ objects from shapes). I will still keep Sdg up to date with Kha, there is people that can prefer it's style (@jrdoughty is making a game with it), but I will probably only use Plume from now (and add new things), and I will only make changes in Sdg from time to time. The last thing that I added to Plume was support to multiple cameras (you can see here http://sudoestegames.com/play/cgagame ). My ludum dare game was also made with Plume (but the code is not public): https://sudoestegames.itch.io/sugarcatcher

About the Sdg tiled-sample, I will port it to Plume (I think I can do today), so if you want to use Plume you will see the code. I will also add a message on the Sdg repo explaining that will be focusing more in Plume now.

These changes for tiled-sample, do you want to make a PR, or are just for you? In the case of a PR you can make for the tiled-sample repo and later port to the Plume repo, if you want.

Sondro commented 7 years ago

That Tiled for Plume would be really great!

The biggest issues for me using Sdg is being unable to see collision rects. I even got to the point where I would have to add dummy sprites to create and test them.

I think I mostly just want to start working with Plume. I've only been coding with Haxe/Kha/Sdg for 5 days. I still haven't figured how to properly target or build in Kode Studio, I managed to somehow switch to CPP and now I can't get back to js--but even when I had it in js it was electron debugging only.

Here's a quick 2 frame screencap to give you an idea where I'm at:

image

Right now I have the platforms mapped by the tile values 1,2,3 and thought that was kinda hackish. So I wanted to have each layer prefixed and parsed by # for grid (auto tile w and tile h) and _ for platforms or rectangles (ie '#mylayer' or '_32_mylayer' with the 32 being the platform height--there's more later but this is the basic part for fast loading).

Anyways worked on this for about an hour yesterday and the latest version copies the two layers by adding onto data so your platforms are now a stage width distance away lol (which I guess is better than overwriting, but not quite what I need).

SO PLATFORM MAPPING IS NOT WORKING BUT CAN BE TURNED BACK ON TO 1, 2, 3, MODE.

I know I wanted to do some optimizations later for combining tiles and layers before they get stored and rendered, but at the same time I feel that needs to be user managed with different layer prefixes.

Like what if someone wanted to reuse floor tiles as platforms, but make them thinner to collide with--the engine shouldn't limit that.

I haven't figured out how the objectMap binds everything up into components. To use moveCollide better (ie for AI in the future) I was building my own horizontal and vertical arrays of tiles.

Don't know if the code is really PR ready. Player 2 has to spawn on top of Player 1 to not get stuck and NPCs (or enemies) get stuck often when spawning (I want dynamic spawning vs spawn points).

To avoid this I have a PlayerMgr class which is getting so bloated it's like a GameMgr class and it has a copy of both bgMap and objectMap the Players can reference. I haven't applied that ref yet since I wanted to use it with moveCollide to narrow for speed against tile x and y tile collision arrays and I am still changing the way the maps load.

Also when you enable moveByCollision or otherwise I think it might benefit by some kind of global or wide referenced/public 'noClip:Bool'. I guess I could write that myself, but I've been avoiding messing directly with the engine.

My Player class is also getting a bit bloated and soon will need to be split into Player, Actor, and Character.

Everything is still just using the same sprites, just animated better. I wanted to do some kind of HSV (non-shader if possible so the shader can actually do normal/height maps later) based color changing. Also there is aliasing and I'm guessing the sprites need bilinear/bicubic filtering enabled somehow when scaled.

The water is looking great (a lot better than the screenshots), almost like 3D rendered, but it's kinda slow in js--I'm guessing Sdg doesn't pre-render every frame? It's just using 4 waters instead of one. One thing that is annoying is that when it vertically moves it clips into a rectangle instead of preserving the original alpha.

The shadows don't quite follow when you jump onto a higher level because they just drop fast using moveByCollision (x is locked to the Player they are attached to) until you land and then they reset and work normally (so they kinda work accurately on stuff that is one level below what you jump over). Have to finish mapping code before they can cast or appear on the proper height of the surface you're jumping over.

Also as you can see in the screenshot above, the shadows add becoming black. Global shadows should NOT add into each other--or in reality there should only one shadow layer per light. Another benefit to prerendering frames is to prerender a shadow layer and then apply the alpha to that instead of all of them individually.

RafaelOliveira commented 7 years ago

Hi, I finished the tiled-sample, you can see here: https://github.com/RafaelOliveira/plume-samples

About your changes, it's difficult to visualize without seeing the code, can you create a public repo with yours changes? You can port to Plume and then put it in github.

I will make a class to render the collision rects.

The water is using the class TileSprite, but it seems the implementation that I made is slow, because it makes many calculations to cut the parts in the graphic that is outside the area choosed. It needs a new implementation, maybe based in Phaser.

About KodeStudio, a short guide: Use F5 to test in Kode Studio. This create a Electron app but it's only used inside KodeStudio. To test with one of the Kha targets, use Ctrl + b. This will open a list with the targets. The js version will be created inside build/html5. Also its good to use a Kha version updated with git together with KodeStudio, because the Kha that is bundled in KodeStudio its only updated with new releases, and I usually always use the lastest changes from git. There is a option in KodeStudio to set the Kha path and you can see in the Kha wiki (https://github.com/Kode/Kha/wiki/Getting-Started) how to clone Kha in a separated folder to use in all projects.

Sondro commented 7 years ago

Hey I downloaded that SugarCatcher game a few days ago when I noticed it posted on the Kha/Rob Dangerous twitter (though normally I don't use twitter).

lol I got insta-killed by the swatter or at least that's how it felt when I hid in the middle and then ventured out for a sugar cube. I think my favorite ant game is Sim Ant if you've played that. It's pretty cool because you starts as a lone queen ant and then become whatever ant you want that it births and then conquer the local area. Then you can create breeder ants and go on to another patch of territory as another queen and repeat.

Anyways this brought back memories of that but was kinda disappointed I had no other ant homies or stuff to fight. I actually hated the humans killing you all the time at the later stages of Sim Ant when you're in the house. I think human/ant interaction would be better via AI mostly like telling the other ants to stay away from poison and they keep killing themselves--ants are actually pretty tough to smash in real life unless you grab them with two fingers and really work hard at it.

RafaelOliveira commented 7 years ago

I dont remember if I played a ant game before.. the idea come because of the theme of Ludum Dare. I had more ideas to implement, maybe I will finish later.

I made some changes in Plume and updated the samples. It's now possible to scale the sprite animations (the class SpriteAnim). You can press S in the tiled-sample to make the player bigger.

You can join the Kha irc if want to talk more about Kha or Plume, I'm always there, and also Robert and other people tha uses Kha. See here: https://github.com/Kode/Kha/wiki/Community

Sondro commented 7 years ago

Hey I really appreciate the work, I haven't had time to port anything or even update Kha yet. Hopefully soon.

Finally got the map working using a new system that compiles tmx layers together:

image

As it compiles your custom layers where you prefix whatever collision you want, ie '#mylayer' for grid, it creates a custom csv and key.

So with the graphics above it spits out for collision: [[-1,-1,-1,-1,-1,-1,-1,-1,-1,1,1,-1,-1,-1,-1],[-1,-1,-1,1,1,1,-1,-1,-1,-1,-1,-1,-1,-1,1],[-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,1,1,1,-1,-1],[-1,-1,-1,-1,-1,-1,-1,0,0,-1,-1,-1,-1,-1,-1],[0,0,0,-1,-1,0,0,0,0,0,0,0,0,0,0]]

It then matches the key it creates, ie '0' for grid, '1' for rect platforms and creates it's own rule mapping system.

Haven't gotten to the part where it writes optimized/compiled tmxs, but you can basically make whatever rules in Tiled for whatever map just by naming layers and every map loaded can be different.

Sondro commented 7 years ago

BTW, I could scale the sprites before using sprite.set_scaleX/Y but the problem was that they had like boxy artifacts on them like they needed to be filtered.

Also there seems to be multiple ways to do things, ie with graphic and sprite. Which is more fast and optimal? Is alpha = 0 as optimal as visible = false?

Which works better in Kha and Plume?

RafaelOliveira commented 7 years ago

Hi, there is two way to smooth things in Kha. The first is setting: framebuffer.g2.imageScaleQuality = ImageScaleQuality.High;

In Sdg is the third argument in engine: var engine = new Engine(800, 600, true); Also make sure the use of a backbuffer is activated, because I configured to only use ImageScaleQuality.High when using a backbuffer (because I usually use a backbuffer for scaling). You can see here: https://github.com/RafaelOliveira/Sdg/blob/master/Sources/sdg/Engine.hx#L218 But I can change this to apply also when not using a backbuffer. so, create a engine this way: var engine = new Engine(800, 600, true, true);

The second way is settting samplesPerPixel in System.init (when Kha is being initialized). See here https://github.com/Kode/Kha/blob/master/Sources/kha/System.hx#L10

In g2 there is also mipmapScaleQuality, but I dont know how this affect g2, because this is thing for 3d.

About alpha and visible in Sdg, when visible is set to false, the rendering is skipped, but when you only set alpha, the rendering is made, but also a opacity is applyied, with g2.pushOpacity(alpha); https://github.com/RafaelOliveira/Sdg/blob/master/Sources/sdg/Graphic.hx#L98 so, alpha = 0 is same thing as visible = false, but visible is faster because all the rendering is skipped.

Plume doesn't have this concept of visible and alpha, because it doesnt have objects, only classes for render things. You do the opacity manually with the Kha api. I think in the end its depends of your project, if you want the facilities of the Sdg, or if want more control to do certain things manually.

Sondro commented 7 years ago

Hey thanks.

In SDG I updated the Showcase and I am working on porting it to Plume with the Tiled example as another state/screen.

Seems a lot more useful.

In my old SDG Tiled I added transparency and parallax with the tilemaps, but I had to edit SDG with g2 graphic calls and didn't want to keep changing the engine so focusing on getting plume working. Also added layer defining of Tilemaps, seems there is a limit 0-9 in SDG--not sure about Plume.

Going to need a lot more to manage z-sorting/draw order for sprites in Plume.

BTW, right now I've added draw FPS, but I'm doing it through each each state's render--is there a way to render in Plume through the project like .