LOVE2D game engine ; 2D platformer collision systems - lua

I have attached 2 photos below. Currently I'm working on simple 2d platformer game; the idea is the player starts from left corner of the screen and if player captures the flag on the right corner of screen player wins and will take the player to the next level.
So I have my player and the ground set up and I applied the gravity and collision bounds to them (picture 1 reflects the situation). Anyways, here's the tricky part, how do I add the collision system to platform1, 2, and 3? I didn't want to use "Tiled Map Editor" or such. Goal is to create the levels using Photoshop & Illustrator and bring those to the game world.
Any thoughts and ideas? Or any advise?

You may want to create a file for each level specifying the location and sizes of the platforms and anything else like background image start location etc. Then work on coding the logic to load that data file and create the physics bodies etc. for the level from there.
an example data file might look like
return {platforms={
{x=200, y=200, width=10, height=20},
{x=200, y=200, width=10, height=20},
{x=200, y=200, width=10, height=20, type="brick"},
},
size={width=300,height=200},
start={x=100,y=200},
goal={x=200,y=100, nextlevel="desert"},
background={image="bluelevel.png"}
}
And then process these files to create the levels in a generic way:
function load_level(filename)
data = dofile(filename)
platforms = {}
for i, p in ipairs(data.platforms) do
body=love.physics.newBody(world, p.x, p.y, "static")
shape=love.physics.newRectangle(p.width, p.height)
fix=love.physics.newFixture(body, shape)
platforms[i] = {body=body, shape=shape, fix=fix}
end
-- .... finish loading data
end

Related

Marker scale and switching to markerless (Kudan + Unity)

I'm trying to use Kudan AR in a project, and I have a couple questions:
1) The marker size relation to the scene seems pretty weird to me. For example, I'm using a 150x150 px image as a marker, and when I use it in the scene it occupies 150 unities! It requires all my objects to be extremely huge, sometimes even extending further than the camera far plane, which breaks the augmentation. Is it correct, or am I missing something?
2) I'm trying to use a marker to define the starter position of the augmentation, and then switch to the markerless tracking to have a broader experience. They have a sample code using the native iOS lib (https://wiki.kudan.eu/Marker_to_Markerless), but no reference on how to do it in Unity. That's what I'm trying:
markerlessDriver.localScale = new Vector3(markerDriver.localScale.x, markerDriver.localScale.x, markerDriver.localScale.z);
markerlessDriver.localPosition = markerDriver.localPosition;
markerlessDriver.localRotation = markerDriver.localRotation;
target.SetParent(markerlessDriver);
tracker.ChangeTrackingMethod(markerlessTracking);
// from the floor placer.
Vector3 floorPosition; // The current position in 3D space of the floor
Quaternion floorOrientation; // The current orientation of the floor in 3D space, relative to the device
tracker.FloorPlaceGetPose(out floorPosition, out floorOrientation);
tracker.ArbiTrackStart(floorPosition, floorOrientation);
It switches, but the position/rotation of the model goes off. Any idea on how that can be done?
Thanks in advance!

Create a level terrain similar to Tiny Wings using SpriteKit

I would like to create a textured terrain in SpriteKit similar to the one in the game Tiny Wings. Using cocos2d, I was able to follow Ray W's tutorial and get the look I wanted...
http://www.raywenderlich.com/32954/how-to-create-a-game-like-tiny-wings-with-cocos2d-2-x-part-1
Is plotting points to make triangles to fill with a repeating texture (or something similar) possible using SpriteKit?
Thanks in advance.
yeah you can create a game like tiny wing with sprite kit
step create serval CGMutablePath using http://dazchong.com/spritekit/ tool its a online SKPhysicsBody Path Generator and save them in a NSMutableArray array suppose you have only one level in your game for multiple level create multiple NSMutableArray array with multiple random saved CGMutablePath items
be sure all CGMutablePath have static physics body don't make it dynamic now
inside your init function add all paths one by one in a order that first path ends start of second path and so on make by this you can make a huge loop of serval path which are connecting with each other.
don't make more paths because too many physics body makes your game slow
now inside update function move all item of your array from right to left be sure
when you reach last item of your NSMutableArray array add it again at the begging of your looping algo.
-(void)update:(CFTimeInterval)currentTime {
}
make a tiny bird and give it a dynamic physics body
set collision and contact category of tiny bird as well as your loop paths
now inside didBeginContact function you can get contact between your tiny bird and path .now you can apply a little Impulse or you can get contact.collisionImpulse between your bird and path apply apply that value to the bird acc to your game
-(void)didBeginContact:(SKPhysicsContact *)contact
{
//contact
CGPoint contactPoint=CGPointMake(0, 0);
}
So it seems what I need to use (or at least I had in mind) are vertex shaders, but those are not currently supported in Spritekit. Right now, only fragment shaders are allowed from what I could find.
I did however see that you can create an SKShapeNode and set its texture property. The only problem with this is there is no option to "tile" that image throughout the SKShapeNode.
I did find this which seems to solve that issue (although I have not tried it out).
https://gist.github.com/man1/413642637ebd0b00fe2b
Seems like quite a work around!
In the end, I decided to use Cocos2d for this project as it supports both vertex and fragment shaders. With a bit of trial and error, I got it to work wonderfully.

