Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @name Lodkagan Pong Chip
- @inputs P1_Keys P2_Keys S:wirelink BT_Reset P1_InUse P2_InUse
- @outputs P1_Score P2_Score P1_X Time Ball_YSpeed
- @persist P2_X Ball_X Ball_Y Ball_XSpeed I Reset Bot1_Key Bot2_Key
- # ==============
- # KEYS
- # A = 97
- # D = 100
- # ==============
- # Default/Reset Config
- interval(50)
- Time += 0.05
- if(first() | (clk("Reset")))
- {
- Time = 0
- Ball_XSpeed = 0
- Ball_YSpeed = 0
- S:egpClear()
- P1_X = 250
- P2_X = 250
- Ball_X = 250
- Ball_Y = 250
- S:egpBox(0,vec2(250,250),vec2(750,750))
- S:egpColor(0,vec4(0,0,0,255))
- S:egpBox(1,vec2(450,250),vec2(5,550))
- S:egpColor(1,vec4(255,255,255,255))
- S:egpBox(2,vec2(50,250),vec2(5,550))
- S:egpColor(2,vec4(255,255,255,255))
- S:egpText(5,"BY MAGUS",vec2(150,250))
- S:egpSize(5,50)
- S:egpColor(5,vec4(255,0,0,255))
- S:egpBox(10,vec2(P1_X,10),vec2(75,5))
- S:egpColor(10,vec4(255,255,255,255))
- S:egpBox(15,vec2(P2_X,500),vec2(75,5))
- S:egpColor(15,vec4(255,255,255,255))
- S:egpBox(20,vec2(Ball_X,Ball_Y),vec2(10,10))
- S:egpColor(20,vec4(255,255,255,255))
- timer("Start",1500)
- }
- if(clk("Start"))
- {
- I = round(random(1,2))
- S:egpRemove(5)
- Ball_XSpeed = round(random(-5,5))
- if(I == 1) {Ball_YSpeed = 10}
- if(I == 2) {Ball_YSpeed = -10}
- I = 0
- }
- # ================================================
- # Reset Button
- if(~BT_Reset & BT_Reset) {timer("Reset",1000)}
- # ================================================
- # Display Player and Ball
- S:egpBox(10,vec2(P1_X,10),vec2(75,5))
- S:egpBox(15,vec2(P2_X,500),vec2(75,5))
- S:egpBox(20,vec2(Ball_X,Ball_Y),vec2(10,10))
- # ================================================
- # Move/Stop Players
- if(P1_Keys == 97 | Bot1_Key == 97 ) {P1_X -= 10}
- if(P1_Keys == 100 | Bot1_Key == 100) {P1_X += 10}
- if(P2_Keys == 97 | Bot2_Key == 97) {P2_X -= 10}
- if(P2_Keys == 100 | Bot2_Key == 100) {P2_X += 10}
- if(P1_X <= 90) {P1_X = 90}
- if(P2_X <= 90) {P2_X = 90}
- if(P1_X >= 410) {P1_X = 410}
- if(P2_X >= 410) {P2_X = 410}
- # ================================================
- # Ball Config
- Ball_Y -= Ball_YSpeed
- Ball_X += Ball_XSpeed
- if(Ball_X <= 70)
- {
- Ball_XSpeed *= -1
- soundPlay(0,0.1,"synth/tri.wav")
- soundPitch(0,50)
- }
- if(Ball_X >= 430)
- {
- Ball_XSpeed *= -1
- soundPlay(0,0.1,"synth/tri.wav")
- soundPitch(0,50)
- }
- if(Ball_Y <= 20 & (P1_X < Ball_X + 37.5) & (P1_X > Ball_X - 37.5))
- {
- soundPlay(0,0.1,"synth/tri.wav")
- soundPitch(0,50)
- Ball_YSpeed *= -1
- Ball_XSpeed -= round(random(-3,3))
- if(P1_Keys == 97) {Ball_XSpeed -= round(random(5,30))}
- if(P1_Keys == 100) {Ball_XSpeed += round(random(5,30))}
- }
- if(Ball_Y >= 490 & (P2_X < Ball_X + 37.5) & (P2_X > Ball_X - 37.5))
- {
- soundPlay(0,0.1,"synth/tri.wav")
- soundPitch(0,50)
- Ball_XSpeed += round(random(-3,3))
- Ball_YSpeed *= -1
- if(P2_Keys == 97) {Ball_XSpeed -= round(random(5,30))}
- if(P2_Keys == 100) {Ball_XSpeed += round(random(5,30))}
- }
- if(Ball_Y < 5)
- {
- soundPlay(0,0.1,"synth/tri.wav")
- soundPitch(0,100)
- P2_Score++
- timer("Reset",0)
- }
- if(Ball_Y > 505)
- {
- soundPlay(0,0.1,"synth/tri.wav")
- soundPitch(0,100)
- P1_Score++
- timer("Reset",0)
- }
- if(Ball_XSpeed > 10)
- {
- Ball_XSpeed = 10
- }
- if(Ball_XSpeed < -10)
- {
- Ball_XSpeed = -10
- }
- if(Ball_YSpeed > 10)
- {
- Ball_YSpeed = -10
- }
- if(Ball_YSpeed < -10)
- {
- Ball_YSpeed = -10
- }
- # ================================================
- # KI Config
- if(P1_InUse == 0)
- {
- if(Ball_Y < 400)
- {
- if(Ball_X+(Ball_XSpeed/3) > P1_X+5)
- {Bot1_Key = 100}
- elseif(Ball_X+(Ball_XSpeed/3) < P1_X-5)
- {Bot1_Key = 97}
- else {Bot1_Key = 0}
- }
- }
- if(P2_InUse == 0)
- {
- if(Ball_Y > 100)
- {
- if(Ball_X > P2_X+5)
- {Bot2_Key = 100}
- elseif(Ball_X < P2_X-5)
- {Bot2_Key = 97}
- else {Bot2_Key = 0}
- }
- }
- # ================================================
- # Credits
- # This was Created by Magus
Advertisement
Add Comment
Please, Sign In to add comment