Magus

(Wiremod Expression 2) Lodkagan Pong Chip

Oct 31st, 2011
472
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 4.05 KB | None | 0 0
  1. @name Lodkagan Pong Chip
  2. @inputs P1_Keys P2_Keys S:wirelink BT_Reset P1_InUse P2_InUse
  3. @outputs P1_Score P2_Score P1_X Time Ball_YSpeed
  4. @persist P2_X Ball_X Ball_Y Ball_XSpeed I Reset Bot1_Key Bot2_Key
  5. # ==============
  6. # KEYS
  7. # A = 97
  8. # D = 100
  9. # ==============
  10. # Default/Reset Config
  11.  
  12. interval(50)
  13. Time += 0.05
  14.  
  15. if(first() | (clk("Reset")))
  16. {
  17.     Time = 0
  18.    
  19.     Ball_XSpeed = 0
  20.     Ball_YSpeed = 0
  21.    
  22.     S:egpClear()
  23.     P1_X = 250
  24.     P2_X = 250
  25.    
  26.     Ball_X = 250
  27.     Ball_Y = 250
  28.  
  29.  
  30.     S:egpBox(0,vec2(250,250),vec2(750,750))
  31.     S:egpColor(0,vec4(0,0,0,255))
  32.     S:egpBox(1,vec2(450,250),vec2(5,550))
  33.     S:egpColor(1,vec4(255,255,255,255))
  34.     S:egpBox(2,vec2(50,250),vec2(5,550))
  35.     S:egpColor(2,vec4(255,255,255,255))
  36.    
  37.     S:egpText(5,"BY MAGUS",vec2(150,250))
  38.     S:egpSize(5,50)
  39.     S:egpColor(5,vec4(255,0,0,255))
  40.    
  41.     S:egpBox(10,vec2(P1_X,10),vec2(75,5))
  42.     S:egpColor(10,vec4(255,255,255,255))
  43.     S:egpBox(15,vec2(P2_X,500),vec2(75,5))
  44.     S:egpColor(15,vec4(255,255,255,255))
  45.     S:egpBox(20,vec2(Ball_X,Ball_Y),vec2(10,10))
  46.     S:egpColor(20,vec4(255,255,255,255))
  47.    
  48.     timer("Start",1500)
  49. }
  50. if(clk("Start"))
  51. {
  52.     I = round(random(1,2))
  53.     S:egpRemove(5)
  54.     Ball_XSpeed = round(random(-5,5))
  55.     if(I == 1) {Ball_YSpeed = 10}
  56.     if(I == 2) {Ball_YSpeed = -10}
  57.     I = 0
  58. }
  59. # ================================================
  60. # Reset Button
  61.  
  62. if(~BT_Reset & BT_Reset) {timer("Reset",1000)}
  63.  
  64. # ================================================
  65. # Display Player and Ball
  66.  
  67. S:egpBox(10,vec2(P1_X,10),vec2(75,5))
  68. S:egpBox(15,vec2(P2_X,500),vec2(75,5))
  69. S:egpBox(20,vec2(Ball_X,Ball_Y),vec2(10,10))
  70.  
  71. # ================================================
  72. # Move/Stop Players
  73.  
  74. if(P1_Keys == 97  | Bot1_Key == 97 ) {P1_X -= 10}
  75. if(P1_Keys == 100 | Bot1_Key == 100) {P1_X += 10}
  76.  
  77. if(P2_Keys == 97  | Bot2_Key == 97) {P2_X -= 10}
  78. if(P2_Keys == 100 | Bot2_Key == 100) {P2_X += 10}
  79.  
  80. if(P1_X <= 90) {P1_X = 90}
  81. if(P2_X <= 90) {P2_X = 90}
  82.  
  83. if(P1_X >= 410) {P1_X = 410}
  84. if(P2_X >= 410) {P2_X = 410}
  85.  
  86. # ================================================
  87. # Ball Config
  88.  
  89.  
  90. Ball_Y -= Ball_YSpeed
  91. Ball_X += Ball_XSpeed
  92.  
  93. if(Ball_X <= 70)
  94. {
  95.     Ball_XSpeed *= -1
  96.     soundPlay(0,0.1,"synth/tri.wav")
  97.     soundPitch(0,50)
  98. }
  99. if(Ball_X >= 430)
  100. {
  101.     Ball_XSpeed *= -1
  102.     soundPlay(0,0.1,"synth/tri.wav")
  103.     soundPitch(0,50)
  104. }
  105.  
  106. if(Ball_Y <= 20 & (P1_X < Ball_X + 37.5) & (P1_X > Ball_X - 37.5))
  107. {
  108.     soundPlay(0,0.1,"synth/tri.wav")
  109.     soundPitch(0,50)
  110.     Ball_YSpeed *= -1
  111.     Ball_XSpeed -= round(random(-3,3))
  112.     if(P1_Keys == 97) {Ball_XSpeed -= round(random(5,30))}
  113.     if(P1_Keys == 100) {Ball_XSpeed += round(random(5,30))}
  114. }
  115.  
  116. if(Ball_Y >= 490 & (P2_X < Ball_X + 37.5) & (P2_X > Ball_X - 37.5))
  117. {
  118.     soundPlay(0,0.1,"synth/tri.wav")
  119.     soundPitch(0,50)
  120.     Ball_XSpeed += round(random(-3,3))
  121.     Ball_YSpeed *= -1
  122.     if(P2_Keys == 97) {Ball_XSpeed -= round(random(5,30))}
  123.     if(P2_Keys == 100) {Ball_XSpeed += round(random(5,30))}
  124. }
  125.  
  126. if(Ball_Y < 5)
  127. {
  128.     soundPlay(0,0.1,"synth/tri.wav")
  129.     soundPitch(0,100)
  130.     P2_Score++
  131.     timer("Reset",0)
  132. }
  133.  
  134. if(Ball_Y > 505)
  135. {
  136.     soundPlay(0,0.1,"synth/tri.wav")
  137.     soundPitch(0,100)
  138.     P1_Score++
  139.     timer("Reset",0)
  140. }
  141.  
  142. if(Ball_XSpeed > 10)
  143. {
  144.     Ball_XSpeed = 10
  145. }
  146. if(Ball_XSpeed < -10)
  147. {
  148.     Ball_XSpeed = -10
  149. }
  150.  
  151. if(Ball_YSpeed > 10)
  152. {
  153.     Ball_YSpeed = -10
  154. }
  155. if(Ball_YSpeed < -10)
  156. {
  157.     Ball_YSpeed = -10
  158. }
  159.  
  160. # ================================================
  161. # KI Config
  162.  
  163. if(P1_InUse == 0)
  164. {
  165.     if(Ball_Y < 400)
  166.     {
  167.         if(Ball_X+(Ball_XSpeed/3) > P1_X+5)
  168.         {Bot1_Key = 100}
  169.         elseif(Ball_X+(Ball_XSpeed/3) < P1_X-5)
  170.         {Bot1_Key = 97}
  171.         else {Bot1_Key = 0}
  172.     }
  173. }
  174.  
  175. if(P2_InUse == 0)
  176. {
  177.     if(Ball_Y > 100)
  178.     {
  179.         if(Ball_X > P2_X+5)
  180.         {Bot2_Key = 100}
  181.         elseif(Ball_X < P2_X-5)
  182.         {Bot2_Key = 97}
  183.         else {Bot2_Key = 0}
  184.     }
  185. }
  186.  
  187. # ================================================
  188. # Credits
  189. # This was Created by Magus
Advertisement
Add Comment
Please, Sign In to add comment