Page 1 of 14

Programming Pimpage Thread

PostPosted: Wed Mar 24, 2010 10:08 pm
by Surfa
Now I noticed a slight increase in coders on interlopers recently so I figure that we (not sure if I count as a coder) deserve a little thread of our own.

So here goes a coder pimpage thread.

Post any exciting piece of code you are working on be it a modding tool or a database editor it really doesn't matter. Now this may not catch on or it could even turn into a look how awesome coder/zombie are thread although it takes off it could also be used to share code snippets.

I will start it off with a small tool I decided to work on.
It basically allows for easy generation of .qc files for static props. Eventually I hope to turn it into a full .qc editor with syntax highlighting and such.
Image
Image

So post your stuff.

Re: Code Pimpage Thread

PostPosted: Wed Mar 24, 2010 10:13 pm
by Major Banter
Code: Select all
"WorldVertexTransition"
{
   "$basetexture" "Nature/forest_dirt_04"
   "$basetexture2" "FZTextures/FZ_floor_leaves2"
   "$surfaceprop" "dirt"
   "$blendmodulatetexture" "nature/blendtexture01"
   "%detailtype" "forest_floor_01"
}



I continue to find VMT construction hideously satisfying. Going to experiment with multiple Alphas and see if I can't find out why valve didn't like using more than 2.

Also going to make some comparison textures; never found the blendtexture raw VTFs, so I'll just make a few up to number 9 or something and see what effects I get.

Not the most amazing of code, but I like it.

Re: Code Pimpage Thread

PostPosted: Thu Mar 25, 2010 12:23 am
by Zipfinator
There's only a blendtexture01. Don't bother finding others. I've seen the .vtf in the GCF and there are no others around it.

Re: Code Pimpage Thread

PostPosted: Thu Mar 25, 2010 1:34 am
by Noodles
Code: Select all
   "...............if (Key.isDown(Key.UP) && canijump){
      jump = -15;
      canijump = false;
      }
      
   hero.y += jump;
   
   if (Key.isDown(Key.RIGHT)){
      hero.scaleX = +1;
      bg.x += -5;
      holerer.x += -5;
      holerer2.x += -5;
      plat.x += -5;
      plat2.x += -5;
      tunnel.x += -5;
      hero.gotoAndStop('walking');
      }.................."


;) No one said it had to be C++!

Re: Code Pimpage Thread

PostPosted: Thu Mar 25, 2010 2:59 am
by Unreal_Me
*snip* turns out the above was AS3


if somebody can actually find a useful implementation of the bozo sort algorothm, I'll be throughly impressed

Re: Code Pimpage Thread

PostPosted: Thu Mar 25, 2010 3:00 am
by city14
Action Script?

Cool stuff

Re: Code Pimpage Thread

PostPosted: Thu Mar 25, 2010 3:06 am
by .treeturtle--
what is that for, looks like a 2d game in C,
if so your jump code looks like it would fail epicly judging that hero.y is the players vertical location, but then again, i really don't know. you should elaborate

oh, and since sharing random code seems to be the thing to do then TADA! its LUA!
this is some simple trig stuff to make a ball follow the mouse. It took me a while to think of but I finally did. Now, a day later I see that I need to completely rewrite it and start over using a different method if i hope to fully get the desired movement... curse you math!
Code: Select all
function love.update(dt)
mouseX = love.mouse.getX()
mouseY = love.mouse.getY()

difinY2 = (mouseY - pointtwoY)
difinX2 = (mouseX - pointtwoX)

--POINT ONE, MOVE TOWARDS THE MOUSE
acthyp2 = math.sqrt( (difinX2 * difinX2) + (difinY2 * difinY2) )
proportion2 = (speed2 / acthyp2)
yforce2 = (difinY2 * proportion2)
xforce2 = (difinX2 * proportion2)
pointtwoX = pointtwoX + (xforce2 * dt * 1)
pointtwoY = pointtwoY + (yforce2 * dt * 1)

love.graphics.draw(ball2, pointtwoX, pointtwoY, r ,sx,sy,32,32)
-----------------------------
difinY = (pointtwoY - ballY)
difinX = (pointtwoX - ballX)


--BALL MOVE TOWARDS POINT TWO (which is actually point one)
acthyp = math.sqrt( (difinX * difinX) + (difinY * difinY))
proportion = (speed / acthyp)
yforce = (difinY * proportion)
xforce = (difinX * proportion)
ballX = ballX + (xforce * dt * 1)
ballY = ballY + (yforce * dt * 1)
love.graphics.draw(ball, ballX, ballY, shiprotation ,sx,sy,32,32)

