'this is to be increased everytime the client
'becomes incompatible with previous versions
gameVersion = 2
CONST True
= -1, False
= 0 CONST mode_onlineclient
= 1
CONST id_PLAYERONLINE
= 10 CONST id_PLAYEROFFLINE
= 11 CONST id_GAMEVERSION
= 14 CONST id_UPDATESERVER
= 17
'DIM SHARED playerStream(1 TO 10) AS STRING
i = 0
i = i + 1: serverList(i) = "localhost Local host"
i = i + 1: serverList(i) = "spriggsyspriggs.ddns.net North America"
i = i + 1: serverList(i) = "alephc.xyz Australia"
i = i + 1: serverList(i) = "187.94.219.178 Brazil"
playerColorPalette:
colors
(i
) = _RGB32(r%
, g%
, b%
)
mainWindow
= _NEWIMAGE(windowWidth
, windowHeight
, 32)
mapImage
= _NEWIMAGE(windowWidth
* 4, windowHeight
* 3, 32)'FOR i = 1 TO 500
' CircleFill RND * _WIDTH, RND * _HEIGHT, RND * 2, _RGB32(255, 80)
'NEXT
ui
(1).
name = "messageicon"ui(1).x = windowWidth - 50
ui(1).y = 10
DIM userName$
, userColor%
choice = "1"
INPUT "Name: ", userName$
userName$
= LEFT$(userName$
, 20)
start:
PRINT "-------------------------" PRINT "(2) Connect to server"
mode = mode_freeplay
PRINT "Choose a server: "
clientTemp:
chosenServer$
= LEFT$(serverList
(VAL(choice
)), INSTR(serverList
(VAL(choice
)), " ") - 1)
PRINT "Attempting to connect to server... ";
attempt = 0
server.handle = 0
server.handle
= _OPENCLIENT("TCP/IP:51512:" + chosenServer$
) attempt = attempt + 1
mode = mode_onlineclient
serverStream = ""
PRINT "Failed to connect to server."
IF mode
= mode_onlineclient
THEN getData server, serverStream
WHILE parse
(serverStream
, id
, value$
) PRINT "Server version incompatible." sendData server, id_GAMEVERSION, ""
sendData server, id_PLAYERQUIT, ""
PRINT "No response from server."
playerSpeed = maxSpeed
shipMovement = True
idSet = False
idSet = True
me = 1
player
(me
).
name = userName$
player(me).state = True
player
(me
).
color = userColor%
player(me).size = 15
shipFlotation = shipFlotation + .05
IF shipFlotation
> _PI(2) THEN shipFlotation
= shipFlotation
- _PI(2) shipFloatAmplitude = 1.5
_PUTIMAGE (camera.x
+ COS(shipFlotation
) * shipFloatAmplitude
, camera.y
+ SIN(shipFlotation
) * shipFloatAmplitude
), mapImage
IF waitingForPong
= False
THEN sendData server, id_PING, ""
waitingForPong = True
getData server, serverStream
DO WHILE parse
(serverStream
, id
, value$
) CASE id_ID
'first piece of data sent by server if not full idSet = True
player
(me
).
name = userName$
player(me).state = True
player
(me
).
color = userColor%
player(me).size = 15
CASE id_NEWCOLOR
'server color changes must always be applied CASE id_NEWNAME
'server name changes must always be applied 'playerStream(CVI(LEFT$(value$, 2))) = playerStream(CVI(LEFT$(value$, 2))) + MID$(value$, 3)
hasUnreadMessages = True
IF target
= me
THEN score
= score
- 100 addParticles player
(target
).x
, player
(target
).y
, 5, _RGB32(255) addParticles player
(target
).x
, player
(target
).y
, 100, colors
(player
(target
).
color) thickLine player
(CVI(LEFT$(value$
, 2))).x
+ camera.x
, player
(CVI(LEFT$(value$
, 2))).y
+ camera.y
, player
(target
).x
+ camera.x
, player
(target
).y
+ camera.y
, 8, _RGB32(227, 78, 6, 80) player
(CVI(value$
)).state
= True
player
(CVI(value$
)).state
= False
addWarning player
(CVI(value$
)).
name + " left the game." waitingForPong = False
PRINT "Kicked from server. Reason: "
IF player
(me
).basicInfoSent
= False
THEN player(me).basicInfoSent = True
sendData server
, id_COLOR
, MKI$(player
(me
).
color) sendData server
, id_NAME
, player
(me
).
name sendData server
, id_SIZE
, MKI$(player
(me
).size
)
IF player
(me
).x
<> player
(me
).prevX
OR player
(me
).y
<> player
(me
).prevY
THEN player(me).prevX = player(me).x
player(me).prevY = player(me).y
sendData server
, id_POS
, MKS$(player
(me
).x
) + MKS$(player
(me
).y
)
totalClients = 0
IF player
(i
).state
= True
THEN totalClients
= totalClients
+ 1
IF playerSpeed
< minSpeed
THEN playerSpeed
= minSpeed
IF playerSpeed
> maxSpeed
THEN playerSpeed
= maxSpeed
IF player
(me
).x
< 0 THEN player
(me
).x
= 0 IF player
(me
).y
< 0 THEN player
(me
).y
= 0 adjustCamera
IF mode
= mode_onlineclient
THEN sendData server
, id_PLAYERQUIT
, ""
IF (mode
= mode_onlineclient
) THEN
chatOpen = False
currentPing
= TIMER - serverPing
PRINT "Connection lost (timed out)"
target = 0
'proximity
IF dist
(player
(me
).x
, player
(me
).y
, player
(i
).x
, player
(i
).y
) < 150 THEN target
= i
targetAnimation = targetAnimation - .1
IF targetAnimation
< 0 THEN targetAnimation
= 5
x
= player
(target
).x
+ camera.x
+ COS(shipFlotation
) * shipFloatAmplitude
y
= player
(target
).y
+ camera.y
+ SIN(shipFlotation
) * shipFloatAmplitude
CircleFill x
, y
, player
(target
).size
+ 10 + targetAnimation
, _RGB32(255, 0, 0, 100)
'IF i <> me AND LEN(playerStream(i)) > 0 THEN
' 'process player stream of coordinates
' player(i).x = CVS(MID$(playerStream(i), 1, 4))
' player(i).y = CVS(MID$(playerStream(i), 5, 4))
' playerStream(i) = MID$(playerStream(i), 9)
'END IF
x
= player
(i
).x
+ camera.x
+ COS(shipFlotation
) * shipFloatAmplitude
y
= player
(i
).y
+ camera.y
+ SIN(shipFlotation
) * shipFloatAmplitude
CircleFill x
, y
+ 6, player
(i
).size
+ 5, _RGB32(0, 50) CircleFill x
, y
, player
(i
).size
+ 5, _RGB32(0) CircleFill x
, y
, player
(i
).size
, colors
(player
(i
).
color)
score = score + 100
sendData server
, id_SHOOT
, MKI$(target
) addParticles player
(target
).x
, player
(target
).y
, 5, _RGB32(255) addParticles player
(target
).x
, player
(target
).y
, 100, colors
(player
(target
).
color) thickLine player
(me
).x
+ camera.x
, player
(me
).y
+ camera.y
, player
(target
).x
+ camera.x
, player
(target
).y
+ camera.y
, 8, _RGB32(227, 78, 6, 80)
updateParticles
'LINE (_WIDTH / 2 - cameraWindow, _HEIGHT / 2 - cameraWindow)-STEP(cameraWindow * 2, cameraWindow * 2), , B
'display warnings
IF warning
(i
).state
= True
THEN IF TIMER - warning
(i
).ping
> 2.5 THEN warning
(i
).state
= False
'display messagebox icon
IF mode
= mode_onlineclient
THEN
hasUnreadMessages = False
x = 60
x = 60
myMessage$ = myMessage$ + char$
myMessage$
= LEFT$(myMessage$
, LEN(myMessage$
) - 1) player(me).size = 15
sendData server
, id_SIZE
, MKI$(player
(me
).size
) myMessage$ = ""
chatOpen = False
player(me).size = 25
sendData server
, id_SIZE
, MKI$(player
(me
).size
) myMessage$ = ""
chatOpen = False
'temporary solution for triggering auto-update checks
sendData server, id_UPDATESERVER, ""
myMessage$ = ""
chatOpen = False
addMessageToChat me, myMessage$
sendData server, id_CHAT, myMessage$
myMessage$ = ""
tooFast = True
m$
= "(too fast - wait" + STR$(s
) + " second" + LEFT$("s", ABS(s
> 1)) + ")" IF TIMER - lastSentChat
> messageSpeed
THEN tooFast
= False
chatOpen = True
mouseWheel = 0
focus = 0
IF mx
> ui
(i
).x
AND mx
< ui
(i
).x
+ ui
(i
).w
AND my
> ui
(i
).y
AND my
< ui
(i
).y
+ ui
(i
).h
THEN focus = i
mouseDownOn = focus
mouseIsDown = True
IF mode
= mode_onlineclient
THEN chatOpen
= NOT chatOpen
mouseIsDown = False
IF mode
= mode_onlineclient
THEN
SWAP chat
(i
), chat
(i
- 1) chat
(UBOUND(chat
)).state
= True
chatOpen = True
chat
(UBOUND(chat
)).text
= text$
IF warning
(i
).state
= False
THEN warning(i).state = True
packet$
= MKI$(id
) + value$
+ endSignal
IF client.handle
THEN PUT #client.handle
, , packet$
GET #client.handle
, , incoming$
buffer = buffer + incoming$
endMarker
= INSTR(buffer
, endSignal
) value$
= MID$(buffer
, 3, endMarker
- 3) buffer
= MID$(buffer
, endMarker
+ LEN(endSignal
)) parse%% = True
camera.x
= _WIDTH / 2 - player
(me
).x
+ cameraWindow
camera.x
= _WIDTH / 2 - player
(me
).x
- cameraWindow
IF camera.x
> 0 THEN camera.x
= 0
camera.y
= _HEIGHT / 2 - player
(me
).y
+ cameraWindow
camera.y
= _HEIGHT / 2 - player
(me
).y
- cameraWindow
IF camera.y
> 0 THEN camera.y
= 0
' CX = center x coordinate
' CY = center y coordinate
' R = radius
' C = fill color
RadiusError = -Radius
X = Radius
Y = 0
LINE (CX
- X
, CY
)-(CX
+ X
, CY
), C
, BF
RadiusError = RadiusError + Y * 2 + 1
LINE (CX
- Y
, CY
- X
)-(CX
+ Y
, CY
- X
), C
, BF
LINE (CX
- Y
, CY
+ X
)-(CX
+ Y
, CY
+ X
), C
, BF
X = X - 1
RadiusError = RadiusError - X * 2
Y = Y + 1
LINE (CX
- X
, CY
- Y
)-(CX
+ X
, CY
- Y
), C
, BF
LINE (CX
- X
, CY
+ Y
)-(CX
+ X
, CY
+ Y
), C
, BF
dummy$ = text$
dist!
= _HYPOT((x2!
- x1!
), (y2!
- y1!
))
x0
= 0.5 * lineWeight%
* COS(a
) y0
= 0.5 * lineWeight%
* SIN(a
)
addedP = 0: p = 0
p = p + 1
addedP = addedP + 1
particle(p).state = True
particle(p).x = x
particle(p).y = y
particle
(p
).xv
= COS(a
) * (RND * 10) particle
(p
).yv
= SIN(a
) * (RND * 10) particle
(p
).start
= TIMER particle
(p
).duration
= RND
particle(i).xv = particle(i).xv + particle(i).xa
particle(i).x = particle(i).x + particle(i).xv
particle(i).yv = particle(i).yv + particle(i).ya + gravity
particle(i).y = particle(i).y + particle(i).yv
particle(i).state = False
CircleFill particle
(i
).x
+ camera.x
, particle
(i
).y
+ camera.y
, particle
(i
).size
, _RGB32(particle
(i
).r
, particle
(i
).g
, particle
(i
).b
, map
(TIMER - particle
(i
).start
, 0, particle
(i
).duration
, 255, 0))
FUNCTION map!
(value!
, minRange!
, maxRange!
, newMinRange!
, newMaxRange!
) map! = ((value! - minRange!) / (maxRange! - minRange!)) * (newMaxRange! - newMinRange!) + newMinRange!