Skip to content

Instantly share code, notes, and snippets.

View LearnCocos2D's full-sized avatar

Steffen Itterheim LearnCocos2D

View GitHub Profile
@LearnCocos2D
LearnCocos2D / gist:4acd1eb6733192aab180
Last active May 31, 2017 17:55
GKMinmaxStrategist stub classes implementing the GKGameModel* protocols for Swift 2.0
/*
Swift classes implementing the GKMinmaxStrategizer protocols, without any logic.
You can use these as a template, copy & paste them into your project and start working. ;)
This gist is provided by http://tilemapkit.com and released into public domain.
Here's my tutorial about GKMinmaxStrategist: http://tilemapkit.com/2015/07/gkminmaxstrategist-build-tictactoe-ai/
*/
class TheGameModel: NSObject, NSCopying, GKGameModel {
@LearnCocos2D
LearnCocos2D / gist:d541d9905d1320ad6d2e
Last active December 16, 2016 18:14
Entity Component Systems compared with pseudo-code (variants: GameplayKit, Adam Martin, Scott Bilas)
@LearnCocos2D
LearnCocos2D / gist:77f0ced228292676689f
Last active November 13, 2024 07:24
Overview of Entity Component System (ECS) variations with pseudo-code

For background and further references see: Entity Component Systems on Wikipedia

ECS by Scott Bilas (GDC 2002)

Entity->Components->Update
  • entity = class: no logic + no data OR at most small set of frequently used data (ie position)
  • component = class: logic + data
foreach entity in allEntities do
    foreach component in entity.components do
-(void) draw:(CCRenderer *)renderer transform:(const GLKMatrix4 *)transform
{
// Drawing the triangle fan. Simple explanation of how a triangle fan is drawn:
// http://stackoverflow.com/questions/8043923/gl-triangle-fan-explanation
// in a triangle fan the first 3 vertices form one triangle, then each additional vertex forms another triangle
// thus number of triangles is number of vertices minus the initial 2 vertices for the first triangle
int numTriangles = _numVertices - 2;
CCRenderBuffer buffer = [renderer enqueueTriangles:numTriangles
andVertexes:_numVertices
@LearnCocos2D
LearnCocos2D / gist:6498646
Last active December 22, 2015 16:19
getting SK opengl context (in viewDidAppear or later)
#if TARGET_OS_IPHONE
id context = [EAGLContext currentContext];
#else
id context = [NSOpenGLContext currentContext];
#endif
@LearnCocos2D
LearnCocos2D / gist:5513068
Last active December 16, 2015 23:21
KoboldTouch tilemap demo code http://www.koboldtouch.com
//
// TilemapWithBorderViewController.m
// _Feature-Demo-Template_
//
// Created by Steffen Itterheim on 19.03.13.
// Copyright 2013 __MyCompanyName__. All rights reserved.
//
#import "TilemapWithBorderSceneViewController.h"
@LearnCocos2D
LearnCocos2D / gist:5513061
Last active December 16, 2015 23:19
KoboldTouch physics collision demo code http://www.koboldtouch.com
//
// PhysicsCollisionSceneViewController.m
// _Feature-Demo-Template_
//
// Created by Steffen Itterheim on 01.05.13.
// Copyright 2013 __MyCompanyName__. All rights reserved.
//
#import "PhysicsCollisionSceneViewController.h"
@LearnCocos2D
LearnCocos2D / gist:5474209
Created April 27, 2013 19:02
ObjC uncrustify config
#
# Uncrustify Configuration File
# File Created With UncrustifyX 0.4.1 (229)
#
# Alignment
# ---------
## Alignment
bool foo(char* p1, int* p2)
{
// local variable declaration
bool bRet = false; // init all local variables here, assume everything is wrong
int* ptr = NULL;
PROFILER_START();
// check input params
if (p1 && p2)
@LearnCocos2D
LearnCocos2D / gist:4569727
Created January 19, 2013 00:02
Initializer object demo. Instead of initializers with dozens of variants of "initWith…" methods, KoboldTouch makes heavy use of initializer object. These are simple Objective-C classes consisting mainly of properties. They set sensible defaults so you only need to change the properties that have to be set, and those you want to change. Then init…
// set menu options with the initializer object
KTTextMenu* textMenu = [KTTextMenu menuWithTextMenuItems:[NSArray arrayWithObjects:item1, item2, nil]];
textMenu.fontName = @"Arial";
textMenu.fontSize = 48;
textMenu.padding = 16;
// init the menu with the initializer object
KTMenuViewController* menuViewController = [KTMenuViewController menuControllerWithTextMenu:textMenu];
[self addSubController:menuViewController];