maze collision in corona - coronasdk

I am planning to create a maze game. I have no idea how can I create the maze. The first thing I do is to make a 1 png file for the maze. I would like to ask if it is possible to create just 1 image for the maze or do I need to create the maze by arranging its block one by one?

Consider using some kind of text format for building the maze. The most convenient way of declaring mazes would be to use lua itself, i.e. by building an array. The next step would be to generate the map to show it to user. I thing it would by a much simpler approach then to work with PNG images.
Your maze example can by divided into rooms with 4 walls/exits facing 4 directions. Have you considered building a two dimensional array of 16 values representing all combination of walls (different rooms) ?

Related

Optimized RPG inventory parsing using OpenCV

I'm trying to develop an OpenCV-based Path of Exile inventory parser. The inventory looks like this, with items left and right. The round things on items are called "sockets", are randomized, but they can be hidden.
There are two options for this:
When you hover an item in game, and press CTRL-C, a description of the item is copied to your clipboard. A solution would be to do this on every single inventory cell, to re-create the whole inventory, bit per bit. There is an issue with this, however: the "item copy" action is probably logged somewhere, and having 12 * 5 = 60 actions like this in under 2 seconds would definitely look fishy on GGG's (the devs) end.
Using image-recognition software to decompose the inventory like a human being would. There are several methods with this, and I'm struggling to find the most effective.
Method 1: Sprite detection
This is the "obvious" method. Store the sprite of every single item in the game (I think there must be around 900-ish sprites for all the bases and unique items, so probably around 250 sprites if we exclude the unique items), and perform sprite detection for each of them, on the whole inventory. This is without a doubt extremely overkill. And it requires tons of storage. Discarded.
Method 2: Reverse sprite detection
For every single sprite in the game, calculate an associated md5, and store it in a file. Using OpenCV, cut the inventory's items one by one, calculate their md5, and match against the file to detect which item it is. It's probably faster this way, but still needs a ton of processing power.
Method 3: Same than #2 but smarter
Use OpenCV to cut the items one by one, and based on their size, optimize the search (2x2 item means that it's either a helmet, boots, gloves, or a shield. 2x1 item is always a belt. 1x1 is always a ring/amulet, and so on).
Is there another method that I'm forgetting? All of these look like they need both heavy processing, code, and before-hand work from me.
Thanks in advance.

Memory Usage of SKSpriteNodes

I'm making a tile-based adventure game in iOS. Currently my level data is stored in a 100x100 array. I'm considering two approaches for displaying my level data. The easiest approach would be to make an SKSpriteNode for each tile. However, I'm wondering if an iOS device has enough memory for 10,000 nodes. If not I can always create and delete nodes from the level data as needed.
I know this is meant to work with Tiled, but the code in there might help you optimize what you are looking to do. I have done my best to optimize for big maps like the one you are making. The big thing to look at is more so how you are creating textures I know that has been a big killer in the past.
Swift
https://github.com/SpriteKitAlliance/SKATiledMap
Object-C
https://github.com/SpriteKitAlliance/SKAToolKit
Both are designed to load in a JSON string too so there is a chance you could still generate random maps without having to use the Tiled Editor as long as you match the expected format.
Also you may want to consider looking at how culling works in the Objective-C version as we found more recently removing nodes from the parent has really optimized performance on iOS 9.
Hopefully you find some of that helpful and if you have any questions feel free to email me.
Edit
Another option would be to look at Object Pooling. The core concept is to create only sprites you need to display and when you are done store them in a collection of sorts. When you need a new sprite you ask the collection for one and if it doesn't have one you create a new one.
For example you need a grass tile and you ask for one and it doesn't have one that has been already created that is waiting to be used so it creates one. You may do this to fill a 9 x 7 grid to fill up your screen. As you move away grass that gets moved off screen gets tossed into the collection to be used again when the new row comes in and needs grass. This works really well if all you are doing is displaying tiles. Not so great if tiles have dynamic properties that need to be updated and are unique in nature.
Here is a great link even if it is for Unity =)
https://unity3d.com/learn/tutorials/modules/beginner/live-training-archive/object-pooling

