iPong

A simple pong implementation that runs on IOS.

Tech stuff

The following stuff is used to create this Pong implementation for IOS:

  • XCode 4.x
  • Objective C
  • Cocos2D
  • Box2D
  • Freetime in an hotel in Rotterdam

Project structure

All real logic and non scaffolding code can be found in three classes.

iPongLayer

Main entry point. Bootstraps all the game objects and is the layer where the game is drawn on. It also holds and manages the game score.

Paddle

The paddle game object. Contains logic to move itself on touch.

Ball

The ball game object. It contains logic to respawn.

What you need to know about Box2D

Box2D works with several fundamental objects. We briefly define these objects here and more details are given later in this document.

world

A physics world is a collection of bodies, fixtures, and constraints that interact together. Box2D supports the creation of multiple worlds, but this is usually not necessary or desirable.

shape

A 2D geometrical object, such as a circle or polygon.

rigid body

A chunk of matter that is so strong that the distance between any two bits of matter on the chunk is completely constant. They are hard like a diamond. In the following discussion we use body interchangeably with rigid body.

fixture

A fixture binds a shape to a body and adds material properties such as density, friction, and restitution.

constraint

A constraint is a physical connection that removes degrees of freedom from bodies. In 2D a body has 3 degrees of freedom (two translation coordinates and one rotation coordinate). If we take a body and pin it to the wall (like a pendulum) we have constrained the body to the wall. At this point the body can only rotate about the pin, so the constraint has removed 2 degrees of freedom.

contact constraint

A special constraint designed to prevent penetration of rigid bodies and to simulate friction and restitution. You do not create contact constraints; they are created automatically by Box2D.

joint

This is a constraint used to hold two or more bodies together. Box2D supports several joint types: revolute, prismatic, distance, and more. Some joints may have limits and motors.

joint limit

A joint limit restricts the range of motion of a joint. For example, the human elbow only allows a certain range of angles.

joint motor

A joint motor drives the motion of the connected bodies according to the joint's degrees of freedom. For example, you can use a motor to drive the rotation of an elbow.

Code Fest

I created this for the Devnology Code Fest. using XCode, ObjC and the Cocos2D Box2d framework.



iPong

在IOS上运行的简单的乒乓实现。

Tech stuff

以下内容用于为IOS创建此Pong实现:

  • XCode 4.x
  • 目标C
  • Cocos2D
  • Box2D
  • 在鹿特丹的一家酒店休息

Project structure

所有真正的逻辑和非脚手架代码都可以在三个类中找到

iPongLayer

主入口点。引导所有游戏对象,并且是游戏绘制的层。它还拥有和管理游戏得分。

桨桨

桨游戏对象。包含触摸自己的逻辑。

球类对象。它包含重新生成的逻辑。

What you need to know about Box2D

Box2D适用于几个基本对象。我们在这里简要定义这些对象,本文档稍后将给出更多细节。

世界

物理世界是一系列物体,夹具和约束,它们在一起相互作用。 Box2D支持创建多个世界,但这通常不是必需或不可取的。

shape

二维几何对象,如圆形或多边形。

刚体

一大块物质如此强大,使得块上任何两个物质之间的距离是完全不变的。他们很像钻石。在下面的讨论中,我们使用身体与刚体互换使用。

夹具

夹具将形状与身体结合,并添加材料属性,如密度,摩擦和恢复

约束

约束是一种物理连接,可以消除身体的自由度。在2D中,主体具有3个自由度(两个平移坐标和一个旋转坐标)。如果我们把身体固定在墙上(像钟摆),我们将身体限制在墙上。在这一点上,身体只能围绕销旋转,因此约束已经消除了2个自由度

联系约束

设计用于防止刚体穿透并模拟摩擦和恢复的特殊约束。您不会创建联系限制;它们由Box2D自动创建。

联合

这是一个约束,用于将两个或多个物体放在一起。 Box2D支持多种联合类型:旋转,棱柱,距离等。某些接头可能有限制和电机。

联合限制

关节限制限制了关节的运动范围。例如,人的弯头仅允许一定范围的角度。

关节马达

联合电机根据接头的自由度驱动连接体的运动。例如,您可以使用电机驱动肘部旋转。

Code Fest

我为Devnology Code Fest 创建了这个。使用XCode,ObjC和Cocos2D Box2d框架。




相关问题推荐