SlideShare a Scribd company logo
1 of 25
Download to read offline
TECNOLOGIAS EMERGENTES EM JOGOS

Engenharia em Desenvolvimento de Jogos Digitais - 2013/2014

February 14, 2014

Daniela da Cruz
dcruz@ipca.pt
C BASICS
C basics

C  COMMENTS
There are two ways to include commentary text in a C program.

→

Inline comments

// This is an inline comment
→

Block comments

/* This is a block comment.
It can span multiple lines. */

3
C basics

C  VARIABLES
Variables are containers that can store dierent values.

type name
the = operator.

To declare a variable, you use the
to assign a value to it you use

syntax, and

double odometer = 9200.8;
int odometerAsInteger = (int)odometer;

4
C basics

C  CONSTANTS

The const variable modier tells to the compiler that a variable is
never allowed to change.

double const pi = 3.14159;

5
C basics

C  ARITHMETIC
The familiar +, -, *, / symbols are used for basic arithmetic
operations, and the modulo operator (%) can be used to return the
remainder of an integer division.

printf(6
printf(6
printf(6
printf(6
printf(6

+
*
/
%

2
2
2
2
2

=
=
=
=
=

%d,
%d,
%d,
%d,
%d,

6
6
6
6

+
*
/

2);
2);
2);
2);
6 % 2);

// 8
// 4
// 12
// 3
// 0

6
C basics

C  ARITHMETIC (2)
C also has increment (++) and decrement () operators. These are
convenient operators for adding or subtracting 1 from a variable.

int i = 0;
printf(%d, i);
i++;
printf(%d, i);
i++;
printf(%d, i);

// 0
// 1
// 2

7
C basics

C  RELATIONAL/LOGICAL OPERATORS
The most common relational/logical operators are shown below.

Operator
a == b

Description
Equal to

!=b
b
a = b
a  b
a = b

Greater than or equal to

!a

Logical negation

a

a

Not equal to
Greater than
Less than
Less than or equal to

a  b

Logical and

||

Logical or

a

b

8
C basics

C  CONDITIONALS
C provides the standard if statement found in most programming
languages.