Tile Game Map Storage in SpriteKit

I'm making a tile-based adventure game in SpriteKit and I'm trying to figure out a good way to store my maps. A typical map might have 100x100 tile dimensions. Currently I have a very small 8x16 map which I'm storing in a 2x2 Swift array. However, making maps in arrays seems like bad practice as the map size increases. What would be the best way to store this map data?
There is nothing wrong with using 2 dimensional arrays, in fact, if you use arrays, then you can save them into plists to make things easier for you.
I would personally write my own class that wraps around the 2D array so that it suits my needs (E.G. if I am adding a column, it will add the column to every row)
I don't know if this suits your need but you could use the editor Tiled which offers you a visual way to create your maps.
Maps are saved as .tmx file (basically an XML file). Then you can import them in your game using one of the listed solutions. You can event create your own solution pretty easily (second answer in the given link)
This solution makes creating/modifying maps easier, but you have to use an external software.

how to generate Tetris piece from a given grid

At first I think my question should have been asked before, but I didn't find what I want.
One element of this iOS app I'm developing is break a 8x8 grid into Tetris pieces (every piece is made of 4 blocks). Two particular question I have are:
what is the best way to represent a Tetris piece in objective-C?
what algorithm to present the grid into random Tetris pieces (and later on how to check if two pieces fits together).
Edition on 01/28
#livingtech, I think I implemented pretty much what you say, except the point of "having a hole". My code works with no hole at simple stage when Tetris block is two blocks only (yes, two squares, connected either horizontally or vertically), but at 3-square Tetris block, I would get holes. I just tested and out of 1000 running, I would get one without a hole. So definitely I need some mechanism to check if next square will be a singleton.
I been trying to do the same thing for my game. Though I am a total beginner, and I'm using XNA and C#.
But the way I'm trying to go about it is: 4x6 grid array
--y123456
X1-000000
X2-000000
X3-000000
X4-000000
Here,
0 signifies no block
1 defines a block
Algorithm
Start by taking the very first 0 in the array ( top left corner )
and randomly pick a 0 or a 1.
Randomly choose the coordinates based on x1/x2-y1/y2, decide 1 or 0.
If it is 1, then decide coordinated based on where that 1 was put.
If it was 1 on x2 y1, then decide if a 1 should go on next touching
coordinate.
If you just have to code in what coordinates touch and which don't,
and the logic will roll through.
I have mine set up bit different. But this is the basic foundation of my random Tetris engine.
I also found that making it like that really helps to have a whiteboard and make a drawing of the grid and label with your coordinates.
since ur board is 8*8, i think u can use a int64 to represent the board. each bit of the int64 represents whether the specific grid is filled or not.
Implementing Tetris is a hobby of mine. First implemented it in Windows/C. Then in Perl/Tk! Last implementation I did in Obj-C/Cocoa (Mac). In all cases, the game logic is the same. Only the UI stuff changes. I treat every little box separately and have a two-dimensional array which contains the presence (and color) of every "set" box on the board. Standard board size I use is 10 boxes wide by 20 boxes high.
Separately I keep track of the "dropping" piece: it's location and what kind of piece it is. Based on a timer, try to make the piece drop. If any of the boxes where the "dropping" piece would drop is already set, then stop dropping the piece and add the piece boxes to the "set" part of the board. Create a new piece, and start over.
It may not be the best way to implement it, but it makes sense in my head. From a pure OO perspective, each shape of a dropping piece could be a subclass of a generic shape class. Override functions that check whether the shape can drop, the offsets of the individual boxes in the shape, etc.
I don't think anybody has taken a stab at your question #2 yet here, so I'm going to outline what I would do.
Setup:
You'll need to represent your grid as an array of some kind. At the very least, you'll want some kind of boolean values, to denote whether each coordinate in the grid is "occupied".
You'll need to keep track of the pieces on your grid. This could be another array, this time holding references to the four coordinates for each piece.
You'll need a variable or variables to keep track of a coordinate in your grid where you'll start filling in pieces, (I would probably populate these with a corner to start).
Set up a "pool" of all possible Tetris pieces and rotations. (You'll want to keep track of which ones you've already checked on every iteration outlined below.)
Iterate:
Get a random piece from your pool that will fit into your starting coordinate. (If you want to get fancy, you could be smart about which ones you choose, or you could just go totally random. As pieces don't fit, mark them checked, so you don't keep checking randomly forever. If you get to a point where you've checked all the pieces, you have a solution that doesn't work, either back up an iteration, or start over.)
Make sure the Tetris piece you selected didn't leave a "hole", or empty space with less than 4 squares. (I don't know your requirements for solving this problem, so I can't say whether you should focus on speed or ease of coding, but you may be able to skip this step if you want, and "brute force" the solution.)
"Place" the piece, by writing it to your piece array and marking the coordinates filled.
Check for "finished" condition, in which all your spaces are filled.
Pick a new coordinate in your grid and repeat #1. (I would pick an empty one next to the previous coordinate.)
If this actual yet, I wrote test tetris app on Objective-C few months ago https://github.com/SonnyBlack/Test-Demo-Tetris . I think my algorithm not very well, but it working. =)

