Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- input wirelink EGP
- // by Magus / Lodkagan
- // Declare Vars
- int P1X, P2X
- int P1Velocity, P2Velocity
- vector2 Ball, BallSpeed
- vector2 Score
- bool KI1, KI2
- sound Sound_Ball = sound(self(), "synth/tri.wav", 0.1)
- // Init Vars
- P1X = 250
- P2X = 250
- Ball = vec2(250,250)
- BallSpeed = vec2(2,-2)
- KI1 = true
- KI2 = true
- // Clearing the Screen
- EGP:egpClear()
- // Display the Walls
- EGP:egpBox(1,vec2(450,250),vec2(5,550))
- EGP:egpColor(1,color(255,255,255,255))
- EGP:egpBox(2,vec2(50,250),vec2(5,550))
- EGP:egpColor(2,color(255,255,255,255))
- // Display Scoreboard
- EGP:egpText(3,"P1: " + Score:x(),vec2(455,50))
- EGP:egpColor(3,color(255,255,255,255))
- EGP:egpText(4,"P2: " + Score:y(),vec2(455,442))
- EGP:egpColor(4,color(255,255,255,255))
- // Display Ball and Player
- EGP:egpBox(10,vec2(P1X,10),vec2(75,5))
- EGP:egpColor(10,color(255,255,255,255))
- EGP:egpBox(15,vec2(P2X,500),vec2(75,5))
- EGP:egpColor(15,color(255,255,255,255))
- EGP:egpBox(20,vec2(Ball:x(),Ball:y()),vec2(10,10))
- EGP:egpColor(20,color(255,255,255,255))
- // ======== FUNCTIONS ========
- // Resets the Position of the Players/Ball
- function gameReset() {
- P1X = 250
- P2X = 250
- Ball = vec2(250,250)
- BallSpeed = vec2(2,-2)
- }
- function addScore(vector2 A) {
- Score += A
- EGP:egpSetText(3,"P1: " + Score:x())
- EGP:egpSetText(4,"P2: " + Score:y())
- }
- // ======== EVENTS ========
- // Register Keypresses from the Chip Owner
- event keypress(int Key) {
- if(Key == 19) {
- // LEFT
- P1Velocity -= 5
- }elseif(Key == 20) {
- // RIGHT
- P1Velocity += 5
- }
- }
- event keyrelease(int Key) {
- if(Key == 19) {
- // LEFT
- P1Velocity += 5
- }elseif(Key == 20) {
- // RIGHT
- P1Velocity -= 5
- }
- }
- // Resets the Game if someone presses the Use-Key on the Chip
- event use(entity E) {
- if(E) {gameReset()}
- }
- // Runs if the Owner types in Chat
- event playerChat(entity E, string Text) {
- if(E = owner()) {
- Text = Text:lower()
- if(Text == ".game reset") {gameReset()}
- elseif(Text == ".game ki1 enable") {KI1 = true; print("KI for Player 1 is now: Enabled"); P1Velocity = 0}
- elseif(Text == ".game ki2 enable") {KI2 = true; print("KI for Player 2 is now: Enabled"); P2Velocity = 0}
- elseif(Text == ".game ki1 disable") {KI1 = false; print("KI for Player 1 is now: Disabled"); P1Velocity = 0}
- elseif(Text == ".game ki2 disable") {KI2 = false; print("KI for Player 2 is now: Disabled"); P2Velocity = 0}
- elseif(Text == ".game sound test") {Sound_Ball:play(0.1)}
- elseif(Text == ".game sound stop") {Sound_Ball:stop()}
- }
- }
- // Runs every Gametick
- event tick() {
- //
- P1X += P1Velocity
- P2X += P2Velocity
- Ball += BallSpeed
- // Player & Wall COllision
- if(P1X <= 90) {P1X = 90}
- if(P2X <= 90) {P2X = 90}
- if(P1X >= 410) {P1X = 410}
- if(P2X >= 410) {P2X = 410}
- // Ball & Wall Collision
- if(Ball:x() <= 70) {
- Sound_Ball:pitch(50)
- Sound_Ball:play(0.1)
- BallSpeed *= vec2(-1,1)
- } elseif(Ball:x() >= 430) {
- Sound_Ball:pitch(50)
- Sound_Ball:play(0.1)
- BallSpeed *= vec2(-1,1)
- }
- // Player & Ball Collision
- if(Ball:y() <= 15 && (P1X < Ball:x() + 37.5) && (P1X > Ball:x() - 37.5)) {
- Sound_Ball:pitch(50)
- Sound_Ball:play(0.1)
- BallSpeed *= vec2(0,-1)
- BallSpeed -= vec2(round(random(-3,3)),0)
- if(P1Velocity > 0) { BallSpeed += vec2(round(random(2,5)),0) }
- elseif(P1Velocity < 0) { BallSpeed -= vec2(round(random(2,5)),0) }
- } elseif(Ball:y() >= 495 && (P2X < Ball:x() + 37.5) && (P2X > Ball:x() - 37.5)) {
- Sound_Ball:pitch(50)
- Sound_Ball:play(0.1)
- BallSpeed -= vec2(round(random(-3,3)),0)
- BallSpeed *= vec2(0,-1)
- if(P2Velocity > 0) { BallSpeed += vec2(round(random(2,5)),0) }
- elseif(P2Velocity < 0) { BallSpeed -= vec2(round(random(2,5)),0) }
- }
- // Add Score if the Ball reach Bottom/Top
- if(Ball:y() < 10) {
- Sound_Ball:pitch(100)
- Sound_Ball:play(0.1)
- addScore(vec2(0,1))
- gameReset()
- }
- if(Ball:y() > 500) {
- Sound_Ball:pitch(100)
- Sound_Ball:play(0.1)
- addScore(vec2(1,0))
- gameReset()
- }
- // Update EGP Drawings to the position
- EGP:egpBox(10,vec2(P1X,10),vec2(75,5))
- EGP:egpBox(15,vec2(P2X,500),vec2(75,5))
- EGP:egpBox(20,vec2(Ball:x(),Ball:y()),vec2(10,10))
- // KI for Player 1 and 2
- if(KI1) {
- if(Ball:y() < 400) {
- if(Ball:x() > P1X+5) {P1Velocity = 5}
- elseif(Ball:x() < P1X-5) {P1Velocity = -5}
- else {P1Velocity = 0}
- }
- }
- if(KI2)
- {
- if(Ball:y() > 100)
- {
- if(Ball:x() > P2X+5) {P2Velocity = 5}
- elseif(Ball:x() < P2X-5) {P2Velocity = -5}
- else {P2Velocity = 0}
- }
- }
- }
- gameReset()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement