Skip to content

Instantly share code, notes, and snippets.

View alinradut's full-sized avatar

alinradut

  • Targu Mures, Romania
View GitHub Profile
@alinradut
alinradut / gist:1025002
Created June 14, 2011 14:27
Print all subviews with a certain type
- (NSString *)superviewPath:(UIView *)view
{
NSMutableArray *path = [NSMutableArray array];
while (view != nil)
{
[path insertObject:[NSString stringWithFormat:@"(%p) %@",view,NSStringFromClass([view class])] atIndex:0];
view = [view superview];
}
@alinradut
alinradut / CGRect helpers
Created May 26, 2011 08:40
Useful CGRect manipulation defines
#define CGRectSetPos( r, x, y ) CGRectMake( x, y, r.size.width, r.size.height )
#define CGRectSetX( r, x ) CGRectMake( x, r.origin.y, r.size.width, r.size.height )
#define CGRectSetY( r, y ) CGRectMake( r.origin.x, y, r.size.width, r.size.height )
#define CGRectSetSize( r, w, h ) CGRectMake( r.origin.x, r.origin.y, w, h )
#define CGRectSetWidth( r, w ) CGRectMake( r.origin.x, r.origin.y, w, r.size.height )
#define CGRectSetHeight( r, h ) CGRectMake( r.origin.x, r.origin.y, r.size.width, h )
- (void)achievementUnlocked:(NSString *)achievement {
[achievements_ addObject:achievement];
// lazy load the achievements layer
if (!achievementLayer_) {
CGSize winSize = [[CCDirector sharedDirector] winSize];
// instantiate the layer
achievementLayer_ = [[CCLayer alloc] init];
achievementLayer_.anchorPoint = ccp(0,0);
@alinradut
alinradut / gameswon.m
Created April 17, 2011 18:35
Achievements - Games won
- (void)updateGamesWon {
gamesWonInARow_++;
if (gamesWonInARow_ && (gamesWonInARow_ % 10 == 0 || gamesWonInARow_ == 5)) {
NSInteger bonus = score_* ((float)gamesWonInARow_ / 100);
score_ += bonus;
NSString *achievement = [NSString stringWithFormat:@"%d games in a row! (+%d)", gamesWonInARow_, bonus];
[self achievementUnlocked:achievement];
}
- (void)updateCorrectKeysPressed {
correctKeysPressed_++;
correctKeysPressedThisGame_++;
// update the current score, 10 points for a correct key and 3 points for each consecutive correct key
score_ += 10 + (correctKeysPressedThisGame_ - 1) * 3;
if (correctKeysPressed_ && correctKeysPressed_ % 10 == 0) {
// compute the bonus based on consecutive correct keys
NSInteger bonus = score_ * ((float)correctKeysPressed_/200);
- (void)updateCorrectKeysPressed {
correctKeysPressed_++;
correctKeysPressedThisGame_++;
// update the current score, 10 points for a correct key and 3 points for each consecutive correct key
score_ += 10 + (correctKeysPressedThisGame_ - 1) * 3;
if (correctKeysPressed_ && correctKeysPressed_ % 10 == 0) {
// compute the bonus based on consecutive correct keys
NSInteger bonus = score_ * ((float)correctKeysPressed_/200);