Scripting language for C game
Has anybody used Boost.Python?
http://www.boost.org/libs/python/doc/tut...index.html
I just stumbled across it. After OSC "glowing" report on SWIG, I thought perhaps I might look in other directions...
http://www.boost.org/libs/python/doc/tut...index.html
I just stumbled across it. After OSC "glowing" report on SWIG, I thought perhaps I might look in other directions...
I might add that sometimes things seem simple and brilliant to people who are brilliant enough to reduce them to simplicity...
Of course I could be wrong and it's really simple for everyone 
Lua is simple for me though, and compared to many programmers I'm relitively inexperienced.
Of course I could be wrong and it's really simple for everyone 
Lua is simple for me though, and compared to many programmers I'm relitively inexperienced.
I would really want to do everything in a scripting language. However, I believe that Writing a collision detection system in a scripting language would be computation expensive. Am I correct?
What is the ultimate answer to Life, the Universe, and Everything?
Everything done in a scripting language is computationally expensive, relatively speaking. Circle and rectangle collision detection are pretty easy though, so you'd probably be able to do that without much problem -- maybe even some polygonal collision detection. Try it and find out!
Sorry, I'm doing 3d games. Should have clarified that.
Still, It doesn't hurt to try scripting based collision
Still, It doesn't hurt to try scripting based collision
What is the ultimate answer to Life, the Universe, and Everything?
I would imagine that AABB and bounding sphere checks could be done pretty easily. I would be skeptical past that. I do my 3D collision in the engine, not the scripts, but like you said, it surely couldn't hurt to try. Good luck with it, and let us know how it goes!
Well, you see, the things is, I'm extremely busy with my science fair project right now. However, I promise I'll come back to trying to do 3d collision detection in Python using scipy as soon as I'm done (which should take about 2 weeks).
What is the ultimate answer to Life, the Universe, and Everything?
I would suggest leaving physics to a compiled language like C. In my game here's what i do:
C Code:
Handles image loading/saving
Physics
Keyboard Input/Output
Drawing functions
Most other stuff
Lua Code:
Menus and Prefs through graphics and file Lua wrappers to my C functions
Setting up each level ("Player 1 Start!")
Game guides/special events (run into a special package and get certain bullets)
Special Collision events (hitting asteroid X runs Win.lua or something)
What Lua allows me to do is extend and expand the game without recompiling the whole thing and because it is simpler it allows me to focus on doing the task at hand.
But for fun, here's Pong.lua that clicking the app's icon in the prefs triggers:
All draw.something functions are openGL tie ins, and all madtak.something functions tie into my game engine, for example:
This checks to see if key 114 (ASCII: r) is pressed, and if it is, enters the command "luamenu menu.lua" in my game's console (which predates has nothing to do with the lua implementation, it's simply my way of switching between in game modes and toggle frames per second counters and other such tasks) before turning off the flag that key 114 was pressed.
I'm not saying that this setup is the best possible scenario (I don't have the experience to back that claim up), but I absolutely love it. I presume that other scripting languages could be integrated in similar ways
C Code:
Handles image loading/saving
Physics
Keyboard Input/Output
Drawing functions
Most other stuff
Lua Code:
Menus and Prefs through graphics and file Lua wrappers to my C functions
Setting up each level ("Player 1 Start!")
Game guides/special events (run into a special package and get certain bullets)
Special Collision events (hitting asteroid X runs Win.lua or something)
What Lua allows me to do is extend and expand the game without recompiling the whole thing and because it is simpler it allows me to focus on doing the task at hand.
But for fun, here's Pong.lua that clicking the app's icon in the prefs triggers:
Code:
--pong in lua...
draw.loadImage("flares.tga",14)
-- set up the variables
playFieldWidth=384
playFieldHeight=240
playFieldX=1024/2-384/2
playFieldY=768/2-240/2
player1x=10
player1y=120
player2x=playFieldWidth-10
player2y=120
score1=0
score2=0
ballx=384/2
bally=120
ballxv=-64
ballyv=64
r=0
function main(timer)
draw.pushMatrix()
r = r + 4*timer
draw.translate(playFieldX,playFieldY) --translate everything to the playfield
-- Draw the background
draw.color(0.0,0.2,0.0,1.0)
draw.rect(0,0,playFieldWidth,playFieldHeight)
draw.color(0.0,1.0,0.0,1.0)
draw.pushMatrix() --push a matrix for draw.text
draw.rotate(math.sin(r)*3) -- rotate the text
draw.text(0,playFieldHeight+10,"Score: "..tostring(score1)..","..tostring(score2))
draw.popMatrix()
-- Draw/move Player 1
draw.color(1.0,0.0,0.0,1.0)
draw.rect(player1x-5,player1y-30,player1x+5,player1y+30)
if player1y<playFieldHeight-32 and madtak.getKey(119)==1 then
player1y = player1y + 512 * timer
end
if player1y>32 and madtak.getKey(115)==1 then
player1y = player1y - 512 * timer
end
if player1y>playFieldHeight-32 then player1y=playFieldHeight-32 end
if player1y<32 then player1y=32 end
if ballx<15 and bally>player1y-30 and bally<player1y+30 then
ballxv = ballxv * -1
ballx=15
end
if ballx<2 then
score2 = score2 + 1
ballx=384/2
bally=120
ballxv=(math.random(1,2)*2-3)*64 -- -64 or 64
ballyv=(math.random(1,2)*2-3)*64
end
-- Draw/move Player 2
draw.color(1.0,0.0,0.0,1.0)
draw.rect(player2x-5,player2y-30,player2x+5,player2y+30)
if player2y<playFieldHeight-32 and madtak.getKey(4)==1 then
player2y = player2y + 512 * timer
end
if player2y>32 and madtak.getKey(3)==1 then
player2y = player2y - 512 * timer
end
if player2y>playFieldHeight-32 then player2y=playFieldHeight-32 end
if player2y<32 then player2y=32 end
if ballx>playFieldWidth-15 and bally>player2y-30 and bally<player2y+30 then
ballxv = ballxv * -1
ballx=playFieldWidth-15
end
if ballx>playFieldWidth-2 then
score1 = score1 + 1
ballx=384/2
bally=120
ballxv=(math.random(1,2)*2-3)*64 -- -64 or 64
ballyv=(math.random(1,2)*2-3)*64
end
-- The ball
draw.color(1.0,1.0,1.0,1.0)
draw.pushMatrix()
draw.translate(ballx,bally)
draw.scale(4*math.cos(r),4*math.sin(r))
draw.rect(-2,-2,2,2)
draw.popMatrix()
ballx = ballx + ballxv*timer
bally = bally + ballyv*timer
if bally<2 then
ballyv = ballyv * -1
bally=2
end
if bally>playFieldHeight-2 then
ballyv = ballyv * -1
bally=playFieldHeight-2
end
draw.popMatrix()
if madtak.getKey(114)==1 then
madtak.console("luamenu menu.lua")
madtak.setKey(114,0)
end
draw.text(20,20,"A,S,D,W and Arrow keys to move, r to return to menu")
return 1;
endCode:
if madtak.getKey(114)==1 then
madtak.console("luamenu menu.lua")
madtak.setKey(114,0)
endI'm not saying that this setup is the best possible scenario (I don't have the experience to back that claim up), but I absolutely love it. I presume that other scripting languages could be integrated in similar ways
Possibly Related Threads...
| Thread: | Author | Replies: | Views: | Last Post | |
| Ruby for scripting my game engine... | djork | 13 | 7,861 |
Aug 20, 2006 06:48 PM Last Post: OneSadCookie |
|
| RGSS: Ruby Game Scripting System | Carlos Camacho | 5 | 7,875 |
Jul 31, 2005 06:26 PM Last Post: Carlos Camacho |
|

