FreeSpace Releases > Scripting Releases

hud pong

(1/10) > >>

Nuke:
put this in scripting.tbl and load a mission
btw this assumes youre running in a resoltuin more than 1024 * 768, i might update it later to sopport lesser resolutions.
btw the mouse controls the paddels, an axis for each, so you might want to turn off mouse flight, that is unless you want to play pong and fight shivans at the same time :D


--- Code: ---
#Global Hooks

$GameInit:

[

--HudPong (tm)
w = gr.getScreenWidth()
h = gr.getScreenHeight()

poneh = 0
ptwoh = 0
gameh = 200
gamew = 300
gamex = w / 2
gamey = h / 2
ballx = gamex
bally = gamey
ballxvel = 1
ballyvel = 1
balla = 255

drawpongarea = function(x, y, sx, sy) --pong box here
gr.setColor(0,200,0,255) --pong green
gr.drawLine(x-sx, y+sy, x+sx, y+sy)
gr.drawLine(x-sx, y-sy, x+sx, y-sy)
end

drawpongpaddle = function(x, y)
gr.setColor(0,0,200,255)
gr.drawRectangle(x+5, y+15, x-5, y-15, true)
end

drawpongball = function(x, y, a)
gr.setColor(200,0,0,a)
gr.drawCircle(10,x,y)
end

--im nuts

]

$HUD:

[

--HudPong

drawpongarea(gamex,gamey,gamew/2,gameh/2) --draw playing area every frame

maxis1 = ((ms.getY() /  768) * (gameh * 0.8)) --paddels, what a mess, my math sucks
maxis2 = ((ms.getX() / 1024) * (gameh * 0.8))
poneh = (maxis1 + (gamey - (gameh / 2))) + ((gameh - (gameh * 0.8)) / 2)
ptwoh = (maxis2 + (gamey - (gameh / 2))) + ((gameh - (gameh * 0.8)) / 2)
drawpongpaddle(gamex + (gamew/2), poneh)
drawpongpaddle(gamex - (gamew/2), ptwoh)

ballx = ballx + ballxvel --move and draw the ball
bally = bally + ballyvel
drawpongball(ballx, bally, balla)

if bally < (gamey - (gameh / 2)) + 5 or bally > (gamey + (gameh / 2)) - 5 then
ballyvel = ballyvel * -1 --bounce off borders
end

if ballx < (gamex - (gamew / 2)) or ballx > (gamex + (gamew / 2)) then --tell the player when he gets castrated and reset the game
gr.setColor(200,200,200,255)
gr.drawString("Dont Loose Your Balls", gamex - 80, gamey)
balla = balla - 10
if balla < 1 then
ballx = gamex
bally = gamey
balla = 255
end
end

if (ballx < (gamex - (gamew / 2)) + 10 and bally > ptwoh - 15 and bally < ptwoh + 15) or (ballx > (gamex + (gamew / 2)) - 10 and bally > poneh - 15 and bally < poneh + 15) then
ballxvel = ballxvel * -1 --bounce off paddles
end

--nuts indeed

]

#End


--- End code ---

:D

Flipside:
:lol::lol::lol:

Nuke:
i hope your not laughing at my code :D

Flipside:
LOL No, it's better than any attempt I could make ;) I think you may have just explained why your co-pilots keep trying to fly into you though, they keep getting the controls confused ;)

Goober5000:
:lol: :lol: :lol:

I think this is going in DEM II. :D

Navigation

[0] Message Index

[#] Next page

Go to full version