SlideShare uma empresa Scribd logo
1 de 3
Baixar para ler offline
Missile Command
The main set of improvements focus on creating dynamic code.

Objectives
    ● dynamic object management with lists
    ● C-style polymorphism
    ● screen to world, world to screen coordinate

Introduction
These are the notes that go along with the presentation.
Missile command turns out to be a relatively simple game to recreate the fun.

Approach
Build up. Tearing down or modifying existing code is hard and error prone. Decisions and tradeoffs
are often hidden and will be lost when you modify code. Copy and paste sets of functionality. Always
keep your game compiling and running.
Copy the working file, start with the game controller class. Copy all the classes. Rip out the insides of
the functions -- add a comment that signals what you have torn out since you will need to recode it.

Pointers
Pointers are fast. One owner.

Doubly Linked Circular Lists
Lists provide a good way to manage dynamic game objects. Many operations involve running through
each of the game objects and a more complex data structure would not help.
The list that I use has 3 fields, a next, previous, and type. The next points to the next node, the
previous points to the previous node, and the type identifies the node type.

C-Style Polymorphism
Use the type in the list node to identify the node type and then use a static cast to cast the node to the
type.
Setup the class structure with the common list node first. This allows you to link through the nodes as
simple nodes, determine the type, and then static cast to the complex type.
The other heavily used type of polymorphism is the matrix type. The mat12 starts with the X, Y, and Z
coordinates. Then the 3x3 rotation matrix follows.

Class Definitions
For the first iteration, define classes with all the fields public.
The first field in the class is a node for ou
// JFL 04 Oct 08
class Input : public qe {
public:
   LLNode lnk; // must be first in structure
   chr name[16]; // name
   Input(chr *name); // constructor
   int fillPlayerInpRec(PlayerInpRec *pir,int playerNum);
}; // class Input

Constants and sizeof()
It is a bad idea to embed naked constants in your code. When defining structures, follow the DRY
principle.

Nesting Depth
Construct functions to improve understanding by avoiding unnecessary nesting.

Flow Of Control
Construct your functions such that flow of control moves down.

Bit Flags
Use bitwise operators to define, set, test, and clear bits.

Use Character Constants for Quick Ids
There are three gun bases. The left, center, and right. Use the character constants 'L' 'C' 'R'. This
approach is good for simple sets of ids, but breaks down when you have more ids.

XYZ as Array
The order of XYZ is always X then Y then Z.

Use One Localized Control System
For example, the dispatch system sets a flag when it is finished. Multiple sections of code may read
this flag, but only one should clear it.

Expiration Times
Guarantee that game objects expire.

Always Be Simplifying
Continually clean your code. Remove unneeded functions and variables. Copy functions you would
like to keep into dead.c. It is easy to add code. It is especially hard for other programmers to
understand dead code.
Be wary of writing code or setting up systems you will need in the future. Procrastination pays.

Protect You Code
Write flexible code that can handle null pointers.

Ray v Plane
The ray versus plane intersection test is useful.
    float a,b,t,dirRay[3],xyzRay[3],nrmPlane[3],kPlane,xyzCol[3];

    // ray v plane
    a = VecDot(dirRay,nrmPlane);
    if((a>-EPSILON)&&(a<EPSILON))
       goto BAIL; // dir in same dir as plane normal, no col
    b = VecDot(xyzRay,nrmPlane);
    t = (kPlane-b)/a; // distance to collision
    VecAddScaled(xyzCol,xyzRay,dirRay,t);

Mais conteúdo relacionado

Mais procurados

06 -working_with_strings
06  -working_with_strings06  -working_with_strings
06 -working_with_strings
Hector Garzo
 
Introduction To Algorithm [2]
Introduction To Algorithm [2]Introduction To Algorithm [2]
Introduction To Algorithm [2]
ecko_disasterz
 
Dynamic memory allocation in c++
Dynamic memory allocation in c++Dynamic memory allocation in c++
Dynamic memory allocation in c++
Tech_MX
 

Mais procurados (20)

Managing I/O & String function in C
Managing I/O & String function in CManaging I/O & String function in C
Managing I/O & String function in C
 
Dynamic memory allocation
Dynamic memory allocationDynamic memory allocation
Dynamic memory allocation
 
Structure in C
Structure in CStructure in C
Structure in C
 
Structure in c
Structure in cStructure in c
Structure in c
 
Breadth first search signed
Breadth first search signedBreadth first search signed
Breadth first search signed
 
8
88
8
 
06 -working_with_strings
06  -working_with_strings06  -working_with_strings
06 -working_with_strings
 
Ruby basics ||
Ruby basics ||Ruby basics ||
Ruby basics ||
 
Rust - Fernando Borretti
Rust - Fernando BorrettiRust - Fernando Borretti
Rust - Fernando Borretti
 
Introduction To Algorithm [2]
Introduction To Algorithm [2]Introduction To Algorithm [2]
Introduction To Algorithm [2]
 
