Hard Light Productions Forums

FreeSpace Releases => Scripting Releases => Topic started by: Nuke on July 10, 2006, 06:24:08 pm

Title: hud pong
Post by: Nuke on July 10, 2006, 06:24:08 pm
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
Title: Re: hud pong
Post by: Flipside on July 10, 2006, 07:10:45 pm
:lol::lol::lol:
Title: Re: hud pong
Post by: Nuke on July 10, 2006, 07:15:24 pm
i hope your not laughing at my code :D
Title: Re: hud pong
Post by: Flipside on July 10, 2006, 07:30:29 pm
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 ;)
Title: Re: hud pong
Post by: Goober5000 on July 10, 2006, 08:52:10 pm
:lol: :lol: :lol:

I think this is going in DEM II. :D
Title: Re: hud pong
Post by: Nuke on July 10, 2006, 11:46:15 pm
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
Title: Re: hud pong
Post by: neoterran on July 11, 2006, 12:39:31 am
 :D :p :p ;)
Title: Re: hud pong
Post by: Nuclear1 on July 11, 2006, 12:29:25 pm
:lol: :lol: :lol:

This is awesome!

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

:D
Title: Re: hud pong
Post by: CP5670 on July 11, 2006, 01:05:32 pm
This is brilliant stuff. :D :yes:
Title: Re: hud pong
Post by: Unknown Target on July 11, 2006, 09:12:42 pm
Screenies for those who don't have access to FS2 just now :(
Title: Re: hud pong
Post by: Nuke on July 12, 2006, 02:33:12 am
if you insist

(http://game-warden.com/nukemod-cos/Images/hudpong.jpg)

i wonder why lvlshots dont work anymore :D
Title: Re: hud pong
Post by: WMCoolmon on July 12, 2006, 04:14:46 am
Here's a fun challenge - can anyone figure out how (in theory) you could do internet multiplayer pong, by expanding on this method?
Title: Re: hud pong
Post by: Nuke on July 12, 2006, 05:39:45 am
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.
Title: Re: hud pong
Post by: karajorma on July 12, 2006, 07:18:41 am
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 :)
Title: Re: hud pong
Post by: Flipside on July 12, 2006, 08:54:48 am
LOL We have it! The final outcome of years of SCP research.


Network Pong!
Title: Re: hud pong
Post by: Colonol Dekker on July 12, 2006, 08:56:30 am
Next step.............snake on colossus... :lol:
Title: Re: hud pong
Post by: castor on July 12, 2006, 09:55:16 am
 :lol: This would provide nice pastime in multi, after one is out of respawns.
Title: Re: hud pong
Post by: aldo_14 on July 12, 2006, 10:24:34 am
LOL We have it! The final outcome of years of SCP research.


Network Pong!
:lol:

The future...is now! :D
Title: Re: hud pong
Post by: Nuclear1 on July 12, 2006, 11:17:05 am
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
Title: Re: hud pong
Post by: Nuke on July 12, 2006, 02:41:17 pm
a cookie for he who makes hud tetris :D
Title: Re: hud pong
Post by: Harbinger of DOOM on July 12, 2006, 04:52:22 pm
ROFL!!!!!
This is great!
Kudos to Nuke.
Title: Re: hud pong
Post by: Goober5000 on July 12, 2006, 04:53:54 pm
:lol: This would provide nice pastime in multi, after one is out of respawns.

:lol: Brilliant idea!
Title: Re: hud pong
Post by: Nuke on July 12, 2006, 09:27:46 pm
feel free to mod my game :D

heres some things you can improve upon

-newtonian physics :D
-textureed objects
-a scoring system
-make the game progressively harder to play (bumpers, faster ball, curved paddles, ect)
-make the game window moveable, scalable, minimizeable, ect.
-give the player lives
-4 paddle mode
-multiplayer support
-soundeffects
-replace ball with a mara class fighter :D
Title: Re: hud pong
Post by: WMCoolmon on January 14, 2007, 09:04:54 pm
http://fs2source.warpcore.org/temp/wmc/hudpong2.zip

For newer builds, requires C01142007b
Title: Re: hud pong
Post by: Dark Hunter on January 14, 2007, 10:17:34 pm
Finally something to do on long escort missions!  :D
Title: Re: hud pong
Post by: bizzybody on January 15, 2007, 12:09:37 am
And nobody's noticed the solitaire game on the upper monitor in that cockpit...