--FACE THE MOUSE
if pointtwoX ~= (ballX+32)then
   if pointtwoX > (ballX+32) then
   shiprotation = (math.atan(difinY / difinX))
   end
   if pointtwoX < (ballX+32) then
   shiprotation = (math.atan(difinY / difinX) + math.rad(180))
   end
else
   if pointwoY > (ballY+32) then
   shiprotation = (math.rad(90))
   else shiprotation = (math.rad(270))
   end
end
end

Re: Code Pimpage Thread

PostPosted: Thu Mar 25, 2010 4:29 am
by coder0xff
No offense Banter, but I think VMT script - though maybe difficult - counts as coding just about as much as HTML does (which means not at all). Specifically, it's a document markup format, not a programming language.

Anyway, I suppose I'll avoid posting in here myself, unless it's something I really think you guys could use, but I'll be sure to drop in and see what's going on and give some crits.

Re: Code Pimpage Thread

PostPosted: Thu Mar 25, 2010 4:51 am
by coder0xff
.treeturtle-- wrote:oh, and since sharing random code seems to be the thing to do then TADA! its LUA!
this is some simple trig stuff to make a ball follow the mouse. It took me a while to think of but I finally did. Now, a day later I see that I need to completely rewrite it and start over using a different method if i hope to fully get the desired movement... curse you math!
Code: Select all
function love.update(dt)
mouseX = love.mouse.getX()
mouseY = love.mouse.getY()

difinY2 = (mouseY - pointtwoY)
difinX2 = (mouseX - pointtwoX)

--POINT ONE, MOVE TOWARDS THE MOUSE
acthyp2 = math.sqrt( (difinX2 * difinX2) + (difinY2 * difinY2) )
proportion2 = (speed2 / acthyp2)
yforce2 = (difinY2 * proportion2)
xforce2 = (difinX2 * proportion2)
pointtwoX = pointtwoX + (xforce2 * dt * 1)
pointtwoY = pointtwoY + (yforce2 * dt * 1)

love.graphics.draw(ball2, pointtwoX, pointtwoY, r ,sx,sy,32,32)
-----------------------------
difinY = (pointtwoY - ballY)
difinX = (pointtwoX - ballX)


--BALL MOVE TOWARDS POINT TWO (which is actually point one)
acthyp = math.sqrt( (difinX * difinX) + (difinY * difinY))
proportion = (speed / acthyp)
yforce = (difinY * proportion)
xforce = (difinX * proportion)
ballX = ballX + (xforce * dt * 1)
ballY = ballY + (yforce * dt * 1)
love.graphics.draw(ball, ballX, ballY, shiprotation ,sx,sy,32,32)

--FACE THE MOUSE
if pointtwoX ~= (ballX+32)then
   if pointtwoX > (ballX+32) then
   shiprotation = (math.atan(difinY / difinX))
   end
   if pointtwoX < (ballX+32) then
   shiprotation = (math.atan(difinY / difinX) + math.rad(180))
   end
else
   if pointwoY > (ballY+32) then
   shiprotation = (math.rad(90))
   else shiprotation = (math.rad(270))
   end
end
end


Got some suggestions for ya. If you are just trying to make pointtwo move towards the mouse (and it looks like the further away it is the less aggressively it accelerates as you have it now? is it supposed to be like gravity? lemme know cause the equation's completely different). This equation makes it move fast if it's far away, and slows as it approaches the mouse, and is correctly integrated over time if you have loss of frame rate.

Code: Select all
//assuming dt is time delta
difinY2 = (mouseY - pointtwoY)
difinX2 = (mouseX - pointtwoX)
step = 1 - math.exp(-dt * speed)
pointtwoY += difinY2 * step
pointtwoX += difinX2 * step


If you are trying to do a system where momentum is preserved and force is used to accelerate the point towards the mouse and then decelerate so that it stops when it reaches the mouse, it's a little more difficult (unless you know how).

Also, you may want to look into the function math.atan2(y, x). It automagically determines which quadrant you're in so you don't have to do all that extra stuff you got at the end there.

Re: Code Pimpage Thread

PostPosted: Thu Mar 25, 2010 12:23 pm
by Major Banter
coder0xff wrote:No offense Banter, but I think VMT script - though maybe difficult - counts as coding just about as much as HTML does (which means not at all). Specifically, it's a document markup format, not a programming language.


Fine, if you're going to be like that, you can taste my weapon_AK code when I get home you philistine.

On a side note, HTML is incredibly complicated and I think being elitist about what specifically counts as code is demotivating and decidely arrogant. No offence, that's my reading of what you've typed.

Zipfinator wrote:There's only a blendtexture01. Don't bother finding others. I've seen the .vtf in the GCF and there are no others around it.


I assume it's an Alpha Channel then; could you drop me the path in a PM?

Re: Code Pimpage Thread

PostPosted: Thu Mar 25, 2010 1:40 pm
by Noodles
@ .treeturtle-- it was AS3, for a sidescroller I made a while ago. Is only a random segment of the code so only half the jump code is there, suffice to say it worked ;)

