player.bmx 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. '===============================================================================
  2. ' Little Shooty Test Thing
  3. ' Code & Stuff by Richard Olpin ([email protected])
  4. '===============================================================================
  5. ' Player.bmx
  6. '===============================================================================
  7. Global score=0, oldswitch=0
  8. Global mx, mn, damping#
  9. Global player:TPlayer
  10. Type TPlayer
  11. Field x#,y#,xs#,ys#
  12. Field rot#,alpha#,img,frame=2
  13. Field primary_weapon, secondary_weapon
  14. Field pshot_timer=0
  15. Field shield = 0
  16. Field invincible =0
  17. Field state=0, lives
  18. '---------------------------------------
  19. Function CreatePlayer()
  20. player=New TPlayer
  21. player.x=320; xs#=0
  22. player.y=240; ys#=0
  23. player.img=LoadAnimImage:TImage("gfx/playera.png",80,64,0,5, MASKEDIMAGE|FILTEREDIMAGE )
  24. mx=6
  25. mn=-6
  26. damping#=0.8
  27. player.rot=0
  28. player.state=1
  29. player.lives=3
  30. player.shield=180
  31. player.invincible=0
  32. player.primary_weapon=WPN_DEFLASER
  33. EndFunction
  34. '---------------------------------------
  35. Method Update()
  36. shield:-1
  37. If state=2 Then Goto pskip
  38. '---------------------------------------------
  39. ' move
  40. If JoyDown(5) Then
  41. If oldswitch=0 Then
  42. direction=-direction
  43. oldswitch=1
  44. Else
  45. oldswitch=0
  46. EndIf
  47. EndIf
  48. If KeyHit(KEY_I) Then invincible=1-invincible
  49. If KeyDown(KEY_RIGHT)Or KeyDown(KEY_D) Then xs:+1
  50. If KeyDown(KEY_LEFT)Or KeyDown(KEY_A) Then xs:-1
  51. If Abs(JoyX(0))>0.2 Then xs:+JoyX(0)
  52. If (xs > mx) Then xs=mx
  53. If (xs < mn) Then xs=mn
  54. xs:*damping# ; If Abs(pvx)<0.5 Then pvx=0
  55. If KeyDown(KEY_UP)Or KeyDown(KEY_W) Then ys:-1
  56. If KeyDown(KEY_DOWN) Or KeyDown(KEY_S) Then ys:+1
  57. If Abs(JoyY(0))>0.2 Then ys:+JoyY(0)
  58. If ys > mx Then ys=mx
  59. If ys < mn Then ys=mn
  60. ys:*damping# ; If Abs(pvy)<0.5 Then pvy=0
  61. frame = 4-(Int(ys/1.5)+2)
  62. x:+xs ; If x>=WIDTH Then x=WIDTH ; If x<=0 Then x=0
  63. y:+ys ; If y>=HEIGHT Then y=HEIGHT ; If y<=0 Then y=0
  64. '---------------------------------------------
  65. ' shoot?
  66. pshot_timer:-1
  67. If (JoyDown(2) Or KeyDown(KEY_SPACE)) And pshot_timer<0 Then fire()
  68. #pskip If state=2 Then
  69. If rot<60 Then rot=rot+0.25
  70. ys=ys+0.05
  71. y=y+ys
  72. x=x+1
  73. ' img,x#,y#,sc#,si#,sp#,gr#, lf
  74. If (Int(y)&3)=1 Then TParticle.Createspark(smoke, x,y,0.25,0.02,Rand(-0.5,0.5),0, Rand(125,175) )
  75. If y>HEIGHT Then
  76. StopChannel TempChannel
  77. PlaySound playerdie
  78. TParticle.PlayerExplosion(x,y)
  79. rot=0
  80. state=1
  81. y=HEIGHT/2
  82. ys=0
  83. shield=180
  84. lives=lives-1
  85. EndIf
  86. EndIf
  87. '---------------------------------------------
  88. ' Draw
  89. SetBlend ALPHABLEND
  90. SetScale 1,1
  91. SetAlpha 1
  92. SetRotation rot
  93. If shield>0 Then SetAlpha Rnd(1)
  94. DrawImage img,x,y,frame
  95. '---------------------------------------------
  96. ' Collisions
  97. If (shield <0) Then
  98. If CollideImage(img,x,y,frame,1,0) Then hit() ' Player/Alien Collision
  99. ' If CollideImage(img,x,y,frame,2,0) Then hit() ' Player/Ground Collision
  100. EndIf
  101. '---------------------------------------------
  102. End Method
  103. Method fire()
  104. Select primary_weapon
  105. Case WPN_NORMAL
  106. TBullet.CreateBullet bull_img,x+24,y+2+(ys*2),(16+spd)*direction
  107. pshot_timer=5
  108. PlaySound player_shot, SoundChannel
  109. Case WPN_DEFLASER
  110. For Local sp=1 To 8
  111. TBullet.CreateBullet bull_img,x+24,y+2+(ys*2),(16+sp)*direction
  112. Next
  113. pshot_timer=5
  114. PlaySound player_shot, SoundChannel
  115. End Select
  116. End Method
  117. Method hit()
  118. If invincible Then Return
  119. If state=1 Then
  120. ' TParticle.PlayerExplosion(x,y)
  121. TParticle.CreateExplosion(x,y)
  122. TempChannel=AllocChannel()
  123. PlaySound bombfall, TempChannel
  124. state=2
  125. EndIf
  126. End Method
  127. End Type
  128. '----------------------------------------------------------------------
  129. ' End of file
  130. '---------------------------------------------------------------------