SpriteKit Racing top down Game

I want to write a simple top down racing game for iOS. I want to use Sprite Kit instead Cocos2D , I'm new to game development and I have a question:
How can I create the race tracks? What I think is: One single big background image for each track and a car that moves over it and remains inside the track by interaction with a path. The path is inserted by a coordinate system in the level code and represents the "borders" of the road.
Is this a good way to start a top down racing game? Or are there better ways? How can I "draw" the path over my background image?
You can use "Tiled Map Editor" http://www.mapeditor.org/ to create your maps. I'm thinking you'll only need a few unique tiles, one for straight track, one for grass, one for curved track, maybe some trees, etc.
As for the path, you can try to use an polygonal edge physics body? And then move the car to where the user touches on the screen. if the user tries to move the car outside, the car will bump against the physics body of the edge.

b2DistanceJointDef anchor point

I just started doing Box2d programming. I'm trying to create a platform game. When the player (dynamic body) jump and landed on the moving platform (kinematic body), I need to make the player stay and move together with the platform. So i try using distance joint to "stick" the player to the platform. However, I've set the anchor point-Y so that the player will stay above the platform but I don't want to set a fix X. What approach should i use?
eg:
A.When player jump from right to left, it will land on left.
B. When player jump from left to right, it will land on right.
So when the player jump from any position, the X will be based on the player except Y is fix. Thank you.
b2DistanceJointDef jointDef;
b2Vec2 playerAnchor = curPlayerBody->GetWorldPoint(b2Vec2( 1, -0.8));
jointDef.Initialize( curPlayerBody, curPlatformBody, playerAnchor, curPlatformBody->GetWorldCenter() );
jointDef.length = 0;
jointDef.dampingRatio = 0;
jointDef.frequencyHz = 0;
jointDef.collideConnected = false;
playerPlatformJoint = (b2DistanceJoint*)world->CreateJoint(&jointDef);
I am assuming that you don't want to fix X because you want the player to move along the X axis on the platform.
I don't think the distance joint is a good solution for this.
One way to do what you want could be to set the friction of the player and platform fixture to a level that makes them "stick" together when the platform is moving. You should also have a look at the Friction Joint which let's you set friction in a more dynamic way. You can learn more about friction and the friction joint in the Fixture and Joint chapters of the Box2D manual.
Another way to do what you want would be to synchronize the movement of your player and the platform. But that depends a bit on how you move the platform and the player. If you are doing it by impulse for example, you could apply the same impulse that you apply to the platform to your player additionally to whatever you already apply to the player. You'll have to take properties like mass into account though.
Also take care on how you move the platform. If you are manually setting the position of the platform instead of using impulses, velocity or forces it will cause problems with the mentioned solutions.
I managed to find the answer. The idea is using weld joint and manually move the player.
Referenced from here

(Follow-up question) How to make a 2D camera that follows a sprite? [for XNA-game]

I was looking for tutorials on the net for a 2d camera that follows a sprite and I found a reply from this site:
(XNA 2D Camera Engine That Follows Sprite)
I made a simple game where in the sprite is loaded at the center of the game screen and it moves according to the direction I press from my directional key pad.
I tried implementing this code and added the Spritebatch instruction to my game. There seem to be no syntax error, but once I run the game, I only see the blue screen. Also, the sprite I used didn't appear.
(I'd like to imitate the player control of Tasty Planet where in the goo is controlled by the mouse and the screen follows it around. - trailer of the game: http://www.youtube.com/watch?v=az4VgetA_n0
Game development is sometimes best accomplished step by step. Especially when one is first learning :-)
What you want to do is first get some basics onto the screen 1) the player's avatar, and b) some static component like a wall, or floor.
With those in place and rendering on the screen, then you implement your camera component. This will be a class that takes the player's position in the world and offsets any "world" item by that much.
For example, if the player is at 10,10 in the world, and there is a tree at 5,5 ... the tree should be drawn at -5,-5, and the player drawn at 0,0 (assuming your coordinate grid's 0,0 is in the middle of the screen). And as the player's position moves, just subtract that from static world object that you draw.

Resources