Argh, so close.
Anyways, passing self as the first argument doesn't work
Squario: A squary survival horror
Re: Squario: The squariest platformer in LOVE.
Erm, you can have the version I played with last night. The only change was to drop in my class library (because I didn't feel like debugging the one you had) and fixing the superclass method calls. This got Mr. Squario to fall, at least.ZenX2 wrote:Argh, so close.
Anyways, passing self as the first argument doesn't work
Full diff (old => new):
Code: Select all
self.super:__init(p, 32, 32, 0, 0) => self.super.__init(self, p, 32, 32, 0, 0)
self.super:__init(p, 32, 32, 50, 0) => self.super.__init(self, p, 32, 32, 50, 0)
self.super:Think() => self.super.Think(self)
class.Color() => Color = class()
class.Ent() => Ent = class()
class.Ground() => Ground = class()
class.GroundPiece(Ent) => GroundPiece = class(Ent)
class.Image() => Image = class()
class.Player(Ent) => Player = class(Ent)
class.Stack() => Stack = class()
class.Vec2() => Vec2 = class()
class.Vector() => Vector = class()
class.World() => World = class()
- Attachments
-
- squario.love
- (11.37 KiB) Downloaded 92 times
Re: Squario: The squariest platformer in LOVE.
Oh, cool. Now I'll have to frankenstine my library.
Re: Squario: The squariest platformer in LOVE.
Uploaded a version where Squario will fall, but he doesn't collide with the ground...
And new graphics
The round thing's pending name is rolly, for obvious reasons. When I implement AI, he'll roll at you and kill you.
And new graphics
The round thing's pending name is rolly, for obvious reasons. When I implement AI, he'll roll at you and kill you.
Re: Squario: The squariest platformer in LOVE.
I've messed with the ground code, and it turns out the graphics are offset and the ground has holes.
Re: Squario: The squariest platformer in LOVE.
Well, since you were feeling so discouraged, I took a look at it (while waiting for Ubunto to download).ZenX2 wrote:I've messed with the ground code, and it turns out the graphics are offset and the ground has holes.
Biggest problem:
self.body = love.physics.newBody(GetWorld(), p.x, p.y, m, i)
self.shape = love.physics.newRectangleShape(self.body, p.x, p.x, w, h, i )
The x,y parameters in the Shape constructor are offsets from the Body position, so you were offsetting the Shape from the Body by large amounts. Since (1) the Shape is used for collision detection, (2) your ground and player Shapes were offset into the boonies, (3) you were drawing the sprites at the Body position and not the Shape position -- it looked like squario was falling through the ground (in reality the ground, for collisions purposes, was quite a ways off screen).
Shape:getBoundingBox() would have shown you this. I added a DrawBoundingBox function to your Ent class for future debugging.
Other issues:
- You use the Body x,y for drawing your sprite, which is fine, but graphics.draw is going to put the top-left corner of your sprite there, so you need to manually offset the sprite to center it on the body position. Alternatively, you could use shape:getBoundingBox to get the top left corner of the Shape and pass that to graphics.draw (I did the former).
- applyForce is appropriate for use on every tick, applyImpulse is not. I left the applyForce calls in your Ent:Think function, but moved the applyImpulse calls into an OnKeyPressed handler which I added to the Player class. I kinda guessed at your intent here, and used applyImpulse only for jumping.
A remaining issue is that you create your ground out of 20 separate Shapes, and although they theoretically should create a perfectly smooth surface (given that they're all squares and positioned at exactly the same y coordinate), squario occasionally catches on the corner of one when he's sliding along. I'm guessing that's something you'll just have to work around by creating a large rectangle Shape for the ground independent of the sprites you use to draw it.
- Attachments
-
- squario.love
- (10.76 KiB) Downloaded 108 times
Re: Squario: A squary survival horror
I feel enlightened. I knew that the sprite's position needed to be offset, but I was unaware about the x and y of the shape being an offset. Hopefully, this might help people in the future so they don't need to deal with love.physics directly.
Re: Squario: A squary survival horror
Alright, I got bored and decided to work a bit on this. I figured out most of the problems, fixed the ground code, and threw in a bit of code that lets you create/destroy pieces of ground, just for fun
If you create lots of entities, it hits your fps a bit, but the drawing code is already as optimized as I know how to make it.
If you create lots of entities, it hits your fps a bit, but the drawing code is already as optimized as I know how to make it.
- Attachments
-
- squario.love
- (11.76 KiB) Downloaded 101 times
Who is online
Users browsing this forum: Hydrogen Maniac and 151 guests