Advertisement
Magus

(Wiremod Lemon Gate) Lodkagan Pong Chip

Jun 10th, 2014
411
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 5.00 KB | None | 0 0
  1. input wirelink EGP
  2. // by Magus / Lodkagan
  3.  
  4. // Declare Vars
  5. int P1X, P2X
  6. int P1Velocity, P2Velocity
  7. vector2 Ball, BallSpeed
  8. vector2 Score
  9. bool KI1, KI2
  10. sound Sound_Ball = sound(self(), "synth/tri.wav", 0.1)
  11.  
  12. // Init Vars
  13. P1X = 250
  14. P2X = 250
  15. Ball = vec2(250,250)
  16. BallSpeed = vec2(2,-2)
  17. KI1 = true
  18. KI2 = true
  19.  
  20. // Clearing the Screen
  21. EGP:egpClear()
  22.  
  23. // Display the Walls
  24. EGP:egpBox(1,vec2(450,250),vec2(5,550))
  25. EGP:egpColor(1,color(255,255,255,255))
  26. EGP:egpBox(2,vec2(50,250),vec2(5,550))
  27. EGP:egpColor(2,color(255,255,255,255))
  28.  
  29. // Display Scoreboard
  30. EGP:egpText(3,"P1: " + Score:x(),vec2(455,50))
  31. EGP:egpColor(3,color(255,255,255,255))
  32. EGP:egpText(4,"P2: " + Score:y(),vec2(455,442))
  33. EGP:egpColor(4,color(255,255,255,255))
  34.  
  35. // Display Ball and Player
  36. EGP:egpBox(10,vec2(P1X,10),vec2(75,5))
  37. EGP:egpColor(10,color(255,255,255,255))
  38. EGP:egpBox(15,vec2(P2X,500),vec2(75,5))
  39. EGP:egpColor(15,color(255,255,255,255))
  40. EGP:egpBox(20,vec2(Ball:x(),Ball:y()),vec2(10,10))
  41. EGP:egpColor(20,color(255,255,255,255))
  42.  
  43.  
  44. // ======== FUNCTIONS ========
  45. // Resets the Position of the Players/Ball
  46. function gameReset() {
  47.     P1X = 250
  48.     P2X = 250
  49.    
  50.     Ball = vec2(250,250)
  51.     BallSpeed = vec2(2,-2)
  52. }
  53.  
  54. function addScore(vector2 A) {
  55.     Score += A
  56.     EGP:egpSetText(3,"P1: " + Score:x())
  57.     EGP:egpSetText(4,"P2: " + Score:y())
  58. }
  59.  
  60. // ======== EVENTS ========
  61. // Register Keypresses from the Chip Owner
  62. event keypress(int Key) {
  63.     if(Key == 19) {
  64.         // LEFT
  65.         P1Velocity -= 5
  66.     }elseif(Key == 20) {
  67.         // RIGHT
  68.         P1Velocity += 5
  69.     }
  70. }
  71.  
  72. event keyrelease(int Key) {
  73.     if(Key == 19) {
  74.         // LEFT
  75.         P1Velocity += 5
  76.     }elseif(Key == 20) {
  77.         // RIGHT
  78.         P1Velocity -= 5
  79.     }
  80. }
  81.  
  82. // Resets the Game if someone presses the Use-Key on the Chip
  83. event use(entity E) {
  84.     if(E) {gameReset()}
  85. }
  86.  
  87. // Runs if the Owner types in Chat
  88. event playerChat(entity E, string Text) {
  89.     if(E = owner()) {
  90.         Text = Text:lower()
  91.             if(Text == ".game reset") {gameReset()}
  92.         elseif(Text == ".game ki1 enable") {KI1 = true; print("KI for Player 1 is now: Enabled"); P1Velocity = 0}
  93.         elseif(Text == ".game ki2 enable") {KI2 = true; print("KI for Player 2 is now: Enabled"); P2Velocity = 0}
  94.         elseif(Text == ".game ki1 disable") {KI1 = false; print("KI for Player 1 is now: Disabled"); P1Velocity = 0}
  95.         elseif(Text == ".game ki2 disable") {KI2 = false; print("KI for Player 2 is now: Disabled"); P2Velocity = 0}
  96.         elseif(Text == ".game sound test") {Sound_Ball:play(0.1)}
  97.         elseif(Text == ".game sound stop") {Sound_Ball:stop()}
  98.        
  99.     }
  100. }
  101.  
  102. // Runs every Gametick
  103. event tick() {
  104.     //
  105.     P1X += P1Velocity
  106.     P2X += P2Velocity
  107.     Ball += BallSpeed
  108.    
  109.     // Player & Wall COllision
  110.     if(P1X <= 90) {P1X = 90}
  111.     if(P2X <= 90) {P2X = 90}
  112.  
  113.     if(P1X >= 410) {P1X = 410}
  114.     if(P2X >= 410) {P2X = 410}
  115.    
  116.     // Ball & Wall Collision
  117.     if(Ball:x() <= 70) {
  118.         Sound_Ball:pitch(50)
  119.         Sound_Ball:play(0.1)
  120.         BallSpeed *= vec2(-1,1)
  121.     } elseif(Ball:x() >= 430) {
  122.         Sound_Ball:pitch(50)
  123.         Sound_Ball:play(0.1)
  124.         BallSpeed *= vec2(-1,1)
  125.     }
  126.    
  127.     // Player & Ball Collision
  128.     if(Ball:y() <= 15 && (P1X < Ball:x() + 37.5) && (P1X > Ball:x() - 37.5)) {
  129.         Sound_Ball:pitch(50)
  130.         Sound_Ball:play(0.1)
  131.         BallSpeed *= vec2(0,-1)
  132.         BallSpeed -= vec2(round(random(-3,3)),0)
  133.             if(P1Velocity > 0) { BallSpeed += vec2(round(random(2,5)),0) }
  134.         elseif(P1Velocity < 0) { BallSpeed -= vec2(round(random(2,5)),0) }
  135.     } elseif(Ball:y() >= 495 && (P2X < Ball:x() + 37.5) && (P2X > Ball:x() - 37.5)) {
  136.         Sound_Ball:pitch(50)
  137.         Sound_Ball:play(0.1)
  138.         BallSpeed -= vec2(round(random(-3,3)),0)
  139.         BallSpeed *= vec2(0,-1)
  140.             if(P2Velocity > 0) { BallSpeed += vec2(round(random(2,5)),0) }
  141.         elseif(P2Velocity < 0) { BallSpeed -= vec2(round(random(2,5)),0) }
  142.     }
  143.    
  144.     // Add Score if the Ball reach Bottom/Top
  145.     if(Ball:y() < 10) {
  146.         Sound_Ball:pitch(100)
  147.         Sound_Ball:play(0.1)
  148.         addScore(vec2(0,1))
  149.         gameReset()
  150.     }
  151.      
  152.     if(Ball:y() > 500) {
  153.         Sound_Ball:pitch(100)
  154.         Sound_Ball:play(0.1)
  155.         addScore(vec2(1,0))
  156.         gameReset()
  157.     }
  158.    
  159.     // Update EGP Drawings to the position
  160.     EGP:egpBox(10,vec2(P1X,10),vec2(75,5))
  161.     EGP:egpBox(15,vec2(P2X,500),vec2(75,5))
  162.     EGP:egpBox(20,vec2(Ball:x(),Ball:y()),vec2(10,10))
  163.    
  164.    
  165.     // KI for Player 1 and 2
  166.     if(KI1) {
  167.         if(Ball:y() < 400) {
  168.             if(Ball:x() > P1X+5) {P1Velocity = 5}
  169.             elseif(Ball:x() < P1X-5) {P1Velocity = -5}
  170.             else {P1Velocity = 0}
  171.         }
  172.     }
  173.      
  174.     if(KI2)
  175.     {
  176.         if(Ball:y() > 100)
  177.         {
  178.             if(Ball:x() > P2X+5) {P2Velocity = 5}
  179.             elseif(Ball:x() < P2X-5) {P2Velocity = -5}
  180.             else {P2Velocity = 0}
  181.         }
  182.     }
  183.  
  184. }
  185.  
  186. gameReset()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement