Beginning: C-Amendments and Prologue to Illustrations.


78 views
Uploaded on:
Description
Next: Reproduction Essentials, Memory Taking care of Beginning: C-Corrections and Prologue to Design 159.234 Components of the Tank Diversion Ordering your project Subjects for Exchange Basic Activity Twofold buffering system Console taking care of Mouse taking care of Demo Tank Amusement 159.234
Transcripts
Slide 1

Next: Simulation Essentials, Memory Handling Getting Started: C-Revisions and Introduction to Graphics

Slide 2

159.234 Elements of the Tank Game Compiling your system Topics for Discussion Simple Animation Double-buffering procedure Keyboard taking care of Mouse taking care of Demo

Slide 3

Tank Game

Slide 4

159.234 Graphics Engine Keyboard & mouse control Elements of the Game Physics Engine Dynamic Memory taking care of Objects: Tank, Alien, Bomb, Bullet, Wall, Ledge Transformation Equations, Zooming components Trigonometric Equations

Slide 5

Demo C:\Core\Massey Papers\159234\Animation-2008-v.4.0 C:\Core\Massey Papers\159234\Bomb-v.1.0 C:\Core\Massey Papers\159234\Bomb-v.11.0 C:\Core\Massey Papers\159234\TankGame-2008-v.1.0 C:\Core\Massey Papers\159234\Assignments\Samples\A1-06193242-Sample\Tank 2.0 Why resort to composing codes utilizing the Object-Oriented methodology?

Slide 6

