Guest User

Untitled

a guest
Jan 12th, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 13.77 KB | None | 0 0
  1. ;
  2. ; ****************************************************************
  3. ; * * * * * * * * * * * * * * * * * * * * * *
  4. ; Zombie_Survivor * * * * * * * * * * * * * * * * * * * * *
  5. ; * * * * * * * * * * * * * * * * * * * * *
  6. ; ****************************************************************
  7.  
  8. ; Initialization of all the used ressources
  9. ;
  10.  
  11. If InitSprite() = 0 Or InitKeyboard() = 0 Or InitMouse() =0
  12. MessageRequester("Error", "Can't open DirectX 7 or later", 0)
  13. End
  14. EndIf
  15.  
  16.  
  17. If InitSound() = 0
  18. MessageRequester("Error", "Can't open DirectX 7 Or Sound Card is not present", 0)
  19. End
  20. EndIf
  21.  
  22.  
  23. ; Our bullet structure, which will be used by the linkedlist Bullet()
  24. Structure Bullet
  25. x.w
  26. y.w
  27. Width.w
  28. Height.w
  29. Image.w
  30. SpeedX.w
  31. SpeedY.w
  32. EndStructure
  33.  
  34. Global NewList Bullet.Bullet()
  35.  
  36.  
  37. Structure Explosion
  38. x.w
  39. y.w
  40. State.w
  41. Delay.w
  42. EndStructure
  43.  
  44. Global NewList Explosion.Explosion()
  45.  
  46.  
  47. Structure Alien
  48. x.w
  49. y.w
  50. Width.w
  51. Height.w
  52. Speed.w
  53. StartImage.w
  54. EndImage.w
  55. ImageDelay.w
  56. NextImageDelay.w
  57. ActualImage.w
  58. Armor.w
  59. EndStructure
  60.  
  61. Global NewList Aliens.Alien()
  62.  
  63.  
  64. Procedure AddBullet(Sprite, x, y, SpeedX, SpeedY)
  65. AddElement(Bullet())
  66. Bullet()\x = x
  67. Bullet()\y = y
  68. Bullet()\Width = SpriteWidth(Sprite)
  69. Bullet()\Height = SpriteHeight(Sprite)
  70. Bullet()\Image = Sprite
  71. Bullet()\SpeedX = SpeedX
  72. Bullet()\SpeedY = SpeedY
  73. EndProcedure
  74.  
  75.  
  76. MessageRequester("Willkommen !", "Zombies 4-Ever, aber jetzt wollen sie DIR an den Kragen. Töte so viele wie möglich, ohne zu sterben!"+Chr(10)+Chr(10)+"Auf den Tasten W, A, S & D läufst du."+Chr(10)+"Auf der linken Maustaste kannst du schießen. "+Chr(10)+"Mit Shift(links) und der Leertaste kannst du dich drehen."+Chr(10)+"Viel Spaß.", 0)
  77.  
  78. ;
  79. ; Now, open a 640*480 - 16 bits colours screen
  80. ;
  81.  
  82. Path$ = "Data\"
  83.  
  84. ; SetRefreshRate(60
  85.  
  86. ;
  87. If OpenScreen (800,600, 16, "Zombie_fever")
  88. LoadSprite(99,Path$+"Beginning.bmp")
  89. Repeat
  90. ExamineKeyboard()
  91. FlipBuffers()
  92. ClearScreen(RGB(0,0,0))
  93. DisplaySprite(99,0,0)
  94. Until KeyboardPushed(#PB_Key_Space)
  95.  
  96.  
  97.  
  98. Gegend = 20
  99.  
  100. PlayerSpeedX = 6
  101. PlayerSpeedY = 6
  102.  
  103. BulletSpeed = 10
  104.  
  105. ;
  106. ; Load the sound effects
  107. ;
  108.  
  109. LoadSound(0, Path$+"Famas.wav")
  110. LoadSound(1, Path$+"Death_1.wav")
  111. LoadSound(2, Path$+"Death_2.wav")
  112. LoadSound(3, Path$+"Death_3.wav")
  113.  
  114. LoadSound(20, Path$+"reload.wav")
  115.  
  116. For k=-1 To 7
  117. LoadSprite(k, Path$+"Player_"+Str(k)+".bmp", 0) ; 8 Spieler Bilder
  118. Next
  119. LoadSprite(29, Path$+"Player_29.bmp", 0)
  120.  
  121. LoadSprite(50, Path$+"Leben_1.bmp", 0) ;1-3Herz(en)
  122. LoadSprite(51, Path$+"Leben_2.bmp", 0) ;1-3Herz(en)
  123. LoadSprite(52, Path$+"Leben_3.bmp", 0) ;1-3Herz(en)
  124. LoadSprite(53,Path$+"End.bmp", 0) ;Game over
  125.  
  126. LoadSprite( 9, Path$+"Bullet_1.bmp", 0) ;Schuesse
  127. LoadSprite(30,Path$+"Bullet_2.bmp",0)
  128. LoadSprite(31,Path$+"Bullet_3.bmp",0)
  129. For k=0 To 5
  130. LoadSprite(k+10, Path$+"Ennemy_3_"+Str(k+1)+".bmp", 0) ;Zombies:bewegung
  131. Next
  132.  
  133.  
  134. For k=2 To 9
  135. LoadSprite(k+30, Path$+"Explosion_"+Str(k)+".bmp", 0) ;Tod der Zombies und des Spielers
  136. Next
  137. a=50
  138.  
  139. LoadSprite(21, Path$+"Back_1.bmp", 0)
  140. LoadSprite(20, Path$+"Back_0.bmp", 0) ;Hintergrundbild
  141. Score=0
  142. ammo=30
  143.  
  144. PlayerImage = 0
  145. PlayerWidth = SpriteWidth(3)
  146. PlayerHeight = SpriteHeight(3)
  147. PlayerX = 300
  148. PlayerY = 400
  149.  
  150. Repeat
  151. FlipBuffers() ; This should be always in the loop, the events are handle by this functions
  152.  
  153. If IsScreenActive() ; Check if is active or not (ALT+TAB symptom :)
  154. db = 1-db
  155.  
  156. If Score >= 20
  157. ;Gegend =21
  158. EndIf
  159.  
  160. For BackX=0 To 800 Step 800 ;Macht den Hintergrund
  161. For BackY=-1200 To 600 Step 600 ;siehe eine zeile höher
  162. DisplaySprite(Gegend, BackX, BackY) ;siehe 2 zeilen höher
  163. Next
  164. Next
  165.  
  166. StartDrawing(ScreenOutput()) ;Scoreanzeige
  167. DrawingMode(#PB_2DDrawing_Transparent )
  168. DrawText(0,35,"Score: "+ Str(Score*10),RGB(99,00,00))
  169. If Zombierunde<= 200 And Zombierunde>190
  170. DrawText(10,400,"1",RGB(99,00,00))
  171. EndIf
  172. If Zombierunde<= 190
  173. DrawText(10,400,"2",RGB(99,00,00))
  174. EndIf
  175. StopDrawing()
  176.  
  177. Gosub CheckCollisions
  178.  
  179. Gosub MovePlayers
  180.  
  181. Gosub DisplayBullets
  182.  
  183. Gosub NewAlienWave
  184.  
  185. Gosub DisplayAliens
  186.  
  187. Gosub DisplayExplosions
  188.  
  189. If BulletDelay > 0
  190. BulletDelay-1
  191. EndIf
  192.  
  193. If ScrollDelay = 0
  194. ScrollY+1
  195. ScrollDelay = 0
  196. Else
  197. ScrollDelay-1
  198. EndIf
  199.  
  200. If ScrollY>31
  201. ScrollY = 0
  202. EndIf
  203. Else
  204. ; The screen is no more active but our game multitask friendly, so we stop the sounds and
  205. ; add a delay to not eat the whole CPU. Smart hey ? :)
  206.  
  207. StopSound(-1)
  208. Delay(20)
  209. EndIf
  210.  
  211. Until KeyboardReleased(#PB_Key_Escape) Or a=53 ;beendet das spiel nachdem esc gedrückt wurde, oder drei Zombies(Alien) einen gekillt haben.
  212. Else
  213. MessageRequester("Waponez II", "Can't open a 800*600 8 bit screen !", 0)
  214. EndIf
  215. CloseScreen()
  216. MessageRequester("Ende","Du hast "+Str(Score)+" Zombies gekillt!!!",#PB_MessageRequester_Ok)
  217. result= MessageRequester("Ende","Game over!")
  218.  
  219. If result= #PB_MessageRequester_No
  220. MessageRequester("Ende","Ciao"+Chr(10)+"Bis zum nächsten mal!")
  221. EndIf
  222. End
  223.  
  224.  
  225.  
  226.  
  227.  
  228. MovePlayers:
  229. Fire = 0
  230. PlayerImage=0 ; nach vorne schauen
  231. LebenImage=52
  232. ExamineMouse()
  233. ExamineKeyboard()
  234.  
  235. If KeyboardPushed(#PB_Key_LeftShift)
  236. PlayerImage=1
  237. EndIf
  238. If KeyboardPushed(#PB_Key_Space)
  239. PlayerImage=2
  240. EndIf
  241. If KeyboardPushed(#PB_Key_A)
  242. PlayerX-PlayerSpeedX
  243. EndIf
  244. If KeyboardPushed(#PB_Key_D)
  245. PlayerX+PlayerSpeedX
  246. EndIf
  247. If KeyboardPushed(#PB_Key_W)
  248. PlayerY-PlayerSpeedY
  249. EndIf
  250. If KeyboardPushed(#PB_Key_S)
  251. PlayerY+PlayerSpeedY
  252. EndIf
  253. ;If KeyboardPushed(#PB_Key_Space)
  254. ; PlayerImage = 29 ; Schuss!
  255. ;EndIf
  256.  
  257.  
  258.  
  259. DisplayTransparentSprite (a,0,-30)
  260.  
  261.  
  262. If PlayerX < 0 : PlayerX = 0 : EndIf
  263. If PlayerY < 0 : PlayerY = 0 : EndIf
  264.  
  265. If PlayerX > 800-PlayerWidth : PlayerX = 800-PlayerWidth : EndIf
  266. If PlayerY > 600-PlayerHeight : PlayerY = 600-PlayerHeight : EndIf
  267.  
  268.  
  269. If Dead = 1
  270. AddElement(Explosion())
  271. Explosion()\x = PlayerX
  272. Explosion()\y = PlayerY
  273.  
  274. Dead = 0
  275. Else
  276. If DeadDelay>0
  277. DeadDelay-1
  278. If db=1
  279. If DeadDelay < 200
  280. DisplayTransparentSprite(PlayerImage, PlayerX, PlayerY)
  281. EndIf
  282. EndIf
  283. Else
  284. DisplayTransparentSprite(PlayerImage, PlayerX, PlayerY)
  285. EndIf
  286. EndIf
  287.  
  288. ExamineMouse()
  289. If MouseButton(#PB_MouseButton_Left) And PlayerImage =0 ;Schuss
  290. If BulletDelay = 0
  291. If DeadDelay < 100
  292. BulletDelay = 30
  293.  
  294. ; AddBullet() syntax: (#Sprite, x, y, SpeedX, SpeedY)
  295. AddBullet(9, PlayerX+17 , PlayerY-40, 0 , -BulletSpeed) ; vorne
  296. ammo-1
  297. PlaySound(0, 0) ; soundeffekte
  298. EndIf
  299. EndIf
  300. EndIf
  301.  
  302. If MouseButton(#PB_MouseButton_Left) And PlayerImage =1 ;Schuss
  303. If BulletDelay = 0
  304. If DeadDelay < 100
  305. BulletDelay = 30
  306. AddBullet(30, PlayerX-11, PlayerY-6 , -BulletSpeed, -BulletSpeed) ; links-oben
  307. ammo-1
  308. PlaySound(0, 0) ; sound effekte
  309. EndIf
  310. EndIf
  311. EndIf
  312.  
  313. ExamineMouse()
  314. If MouseButton(#PB_MouseButton_Left) And PlayerImage=2 ;Schuss
  315. If BulletDelay = 0
  316. If DeadDelay < 100
  317. BulletDelay = 30
  318. AddBullet(31, PlayerX+45, PlayerY-6 , BulletSpeed, -BulletSpeed) ; Front-Right bullet
  319. ammo-1
  320. PlaySound(0, 0) ; soundeffekte
  321. EndIf
  322. EndIf
  323. EndIf
  324. Return
  325.  
  326.  
  327. If ammo<=0
  328. PlaySound(20)
  329. EndIf
  330.  
  331.  
  332. DisplayBullets:
  333.  
  334. ResetList(Bullet())
  335. While NextElement(Bullet()) ; Process all the bullet actualy displayed on the screen
  336.  
  337. If Bullet()\y < 0 ; If a bullet is now out of the screen, simply delete it..
  338. DeleteElement(Bullet())
  339. Else
  340. If Bullet()\x < 0 ; If a bullet is now out of the screen, simply delete it..
  341. DeleteElement(Bullet())
  342. Else
  343. If Bullet()\x > 800-Bullet()\Width
  344. DeleteElement(Bullet())
  345. Else
  346. If Bullet()\y > 600
  347. DeleteElement(Bullet())
  348. Else
  349. DisplayTransparentSprite(Bullet()\Image, Bullet()\x, Bullet()\y) ; Display the bullet..
  350.  
  351. Bullet()\y + Bullet()\SpeedY
  352. Bullet()\x + Bullet()\SpeedX
  353. EndIf
  354. EndIf
  355. EndIf
  356. EndIf
  357.  
  358. Wend
  359.  
  360. Return
  361.  
  362.  
  363. NewAlienWave:
  364.  
  365.  
  366.  
  367.  
  368. If AlienDelay = 0
  369.  
  370. AddElement(Aliens())
  371.  
  372. If Boss = 1
  373.  
  374. Aliens()\x = 100
  375. Aliens()\y = -16
  376. Aliens()\Width = SpriteWidth(50)
  377. Aliens()\Height = SpriteHeight(50)
  378. Aliens()\Speed = 2
  379. Aliens()\StartImage = 50
  380. Aliens()\EndImage = 50
  381. Aliens()\ImageDelay = 1
  382. Aliens()\NextImageDelay = 1
  383. Aliens()\ActualImage = 50
  384. Aliens()\Armor = 20
  385.  
  386. AlienDelay = 80
  387.  
  388. Else
  389.  
  390. Aliens()\x = Random(800)
  391. Aliens()\y = -32
  392. Aliens()\Width = SpriteWidth(10)
  393. Aliens()\Height = SpriteHeight(10)
  394. Aliens()\Speed = 3
  395. Aliens()\StartImage = 10
  396. Aliens()\EndImage = 15
  397. Aliens()\ImageDelay = 4
  398. Aliens()\NextImageDelay = Aliens()\ImageDelay
  399. Aliens()\ActualImage = 10
  400. Aliens()\Armor = 5
  401.  
  402. AlienDelay = Random(200) ;; Zombie wave
  403.  
  404.  
  405.  
  406. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  407. If Score => 10
  408. AlienDelay = Random(150)
  409. ;newwave()
  410. EndIf
  411. If Score => 20
  412. AlienDelay = Random(100)
  413. ;newwave()
  414. EndIf
  415. If Score => 30
  416. AlienDelay = Random(80)
  417. ;newwave()
  418. EndIf
  419. If Score => 40
  420. AlienDelay = Random(70)
  421. ;newwave()
  422. EndIf
  423. If Score => 50
  424. AlienDelay = Random(60)
  425. ;newwave()
  426. EndIf
  427. If Score => 70
  428. AlienDelay = Random(30)
  429. ;newwave()
  430. EndIf
  431. If Score => 100
  432. AlienDelay = Random(10)
  433. ;newwave()
  434. EndIf
  435. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  436.  
  437.  
  438.  
  439.  
  440.  
  441.  
  442. EndIf
  443. Else
  444. AlienDelay-1
  445. EndIf
  446.  
  447. Return
  448.  
  449.  
  450. DisplayAliens:
  451.  
  452. ResetList(Aliens())
  453. While NextElement(Aliens())
  454.  
  455. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  456. If PlayerX>Aliens()\x
  457. Aliens()\x +1
  458. EndIf
  459. If Playerx <Aliens()\x
  460. Aliens()\x -1
  461. EndIf
  462. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  463.  
  464. DisplayTransparentSprite(Aliens()\ActualImage, Aliens()\x, Aliens()\y)
  465.  
  466. Aliens()\y + Aliens()\Speed
  467.  
  468. If Aliens()\NextImageDelay = 0
  469.  
  470. Aliens()\ActualImage+1
  471.  
  472. If Aliens()\ActualImage > Aliens()\EndImage
  473. Aliens()\ActualImage = Aliens()\StartImage
  474. EndIf
  475.  
  476. Aliens()\NextImageDelay = Aliens()\ImageDelay
  477. Else
  478. Aliens()\NextImageDelay-1
  479. EndIf
  480.  
  481. If Aliens()\Armor <= 0
  482. AddElement(Explosion())
  483. Explosion()\x = Aliens()\x
  484. Explosion()\y = Aliens()\y
  485.  
  486. Score+1
  487. DeleteElement(Aliens())
  488. Else
  489. If Aliens()\y > 600
  490. DeleteElement(Aliens())
  491. EndIf
  492. EndIf
  493.  
  494. Wend
  495. Return
  496.  
  497.  
  498. CheckCollisions:
  499.  
  500. ResetList(Aliens())
  501. While NextElement(Aliens())
  502. ResetList(Bullet())
  503. While NextElement(Bullet())
  504.  
  505. If SpritePixelCollision(Bullet()\Image, Bullet()\x, Bullet()\y, Aliens()\ActualImage, Aliens()\x, Aliens()\y)
  506. Aliens()\Armor-5
  507. DeleteElement(Bullet())
  508.  
  509. EndIf
  510.  
  511. Wend
  512.  
  513. If DeadDelay = 0 ; No more invincible...
  514. If SpritePixelCollision(PlayerImage, PlayerX, PlayerY, Aliens()\ActualImage, Aliens()\x, Aliens()\y)
  515. Dead = 1
  516. DeadDelay = 300
  517.  
  518. AddElement(Explosion())
  519. Explosion()\x = Aliens()\x
  520. Explosion()\y = Aliens()\y
  521. DeleteElement(Aliens())
  522.  
  523. LebenImage-1
  524. a+1
  525.  
  526. EndIf
  527. EndIf
  528.  
  529. Wend
  530. Return
  531.  
  532.  
  533. ; DisplayExplosion:
  534. ; -----------------
  535. ;
  536. ; Once an explosion has been declared (an aliens has been destroyed or the player...), it will be
  537. ; displayed inside this routine. The object remains until the end of the explosion (all the pictures
  538. ; have been displayed). Then the object is removed with DeleteElement().
  539. ;
  540.  
  541. DisplayExplosions:
  542.  
  543. ResetList(Explosion())
  544. While NextElement(Explosion()) ; Take the explosions objects, one by one.
  545.  
  546. ; For each object, display the current explosion image (called state here)
  547.  
  548. DisplayTransparentSprite(Explosion()\State+31, Explosion()\x, Explosion()\y)
  549.  
  550. If Explosion()\Delay = 0
  551. If Explosion()\State = 0 ; Play the sound only at the explosion start.
  552. PlaySound(Random(3), 0)
  553. EndIf
  554.  
  555. If Explosion()\State < 7
  556. Explosion()\State+1
  557. Explosion()\Delay = 3
  558. Else
  559. DeleteElement(Explosion())
  560. EndIf
  561. Else
  562. Explosion()\Delay-1
  563. EndIf
  564. Wend
  565.  
  566. Return
Add Comment
Please, Sign In to add comment