VC and SDL compilation of flight shooting games

Source: Internet
Author: User

I got up early in the morning and didn't go to class. I felt boring. It was also a bio-chemistry class. I was so tired that I could just enrich my life, it took a day to Use SDL to write a flying shooting game, which should have been played by everyone.

# Include <iostream> <br/> # include "SDL/SDL. H "<br/> # include" windows. H "<br/> # include" time. H "<br/> # include" math. H "<br/> using namespace STD; <br/> sdl_surface * screen; <br/> sdl_surface * PB1; // map your plane <br/> sdl_surface * PBS; // enemy texture <br/> sdl_surface * PB3; // bullet texture <br/> sdl_surface * pb4; // enemy bullet texture <br/> struct P1 {// enemy plane <br/> sdl_rect R; <br/> P1 * Previous; <br/> P1 * next; <br/>}; <br/> struct PP1 {// bullet <br/> SDL _ Rect R; <br/> PP1 * Previous; <br/> PP1 * Next; <br/> }; <br/> struct PP2 {// enemy bullet <br/> sdl_rect R; <br/> int X; <br/> int y; <br/> PP2 * Previous; <br/> PP2 * Next; <br/>}; <br/> P1 * p1s = 0, * p1e = 0; <br/> PP1 * pp1s = 0, * pp1e = 0; <br/> PP2 * pp2s = 0, * pp2e = 0; <br/> sdl_rect P; <br/> int T1 = 0; <br/> int t2 = 0; <br/> int T3 = 0; <br/> int big = 0; <br/> int C = 0; <br/> char text [50]; <br/> int main (INT argc, char * argv []) {<br/> srand (tim E (0); <br/> sdl_init (sdl_init_everything); <br/> atexit (sdl_quit); </P> <p> screen = sdl_setvideomode (640,480, 32, sdl_swsurface); <br/> PB1 = sdl_loadbmp ("D: // 1.bmp"); <br/> PBS = sdl_loadbmp ("D: // 2.bmp "); <br/> PB3 = sdl_loadbmp ("D: // 3.bmp"); <br/> pb4 = sdl_loadbmp ("D: // 4.bmp"); <br/> P. X = 320; <br/> P. y = 450; <br/> while (1) {</P> <p> sdl_event E; <br/> uint8 * Key = sdl_getkeystate (0 ); <br/> If (Key [sdlk_up]) {<br/> If (P. y-10> = 0) <br/> P. y-= 10; <br/>}< br/> If (Key [sdlk_down]) {<br/> If (P. Y + 10 + 30 <= 480) <br/> P. Y + = 10; <br/>}< br/> If (Key [sdlk_left]) {<br/> If (P. x-10 & gt; = 0) <br/> P. x-= 10; <br/>}< br/> If (Key [sdlk_right]) {<br/> If (P. X + 30 + 10 <= 640) <br/> P. X + = 10; <br/>}< br/> If (Key [sdlk_space]) {<br/> If (big <5) {<br/> big ++; <br/> int X1 = P. x-40; <br/> int X2 = P. X + 70; <br/> P1 * T1 = p1s; <br/> while (T1) {<br/> If (T1-> r. x> x1-30 & T1-> r. x <X2) {<br/> C ++; <br/> If (p1s = p1e) {<br/> If (p1s) {<br/> Delete p1s; <br/> p1s = 0; <br/> p1e = 0; <br/>}< br/> else if (T1 = p1s) {<br/> P1 * t = T1; <br/> T-> next-> previous = 0; <br/> p1s = T-> next; <br/> Delete t; <br/> T1 = p1s; <br/> continue; <br/>} else if (T1 = p1e) {<br/> P1 * t = T1; <br/> T-> previous-> next = 0; <br/> p1e = T-> previous; <br/> Delete t; <br/> T1 = 0; <br/> continue; <br/>}else {<br/> P1 * t = T1; <br/> T-> previous-> next = T-> N EXT; <br/> T-> next-> previous = T-> previous; <br/> T1 = T-> next; <br/> Delete T; <br/> continue; <br/>}< br/> T1 = T1-> next; <br/>}< br/> PP2 * t2 = pp2s; <br/> while (T2) {<br/> If (T2-> r. x> x1-10 & t2-> r. x <X2) {<br/> If (pp2s = pp2e) {<br/> If (pp2s) {<br/> Delete pp2s; <br/> pp2s = 0; <br/> pp2e = 0; <br/>}< br/> else if (t2 = pp2s & T2! = Pp2e) {<br/> PP2 * t = t2; <br/> T-> next-> previous = 0; <br/> pp2s = T-> next; <br/> Delete t; <br/> T2 = pp2s; <br/> continue; <br/>} else if (t2 = pp2e) {<br/> PP2 * t = t2; <br/> T-> previous-> next = 0; <br/> pp2e = T-> previous; <br/> Delete t; <br/> T2 = 0; <br/> continue; <br/>}else {<br/> PP2 * t = t2; <br/> T-> previous-> next = T-> next; <br/> T-> next-> previous = T-> previous; <br/> T2 = T-> next; <br/> Delete t; <br/> continue; <br/>}< br/> T2 = t2-> next; <br/>}< br/> sdl_rect RR; <br/> RR. X = x1; <br/> RR. W = x2-x1; <br/> RR. y = 0; <br/> RR. H = 480; <br/> sdl_fillrect (screen, & RR, sdl_maprgb (screen-> Format, 200,200,200); <br/> sdl_flip (screen ); <br/> sdl_delay (1000); <br/>}< br/> while (sdl_pollevent (& E )) {</P> <p> switch (E. type) {<br/> case sdl_keyup: <br/> If (E. key. keysym. sym = sdlk_escape) {<br/> return 0; <br/>}< br/> break; <br/> case sdl_quit: <br/> return 0; <br/> break; </P> <p >}< br/> sdl_delay (50); <br/> If (T1> 800) {<br/> If (p1s) {<br/> P1 * TP1 = new P1; <br/> TP1-> next = NULL; <br/> TP1-> previous = p1e; <br/> TP1-> r. y = 0; <br/> TP1-> r. X = rand () % 610/10*10; <br/> p1e-> next = TP1; <br/> p1e = TP1; <br/>} else {<br/> P1 * TP1 = new P1; <br/> TP1-> next = NULL; <br/> TP1-> previous = NULL; <br/> TP1-> r. y = 0; <br/> TP1-> r. X = rand () % 610/10*10; <br/> p1s = TP1; <br/> p1e = TP1; <br/>}< br/> T1 = 0; <br/>}else {<br/> T1 + = 50; <br/>}< br/> If (T2> 400) {<br/> If (pp1s) {<br/> PP1 * tpp1 = new PP1; <br/> tpp1-> next = NULL; <br/> tpp1-> previous = pp1e; <br/> tpp1-> r. y = P. y; <br/> tpp1-> r. X = P. X + 10; <br/> pp1e-> next = tpp1; <br/> pp1e = tpp1; <br/>} else {<br/> PP1 * tpp1 = new PP1; <br/> tpp1-> next = NULL; <br/> tpp1-> previous = NULL; <br/> tpp1-> r. y = P. y; <br/> tpp1-> r. X = P. X + 10; <br/> pp1s = tpp1; <br/> pp1e = tpp1; <br/>}< br/> T2 = 0; <br/>}else {<br/> T2 + = 40; <br/>}< br/> If (T3> 2000) {<br/> P1 * t = p1s; <br/> while (t) {<br/> If (pp2s) {<br/> PP2 * tpp2 = new PP2; <br/> tpp2-> next = NULL; <br/> tpp2-> previous = pp2e; <br/> tpp2-> r. y = T-> r. Y + 20; <br/> tpp2-> r. X = T-> r. X + 10; <br/> int A = SQRT (POW (ABS (P. x-tpp2-> r. x), 2) + POW (ABS (P. y-tpp2-> r. y), 2); <br/> tpp2-> X = 10 * (P. x-tpp2-> r. x) * 1.0/a); <br/> tpp2-> Y = 10 * (P. y-tpp2-> r. y) * 1.0/a); <br/> // cout <p. x-tpp2-> r. x <"" <p. y-tpp2-> r. Y <"" <A <Endl; <br/> pp2e-> next = tpp2; <br/> pp2e = tpp2; <br/>} else {<br/> PP2 * tpp2 = new PP2; <br/> tpp2-> next = NULL; <br/> tpp2-> previous = NULL; <br/> tpp2-> r. y = T-> r. Y + 20; <br/> tpp2-> r. X = T-> r. X + 10; <br/> int A = SQRT (POW (ABS (P. x-tpp2-> r. x), 2) + POW (ABS (P. y-tpp2-> r. y), 2); <br/> tpp2-> X = 10 * (P. x-tpp2-> r. x) * 1.0/a); <br/> tpp2-> Y = 10 * (P. y-tpp2-> r. y) * 1.0/a); <br/> pp2s = tpp2; <br/> pp2e = tpp2; <br/>}< br/> T = T-> next; <br/>}< br/> T3 = 0; <br/>} else {<br/> T3 + = 50; <br/>}< br/> sdl_fillrect (screen, 0, sdl_maprgb (screen-> Format, 0, 0); <br/> sdl_blitsurface (PB1, 0, screen, & P); <br/> P1 * p1t = p1s; <br/> while (p1t) {<br/> If (P. x> = p1t-> r. X & P. x <p1t-> r. X + 30 & P. y> = p1t-> r. Y & P. Y <p1t-> r. Y + 30) {<br/> MessageBox (0, text, 0, 0); <br/> return 0; <br/>}< br/> If (P. X + 30> = p1t-> r. X & P. X + 30 <p1t-> r. X + 30 & P. y> = p1t-> r. Y & P. Y <p1t-> r. Y + 30) {<br/> MessageBox (0, text, 0, 0); <br/> return 0; <br/>}< br/> If (P. x> = p1t-> r. X & P. x <p1t-> r. X + 30 & P. Y + 30> = p1t-> r. Y & P. Y + 30 <p1t-> r. Y + 30) {<br/> MessageBox (0, text, 0, 0); <br/> return 0; <br/>}< br/> If (P. X + 30> = p1t-> r. X & P. X + 30 <p1t-> r. X + 30 & P. Y + 30> = p1t-> r. Y & P. Y + 30 <p1t-> r. Y + 30) {<br/> MessageBox (0, text, 0, 0); <br/> return 0; <br/>}< br/> p1t-> r. Y + = 5; <br/> If (p1t-> r. y> = 480) {<br/> If (p1s = p1e) {<br/> If (p1s) {<br/> Delete p1s; <br/> p1s = 0; <br/> p1e = 0; <br/>}< br/> else if (p1t = p1s) {<br/> P1 * t = p1t; <br/> T-> next-> previous = 0; <br/> p1s = T-> next; <br/> Delete t; <br/> p1t = p1s; <br/> continue; <br/>} else if (p1t = p1e) {<br/> P1 * t = p1t; <br/> T-> previous-> next = 0; <br/> p1e = T-> previous; <br/> Delete t; <br/> p1t = 0; <br/> continue; <br/>} else {<br/> P1 * t = p1t; <br/> T-> previous-> next = T-> next; <br/> T-> next-> previous = T-> previous; <br/> p1t = T-> next; <br/> Delete t; <br/> continue; <br/>}< br/> sdl_blitsurface (PBS, 0, screen, & p1t-> r); <br/> p1t = p1t-> next; <br/>}< br/> PP1 * pp1t = pp1s; <br/> while (pp1t) {<br/> P1 * p1t = p1s; <br/> while (p1t) {<br/> If (pp1t-> r. x> = p1t-> r. X & pp1t-> r. x <p1t-> r. X + 30 & pp1t-> r. y> = p1t-> r. Y & pp1t-> r. Y <p1t-> r. Y + 30) | (pp1t-> r. X + 10> = p1t-> r. X & pp1t-> r. X + 10 <p1t-> r. X + 30 & pp1t-> r. y> = p1t-> r. Y & pp1t-> r. Y <p1t-> r. Y + 30) | (pp1t-> r. x> = p1t-> r. X & pp1t-> r. x <p1t-> r. X + 30 & pp1t-> r. Y + 10> = p1t-> r. Y & pp1t-> r. Y + 10 <p1t-> r. Y + 30) | (pp1t-> r. X + 10> = p1t-> r. X & pp1t-> r. X + 10 <p1t-> r. X + 30 & pp1t-> r. Y + 10> = p1t-> r. Y & pp1t-> r. Y + 10 <p1t-> r. Y + 30) {<br/> C ++; <br/> If (pp1s = pp1e) {<br/> If (pp1s) {<br/> Delete pp1s; <br/> pp1s = 0; <br/> pp1e = 0; <br/>}< br/> elseif (pp1t = pp1s) {<br/> PP1 * t = pp1t; <br/> T-> next-> previous = 0; <br/> pp1s = T-> next; <br/> Delete t; <br/> pp1t = pp1s; </P> <p >}else if (pp1t = pp1e) {<br/> PP1 * t = pp1t; <br/> T-> previous-> next = 0; <br/> pp1e = T-> previous; <br/> Delete t; <br/> pp1t = pp1e; </P> <p >}else {<br/> PP1 * t = pp1t; <br/> T-> previous-> next = T-> next; <br/> T-> next-> previous = T-> previous; <br/> pp1t = T-> next; <br/> Delete T; </P> <p >}< br/> If (p1s = p1e) {<br/> If (p1s) {<br/> Delete p1s; <br/> p1s = 0; <br/> p1e = 0; <br/>}< br/> else if (p1t = p1s) {<br/> P1 * t = p1t; <br/> T-> next-> previous = 0; <br/> p1s = T-> next; <br/> Delete t; <br/> p1t = p1s; <br/> break; <br/>} else if (p1t = p1e) {<br/> P1 * t = p1t; <br/> T-> previous-> next = 0; <br/> p1e = T-> previous; <br/> Delete t; <br/> p1t = 0; <br/> break; <br/>} else {<br/> P1 * t = p1t; <br/> T-> previous-> next = T-> next; <br/> T-> next-> previous = T-> previous; <br/> p1t = T-> next; <br/> Delete t; <br/> break; <br/>}</P> <p >}< br/> p1t = p1t-> next; <br/>}< br/> pp1t-> r. y-= 5; <br/> If (pp1t-> r. Y <= 0) {<br/> If (pp1s = pp1e) {<br/> If (pp1s) {<br/> Delete pp1s; <br/> pp1s = 0; <br/> pp1e = 0; <br/>}< br/> elseif (pp1t = pp1s) {<br/> PP1 * t = pp1t; <br/> T-> next-> previous = 0; <br/> pp1s = T-> next; <br/> Delete t; <br/> pp1t = pp1s; <br/> continue; <br/>} else if (pp1t = pp1e) {<br/> PP1 * t = pp1t; <br/> T-> previous-> next = 0; <br/> pp1e = T-> previous; <br/> Delete t; <br/> pp1t = 0; <br/> continue; <br/>} else {<br/> PP1 * t = pp1t; <br/> T-> previous-> next = T-> next; <br/> T-> next-> previous = T-> previous; <br/> pp1t = T-> next; <br/> Delete t; <br/> continue; <br/>}< br/> sdl_blitsurface (PB3, 0, screen, & pp1t-> r); <br/> pp1t = pp1t-> next; <br/>}< br/> PP2 * pp2t = pp2s; <br/> while (pp2t) {<br/> If (pp2t-> r. x> = P. X & pp2t-> r. x <p. X + 30 & amp; pp2t-> r. y> = P. Y & pp2t-> r. Y <p. Y + 30) | (pp2t-> r. X + 10> = P. X & pp2t-> r. X + 10 <p. X + 30 & amp; pp2t-> r. y> = P. Y & pp2t-> r. Y <p. Y + 30) | (pp2t-> r. x> = P. X & pp2t-> r. x <p. X + 30 & amp; pp2t-> r. Y + 10> = P. Y & pp2t-> r. Y + 10 <p. Y + 30) | (pp2t-> r. X + 10> = P. X & pp2t-> r. X + 10 <p. X + 30 & amp; pp2t-> r. Y + 10> = P. Y & pp2t-> r. Y + 10 <p. Y + 30) {<br/> MessageBox (0, text, 0, 0); <br/> return 0; <br/>}< br/> pp2t-> r. Y + = pp2t-> Y; <br/> pp2t-> r. X + = pp2t-> X; <br/> If (pp2t-> r. Y <= 0 | pp2t-> r. y> = 480 | pp2t-> r. x <= 0 | pp2t-> r. X >=640) {<br/> If (pp2s = pp2e) {<br/> If (pp2s) {<br/> Delete pp2s; <br/> pp2e = 0; <br/> pp2s = 0; <br/>}< br/> else if (pp2t = pp2s) {<br/> PP2 * t = pp2t; <br/> T-> next-> previous = 0; <br/> pp2s = T-> next; <br/> Delete t; <br/> pp2t = pp2s; <br/> continue; <br/>} else if (pp2t = pp2e) {<br/> PP2 * t = pp2t; <br/> T-> previous-> next = 0; <br/> pp2e = T-> previous; <br/> Delete t; <br/> pp2t = 0; <br/> continue; <br/>} else {<br/> PP2 * t = pp2t; <br/> T-> previous-> next = T-> next; <br/> T-> next-> previous = T-> previous; <br/> pp2t = T-> next; <br/> Delete t; <br/> continue; <br/>}< br/> sdl_blitsurface (pb4, 0, screen, & pp2t-> r); <br/> pp2t = pp2t-> next; <br/>}< br/> sprintf (text, "Destroy % d", c); <br/> sdl_wm_setcaption (text, 0 ); <br/> sdl_flip (screen); <br/>}< br/> return 0; <br/>} 

There is nothing to say, It is boundary judgment, and the code is somewhat lengthy. Don't laugh.

I have been working on SDL recently and found that SDL is really a good thing to write graphics, so I have the opportunity to take a deeper look. (I only use the tip of the iceberg)

If you have any shortcomings in this article, I hope you can correct them more.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.