Everyone makes it at some point, its pong
This is a Pong Remake with AI, 2 Player Local and 2 Player Online! (Client and Server)
Currenly, the AI and 2 Player Local works perfectly, except for an annoying bug where the ball gets caught on the bat and flings off at 100 mph XD
Currently, only one of the bats works online (P1 Bat), if someone could figure this out, I would be VERY happy XD...
It uses the free multiplayer plugin from the program announcements... Cant remember the name sorry
Download Link: http://www.mediafire.com/?fh7thyoxm1dkyzm
Anyways, have a go and tell me what you think
You can test the online if you set the width and height at the top to something smaller and put window mode on
Client:
`Setup
width = desktop width()
height = desktop height()
set display mode width, height, 32
set window off
hide mouse
backdrop on
color backdrop 0
sync on
sync rate 0
`Menu Variables
t1$ = "Single Player"
t2$ = "Multi Player"
t3$ = "Online"
t4$ = "Exit"
y1 = height / 5
y2 = (height / 5) * 2
y3 = (height / 5) * 3
y4 = (height / 5) * 4
x1 = (width / 2) - text width(t1$)
x2 = (width / 2) - text width(t2$)
x3 = (width / 2) - text width(t3$)
x4 = (width / 2) - text width(t4$)
`Sounds
`Images
load image "images\bat.bmp", 1
load image "images\bat.bmp", 2
load image "images\ball.bmp", 3
`Menu
menu:
singleplayer = 0
multiplayer = 0
online = 0
do
show mouse
set text font "Calibri"
set text size 48
ink rgb(0,192,36),0
if button(x1, y1, t1$) = 1
singleplayer = 1
goto play
endif
if button(x2, y2, t2$) = 1
multiplayer = 1
goto play
endif
if button(x3, y3, t3$) = 1
online = 1
goto play
endif
if button(x4, y4, t4$) = 1
end
endif
sync
loop
play:
`Setup
cls
hide mouse
backdrop on
color backdrop 0
if online = 1
sync off
backdrop off
repeat
cls
input "IP Address of Server: ",ipaddress$
net connect ipaddress$
if net connected() = 1
repeat
if net get message() = 1 then player = net get int()
until player = 1 or player = 2
endif
until player = 1 or player = 2
sync on
backdrop on
color backdrop 0
endif
`Game Variables
ballspeed = width / 250
batspeed = height / 70
b1y = height / 2
b2y = height / 2
points = 0
`Sprites
sprite 1, 50, b1y, 1
sprite 2, width - 50, b2y, 2
sprite 3, width / 2, height / 2, 3
offset sprite 1, sprite width(1) / 2, sprite height(1) / 2
offset sprite 2, sprite width(2) / 2, sprite height(2) / 2
offset sprite 3, sprite width(3) / 2, sprite height(3) / 2
rotate sprite 3, 90
`Main
do
`Controls
if singleplayer = 1 or multiplayer = 1
`P1
if keystate(16) = 1
if sprite y(1) - (sprite height(1) / 2) > 0
rotate sprite 1, 0
move sprite 1, batspeed
else
move sprite 1, 0
endif
endif
if keystate(44) = 1
if sprite y(1) + (sprite height(1) / 2) < height
rotate sprite 1, 180
move sprite 1, batspeed
else
move sprite 1, 0
endif
endif
endif
`P2
`if mulitplayer = 1
if keystate(24) = 1
if sprite y(2) - (sprite height(2) / 2) > 0
rotate sprite 2, 0
move sprite 2, batspeed
else
move sprite 2, 0
endif
endif
if keystate(50) = 1
if sprite y(2) + (sprite height(2) / 2) < height
rotate sprite 2, 180
move sprite 2, batspeed
else
move sprite 2, 0
endif
endif
`endif
`Online Controls
if online = 1
`P1
if player = 1
if keystate(16) = 1
if sprite y(1) - (sprite height(1) / 2) > 0
rotate sprite 1, 0
move sprite 1, 10
else
move sprite 1, 0
endif
endif
if keystate(44) = 1
if sprite y(1) + (sprite height(1) / 2) < height
rotate sprite 1, 180
move sprite 1, 10
else
move sprite 1, 0
endif
endif
endif
`P2
if player = 2
if keystate(24) = 1
if sprite y(2) - (sprite height(2) / 2) > 0
rotate sprite 2, 0
move sprite 2, 10
else
move sprite 2, 0
endif
endif
if keystate(50) = 1
if sprite y(2) + (sprite height(2) / 2) < height
rotate sprite 2, 180
move sprite 2, 10
else
move sprite 2, 0
endif
endif
endif
endif
`Collision
if sprite hit(3, 1)
points = points + 10
rotated = 0
ballspeed = ballspeed + 1
if keystate(16) = 1
if rotated = 0
rotate sprite 3, sprite angle(3) + 180 - rnd(30)
rotated = 1
endif
endif
if keystate(44) = 1
if rotated = 0
rotate sprite 3, sprite angle(3) + 180 + rnd(30)
rotated = 1
endif
endif
if rotated = 0
plusorminus = rnd(1)
if plusorminus = 0
rotate sprite 3, sprite angle(3) + 180 + rnd(10)
endif
if plusorminus = 1
rotate sprite 3, sprite angle(3) + 180 - rnd(10)
endif
rotated = 1
endif
endif
if sprite hit(3, 2)
points = points + 10
rotated = 0
ballspeed = ballspeed + 1
if keystate(24) = 1
if rotated = 0
rotate sprite 3, sprite angle(3) + 180 + rnd(30)
rotated = 1
endif
endif
if keystate(50) = 1
if rotated = 0
rotate sprite 3, sprite angle(3) + 180 - rnd(30)
rotated = 1
endif
endif
if rotated = 0
plusorminus = rnd(1)
if plusorminus = 0
rotate sprite 3, sprite angle(3) + 180 + rnd(10)
endif
if plusorminus = 1
rotate sprite 3, sprite angle(3) + 180 - rnd(10)
endif
rotated = 1
endif
endif
`Ball handler
if singleplayer = 1 or multiplayer = 1 or player = 1
`Speed
move sprite 3, ballspeed
`Win Handler
if sprite x(3) < -50 then win(2)
if sprite x(3) > width + 50 then win(1)
`Ball Boundaries
if sprite y(3) < 0 and copy = 0
angle = 180 - sprite angle(3)
copy = 1
endif
if sprite y(3) > height and copy = 0
angle = 180 - sprite angle(3)
copy = 1
endif
if sprite y(3) < 0 then rotate sprite 3, angle
if sprite y(3) > height then rotate sprite 3, angle
if copy = 1 and sprite y(3) > 0 and sprite y(3) < height then copy = 0
endif
if online = 1 and player = 2
delete sprite 3
sprite 3, ballx, bally, 3
endif
`AI
if singleplayer = 1
if sprite y(3) < sprite y(2)
if sprite y(2) - (sprite height(2) / 2) > 0
rotate sprite 2, 0
move sprite 2, batspeed
else
move sprite 2, 0
endif
endif
if sprite y(3) > sprite y(2)
if sprite y(2) + (sprite height(2) / 2) < height
rotate sprite 2, 180
move sprite 2, batspeed
else
move sprite 2, 0
endif
endif
endif
`GUI
cls
set text size 48
set text font "Calibri"
ink rgb(0,192,36) ,0
center text width / 2, 100, "Points: " + str$(points)
`Other Player Handler
if online = 1
if player = 1
delete sprite 2
sprite 2, width - 50, otherplayery, 1
offset sprite 2, sprite width(2) / 2, sprite height(2) / 2
endif
if player = 2
delete sprite 1
sprite 1, 50, otherplayery, 1
offset sprite 1, sprite width(1) / 2, sprite height(1) / 2
endif
endif
`Player 2 Win Handler
if playerwon <> 0
win(playerwon)
endif
`Send / Recieve Data
if online = 1
`Send
if player = 1
net put int sprite y(1)
net put int sprite x(3)
net put int sprite y(3)
net put int 0
endif
if player = 2 then net put int sprite y(2)
net send
`Receive
if net get message() = 1
if player = 1 then otherplayery = net get int()
if player = 2
otherplayery = net get int()
ballx = net get int()
bally = net get int()
playerwon = net get int()
endif
endif
endif
sync
loop
function win(player)
net put int player
net put int player
net put int player
net put int player
net send
otherplayery = 0
ballx = 0
bally = 0
playerwon = 0
backdrop off
delete sprite 1
delete sprite 2
delete sprite 3
ink rgb(0,192,36),0
for seconds = 1 to 5
cls
set text font "Calibri"
set text size 48
center text desktop width() / 2, desktop height() / 2, "Player " + str$(player) + " wins!"
set text size 38
center text desktop width() / 2, desktop height() / 2 + 100 + text height("Player " + str$(player) + " wins!"), "Please wait " + str$(seconds) + " seconds to continue..."
sync
wait 1000
next seconds
cls
goto menu
endfunction
function button(x1,y1,words$)
pressed=0
x2=text width(words$)
y2=text height(words$)
if mousex()>x1 and mousex()<x1+x2
if mousey()>y1-y2 and mousey()<y1+y2
pressed=1
endif
endif
if pressed=1 then ink rgb(255,255,255),0 else ink rgb(0,192,36),0
if pressed=1
pressed=mouseclick()
else
pressed = 0
endif
text x1,y1,words$
endfunction pressed
Server:
`Setup
set display mode 500, 500, 32
disable escapekey
start:
host:
`Host the server
net host 20
if net connected() = 1 then goto console
goto host
console:
while returnkey() = 1
endwhile
print "Server started. Type "Help" for commands"
`Wait for connections
print "Waiting for Player 1..."
repeat
if returnkey() = 1
while returnkey() = 1
endwhile
input "CONSOLE: ",command$
gosub checkcommand
while returnkey() = 1
endwhile
endif
pid1 = net player joined()
until pid1 > 0
print "Player 1 Connected, Waiting for Player 2"
repeat
if returnkey() = 1
while returnkey() = 1
endwhile
input "CONSOLE: ",command$
gosub checkcommand
while returnkey() = 1
endwhile
endif
pid2 = net player joined()
until pid2 > 0
print "Player 2 Connected, Starting the Game"
playercount = 2
net put int 1
net send pid1
net put int 2
net send pid2
do
`Send / Recieve Variables
`Recieve
if net get message() = 1
if net message from() = pid1
messagefrom = 1
else
messagefrom = 2
endif
if messagefrom = 1
tempint1 = net get int()
tempint2 = net get int()
tempint3 = net get int()
tempint4 = net get int()
print "Message From: Player 2, "; tempint1; ", "; tempint2; ", "; tempint3; ", "; tempint4
else
tempint = net get int()
print "Message From: Player 1, "; tempint1
endif
send = 1
endif
`Send
if send = 1
if messagefrom = 1
net put int tempint1
net put int tempint2
net put int tempint3
net put int tempint4
net send pid2
else
net put int tempint1
net send pid1
endif
send = 0
endif
`Enter Commands
if returnkey() = 1
while returnkey() = 1
endwhile
input "CONSOLE: ",command$
gosub checkcommand
while returnkey() = 1
endwhile
endif
loop
checkcommand:
if lower$(command$) = "help"
print "Commands: "
print "Stop - Stops the Server"
print "Reset - Resets the Server"
endif
if lower$(command$) = "stop"
net disconnect
end
endif
if lower$(command$) = "reset"
net disconnect
wait 1000
tempint1 = 0
tempint2 = 0
tempint3 = 0
tempint4 = 0
goto start
endif
return
Matt
Umm...