160 likes | 266 Views
Web Games Programming. Game Elements and Generic Content. Agenda. Consider generic features of a computer game Dealing with hardware devices Game scenario and player interest Deployment. Elements: User Input. Capturing application-wide keyboard input
E N D
Web Games Programming Game Elements and Generic Content
Agenda • Consider generic features of a computer game • Dealing with hardware devices • Game scenario and player interest • Deployment
Elements: User Input • Capturing application-wide keyboard input • Capturing keyboard input to a specific object • Capturing application-wide mouse actions • Capturing mouse input to a specific object • Creating drag-and-drop interactivity • Creating a custom mouse cursor (mouse pointer) • Managing focus • Game controller input support • Feedback device support
Elements: Visuals and Sound • Visuals - Game World viewpoint • 2D - Side View or Top Down (Static, Scrolling) - e.g. PacMan, Frogger static topdown, Defender, Sonic - side view - scrolling. Finite game world or infinite. • 3D Simulated or Real time - simulated (Isometric, changing scenes)Flash-base 3D (Papervision API, Starling API) • Sound - Audio and Music • Music = MIDI generated sound, Audio = digital sound • Sound ‘candy’ at start of game, between levels, game over • Ambient sounds • Sprite sounds • Event sounds
Elements:Maths,Physics and AI • Maths and Physics • Maths - calculating the distance between objects and points, collisions, rotations, movement around the game world using geometry and trigonometry, based on known theorems (Pythagoras) and rules - sine and cosine of angles (radians) - random integers for logic / state control, real values for probabilities. • Physics - reaction to collisions - motion under gravity (or not), speed, acceleration, velocity, friction, inertia. Some plug-ins available which provide physics properties e.g Ageia PhysX (Shockwave 3D and Unity 3D) • Artificial Intelligence • Simulated AI - tracking and evasion algorithms, patterns, finite state structures, fuzzy logic • Path finding algorithms (A*) flocking and swarming algorithms
Game Setup and Launch • Set the Graphics Device (Poll hardware - get the best available screen resolution mode(s) - user decides) • Set the Sound Devices (Audio, MIDI, set levels - user) • Set Input Devices (Keyboard, mouse, joystick, controller) • Run the game intro and credits • User configuration - load last game state if available • Launch the game • while (runTheGameIsTrue){ // main game loop • setTimer • getPlayerInput • setSprites, applyAI, doCollisionDetection, addPhysics • renderFrameToBuffer • renderBufferToScreen • // end while (player wins/loses/quits) • Game Over - rerun save and or exit
Device Handling (DirectX) Code fragment copied straight out of SimpleSample.cpp (Direct3D DirectX 9.0 SDK) • bool CALLBACK IsDeviceAcceptable( D3DCAPS9* pCaps, D3DFORMAT AdapterFormat, • D3DFORMAT BackBufferFormat, bool bWindowed, void* pUserContext ) • { • // Skip backbuffer formats that don't support alpha blending • IDirect3D9* pD3D = DXUTGetD3DObject(); • if( FAILED( pD3D->CheckDeviceFormat( pCaps->AdapterOrdinal, pCaps->DeviceType, • AdapterFormat, D3DUSAGE_QUERY_POSTPIXELSHADER_BLENDING, • D3DRTYPE_TEXTURE, BackBufferFormat ) ) ) • return false; • return true; • }
Device Handling (Java) • public DisplayMode[] getCompatibleDisplayModes() { • return device.getDisplayModes(); • } • /** • Returns the first compatible mode in a list of modes. • Returns null if no modes are compatible. • */ • public DisplayMode findFirstCompatibleMode( • DisplayMode modes[]) • { • DisplayMode goodModes[] = device.getDisplayModes(); • for (int i = 0; i < modes.length; i++) { • for (int j = 0; j < goodModes.length; j++) { • if (displayModesMatch(modes[i], goodModes[j])) { • return modes[i]; • } • } • } • return null; • }
Device Handling (C#) • /** Code fragment from SpaceWar (SceneGraph.cs) Microsoft XNA Framework • public Screen(Game game) • { • this.game = game; • this.scene = new SceneItem(game); • if (game != null) • { • IGraphicsDeviceService graphicsService = (IGraphicsDeviceService)game.Services.GetService(typeof(IGraphicsDeviceService)); • batch = new SpriteBatch(graphicsService.GraphicsDevice); • } • }
ActionScript 3.0 Graphics Device Poll • Not required...Phew! • Flash comes with a ready-to-go graphics / animation engine • Just need to think about the screen resolution appropriate for a browser-based audience • ActionScript 3.0 has a Stage class that acts as a top level container for other container objects such as sprites
Game Play: Getting the Right Balance Game Play Success and Progression Challenges / Difficulty
Game Play:Boredom Challenges / Difficulty Game Play Success and Progression
Game Play: Frustration Game Play Success and Progression Challenges / Difficulty
Game Play: Vary the Balance Game Play Success and Progression Challenges / Difficulty Make early levels easy to encourage progression Provide game entry points - novice, expert etc.
Elements of a Computer Game • Visuals • Sound • Action • Input • Objectives / Challenges • Time Limits • Levels / Progression with Rising Difficulty • Scoring • Saving Game State • Addictive Quality - the hardest thing to code - more about artistry and ideas!
Game Deployment • How will your game be accessed? • CD / DVD (localised) • Network Play • Mobile Device - Smart Phone, Tablet • Web All will have deployment considerations which must balance game sophistication with technical constraints of device and / or network bandwidth