Author Topic: hud pong  (Read 8123 times)

0 Members and 1 Guest are viewing this topic.

Offline Nuke

  • Ka-Boom!
  • 212
  • Mutants Worship Me
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: [Select]

#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


:D
« Last Edit: July 10, 2006, 06:36:27 pm by Nuke »
I can no longer sit back and allow communist infiltration, communist indoctrination, communist subversion, and the international communist conspiracy to sap and impurify all of our precious bodily fluids.

Nuke's Scripting SVN

 

Offline Flipside

  • əp!sd!l£
  • 212

 

Offline Nuke

  • Ka-Boom!
  • 212
  • Mutants Worship Me
i hope your not laughing at my code :D
I can no longer sit back and allow communist infiltration, communist indoctrination, communist subversion, and the international communist conspiracy to sap and impurify all of our precious bodily fluids.

Nuke's Scripting SVN

 

Offline Flipside

  • əp!sd!l£
  • 212
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 ;)

 

Offline Goober5000

  • HLP Loremaster
  • Administrator
  • 214
    • Goober5000 Productions
:lol: :lol: :lol:

I think this is going in DEM II. :D

 

Offline Nuke

  • Ka-Boom!
  • 212
  • Mutants Worship Me
an update
now it supports any resolution, and you can set different constants for where to draw the game and how big.

Code: [Select]

#Global Hooks

$GameInit:

[

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

poneh = 0
ptwoh = 0
gameh = 300 --you can change this to what
gamew = 600 --ever resolution you want.
gamex = w / 2 --set what coords to draw
gamey = h / 2 --the game at here (game center).
ballx = gamex
bally = gamey
ballxvel = 1 --or change theese if you
ballyvel = 1 --want a faster ball speed
balla = 255
deathmsg = "Dont Loose Your Balls!"

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)
gr.setColor(0,100,0,20)
gr.drawRectangle(x-sx, y+sy, x+sx, y-sy) --now featuring a transparent back
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

if w >= 1024 then --compensate for resolution
maxis1 = ((ms.getY() /  768) * (gameh * 0.9)) --paddels, what a mess, my math sucks
maxis2 = ((ms.getX() / 1024) * (gameh * 0.9))
else
maxis1 = ((ms.getY() / 480) * (gameh * 0.9)) --paddels, what a mess, my math sucks, now in lowres!
maxis2 = ((ms.getX() / 640) * (gameh * 0.9))
end


poneh = (maxis1 + (gamey - (gameh / 2))) + ((gameh - (gameh * 0.9)) / 2)
ptwoh = (maxis2 + (gamey - (gameh / 2))) + ((gameh - (gameh * 0.9)) / 2)
drawpongpaddle(gamex + (gamew/2) - 5, poneh)
drawpongpaddle(gamex - (gamew/2) + 5, 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(deathmsg, gamex - (gr.getStringWidth(deathmsg) / 2) , gamey)
balla = balla - 8
if balla < 1 then
ballx = gamex
bally = gamey
balla = 255
end
end

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

--nuts indeed

]

#End


im gonna put it up on the wiki cause i guess it can be educational :D
« Last Edit: July 10, 2006, 11:49:28 pm by Nuke »
I can no longer sit back and allow communist infiltration, communist indoctrination, communist subversion, and the international communist conspiracy to sap and impurify all of our precious bodily fluids.

Nuke's Scripting SVN

 

Offline neoterran

  • 210
Official Taylor Fan Club Member.
Chief Grognard.
"How much code could a coder code if a coder could code code?"

 

Offline Nuclear1

  • 211
:lol: :lol: :lol:

This is awesome!

Quote
I think this is going in DEM II. :D

:D
Spoon - I stand in awe by your flawless fredding. Truely, never before have I witnessed such magnificant display of beamz.
Axem -  I don't know what I'll do with my life now. Maybe I'll become a Nun, or take up Macrame. But where ever I go... I will remember you!
Axem - Sorry to post again when I said I was leaving for good, but something was nagging me. I don't want to say it in a way that shames the campaign but I think we can all agree it is actually.. incomplete. It is missing... Voice Acting.
Quanto - I for one would love to lend my beautiful singing voice into this wholesome project.
Nuclear1 - I want a duet.
AndrewofDoom - Make it a trio!

 