Cocos2d: graphics tool

I started to learn Cocos2d to develop games and also Box2d; I read some tutorials and I seen that are used two couples of tool "LevelHelper-SpriteHelper" & "PhysicsEditor-TexturePacker".
I noticed that LevelHelper-SpriteHelper are more "simply" and organize levels and physics objects very well.
While with PhysicsEditor-TexturePacker I noticed some difficulties where the approach is not very clear.
So what are the best tools between "LevelHelper-SpriteHelper" & "PhysicsEditor-TexturePacker"?
And what are the differences? Can you explain me? thanks
This should answer your questions: http://abitofcode.com/2012/07/cocos2d-useful-tools/
Physics editor is a program that you use to create a tracing around a sprite that isn't a simple polygon. For example it could trace an image of a car, so that when you went to detect a collision between your car and another object with a physics engine (something like box2d) it registers a collision just with the car and not a square surrounding the car. Here is a picture that shows you what it does: http://www.codeandweb.com/physicseditor/features.
Texture-packer is used to put all your sprites that you use in your game into one spritesheet. This allows you to minimize the amount of memory that all of your sprites take up.
http://www.codeandweb.com/texturepacker That picture shows you what it does. Instead of having to add all your individual sprite images to your game you put them all on a spritesheet, which trims the space around each image and puts it into a file size that cocos2d and the iphone can work with.
This is helpful because cocos2d only takes images that have dimensions to the power of two. (2,4,8,16....) If you had a sprite that was 50x50, it would actually take up 64x64 amount of space in your game.
Here is a tutorial that explains most of that better than i did: http://www.raywenderlich.com/2361/how-to-create-and-optimize-sprite-sheets-in-cocos2d-with-texture-packer-and-pixel-formats
And here is project where both are used: http://www.raywenderlich.com/7261/monkey-jump
And here is one with levelhelper and spritehelper: http://www.raywenderlich.com/6929/how-to-make-a-game-like-jetpack-joyride-using-levelhelper-spritehelper-part-1
For a list of more tools go here"
http://www.learn-cocos2d.com/2011/06/complete-list-cocos2d-tools/
SpriteHelper is essentially the same tool as TexturePacker. Both create a single large texture from individual images.
LevelHelper is an editing tool to design your game visually. It also allows editing of the physics world.
PhysicsEditor is a tool to create the (collision) shapes of physics bodies from images. No more, no less.

Resources