What would you be able to notice here? if(clock() > detonationTime){ for(int i=0; i < tally; i++){ //Note: annex Tank\'s x and y-parts Wx = Xdev(WBound,DBound,x(obj[i].t,obj[i].vO, obj[i].theta) + TankX); Wy = Ydev(WBound,DBound,y(obj[i].t,obj[i].vO, obj[i].theta) + TankY); setlinestyle(SOLID_LINE, 0, 1); fillellipse(Wx,Wy,Xdev(WBound,DBound,3.0),Xdev(WBound,DBound,3.0)); obj[i].t=obj[i].t + obj[i].tInc; } t=t+tinc; }

Slide 7

What about here? for(int i=0; i < numOfBombs; i++){ b[i].activate(); b[i].tick(tfm); b[i].draw(tfm); }

Slide 8

159.234 C-LANGUAGE STRUCTURE/* incorporate articulations */#include <stdio.h> #include <string.h>/* characterize proclamations */#define MAX 2000/* capacity models */void subfunc(int contention);/* worldwide variables */int i, j; roast c; coast x,y; burn s[80];/* capacities */void subfunc(int contention) { int i;/* nearby variables */explanations ... }/* principle program */int primary() { proclamations... } C-Programming Revisions

Slide 9

159.234 MAKEFILE (for JFE ) Turn on all the notice messages conceivable Compiling your Program MyProg.exe : MyProg.o graphics.o gcc - wl ,- s - o MyProg.exe MyProg.o graphics.o MyProg.o : MyProg.cpp graphics.h gcc - c - fpermissive - fconserve-space MyProg.cpp graphics.o : graphics.cpp graphics.h gcc - c - fpermissive - fconserve-space graphics.cpp Should begin with a tab This is the base prerequisite for gathering.

Slide 10

159.234 WORKSPACE (JFE) Graphics Project MYPROG.CPP GRAPHICS.CPP GRAPHICS.H MAKEFILE GAME.WSP

Slide 11

159.234 MAKEFILE (for scite ) Compiling your Program MyProg.exe : MyProg.o graphics.o g++ - wl ,- s - o MyProg.exe MyProg.o graphics.o MyProg.o : MyProg.cpp graphics.h g++ - c - fpermissive - fconserve - space MyProg.cpp graphics.o : graphics.cpp graphics.h g++ - c - fpermissive - fconserve - space graphics.cpp This is the base prerequisite for assemblage.

Slide 12

All must live in the same organizer Makefile graphics.cpp MyProg.cpp physics.cpp graphics.h physics.h It’s better to place classes in discrete documents. The cpp record will incorporate the capacity Implementations, while the header document ( *.h ) will incorporate the capacity models and the class definition.

Slide 13

159.234 MAKEFILE (for scite) MyProg.exe : MyProg.o transform.o fuzzylogic.o physics.o bomb.o graphics.o g++ - Wl,- s - o MyProg.exe MyProg.o transform.o fuzzylogic.o physics.o bomb.o graphics.o MyProg.o : MyProg.cpp graphics.h transform.h fuzzylogic.h bomb.h gameDef.h g++ - c - fpermissive - fconserve-space MyProg.cpp transform.o : transform.cpp transform.h g++ - c - fpermissive - fconserve-space transform.cpp fuzzylogic.o : fuzzylogic.cpp fuzzylogic.h g++ - c - fpermissive - fconserve-space fuzzylogic.cpp physics.o : physics.cpp physics.h g++ - c - fpermissive - fconserve-space physics.cpp bomb.o : bomb.cpp bomb.h g++ - c - fpermissive - fconserve-space bomb.cpp graphics.o : graphics.cpp graphics.h g++ - c - fpermissive - fconserve-space graphics.cpp Incorporating more documents...

Slide 14

159.234 INITIALIZING GRAPHICS #include <windows.h> #include <stdio.h> #include <math.h> #include <time.h> #include "graphics.h" int main(void) { srand(time(NULL));/Seed the arbitrary number generator int GraphDriver=0,GraphMode=0; initgraph(&GraphDriver, &GraphMode, "", 1280, 1024 ); TankGame();/begin the amusement – this is client characterized capacity return 0; } C-Programming Revisions User-characterized, observe the twofold quotes.

Slide 15

159.234 Single Page Animation ( flickery ! ) void SinglePage() { int i; int x,y; cleardevice(); y=getmaxy()/2; while( (GetAsyncKeyState(VK_ESCAPE))==0 ) for(x=0;x<getmaxx();x++) { if(GetAsyncKeyState(VK_ESCAPE) != 0) break; setactivepage(0); cleardevice(); setfillstyle(SOLID_FILL,RED); fillellipse(x,y,12,12); rectangle(x,y+(getmaxy()/12),x+100,y+(getmaxy()/11)); settextjustify(CENTER_TEXT, CENTER_TEXT); settextstyle(TRIPLEX_FONT, HORIZ_DIR, 4); outtextxy(getmaxx()/2,getmaxy()/8,"PAGE 0"); } Simple Animation Check if the ESC key has been squeezed

Slide 16

Demo C:\Core\Massey Papers\159234\TankGame-2008-v.1.0 See SinglePage and twofold buffering livelinesss

Slide 17

159.234 Double-buffering Animation ( glint free ! ) void MultiplePages() { int i, x, y; bool PageFlag=TRUE; setactivepage(1); cleardevice(); outtext("PAGE 1"); setvisualpage(1); y=getmaxy()/2; while( (GetAsyncKeyState(VK_ESCAPE))==0 ) for(x=0;x<getmaxx();x++) { if(GetAsyncKeyState(VK_ESCAPE) != 0) break; if (PageFlag) { setactivepage(0); cleardevice(); setfillstyle(SOLID_FILL,RED); fillellipse(x,y,12,12); rectangle(x,y+(getmaxy()/12),x+100,y+(getmaxy()/11)); settextjustify(CENTER_TEXT, CENTER_TEXT); settextstyle(TRIPLEX_FONT, HORIZ_DIR, 4); outtextxy(getmaxx()/2,getmaxy()/8,"PAGE 0"); setvisualpage(0); } Simple Animation Continued...

Slide 18

159.234 Double-buffering Animation ( gleam free! ) void MultiplePages() { ... while( (GetAsyncKeyState(VK_ESCAPE))==0 ) for(x=0;x<getmaxx();x++) { if(GetAsyncKeyState(VK_ESCAPE) != 0) break; if (PageFlag) { ... } else { setactivepage(1); cleardevice(); setfillstyle(SOLID_FILL,RED); fillellipse(x,y,12,12); rectangle(x,y+(getmaxy()/12),x+100,y+(getmaxy()/11)); settextjustify(CENTER_TEXT, CENTER_TEXT); settextstyle(TRIPLEX_FONT, HORIZ_DIR, 4); outtextxy(getmaxx()/2,getmaxy()/8,"PAGE 1"); setvisualpage(1); } if(mousedown()) { } PageFlag=!PageFlag; } C-Programming Revisions

Slide 19

159.234 void cleardevice (void); cleardevice eradicates (that is, loads with the present foundation shading) the whole representation screen and moves the CP (current position) to home (0,0). Design Functions 0 +x e.g. 1280 x 1024 pixels (X Device ,Y Device ) +y Device System of Coordinates

Slide 20

159.234 int getmaxx (void); int getmaxy (void); Maximum Boundaries outtextxy(getmaxx()/2, getmaxy()/2, “Graphics"); (0,0) Graphics (getmaxx(), getmaxy())

Slide 21

159.234 DISPLAYING TEXT Graphics Functions See graphics.h for more choices setcolor(YELLOW); settextstyle(DEFAULT_FONT, HORIZ_DIR, 3); settextjustify(CENTER_TEXT, CENTER_TEXT); outtextxy(200, 300, “Graphics");

Slide 22

Demo C:\Core\Massey Papers\159234\TankGame-2008-v.1.0 See GraphicsDemo ()

Slide 23

159.234 DISPLAYING TEXT scorch mx[80]; glide N; sprintf(mx,"%d",mousecurrentx()); moveto(105, 224); outtext(mx); N=4.5; sprintf(mx,"%3.2f", N); outtextxy(100, 250, mx); Graphics Functions Get mouse current x - position

Slide 24

159.234 DISPLAYING TEXT void settextstyle (int textual style, int bearing, int charsize); Graphics Functions

Slide 25

159.234 DISPLAYING TEXT void settextjustify (int horiz, int vert); Graphics Functions

Slide 26

159.234 int textheight (burn *textstring); int textwidth (roast *textstring); Text Height, Text Width Use textheight to figure the stature of strings, rather than doing the calculations physically. By utilizing this capacity, no source code alterations must be made when distinctive textual styles are chosen

Slide 27

159.234 int mousecurrentx(); int mousecurrenty(); int whichmousebutton(); LEFT_BUTTON RIGHT_BUTTON bool mouseup(); bool mousedown(); void clearmouse(); Mouse Routines

Slide 28

159.234 void deferral (int millisec); the time allotment to rest in milliseconds. Presenting Delay delay(50); Sleep(100);

Slide 29

159.234 void setcolor (int shading); Sets the content, line, circle, rectangle, oval, circular segment hues Affects diagram shade of every single filled shape Setting the Color setcolor(RED); setcolor(50);/From 0 to 64

Slide 30

159.234 void setlinestyle (int linestyle, unsigned upattern, int thickness); Line Style thickness determines whether the width of resulting lines drawn will be ordinary or thick.

Slide 31

159.234 void rectangle (int left, int top, int right, int base); Rectangle

Slide 32

159.234 void setfillstyle (int design, int shading); Pattern: EMPTY_FILL, SOLID_FILL, LINE_FILL, LTSLASH_FILL, SLASH_FILL, BKSLASH_FILL, LTBKSLASH_FILL, HATCH_FILL, XHATCH_FILL, INTERLEAVE_FILL, WIDE_DOT_FILL, CLOSE_DOT_FILL, USER_FILL Fill Style Affects filled-shapes

Slide 33

159.234 void bar (int left, int top, int right, int ba

Recommended
View more...