Hours remaining: 79.
The Name
The young boy was walking
When the old man appeared
"Hey, you!" said the man
As he stroked his white beard.
"Now where do you travel?
To where do you head?
To the forest? The desert?
Or home to your bed?"
"My desk!" cried the boy,
"To work my idea!
It’s a wonderful thing,
An idea without peer!"
"Good gracious, what luck!
I wish you fortune and fame!
Now tell me, young man,
Just what is its name?"
The boy froze in his tracks,
His smile did quiet fade,
As buckets of rain
Rained on his parade.
The man looked concerned,
Raised his arms to the sky,
"Dear me, that won’t do,
That simply won’t fly."
"My boy," he continued,
"I don’t want to spoil it,
But words are important,
Like the name that you call it!"
"Why a name is a word
And words, they have power,
So, boy, you must name it
And name it this hour!"
"A name gives it weight,
Gives it shape, makes it real.
It makes it a thing,
A thing you can feel."
He held the boy’s gaze,
Looked him deep in the eye,
And said in a whisper
As soft as a sigh:
"A name gives it life,
A name makes it whole,
A name shows it love,
A name gives it soul."
He stepped back and smiled,
As he gathered his cloak.
Then a wink, and he vanished
In a puff of white smoke.
The boy was quite startled
At what he had seen
As now there was nothing
Where an old man had been!
After a moment, a pause,
He left at a run:
As fast as he could,
There was work to be done!
He ran ‘cross the bridge,
where the railway had been.
He ran through the town
Past the old village green.
He ran past the church,
The post office, the pub.
He ran past the shop
And the gentlemen’s club.
He ran down his lane,
Ran past the old stable,
Ran straight through his kitchen
(Past his mum at the table).
He ran to his Mac,
And fired up Xcode.
He sat ready to type, but…
No words flowed.
He sat there for hours,
He sat there and thought,
He even ignored
The snack his mum brought.
Outside the sun set,
And the day turned to night.
He sat in the dark,
With just the screen’s light.
It was way past his bedtime,
But as they observed him,
His mum and his dad
Thought they shouldn’t disturb him.
At last, in the dark
(it must have been three),
He leaned forward and typed
On a few of the keys.
He sat back and he smiled,
He had woken his game
He had given it life:
The soul of a name.
Barista!
My game has a name, and that name is Barista! Granted, after that Seussian introduction, the name of my game is probably a bit of a let down, but I really like writing Dr Seuss-style verse.
With a name comes an app entry in iTunesConnect and an app ID which makes it all seem that much more real and possible, so yay!
After I set up a new Xcode project, installed my standard set of utilities (not public yet) via Cocoapods, and installed Fastlane, I got to work on setting up a prototype. My goal was to have some simulated cups and a simulated espresso machine and have the cups be draggable and I did it!
I also managed to get some nice physics on the cups so that they bounce around the screen in a totally unrealistic manner:
After saying yesterday that this game wouldn’t require that much in the way of physics, I quickly came to the conclusion today that, actually, using physics is kind of fun and could be useful for more than just collision detection.
Implementation
Right now, everything is being dumped in the main GameScene class which is ugly, but prototyping is about speed. I am considering various options (including maybe using GameKit’s new Component Entity systems) but right now it’s just all being dumped in one place.
In the animation above, you’ll see that the cups lock
into the blue holders (which will eventually be invisible), and this turned out to be a bit of a stumbling block.
I was using the didBeginContact
method of the SKPhysicsContactDelegate
, which is now set up as follows:
func didBeginContact(contact: SKPhysicsContact) {
let collision = contact.bodyA.categoryBitMask | contact.bodyB.categoryBitMask
if collision == PhysicsCategory.Holder | PhysicsCategory.Cup {
if let nodeNameA = contact.bodyA.node?.name {
let cupNode : SKNode
let holderNode : SKNode
if nodeNameA.containsString("Item") {
cupNode = contact.bodyA.node!
holderNode = contact.bodyB.node!
} else {
cupNode = contact.bodyB.node!
holderNode = contact.bodyA.node!
}
cupNode.physicsBody?.velocity = CGVector.zero
self.cupNode = cupNode
self.newPosition = CGPoint(x: holderNode.position.x, y: holderNode.position.y)
self.endTouches()
}
}
The problem was that I was trying to set the position property of the cupNode
directly in this method, but it was not respecting it.
After trying a whole bunch of different things, I realised that it was probably something to do with the SpriteKit update loop and where this method was being called within that loop. It seems that setting a node’s position within this method won’t stick (my guess is that the update physics
portion of the loop overwrites it), so as a workaround I just stored the node and the position in two variables and then, in update
, checked for them and, if they were set, updated the node with the new position:
if let position = self.newPosition, node = self.cupNode {
node.position = position
self.newPosition = nil
self.cupNode = nil
}
It’s ugly, but it’s good enough to get started with.