Two-Player mini game: Cornhole

This is a mini game for two players on one Playdate, that I put together in a day.
I am not a US citizen, but living on the East Coast since 2016, I felt qualified enough to make a Playdate version of Cornhole :grinning_face_with_smiling_eyes:


In this slightly modified version of the game, two players take turns in throwing bags at a randomly placed cornhole board. One player can throw 6 bags, before it is the other's turn. A bag that lands on the board is 1 points, a bag that goes into the hole is 3. At the moment a game is over when one player gets 6 points. But this can be easily modified by changing the "max" variable.

Before I continue,, it is important to state that I stole the most difficult part of the game, from the amazing sin/cos demo, that was shared in this forum by @BoldBigflank which I combined with some very basic projectile motion.

So here's how the game works: You use the crank to swing your arm back and forth (or do a full windmill), and at any point press A/Confirm to let go of the bag.
Your throw is determined by the angle and the speed of the swing (well crank) at the time you press A.
Of course only underhand throws work.
This can be a bit tricky at first (and quite fatiguing if you do the cranking in the simulator with a touchpad), but it is absolutely possible to throw any distance (and way beyond the screen)
When you have thrown all 6 bags, hand the Playdate over to your opponent.
That's pretty much it.

Enjoy. If anyone cares to test this on an actual Playdate, I'd love to hear whether it works.

Corn Hole.json.zip (5.4 KB)

6 Likes

Brilliant. Excellent use of the crank.

2 Likes

Yeah, this is a great use for the crank. I gave it a shot on the device and it runs pretty slowly. I’ll take a look at the PulpScript and see if there’s any obvious causes. (I’m planning on adding some basic trig functions to PulpScript this week, kind of a glaring omission when you consider the crank :sweat_smile:)


(The 7 in the top left is an FPS hud)

2 Likes

Oh, thanks so much for trying!!

I'll have a look at the code, too. The whole draw event is still a hack-y mess and can do with at least a clean-up.

Is the game slow during the arm movement, or also when the corn sack is flying?

I had a look at the code. Currently the position of the crank is checked from the Draw event. I moved this into the crank handler now. Maybe it helps.
The other thing I could think of, is, sin and cos are handlers in game. And called through emit from the players draw event.
I think I remember reading that performance can take a hit because of emit.
This part I just adopted from the original sin/cos script, but maybe it helps if it is moved to the player, so emit is not necessary.
Corn Hole.json.zip (6.2 KB)

EDIT: Just saw your post in the sin/cos thread, which confirms, what I suspected.
EDIT: #2 and #3: In the above updated file, the arm movement is moved to crank, and emit was replaced by call. I hope this improves performance.
As a side effect, it is my impression, that moving the chunk of code to crank, made the throwing a little easier. Or it's just my practice :wink:

I’ve added “native” sine and cosine functions to PulpScript (plus tangent, radians, and degrees) and it’s maintaining 20fps on the hardware now. One thing I noticed is that the values returned by the pure PulpScript event handler versions are inverted (causing the ball to rotate in the opposite direction from the arm). The native values are coming straight from Lua/JavaScript so I trust the sign on those are accurate. The easy fix is just to invert the results with *= -1.

These additions to PulpScript should be up sometime this week.

4 Likes