What's next? Mara Sweeper?  :wakka:
Title: Re: hud pong
Post by: Nuke on January 15, 2007, 07:54:08 am
i figured all it needed was to ckange ms. to io.

heh finally people noticed that sepulture bomber pilots get bored and need to play silly little games to keep their sanity :D
anyway it was a little joke i guess. i was anticipating rtt to work and so didnt put much effort into the screens. if i got time tomorrow i may try to rtt this thing onto the side of an orion :D
Title: Re: hud pong
Post by: takashi on March 25, 2007, 04:45:01 pm
necrothreadaged!...?

i think i'll make a place in the HUD juuust for this.

Title: Re: hud pong
Post by: Nuke on March 25, 2007, 07:31:30 pm
youl never get hud pong to compile! muhahahaha!
Title: Re: hud pong
Post by: takashi on March 26, 2007, 04:04:34 pm
think not! i will improve on your work!
Title: Re: hud pong
Post by: Snail on March 26, 2007, 04:05:48 pm
You can do scripting? Word.
Title: Re: hud pong
Post by: takashi on March 26, 2007, 07:49:16 pm
as long as i get a way to get images into hudpong, then yes i will script.
Title: Re: hud pong
Post by: Nuke on March 26, 2007, 10:49:09 pm
rather than upgrade hudpong why dont you do hud asteroids or hud centepede:D
Title: Re: hud pong
Post by: takashi on March 29, 2007, 01:28:15 pm
because those are way to complex for a n00b scripter. besides, why cant you make a mission in a huge asteroid field and set alpha 1's hitpoits to 0.00001?
Title: Re: hud pong
Post by: jr2 on March 29, 2007, 02:33:54 pm
a) Because the lowest you can go is 1, and even if you could get to 0.00001,
b) The blast from the asteroids would kill you.
Title: Re: hud pong
Post by: takashi on March 29, 2007, 07:09:04 pm
then set special explosions, and then get back to the topic of hudpong(tm)
Title: Re: hud pong
Post by: Unknown Target on March 29, 2007, 07:12:24 pm
I seriously doubt you know how to script takashi.
Title: Re: hud pong
Post by: jr2 on March 29, 2007, 08:05:44 pm
then set special explosions,

- That would work..

and then get back to the topic of hudpong(tm)
:p ::)
Title: Re: hud pong
Post by: WMCoolmon on March 29, 2007, 11:01:11 pm
because those are way to complex for a n00b scripter. besides, why cant you make a mission in a huge asteroid field and set alpha 1's hitpoits to 0.00001?

FRED and FS2_Open should still have 2D mission support. All you'd need to do would be to define an asteroid field that asteroids don't move or spawn on any other plane than the one the player ship is on.
Title: Re: hud pong
Post by: takashi on April 14, 2007, 11:53:11 am
still working on hudpong. so far:

textures
better physics
Title: Re: hud pong
Post by: Vretsu on April 17, 2007, 05:24:54 pm
still working on hudpong. so far:

textures
better physics

Screenshots.  :doubt:

Ha, I've always wanted to use that smilie. Now my wildest dreams are...no...longer...my dreams...?
Title: Re: hud pong
Post by: Nuke on April 18, 2007, 12:03:26 am
taking you awhile there, takashi. hudpong took me a whole 2 hours to program and im sure one of the scp coders could make a better version, from scratch, in about 15 minutes.
Title: Re: hud pong
Post by: takashi on April 18, 2007, 11:11:17 pm
its the image creation that takes time. seriously. im not going to settle for an 8 bit mara fighter.
Title: Re: hud pong
Post by: WMCoolmon on April 19, 2007, 02:15:00 am
You should be able to use the renderTechModel() function to draw fighters at whatever size you want.

I'm not sure, but I think you might also be able to render them to a texture to reduce lag. That's probably going a little beyond where you are at in scripting, though.
Title: Re: hud pong
Post by: Nuke on April 19, 2007, 04:16:12 am
ive never been able to get rtt to work at all it seems. its probibly faster just to draw them on the hud directly, ive done it before when trying to get my 3d shield gauges to worrk.
Title: Re: hud pong
Post by: takashi on April 19, 2007, 07:29:07 pm
what 3d shield gauges?