A Novel Game Programming in DOS

Tags: basic level, graphics library, food, Game Programming, design paper, Basic Input Output System, video mode, hexadecimal code, Drive EXIT, function, Read Only Memory, creating graphics, the snake, linked list, Game Engine, hardware components, current mode, students, Bengal Engineering and Science University, Shibpur, Minimal graphics, standard graphics library, complete game, Ghosal Department, ACKNOWLEDGMENT Department Of Information Technology, Bengal Engineering and Science University, text books, Video Buffer, Snake Food, Alex Russell, Brian Bush
Content: A Novel Game Programming in DOS
Amul Kumar Saha Department of IT Bengal Engineering and Science University, Shibpur [email protected]
Prasun Ghosal Department of IT Bengal Engineering and Science University, Shibpur [email protected]
Abstract- "Game Programming" is a really challenging as well as interesting area for decades to the programmers. This design paper tries to implement a novel game named "Snaek" using graphics at the very basic level. In this game a snake like object automatically man oeuvres on the screen with a resolution 320 Ч 200 pixels on the direction of its head trying to accumulate points by eating randomly placed foods on the screen. The novelty of the design lies in the fact that no standard graphics library has been used throughout the design. Instead the CRT controlling and masking of the keyboard has been done through the program itself. Comparing with the standard graphics library based designs those are very slow in invoking graphics oriented functions this design claims greater flexibility and better speed using interrupts and registers. I. INTRODUCTION "Game Programming" is a really challenging as well as interesting area for decades to the programmers. As a term it sounds very exciting to a youngster, but there is a lot that goes on behind the scene when it comes to making a complete game. It's important for a game to display completeness in form of:- a) Minimal graphics, b) Interaction between user and game, c) Hardware control, d) Implementing a database, and e) Slight Artificial Intelligence The world is experiencing a revolution when it comes to game development. Big enterprises like CAPCOM, EA, etc. have already produced plethora of games. But all these companies started from scratch someday. A game tries to achieve a near reality dynamic environment within a machine. This game tries to do the same by incorporating most basic features of graphics, accuracy, etc. II. brief description This design paper tries to implement a novel game named "Snaek" using graphics at the very basic level. In this game a snake like object automatically man oeuvres on the screen with a resolution 320 Ч 200 pixels on the direction of its head trying
to accumulate points by eating randomly placed foods on the screen. The length of the snake increases with every food that it eats. The game ends the moment it collides with its body. The snake can only change its direction of motion by 90o at a time. III. technical features Main technical features of this design include the followings: a) Using microprocessor interrupts and registers to initialise, execute and exit Video modes. b) Controlling the cathode ray tube (CRT) using the program itself. c) Masking keyboard buttons for allowing only a specific set of keys to work. d) Allowing snake speed calibration on keeping a directional key pressed. e) Not using any graphics library or function because this game requires a high refresh rate on screen. The inbuilt graphics.h library is very slow in invoking its graphics oriented functions. Moreover using interrupts and registers for creating graphics offers:a. Greater flexibility b. Better Speed IV. WORKING A brief outline of the working may be stated as follows: A. data structure 1. One unit of the snake on the screen is represented using a linked list. struct Rectangle { int x; int y; int width; int height; int colour; struct Rectangle *next; }
struct Rectangle *head=null; a) x: location along X axis of the monitor. b) y: location along Y axis of the monitor c) width: number of pixels for showing the width. d) height: number of pixels for showing the height. e) colour: colour for this unit of snake body. f) next: pointer to the next unit of the snake body. next=null; if there is no body part of the snake after this one. It is the tail. g) "head" is allocated a value after the snake initialisation. 2. The whole of the snake is represented as a Singly Linked List of the structure Rectangle. a) Initially just the head of the snake exists, but as and when the snake collides with any food. A signal is returned to the "game engine" which in turn stores the current co-ordinate of a collision with food into an instance of the structure Rectangle and makes it the new head. b) This way the food becomes the new head of the linked list. c) That is, the linked list in this design is implemented in such a manner that it remains frozen from the tail but it grows from the head. B. Graphics In this design the current video mode of the DOS prompt has been changed to the desired video mode (resolution). Reason: It is done because for a screen having lesser resolution the Operating System (OS) can easily allocate the required memory space to the game.
//changing mode in.h.ah=0; in.h.al=mode; int86(VIDADDR,&in,&out); return OK; } int86(int, int*, int*) is the function for executing Read Only Memory Basic Input Output System(ROM BIOS) Calls. 0x10 is the ROM BIOS code for executing Video Routines. We call enter_mode(int ) function with a parameter 0x13, which is the hexadecimal code for our desired video mode. For further information regarding the various ROM BIOS calls and their corresponding results [1] may be used. We have not used graphics.h anywhere in our program and have made use of int86 interrupts very extensively. So understanding the working and behaviour of this function can greatly help the reader while going through this paper. We can read the values (at low level) of various hardware components by using functions like int inportb(int portno). The values at different ports can be extracted by using this function. It takes the input as the port number and brings the output as the value at that port. Using inport function we check the CRT whether it is currently making a vertical retrace or not. The moment we get a true return value, we replace the current memory buffer with our 320 X 200 buffer. This update is constantly done during each time-slice to simulate the movement of the snake on the screen. V. DESIGN FLOWCHARTS The flowchart depicts the overall structuring (control flow) of the game followed by the backbone of the game; its Engine. A. Overall Game Everything in the C language begins with the main() program. So the steps that the main program involves are: 1. Splash Screen
In this design 320 X 200 resolution has been used.
2. Initialize Video Mode
#define VIDADDR 0x10 #define VIDMOD 0x13 int enter_mode(int mode) { //getting current mode and storing it for future restoring in.h.ah=0xf; int86(VIDADDR,&in,&out); PrevMode=out.h.al;
3. Enter Video Mode 4. Drive Management 5. Taking name from the player 6. Initialize keyboard 7. Engine 8. Leave Video Mode
9. De-initialize Keyboard 10. Leave Drive 11. EXIT -> (a timed self-destructing DOS screen) The following flowchart describes the flow of the overall game. START
Splash Screen Enter Video Mode
Drive Management Main Menu
Play Play/Exit Exit Leave Video Mode
Store Player name in File with encryption Leave the Drive
EXIT Figure 1: Flowchart illustrating the primary flow of the overall game
B. Game Engine All Other functions that have been given prior to this are the supportive features that have been added into the game for better performance. However the main algorithm by the virtue of which the game runs lies within the engine part. It again has various sub-routines that are critical to the algorithm. Most of the bugs are generally found in this part of the game. It is a part which defines how each and every action takes place within the game. In other words the better the engine, the better the game.
START yes First Pixel ? no Replace Video Buffer with our buffer. Start Time Slice Time Slice completed AND No head collision detected?
Dynamically Allocate Rectangle say "this"
yes First Pixel ? no
Fix Rectangle colour
Make head point to "this" Rectangle.
no no Collision is NOT with food. yes Store SCORE
Replace food>(x,y).colour=0 in the our buffer. (0 for BLACK) 1. Store the current location of head. 2. Make head point to "this" Rectangle. 3. Make this->next=previous head.
1. Randomly decide the location of food on the screen, update our buffer. 2. Update the buffer with the location of each UNIT of Rectangle.
Retrace of CRT gun?
Figure 2: Flow of the Game Engine
VI. GAME SCREEN SNAPSHOT A snapshot of the game screen looks as follows:
Total food
ACKNOWLEDGMENT Department Of information technology, Bengal Engineering and Science University, Shibpur for encouraging its students to think beyond what is given just in the text books. REFERENCES 1. Brian Bush, Advanced C:Part 1 of 3 http://gd.tuwien.ac.at/languages/c/programming-bbrown/advcw1.htm 2. Alex Russell, DOS Game Programming http://www3.telus.net/alexander_russell/course/introduction.htm

File: a-novel-game-programming-in-dos.pdf
Title: Microsoft Word - EDCC08 A Novel Game Programming in DOS.doc
Author: ThinkCentre
Published: Tue May 20 23:36:54 2008
Pages: 4
File size: 0.14 Mb

Ask the Man Who Owns One, 27 pages, 0.78 Mb

, pages, 0 Mb
Copyright © 2018 doc.uments.com