Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
SFML Game Development.pdf
Скачиваний:
194
Добавлен:
28.03.2016
Размер:
4.19 Mб
Скачать

Table of Contents

Preface

1

Chapter 1: Making a Game Tick

7

Introducing SFML

7

Downloading and installation

8

A minimal example

9

A few notes on C++

10

Developing the first game

12

The Game class

13

Game loops and frames

16

Input over several frames

17

Vector algebra

19

Frame-independent movement

21

Fixed time steps

22

Other techniques related to frame rates

24

Displaying sprites on the screen

24

File paths and working directories

25

Real-time rendering

25

Adapting the code

27

Summary

28

Chapter 2: Keeping Track of Your Textures – Resource

 

Management

29

Defining resources

29

Resources in SFML

30

Textures

31

Images

31

Fonts

32

Shaders

32

Sound buffers

33

www.it-ebooks.info

Table of Contents

Music

33

A typical use case

34

Graphics

34

Audio

35

Acquiring, releasing, and accessing resources

35

An automated approach

36

Finding an appropriate container

37

Loading from files

38

Accessing the textures

39

Error handling

40

Boolean return values

41

Throwing exceptions

41

Assertions

42

Generalizing the approach

43

Compatibility with sf::Music

45

A special case – sf::Shader

45

Summary

47

Chapter 3: Forge of the Gods – Shaping Our World

49

Entities

50

Aircraft

51

Alternative entity designs

52

Rendering the scene

53

Relative coordinates

53

SFML and transforms

54

Scene graphs

55

Scene nodes

55

Node insertion and removal

56

Making scene nodes drawable

58

Drawing entities

61

Connecting entities with resources

61

Aligning the origin

63

Scene layers

64

Updating the scene

64

One step back – absolute transforms

66

The view

67

Viewport

68

View optimizations

68

Resolution and aspect ratio

69

View scrolling

70

Zoom and rotation

71

[ ii ]

www.it-ebooks.info

 

Table of Contents

Landscape rendering

71

SpriteNode

71

Landscape texture

73

Texture repeating

73

Composing our world

74

World initialization

76

Loading the textures

77

Building the scene

78

Update and draw

80

Integrating the Game class

81

The run() method

81

Summary

83

Chapter 4: Command and Control – Input Handling

85

Polling events

86

Window events

87

Joystick events

88

Keyboard events

88

Mouse events

89

Getting the input state in real time

90

Events and real-time input – when to use which

92

Delta movement from the mouse

93

Playing nice with your

 

application neighborhood

94

A command-based communication system

95

Introducing commands

96

Receiver categories

98

Command execution

100

Command queues

101

Handling player input

102

Commands in a nutshell

106

Implementing the game logic

107

A general-purpose communication mechanism

108

Customizing key bindings

109

Why a player is not an entity

111

Summary

112

Chapter 5: Diverting the Game Flow – State Stack

113

Defining a state

113

The state stack

114

Adding states to StateStack

117

Handling updates, input, and drawing

118

[ iii ]

www.it-ebooks.info

Table of Contents

Input

119

Update

119

Draw

119

Delayed pop/push operations

120

The state context

121

Integrating the stack in the Application class

121

Navigating between states

123

Creating the game state

123

The title screen

124

Main menu

125

Pausing the game

128

The loading screen – sample

129

Progress bar

130

ParallelTask

132

Thread

133

Concurrency

133

Task implementation

134

Summary

136

Chapter 6: Waiting and Maintenance Area – Menus

137

The GUI hierarchy, the Java way

138

Updating the menu

146

The promised key bindings

147

Summary

150

Chapter 7: Warfare Unleashed – Implementing Gameplay

151

Equipping the entities

151

Introducing hitpoints

152

Storing entity attributes in data tables

152

Displaying text

154

Creating enemies

156

Movement patterns

156

Spawning enemies

158

Adding projectiles

161

Firing bullets and missiles

163

Homing missiles

167

Picking up some goodies

170

Collision detection and response

173

Finding the collision pairs

174

Reacting to collisions

176

An outlook on optimizations

179

An interacting world

180

Cleaning everything up

180

[ iv ]

www.it-ebooks.info

Table of Contents

Out of view, out of the world

181

The final update

182

Victory and defeat

183

Summary

183

Chapter 8: Every Pixel Counts – Adding Visual Effects

185

Defining texture atlases

186

Adapting the game code

187

Low-level rendering

189

OpenGL and graphics cards

189

Understanding render targets

189

Texture mapping

190

Vertex arrays

191

Particle systems

192

Particles and particle types

193

Particle nodes

194

Emitter nodes

197

Affectors

199

Embedding particles in the world

200

Animated sprites

200

The Eagle has rolled!

204

Post effects and shaders

205

Fullscreen post effects

205

Shaders

208

The bloom effect

208

Summary

215

Chapter 9: Cranking Up the Bass – Music and Sound Effects

217

Music themes

218

Loading and playing

219

Use case – In-game themes

220

Sound effects

221

Loading, inserting, and playing

223

Removing sounds

224

Use case – GUI sounds

224

Sounds in 3D space

225

The listener

226

Attenuation factor and minimum distance

227

Positioning the listener

227

Playing spatial sounds

228

Use case – In-game sound effects

230

Summary

233

[ v ]

www.it-ebooks.info

Table of Contents

Chapter 10: Company Atop the Clouds – Co-op Multiplayer

235

Playing multiplayer games

236

Interacting with sockets

236

TCP

237

UDP

238

Socket selectors

239

Custom protocols

240

Data transport

241

Network architectures

242

Peer-to-peer

242

Client-server architecture

243

Authoritative servers

244

Creating the structure for multiplayer

245

Working with the Server

246

Server thread

246

Server loop

247

Peers and aircraft

248

Hot Seat

250

Accepting new clients

250

Handling disconnections

252

Incoming packets

253

Studying our protocol

256

Understanding the ticks and updates

257

Synchronization issues

258

Taking a peek in the other end – the client

258

Client packets

261

Transmitting game actions via network nodes

261

The new pause state

263

Settings

263

The new Player class

264

Latency

264

Latency versus bandwidth

265

View scrolling compensation

265

Aircraft interpolation

266

Cheating prevention

267

Summary

268

Index

269

[ vi ]

www.it-ebooks.info

Соседние файлы в предмете [НЕСОРТИРОВАННОЕ]