Re: Code Pimpage Thread

PostPosted: Thu Mar 25, 2010 6:13 pm
by .treeturtle--
coder0xff wrote:
Got some suggestions for ya. If you are just trying to make pointtwo move towards the mouse (and it looks like the further away it is the less aggressively it accelerates as you have it now? is it supposed to be like gravity? lemme know cause the equation's completely different). This equation makes it move fast if it's far away, and slows as it approaches the mouse, and is correctly integrated over time if you have loss of frame rate.

If you are trying to do a system where momentum is preserved and force is used to accelerate the point towards the mouse and then decelerate so that it stops when it reaches the mouse, it's a little more difficult (unless you know how).

Also, you may want to look into the function math.atan2(y, x). It automagically determines which quadrant you're in so you don't have to do all that extra stuff you got at the end there.


I'm definitely going to look into math.atan2 thanks
basically, this creates two points, the first point moves at a specified speed always directly at the mouse, the second point does the same but it always moves towards the first invisible point, this second point is where the actual object is. This makes the ball follow the mouse, but not directly, it takes time to make wide turns instead of just going straight at the mouse. It's like a three car train. its based off constantly updating the x and y value of the ball so that its "vector" or hypotenuse is. It works, the problem is that the "train cars" can go on top of each other. I'm redoing it by updating the angle of movement and basing the x y off that, instead of making a "train" which should fix it I think. I've got all the math down on paper but haven't typed it up yet.

this doesn't change the speed based off the distance of the mouse because of the use of "proportion", however i plan on implementing that in the game, which is a prototype for a soon to be iphone game. if i can prove my concept in lua on LOVE ( http://www.love2d.org ) then i'll start on the iphone version

Re: Code Pimpage Thread

PostPosted: Thu Mar 25, 2010 6:51 pm
by Terr
This is an old picture from the pre-rewrite version, but... TF2Maps released a pack of custom materials called "The Swamp Pack". Since I was working on a dependency-solver for custom map content, here's the dependencies (in terms of models, materials, and textures.)
Image
The blue nodes are logical helpers, since model-materials are actually specified based on search paths which must be evaluated.


Major Banter wrote:On a side note, HTML is incredibly complicated and I think being elitist about what specifically counts as code


The Mona Lisa is special, but it isn't "code" either. Nor is written prose like "War and Peace"*. It's not elitist, it's simply that HTML--alone--doesn't have any algorithmic content.

*Some laws/contracts/spreadsheets would qualify as having algorithmic content.

Re: Code Pimpage Thread

PostPosted: Thu Mar 25, 2010 9:10 pm
by coder0xff
Major Banter wrote:On a side note, HTML is incredibly complicated and I think being elitist about what specifically counts as code is demotivating and decidely arrogant. No offence, that's my reading of what you've typed.


Perhaps I am being elitist, since "code" doesn't necessarily mean "programming", but then I guess I could just post pig-latin translations of regular English. :lol:

But if we are to assume that code means programming (which I believe was the intent) then HTML, however complicated is still not programming. The very name itself states that it's a document markup language. Programs take input, perform operations on that input using arithmetic and control structures, and generate output. HTML and VMTs do none of these. They are documents.

Just to clarify, I'm not trying to be mean or offensive, and I in no way take offense. I just feel strongly about this topic (as most programmers do) because people believing that HTML is programming trivializes the skill that it takes to make a real program. I'd like to see HTML make that physics engine recently posted in Random Thread.

Re: Code Pimpage Thread

PostPosted: Thu Mar 25, 2010 9:20 pm
by Major Banter
A code is a rule for converting a piece of information (for example, a letter, word, phrase, or gesture) into another form or representation (one sign into another sign), not necessarily of the same type.


Ergo. Condensing of information. Code is specifically the transference of specific stuff into a different form where it can be read and utilised differently; as said there. Programming is a sub-section of coding. Ergo, chill out and look at my coverted information within these VMTs and .txts; if you're lucky, you can check out me totally destroying a .dll later if VisualStudio decides to work.

Oh, by the way


I NEVER MENTIONED PROGRAMMING.


So chill. Programming = Code. Code does NOT = programming.

Ps: Yes you're better and can program, which is so talented I can't comprehend that shit. But there's no need to be cockend, you're massively superior regardless.


EDIT: Name change = Banter exits through side door. Thank you all.