Write a function called float dotproduct (links to an external site.)(float a...
Write a function called float dotproduct (links to an external site.)(float a...Write a function called float dotproduct (links to an external site.)(float a...
Write a function called float dotproduct (links to an external site.)(float a...
 
C string
C stringC string
C string
 
Basics of Python Programming
Basics of Python ProgrammingBasics of Python Programming
Basics of Python Programming
 
Breadth First Search Algorithm In 10 Minutes | Artificial Intelligence Tutori...
Breadth First Search Algorithm In 10 Minutes | Artificial Intelligence Tutori...Breadth First Search Algorithm In 10 Minutes | Artificial Intelligence Tutori...
Breadth First Search Algorithm In 10 Minutes | Artificial Intelligence Tutori...
 
Dynamic memory allocation in c++
Dynamic memory allocation in c++Dynamic memory allocation in c++
Dynamic memory allocation in c++
 
Cryptographic algorithms
Cryptographic algorithmsCryptographic algorithms
Cryptographic algorithms
 
C Structures And Unions
C  Structures And  UnionsC  Structures And  Unions
C Structures And Unions
 
DFS & BFS in Computer Algorithm
DFS & BFS in Computer AlgorithmDFS & BFS in Computer Algorithm
DFS & BFS in Computer Algorithm
 
Structures
StructuresStructures
Structures
 
Strings
StringsStrings
Strings
 

Destaque (9)

07 10 anjak piutang
07 10 anjak piutang07 10 anjak piutang
07 10 anjak piutang
 
Evaluation question 1
Evaluation question 1Evaluation question 1
Evaluation question 1
 
Session 51_1 Else-Marie Malmek
Session 51_1 Else-Marie MalmekSession 51_1 Else-Marie Malmek
Session 51_1 Else-Marie Malmek
 
ועידת חינוך 2014
ועידת חינוך 2014ועידת חינוך 2014
ועידת חינוך 2014
 
Geog fundamental
Geog fundamentalGeog fundamental
Geog fundamental
 
Jam Socotra
Jam SocotraJam Socotra
Jam Socotra
 
25 0
25 025 0
25 0
 
ICEC
ICECICEC
ICEC
 
Community
CommunityCommunity
Community
 

Semelhante a Missilecommand

Semelhante a Missilecommand (20)

C# note
C# noteC# note
C# note
 
ptu3-harvey-m-deitel-paul-j-deitel-tem-r-nieto-contributor-paul-j-deitel.pdf
ptu3-harvey-m-deitel-paul-j-deitel-tem-r-nieto-contributor-paul-j-deitel.pdfptu3-harvey-m-deitel-paul-j-deitel-tem-r-nieto-contributor-paul-j-deitel.pdf
ptu3-harvey-m-deitel-paul-j-deitel-tem-r-nieto-contributor-paul-j-deitel.pdf
 
C language
C languageC language
C language
 
C –FAQ:
C –FAQ:C –FAQ:
C –FAQ:
 
C language
C languageC language
C language
 
Improve Your Edge on Machine Learning - Day 1.pptx
Improve Your Edge on Machine Learning - Day 1.pptxImprove Your Edge on Machine Learning - Day 1.pptx
Improve Your Edge on Machine Learning - Day 1.pptx
 
Cyclcone a safe dialect of C
Cyclcone a safe dialect of CCyclcone a safe dialect of C
Cyclcone a safe dialect of C
 
GSP 125 Entire Course NEW
GSP 125 Entire Course NEWGSP 125 Entire Course NEW
GSP 125 Entire Course NEW
 
C programming part2
C programming part2C programming part2
C programming part2
 
C programming part2
C programming part2C programming part2
C programming part2
 
C programming part2
C programming part2C programming part2
C programming part2
 
CSharp Presentation
CSharp PresentationCSharp Presentation
CSharp Presentation
 
C programming language tutorial
C programming language tutorial C programming language tutorial
C programming language tutorial
 
C Programming - Refresher - Part IV
C Programming - Refresher - Part IVC Programming - Refresher - Part IV
C Programming - Refresher - Part IV
 
1183 c-interview-questions-and-answers
1183 c-interview-questions-and-answers1183 c-interview-questions-and-answers
1183 c-interview-questions-and-answers
 
unit 1 (1).pptx
unit 1 (1).pptxunit 1 (1).pptx
unit 1 (1).pptx
 
C++ Interview Question And Answer
C++ Interview Question And AnswerC++ Interview Question And Answer
C++ Interview Question And Answer
 
C++ questions And Answer
C++ questions And AnswerC++ questions And Answer
C++ questions And Answer
 
Oops lecture 1
Oops lecture 1Oops lecture 1
Oops lecture 1
 
1.Philosophy of .NET
1.Philosophy of .NET1.Philosophy of .NET
1.Philosophy of .NET
 

Mais de Susan Gold (20)

Dgxpo
DgxpoDgxpo
Dgxpo
 
Fog
FogFog
Fog
 
Ivdc
IvdcIvdc
Ivdc
 
Gold And Robinson 2009
Gold And Robinson 2009Gold And Robinson 2009
Gold And Robinson 2009
 
GDC 2009 Game Design Improv
GDC 2009 Game Design ImprovGDC 2009 Game Design Improv
GDC 2009 Game Design Improv
 
Gdc09 Minimissile
Gdc09 MinimissileGdc09 Minimissile
Gdc09 Minimissile
 
Setup
SetupSetup
Setup
 
Qe Reference
Qe ReferenceQe Reference
Qe Reference
 
Pong
PongPong
Pong
 
Gdc09 Minipong
Gdc09 MinipongGdc09 Minipong
Gdc09 Minipong
 
Gdc09 Minigames
Gdc09 MinigamesGdc09 Minigames
Gdc09 Minigames
 
Assignment Pong
Assignment PongAssignment Pong
Assignment Pong
 
Global Game Jam Overview
Global Game Jam OverviewGlobal Game Jam Overview
Global Game Jam Overview
 
Agd Talk Speed Run
Agd Talk   Speed RunAgd Talk   Speed Run
Agd Talk Speed Run
 
SIGGRAPH 2007 IGDA Presentation
SIGGRAPH 2007 IGDA PresentationSIGGRAPH 2007 IGDA Presentation
SIGGRAPH 2007 IGDA Presentation
 
Mscruise
MscruiseMscruise
Mscruise
 
GDC China 2007
GDC China 2007GDC China 2007
GDC China 2007
 
Digra07
Digra07Digra07
Digra07
 
Boston IGDA Meeting
Boston IGDA MeetingBoston IGDA Meeting
Boston IGDA Meeting
 
Curriculumframework2008
Curriculumframework2008Curriculumframework2008
Curriculumframework2008
 

Missilecommand

  • 1. Missile Command The main set of improvements focus on creating dynamic code. Objectives ● dynamic object management with lists ● C-style polymorphism ● screen to world, world to screen coordinate Introduction These are the notes that go along with the presentation. Missile command turns out to be a relatively simple game to recreate the fun. Approach Build up. Tearing down or modifying existing code is hard and error prone. Decisions and tradeoffs are often hidden and will be lost when you modify code. Copy and paste sets of functionality. Always keep your game compiling and running. Copy the working file, start with the game controller class. Copy all the classes. Rip out the insides of the functions -- add a comment that signals what you have torn out since you will need to recode it. Pointers Pointers are fast. One owner. Doubly Linked Circular Lists Lists provide a good way to manage dynamic game objects. Many operations involve running through each of the game objects and a more complex data structure would not help. The list that I use has 3 fields, a next, previous, and type. The next points to the next node, the previous points to the previous node, and the type identifies the node type. C-Style Polymorphism Use the type in the list node to identify the node type and then use a static cast to cast the node to the type. Setup the class structure with the common list node first. This allows you to link through the nodes as simple nodes, determine the type, and then static cast to the complex type. The other heavily used type of polymorphism is the matrix type. The mat12 starts with the X, Y, and Z coordinates. Then the 3x3 rotation matrix follows. Class Definitions For the first iteration, define classes with all the fields public.
  • 2. The first field in the class is a node for ou // JFL 04 Oct 08 class Input : public qe { public: LLNode lnk; // must be first in structure chr name[16]; // name Input(chr *name); // constructor int fillPlayerInpRec(PlayerInpRec *pir,int playerNum); }; // class Input Constants and sizeof() It is a bad idea to embed naked constants in your code. When defining structures, follow the DRY principle. Nesting Depth Construct functions to improve understanding by avoiding unnecessary nesting. Flow Of Control Construct your functions such that flow of control moves down. Bit Flags Use bitwise operators to define, set, test, and clear bits. Use Character Constants for Quick Ids There are three gun bases. The left, center, and right. Use the character constants 'L' 'C' 'R'. This approach is good for simple sets of ids, but breaks down when you have more ids. XYZ as Array The order of XYZ is always X then Y then Z. Use One Localized Control System For example, the dispatch system sets a flag when it is finished. Multiple sections of code may read this flag, but only one should clear it. Expiration Times Guarantee that game objects expire. Always Be Simplifying Continually clean your code. Remove unneeded functions and variables. Copy functions you would like to keep into dead.c. It is easy to add code. It is especially hard for other programmers to understand dead code.
  • 3. Be wary of writing code or setting up systems you will need in the future. Procrastination pays. Protect You Code Write flexible code that can handle null pointers. Ray v Plane The ray versus plane intersection test is useful. float a,b,t,dirRay[3],xyzRay[3],nrmPlane[3],kPlane,xyzCol[3]; // ray v plane a = VecDot(dirRay,nrmPlane); if((a>-EPSILON)&&(a<EPSILON)) goto BAIL; // dir in same dir as plane normal, no col b = VecDot(xyzRay,nrmPlane); t = (kPlane-b)/a; // distance to collision VecAddScaled(xyzCol,xyzRay,dirRay,t);