Offline CP5670

  • Dr. Evil
  • Global Moderator
  • 212
  • 142857
This is brilliant stuff. :D :yes:

 

Offline Unknown Target

  • Get off my lawn!
  • Global Moderator
  • 212
  • Push.Pull?
Screenies for those who don't have access to FS2 just now :(

 

Offline Nuke

  • Ka-Boom!
  • 212
  • Mutants Worship Me
if you insist



i wonder why lvlshots dont work anymore :D
I can no longer sit back and allow communist infiltration, communist indoctrination, communist subversion, and the international communist conspiracy to sap and impurify all of our precious bodily fluids.

Nuke's Scripting SVN

 

Offline WMCoolmon

  • Purveyor of space crack
  • 213
Here's a fun challenge - can anyone figure out how (in theory) you could do internet multiplayer pong, by expanding on this method?
-C

 

Offline Nuke

  • Ka-Boom!
  • 212
  • Mutants Worship Me
you would first need to share the variables of the game between client and server. there arent many of them. could pretty much all be crammed into one packet. the server would be responsible for all the colision detection, scoring, ect. the only variable the client would be allowed to modify is the paddle location (poneh or ptwoh, depending on which side the client is on). the client code would be responsible for getting the mouse coords and calculating the paddle location for that player. the client paddle location would be sent to the server so colisions could be detected  the client would have the draw functions available, however the function calls would be relayed from the server to the client. the background as its static would be drawn by the client, same as their paddle, but the ball and server's paddle would be called from the server. i could probibly set it up fairly easy if i had network-global variables, and some sort of function call forwarding.
I can no longer sit back and allow communist infiltration, communist indoctrination, communist subversion, and the international communist conspiracy to sap and impurify all of our precious bodily fluids.

Nuke's Scripting SVN

 

Offline karajorma

  • King Louie - Jungle VIP
  • Administrator
  • 214
    • Karajorma's Freespace FAQ
If you can get the variables from the script into SEXP variables and visa versa the game now handles the updating of those automatically for you.

Might not be the most efficient way of doing things though :)
Karajorma's Freespace FAQ. It's almost like asking me yourself.

[ Diaspora ] - [ Seeds Of Rebellion ] - [ Mind Games ]

 

Offline Flipside

  • əp!sd!l£
  • 212
LOL We have it! The final outcome of years of SCP research.


Network Pong!

 

Offline Colonol Dekker

  • HLP is my mistress
  • 213
  • Aken Tigh Dekker
    • My old squad sub-domain
Next step.............snake on colossus... :lol:
Your friendly Orestes tactical controller
GO GO DEKKER RANGERSSSS!!!!!!!!!!!!!!!!!
President of the Scooby Doo Model Appreciation Society
The only good Zod is a dead Zod
NEWGROUNDS COMEDY GOLD, UPDATED DAILY
http://badges.steamprofile.com/profile/default/steam/76561198011784807.png

 

Offline castor

  • 29
    • http://www.ffighters.co.uk./home/
 :lol: This would provide nice pastime in multi, after one is out of respawns.

 

Offline aldo_14

  • Gunnery Control
  • 213
LOL We have it! The final outcome of years of SCP research.


Network Pong!
:lol:

The future...is now! :D

 

Offline Nuclear1

  • 211
LOL We have it! The final outcome of years of SCP research.


Network Pong!

I sense that I Spy's rule as the official GTVA pasttime is over. :D
Spoon - I stand in awe by your flawless fredding. Truely, never before have I witnessed such magnificant display of beamz.
Axem -  I don't know what I'll do with my life now. Maybe I'll become a Nun, or take up Macrame. But where ever I go... I will remember you!
Axem - Sorry to post again when I said I was leaving for good, but something was nagging me. I don't want to say it in a way that shames the campaign but I think we can all agree it is actually.. incomplete. It is missing... Voice Acting.
Quanto - I for one would love to lend my beautiful singing voice into this wholesome project.
Nuclear1 - I want a duet.
AndrewofDoom - Make it a trio!

 

Offline Nuke

  • Ka-Boom!
  • 212
  • Mutants Worship Me
a cookie for he who makes hud tetris :D
I can no longer sit back and allow communist infiltration, communist indoctrination, communist subversion, and the international communist conspiracy to sap and impurify all of our precious bodily fluids.

Nuke's Scripting SVN