int modelYear = 1990;
if (modelYear  1967) {
printf(That car is an antique!!!);
} else if (modelYear = 1991) {
printf(That car is a classic!);
} else if (modelYear == 2014) {
printf(That's a brand new car!);
} else {
printf(There's nothing special about that car.);
}
9
C basics

C  CONDITIONALS (2)
C also includes a
integral types 

switch

statement, however it

only works with

not oating-point numbers, pointers, or

Objective-C objects.

switch (modelYear) {
case 1987:
printf(Your car is from 1987.); break;
case 1989:
case 1990:
printf(Your car is from 1989 or 1990.); break;
default:
printf(I have no idea when your car was made.);
break;
}
10
C basics

C  LOOPS
The

while

the related

for loops can be used for iterating over values,
break and continue keywords let you exit a loop
and

and

prematurely or skip an iteration, respectively.

int modelYear = 1990;
int i = 0;
while (i5) {
if (i == 3) {
printf(Aborting the while-loop);
break;
}
printf(Current year: %d, modelYear + i);
i++;
}
11
C basics

C  LOOPS (2)
int modelYear = 1990, i;
for (i=0; i5; i++) {
if (i == 3) {
printf(Skipping a for-loop iteration);
continue;
}
printf(Current year: %d, modelYear + i);
}

12
C basics

C  TYPEDEF
The

typedef

keyword lets you create new data types or redene

existing ones.

typedef unsigned char ColorComponent;
int main() {
ColorComponent red = 255;
return 0;
}

13
C basics

C  STRUCTS
A struct is like a simple, primitive C object. It lets you aggregate
several variables into a more complex data structure, but doesn't
provide any OOP features (e.g., methods).

typedef struct {
unsigned char red;
unsigned char green;
unsigned char blue;
} Color;
int main() {
Color carColor = {255, 160, 0};
printf(Your color is (R: %u, G: %u, B: %u),
carColor.red, carColor.green, carColor.blue);
return 0;
}
14
C basics

C  ENUMS
The

enum

keyword is used to create an enumerated type, which is a

collection of related constants.

typedef enum {
FORD,
HONDA,
NISSAN,
PORSCHE
} CarModel;
int main() {
CarModel myCar = NISSAN;
return 0;
}
15
C basics

C  ARRAYS
The higher-level
the

NSArray

and

NSMutableArray

classes provided by

Foundation Framework are much more convenient than C

arrays.

int years[4] = {1968, 1970, 1989, 1999};

16
C basics

C  POINTERS
A pointer is a direct reference to a memory address.

→

The reference operator () returns the memory address of a
normal variable. This is how we create pointers.

→

The dereference operator (*) returns the contents of a
pointer's memory address.

int year = 1967;
int *pointer;
pointer = year;
printf(%d, *pointer);
*pointer = 1990;
printf(%d, year);

17
C basics

C  FUNCTIONS
There are four components to a C function: its return value, name,
parameters, and associated code block.

18
C basics

C  FUNCTIONS
Functions need to be dened before they are used.
C lets you separate the

implementation.
→

declaration of a function from its

A function declaration tells the compiler what the function's
inputs and outputs look like.

→

The corresponding implementation attaches a code block to
the declared function.

Together, these form a complete function denition.

19
C basics

C  STATIC FUNCTIONS
The

static

keyword let us alter the availability of a function or

variable.
By default, all functions have a global scope.
This means that as soon as we dene a function in one le, it's
immediately available everywhere else.
The

static

specier let us limit the function's scope to the current

le, which is useful for creating private functions and avoiding
naming conicts.

20
C basics

C  STATIC FUNCTIONS (2)
File

functions.m:

// Static function declaration
static int getRandomInteger(int, int);
// Static function implementation
static int getRandomInteger(int minimum, int maximum) {
return ((maximum - minimum) + 1) + minimum;
}
You would not be able to access

main.m.

getRandomInteger()

from

Note that the static keyword should be used on both the function
declaration and implementation.
21
C basics

C  STATIC VARIABLES

Variables declared inside of a function are reset each time the
function is called.
However, when you use the

static

modier on a local variable, the

function remembers its value across invocations.

22
C basics

C  STATIC VARIABLES (2)
int countByTwo() {
static int currentCount = 0;
currentCount += 2;
return currentCount;
}
int main(int argc, const char * argv[]) {
printf(%d, countByTwo());
// 2
printf(%d, countByTwo());
// 4
printf(%d, countByTwo());
// 6
}

return 0;

23
C basics

C  STATIC VARIABLES (2)

This use of the static keyword

does not aect the scope of local

variables.
Local variables are still only accessible inside of the function itself.

24
C basics

C  SUMMARY
We reviewed:

→

Variables

→

Conditionals

→

Loops

→

Typedef

→

Struct's

→

Enum's

→

Arrays

→

Pointers

→

Functions

→

Static (functions and variables)

25

More Related Content

What's hot

Programming in C [Module One]
Programming in C [Module One]Programming in C [Module One]
Programming in C [Module One]Abhishek Sinha
 
Advanced Programming C++
Advanced Programming C++Advanced Programming C++
Advanced Programming C++guestf0562b
 
Lecture 3 getting_started_with__c_
Lecture 3 getting_started_with__c_Lecture 3 getting_started_with__c_
Lecture 3 getting_started_with__c_eShikshak
 
C++ Advanced
C++ AdvancedC++ Advanced
C++ AdvancedVivek Das
 
Introduction to Basic C programming 02
Introduction to Basic C programming 02Introduction to Basic C programming 02
Introduction to Basic C programming 02Wingston
 
Data structures question paper anna university
Data structures question paper anna universityData structures question paper anna university
Data structures question paper anna universitysangeethajames07
 
C programming session 02
C programming session 02C programming session 02
C programming session 02Vivek Singh
 
Lec 02. C Program Structure / C Memory Concept
Lec 02. C Program Structure / C Memory ConceptLec 02. C Program Structure / C Memory Concept
Lec 02. C Program Structure / C Memory ConceptRushdi Shams
 

What's hot (20)

C introduction by thooyavan
C introduction by  thooyavanC introduction by  thooyavan
C introduction by thooyavan
 
Assignment12
Assignment12Assignment12
Assignment12
 
Assignment6
Assignment6Assignment6
Assignment6
 
Programming in C [Module One]
Programming in C [Module One]Programming in C [Module One]
Programming in C [Module One]
 
Savitch Ch 09
Savitch Ch 09Savitch Ch 09
Savitch Ch 09
 
Savitch ch 09
Savitch ch 09Savitch ch 09
Savitch ch 09
 
Advanced Programming C++
Advanced Programming C++Advanced Programming C++
Advanced Programming C++
 
C++ book
C++ bookC++ book
C++ book
 
C++ Training
C++ TrainingC++ Training
C++ Training
 
C introduction by piyushkumar
C introduction by piyushkumarC introduction by piyushkumar
C introduction by piyushkumar
 
Lecture 3 getting_started_with__c_
Lecture 3 getting_started_with__c_Lecture 3 getting_started_with__c_
Lecture 3 getting_started_with__c_
 
UNIT-II CP DOC.docx
UNIT-II CP DOC.docxUNIT-II CP DOC.docx
UNIT-II CP DOC.docx
 
C++ Advanced
C++ AdvancedC++ Advanced
C++ Advanced
 
C Programming
C ProgrammingC Programming
C Programming
 
Introduction to Basic C programming 02
Introduction to Basic C programming 02Introduction to Basic C programming 02
Introduction to Basic C programming 02
 
Data structures question paper anna university
Data structures question paper anna universityData structures question paper anna university
Data structures question paper anna university
 
Assignment8
Assignment8Assignment8
Assignment8
 
Le langage rust
Le langage rustLe langage rust
Le langage rust
 
C programming session 02
C programming session 02C programming session 02
C programming session 02
 
Lec 02. C Program Structure / C Memory Concept
Lec 02. C Program Structure / C Memory ConceptLec 02. C Program Structure / C Memory Concept
Lec 02. C Program Structure / C Memory Concept
 

Similar to TECNOLOGIAS EMERGENTES EM JOGOS DIGITAIS

UNIT-1 notes(Data Types – Variables – Operations – Expressions and Statements...
UNIT-1 notes(Data Types – Variables – Operations – Expressions and Statements...UNIT-1 notes(Data Types – Variables – Operations – Expressions and Statements...
UNIT-1 notes(Data Types – Variables – Operations – Expressions and Statements...RSathyaPriyaCSEKIOT
 
Report on c and c++
Report on c and c++Report on c and c++
Report on c and c++oggyrao
 
Ch2 introduction to c
Ch2 introduction to cCh2 introduction to c
Ch2 introduction to cHattori Sidek
 
Hello world! Intro to C++
Hello world! Intro to C++Hello world! Intro to C++
Hello world! Intro to C++DSCIGDTUW
 
88 c programs 15184
88 c programs 1518488 c programs 15184
88 c programs 15184Sumit Saini
 
Overview of C Mrs Sowmya Jyothi
Overview of C Mrs Sowmya JyothiOverview of C Mrs Sowmya Jyothi
Overview of C Mrs Sowmya JyothiSowmya Jyothi
 
The Ring programming language version 1.10 book - Part 97 of 212
The Ring programming language version 1.10 book - Part 97 of 212The Ring programming language version 1.10 book - Part 97 of 212
The Ring programming language version 1.10 book - Part 97 of 212Mahmoud Samir Fayed
 
Fundamental of C Programming Language and Basic Input/Output Function
  Fundamental of C Programming Language and Basic Input/Output Function  Fundamental of C Programming Language and Basic Input/Output Function
Fundamental of C Programming Language and Basic Input/Output Functionimtiazalijoono
 
The Ring programming language version 1.5.3 book - Part 91 of 184
The Ring programming language version 1.5.3 book - Part 91 of 184The Ring programming language version 1.5.3 book - Part 91 of 184
The Ring programming language version 1.5.3 book - Part 91 of 184Mahmoud Samir Fayed
 
cuptopointer-180804092048-190306091149 (2).pdf
cuptopointer-180804092048-190306091149 (2).pdfcuptopointer-180804092048-190306091149 (2).pdf
cuptopointer-180804092048-190306091149 (2).pdfYashwanthCse
 
C Programming Language Tutorial for beginners - JavaTpoint
C Programming Language Tutorial for beginners - JavaTpointC Programming Language Tutorial for beginners - JavaTpoint
C Programming Language Tutorial for beginners - JavaTpointJavaTpoint.Com
 

Similar to TECNOLOGIAS EMERGENTES EM JOGOS DIGITAIS (20)

UNIT-1 notes(Data Types – Variables – Operations – Expressions and Statements...
UNIT-1 notes(Data Types – Variables – Operations – Expressions and Statements...UNIT-1 notes(Data Types – Variables – Operations – Expressions and Statements...
UNIT-1 notes(Data Types – Variables – Operations – Expressions and Statements...
 
Ppt of c vs c#
Ppt of c vs c#Ppt of c vs c#
Ppt of c vs c#
 
C Programming Tutorial - www.infomtec.com
C Programming Tutorial - www.infomtec.comC Programming Tutorial - www.infomtec.com
C Programming Tutorial - www.infomtec.com
 
C programming
C programmingC programming
C programming
 
Report on c and c++
Report on c and c++Report on c and c++
Report on c and c++
 
Unit-IV.pptx
Unit-IV.pptxUnit-IV.pptx
Unit-IV.pptx
 
Ch2 introduction to c
Ch2 introduction to cCh2 introduction to c
Ch2 introduction to c
 
Hello world! Intro to C++
Hello world! Intro to C++Hello world! Intro to C++
Hello world! Intro to C++
 
88 c-programs
88 c-programs88 c-programs
88 c-programs
 
88 c programs 15184
88 c programs 1518488 c programs 15184
88 c programs 15184
 
88 c-programs
88 c-programs88 c-programs
88 c-programs
 
Overview of C Mrs Sowmya Jyothi
Overview of C Mrs Sowmya JyothiOverview of C Mrs Sowmya Jyothi
Overview of C Mrs Sowmya Jyothi
 
The Ring programming language version 1.10 book - Part 97 of 212
The Ring programming language version 1.10 book - Part 97 of 212The Ring programming language version 1.10 book - Part 97 of 212
The Ring programming language version 1.10 book - Part 97 of 212
 
Programming in C
Programming in CProgramming in C
Programming in C
 
Fundamental of C Programming Language and Basic Input/Output Function
  Fundamental of C Programming Language and Basic Input/Output Function  Fundamental of C Programming Language and Basic Input/Output Function
Fundamental of C Programming Language and Basic Input/Output Function
 
C language tutorial
C language tutorialC language tutorial
C language tutorial
 
The Ring programming language version 1.5.3 book - Part 91 of 184
The Ring programming language version 1.5.3 book - Part 91 of 184The Ring programming language version 1.5.3 book - Part 91 of 184
The Ring programming language version 1.5.3 book - Part 91 of 184
 
cuptopointer-180804092048-190306091149 (2).pdf
cuptopointer-180804092048-190306091149 (2).pdfcuptopointer-180804092048-190306091149 (2).pdf
cuptopointer-180804092048-190306091149 (2).pdf
 
C Programming
C ProgrammingC Programming
C Programming
 
C Programming Language Tutorial for beginners - JavaTpoint
C Programming Language Tutorial for beginners - JavaTpointC Programming Language Tutorial for beginners - JavaTpoint
C Programming Language Tutorial for beginners - JavaTpoint
 

More from Daniela Da Cruz

Introduction to iOS and Objective-C
Introduction to iOS and Objective-CIntroduction to iOS and Objective-C
Introduction to iOS and Objective-CDaniela Da Cruz
 
Game Development with AndEngine
Game Development with AndEngineGame Development with AndEngine
Game Development with AndEngineDaniela Da Cruz
 
Interactive Verification of Safety-Critical Systems
Interactive Verification of Safety-Critical SystemsInteractive Verification of Safety-Critical Systems
Interactive Verification of Safety-Critical SystemsDaniela Da Cruz
 
Android Lesson 3 - Intent
Android Lesson 3 - IntentAndroid Lesson 3 - Intent
Android Lesson 3 - IntentDaniela Da Cruz
 
Comment Analysis approach for Program Comprehension (Software Engineering Wor...
Comment Analysis approach for Program Comprehension (Software Engineering Wor...Comment Analysis approach for Program Comprehension (Software Engineering Wor...
Comment Analysis approach for Program Comprehension (Software Engineering Wor...Daniela Da Cruz
 
Android Introduction - Lesson 1
Android Introduction - Lesson 1Android Introduction - Lesson 1
Android Introduction - Lesson 1Daniela Da Cruz
 

More from Daniela Da Cruz (9)

Introduction to iOS and Objective-C
Introduction to iOS and Objective-CIntroduction to iOS and Objective-C
Introduction to iOS and Objective-C
 
Games Concepts
Games ConceptsGames Concepts
Games Concepts
 
Game Development with AndEngine
Game Development with AndEngineGame Development with AndEngine
Game Development with AndEngine
 
Interactive Verification of Safety-Critical Systems
Interactive Verification of Safety-Critical SystemsInteractive Verification of Safety-Critical Systems
Interactive Verification of Safety-Critical Systems
 
Android Introduction
Android IntroductionAndroid Introduction
Android Introduction
 
Android Lesson 3 - Intent
Android Lesson 3 - IntentAndroid Lesson 3 - Intent
Android Lesson 3 - Intent
 
Comment Analysis approach for Program Comprehension (Software Engineering Wor...
Comment Analysis approach for Program Comprehension (Software Engineering Wor...Comment Analysis approach for Program Comprehension (Software Engineering Wor...
Comment Analysis approach for Program Comprehension (Software Engineering Wor...
 
Android Lesson 2
Android Lesson 2Android Lesson 2
Android Lesson 2
 
Android Introduction - Lesson 1
Android Introduction - Lesson 1Android Introduction - Lesson 1
Android Introduction - Lesson 1
 

Recently uploaded

HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...Nguyen Thanh Tu Collection
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatYousafMalik24
 
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdfVirtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdfErwinPantujan2
 
Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Celine George
 
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...Postal Advocate Inc.
 
Choosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for ParentsChoosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for Parentsnavabharathschool99
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for BeginnersSabitha Banu
 
4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptxmary850239
 
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdfInclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdfTechSoup
 
Transaction Management in Database Management System
Transaction Management in Database Management SystemTransaction Management in Database Management System
Transaction Management in Database Management SystemChristalin Nelson
 
Integumentary System SMP B. Pharm Sem I.ppt
Integumentary System SMP B. Pharm Sem I.pptIntegumentary System SMP B. Pharm Sem I.ppt
Integumentary System SMP B. Pharm Sem I.pptshraddhaparab530
 
4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptx4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptxmary850239
 
Daily Lesson Plan in Mathematics Quarter 4
Daily Lesson Plan in Mathematics Quarter 4Daily Lesson Plan in Mathematics Quarter 4
Daily Lesson Plan in Mathematics Quarter 4JOYLYNSAMANIEGO
 
Activity 2-unit 2-update 2024. English translation
Activity 2-unit 2-update 2024. English translationActivity 2-unit 2-update 2024. English translation
Activity 2-unit 2-update 2024. English translationRosabel UA
 
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdfGrade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdfJemuel Francisco
 
Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Celine George
 
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptxQ4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptxlancelewisportillo
 

Recently uploaded (20)

HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice great
 
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdfVirtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
 
Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17
 
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
 
Choosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for ParentsChoosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for Parents
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for Beginners
 
4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx
 
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdfInclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
 
Transaction Management in Database Management System
Transaction Management in Database Management SystemTransaction Management in Database Management System
Transaction Management in Database Management System
 
FINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptx
FINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptxFINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptx
FINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptx
 
YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptxYOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
 
Integumentary System SMP B. Pharm Sem I.ppt
Integumentary System SMP B. Pharm Sem I.pptIntegumentary System SMP B. Pharm Sem I.ppt
Integumentary System SMP B. Pharm Sem I.ppt
 
4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptx4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptx
 
Daily Lesson Plan in Mathematics Quarter 4
Daily Lesson Plan in Mathematics Quarter 4Daily Lesson Plan in Mathematics Quarter 4
Daily Lesson Plan in Mathematics Quarter 4
 
Activity 2-unit 2-update 2024. English translation
Activity 2-unit 2-update 2024. English translationActivity 2-unit 2-update 2024. English translation
Activity 2-unit 2-update 2024. English translation
 
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdfGrade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
 
Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17
 
LEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptx
LEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptxLEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptx
LEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptx
 
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptxQ4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
 

TECNOLOGIAS EMERGENTES EM JOGOS DIGITAIS

  • 1. TECNOLOGIAS EMERGENTES EM JOGOS Engenharia em Desenvolvimento de Jogos Digitais - 2013/2014 February 14, 2014 Daniela da Cruz dcruz@ipca.pt
  • 3. C basics C COMMENTS There are two ways to include commentary text in a C program. → Inline comments // This is an inline comment → Block comments /* This is a block comment. It can span multiple lines. */ 3
  • 4. C basics C VARIABLES Variables are containers that can store dierent values. type name the = operator. To declare a variable, you use the to assign a value to it you use syntax, and double odometer = 9200.8; int odometerAsInteger = (int)odometer; 4
  • 5. C basics C CONSTANTS The const variable modier tells to the compiler that a variable is never allowed to change. double const pi = 3.14159; 5
  • 6. C basics C ARITHMETIC The familiar +, -, *, / symbols are used for basic arithmetic operations, and the modulo operator (%) can be used to return the remainder of an integer division. printf(6 printf(6 printf(6 printf(6 printf(6 + * / % 2 2 2 2 2 = = = = = %d, %d, %d, %d, %d, 6 6 6 6 + * / 2); 2); 2); 2); 6 % 2); // 8 // 4 // 12 // 3 // 0 6
  • 7. C basics C ARITHMETIC (2) C also has increment (++) and decrement () operators. These are convenient operators for adding or subtracting 1 from a variable. int i = 0; printf(%d, i); i++; printf(%d, i); i++; printf(%d, i); // 0 // 1 // 2 7
  • 8. C basics C RELATIONAL/LOGICAL OPERATORS The most common relational/logical operators are shown below. Operator a == b Description Equal to !=b b a = b a b a = b Greater than or equal to !a Logical negation a a Not equal to Greater than Less than Less than or equal to a b Logical and || Logical or a b 8
  • 9. C basics C CONDITIONALS C provides the standard if statement found in most programming languages. int modelYear = 1990; if (modelYear 1967) { printf(That car is an antique!!!); } else if (modelYear = 1991) { printf(That car is a classic!); } else if (modelYear == 2014) { printf(That's a brand new car!); } else { printf(There's nothing special about that car.); } 9
  • 10. C basics C CONDITIONALS (2) C also includes a integral types switch statement, however it only works with not oating-point numbers, pointers, or Objective-C objects. switch (modelYear) { case 1987: printf(Your car is from 1987.); break; case 1989: case 1990: printf(Your car is from 1989 or 1990.); break; default: printf(I have no idea when your car was made.); break; } 10
  • 11. C basics C LOOPS The while the related for loops can be used for iterating over values, break and continue keywords let you exit a loop and and prematurely or skip an iteration, respectively. int modelYear = 1990; int i = 0; while (i5) { if (i == 3) { printf(Aborting the while-loop); break; } printf(Current year: %d, modelYear + i); i++; } 11
  • 12. C basics C LOOPS (2) int modelYear = 1990, i; for (i=0; i5; i++) { if (i == 3) { printf(Skipping a for-loop iteration); continue; } printf(Current year: %d, modelYear + i); } 12
  • 13. C basics C TYPEDEF The typedef keyword lets you create new data types or redene existing ones. typedef unsigned char ColorComponent; int main() { ColorComponent red = 255; return 0; } 13
  • 14. C basics C STRUCTS A struct is like a simple, primitive C object. It lets you aggregate several variables into a more complex data structure, but doesn't provide any OOP features (e.g., methods). typedef struct { unsigned char red; unsigned char green; unsigned char blue; } Color; int main() { Color carColor = {255, 160, 0}; printf(Your color is (R: %u, G: %u, B: %u), carColor.red, carColor.green, carColor.blue); return 0; } 14
  • 15. C basics C ENUMS The enum keyword is used to create an enumerated type, which is a collection of related constants. typedef enum { FORD, HONDA, NISSAN, PORSCHE } CarModel; int main() { CarModel myCar = NISSAN; return 0; } 15
  • 16. C basics C ARRAYS The higher-level the NSArray and NSMutableArray classes provided by Foundation Framework are much more convenient than C arrays. int years[4] = {1968, 1970, 1989, 1999}; 16
  • 17. C basics C POINTERS A pointer is a direct reference to a memory address. → The reference operator () returns the memory address of a normal variable. This is how we create pointers. → The dereference operator (*) returns the contents of a pointer's memory address. int year = 1967; int *pointer; pointer = year; printf(%d, *pointer); *pointer = 1990; printf(%d, year); 17
  • 18. C basics C FUNCTIONS There are four components to a C function: its return value, name, parameters, and associated code block. 18
  • 19. C basics C FUNCTIONS Functions need to be dened before they are used. C lets you separate the implementation. → declaration of a function from its A function declaration tells the compiler what the function's inputs and outputs look like. → The corresponding implementation attaches a code block to the declared function. Together, these form a complete function denition. 19
  • 20. C basics C STATIC FUNCTIONS The static keyword let us alter the availability of a function or variable. By default, all functions have a global scope. This means that as soon as we dene a function in one le, it's immediately available everywhere else. The static specier let us limit the function's scope to the current le, which is useful for creating private functions and avoiding naming conicts. 20
  • 21. C basics C STATIC FUNCTIONS (2) File functions.m: // Static function declaration static int getRandomInteger(int, int); // Static function implementation static int getRandomInteger(int minimum, int maximum) { return ((maximum - minimum) + 1) + minimum; } You would not be able to access main.m. getRandomInteger() from Note that the static keyword should be used on both the function declaration and implementation. 21
  • 22. C basics C STATIC VARIABLES Variables declared inside of a function are reset each time the function is called. However, when you use the static modier on a local variable, the function remembers its value across invocations. 22
  • 23. C basics C STATIC VARIABLES (2) int countByTwo() { static int currentCount = 0; currentCount += 2; return currentCount; } int main(int argc, const char * argv[]) { printf(%d, countByTwo()); // 2 printf(%d, countByTwo()); // 4 printf(%d, countByTwo()); // 6 } return 0; 23
  • 24. C basics C STATIC VARIABLES (2) This use of the static keyword does not aect the scope of local variables. Local variables are still only accessible inside of the function itself. 24
  • 25. C basics C SUMMARY We reviewed: → Variables → Conditionals → Loops → Typedef → Struct's → Enum's → Arrays → Pointers → Functions → Static (functions and variables) 25