_shooter_main.bmx 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. '===============================================================================
  2. ' Little Shooty Test Thing
  3. ' Code & Stuff by Richard Olpin ([email protected])
  4. '===============================================================================
  5. ' main
  6. '===============================================================================
  7. ' A little shooty thing! Needs a lot of work as I only hacked it together in
  8. ' about three hours one night and it's a right mix of both procedural and OO
  9. ' but it may inspire someone to do something..
  10. '===============================================================================
  11. Include "globals.bmx"
  12. Include "player.bmx"
  13. Include "playershots.bmx"
  14. Include "enemies.bmx"
  15. Include "background.bmx"
  16. Include "particles.bmx"
  17. Include "sound.bmx"
  18. Include "init.bmx"
  19. Include "titles.bmx"
  20. Include "gfont.bmx"
  21. ' -----------------------------------------------------------------------------
  22. Global tm, ms, old
  23. AppTitle$="Choose Screen Mode"
  24. Graphics 320,240,0,60
  25. DrawText "(W)indowed or (F)ullscreen?",0,120 ; Flip
  26. Repeat
  27. Until (KeyDown(KEY_F) Or KeyDown(KEY_W)) Or JoyDown(2)
  28. AppTitle$="Little Shooty Test by RiK (ESC To quit)"
  29. If KeyDown(KEY_W) Or JoyDown(2) Then
  30. Graphics WIDTH, HEIGHT,0,60
  31. Else
  32. Graphics WIDTH, HEIGHT,32,60
  33. EndIf
  34. AutoMidHandle True
  35. SeedRnd(MilliSecs())
  36. ' -----------------------------------------------------------------------------
  37. ' init
  38. ' -----------------------------------------------------------------------------
  39. init()
  40. Gfont.Init()
  41. HideMouse()
  42. ShowTitlePage()
  43. ' -----------------------------------------------------------------------------
  44. ' Main game loop
  45. ' -----------------------------------------------------------------------------
  46. ' Just stick an OGG called "music.ogg" in the sounds dir
  47. ' PlaySound(music,musicchannel)
  48. 'SetChannelVolume SoundChannel,1
  49. SetChannelVolume MusicChannel,0.75
  50. While Not KeyHit(KEY_ESCAPE)
  51. While JoyDown(5)
  52. Wend
  53. Cls
  54. ResetCollisions
  55. ' -------------------------------------------------------------------------
  56. ' Spawn a random spikey thing, joypad/keyboard check are for testing.
  57. ' -------------------------------------------------------------------------
  58. If Spawntimer<=0 Or JoyDown(3) Or KeyDown(key_e) Then
  59. Local nx=Rand(0,800)
  60. If Abs(player.x-nx)<200 Then nx=nx+400 ' dont spawn on top of player!
  61. Local ny=Rand(0,600)
  62. TEnemy.CreateEnemy (nx,ny)
  63. Spawntimer=60
  64. EndIf
  65. spawntimer:-1
  66. ' -------------------------------------------------------------------------
  67. ' Update Everything
  68. ' -------------------------------------------------------------------------
  69. UpdateEntities()
  70. ' -------------------------------------------------------------------------
  71. ' HUD/Score/whatever
  72. ' -------------------------------------------------------------------------
  73. SetColor 255,255,255; SetRotation 0; SetAlpha 1
  74. DrawText player.invincible,0,0 ' just for debug purposes
  75. DrawText "Little Shooty Test by RiK (ESC to quit)",20,0
  76. GFont.DrawString 800,16,score,-1,0
  77. If player.state=2 Then GFont.Drawstring 400,300,"YOU SUCK!",1,1
  78. Flip
  79. Wend
  80. ShowMouse()
  81. ' -----------------------------------------------------------------------------
  82. ' Update/draw everything
  83. '
  84. ' I've only stuck in out here as I like to keep the main loop small for clarity
  85. '
  86. ' -----------------------------------------------------------------------------
  87. Function UpdateEntities( )
  88. MoveBG()
  89. RenderBackGround(0,player.y)
  90. SetScale 1,1
  91. For Local b:TBullet =EachIn bullets
  92. b.Update
  93. Next
  94. SetScale 1,1
  95. For Local e:TEnemy =EachIn enemies
  96. e.Update
  97. Next
  98. For Local p:TParticle =EachIn particles
  99. p.Update
  100. Next
  101. player.update()
  102. ' Reset everything
  103. SetBlend ALPHABLEND
  104. SetScale 1,1
  105. SetAlpha 1
  106. SetRotation 0
  107. End Function
  108. ' -----------------------------------------------------------------------------
  109. ' End
  110. ' -----------------------------------------------------------------------------