Making a SketchUp game named "Resballiza"
-
Hi,
This Thread is meant to document my progress in learning ruby inside sketchup while trying to make a simple game. So any questions or discoveries will be posted here.
Before venturing in trying to figure out how to make a game inside sketchup, I started one called “Resballiza” with ruby and Gosu. The progress of that task was successful and more info can be found here: Resballiza info and Video Preview
My future goal is to try and replicate “Resballiza” inside sketchup.
Wish me luck!
Here is a game I am developing for SketchUp
Video Update #1
Youtube VideoVideo Update #2
Youtube Video
Video Update #3
To download the latest SketchUp game version go here;
https://www.dropbox.com/sh/w9m7du0fnhkgwv0/bIqndmMs1SThanks
-
transform! Vs move!
The method “move!” seems to behave similar to how the objects move in “Resballiza” with the “gosu” extension for ruby. It uses a global axis as reference for the (x,y,z) coordinates of the object while the Method “transform!” seems to use the local axis of that entity. I kind of figured out how to reset the position of an object when the Zaxis reaches a certain point using the method “move!” with the following code…
# This file attepts to move an object down and when it reachea a certain distance it resets. require('sketchup.rb') #============================================================= module Game # # module Resballiza # # class MyGame # # def inicializa () @x = 600 @z = 800 end # #-------------------------------------------------------- @x = 600 #Delete this after 1st exec hit for ball to move @z = 800 #Delete this after 1st exec hit for ball to move #-------------------------------------------------------- # @ball = Sketchup.active_model.selection @move = Geom;;Vector3d.new(@x,0,@z) # # @ball.each do |ball| ball.move!(Geom;;Transformation.translation(@move)) # # if @z <= 800 @z = @z - 50 end #if # # if @z <= -200 @z = 800 @x = rand(600) end #if # # end #do # # end #class MyGame # window = MyGame.new #If this is not here the above script won't work. # end #module Resballiza # # end # module Game
The code doesn’t run smoothly inside “Sketchup” because ones you hit “exec” in the Web Console for the first time, you have to delete the code line that says “#Delete this after 1st exec hit for ball to move”. Once that is done you need to keep hitting “exec” for object to keep falling until it resets. I wish I can figure out how to solve this so I can move to the next step.
Thanks
-
Cool game
Black Ball can't move over the horizontal middle line ?
Bon courage! -
error 404
-
@unknownuser said:
Black Ball can't move over the horizontal middle line ?
The ball can move freely all over the screen (even above the middle line)...There is a Resballiza.exe that runs without install, you can try it yourself with this following link.
http://www.dropbox.com/sh/b9wp4fnvisd0qyd/-D3fdDBkZWThanks
-
The link is fixed....thanks for letting me know.
Just drop the files inside a folder and done.
-
@unknownuser said:
transform!
Vsmove!
transform!
puts entries on the undo stack
move!
does not put entries on the undo stack (so it's faster.)Both only work on a
Group
orComponentInstance
For primitives you must use:
Entities.transform_entities()
.. which says:
@unknownuser said:Important note: If you apply a transformation to entities that are not in the current edit context (i.e. faces that are inside a group), SketchUp will apply the transformation incorrectly, since the geometry has one origin and the current edit context has another. You can correct for this by watching the
Model.edit_transform
andModel.active_path
. SeeModelObserver.onActivePathChanged
for more information. -
Oh.. and the toplevel namespace (module) should be YOUR company or author name.
Not something common like "Game"... maybe
Renderiza
orRiveraR
?? -
Problem fixed!
I now don’t have to delete any line of code after I hit the “exec” button for the script to work. Let me explain how this issue on the last code I posted was fixed. I was looking through the code Dan Rathbun posted in the following link.
http://forums.sketchucation.com/viewtopic.php?f=180&t=48045
I was asking myself why he uses this “||” in “@@duration ||= 15” for example and decided to put “||” in my own code. For some “magical” reason the script now works.
Here is the new code:
# This file attepts to move an object down and when it reachea a certain distance it resets. require('sketchup.rb') #============================================================= module Renderiza # # module Resballiza # # class MyGame # # @@x ||= 600 @@z ||= 800 if @@z <= 800 @@z = @@z - 100 end if @@z <= -200 @@z = 800 @@x = rand(600) end @ball = Sketchup.active_model.selection @move = Geom;;Vector3d.new(@@x,0,@@z) # # @ball.each do |ball| ball.move!(Geom;;Transformation.translation(@move)) end #do # # end #class MyGame # window = MyGame.new #If this is not here the above script won't work. # end #module Resballiza # # end # module Renderiza
Also the object is Xaxis randomly generates every time it resets. Now I can move to the next step which is to animate the object without having to keep clicking the “exec” button.
Wish me luck!
-
Please use [ code ] ... [ /code ] bbTags, with space indenting.
I did say those snippets had problems...
Look at my example: AnimateSelection
Look at the
Animate
class. See how I defined aninitialize()
method ??When you call a class' public class constructor method
new()
, it creates the instance, THEN calls the instance's copy of theinitialize()
method.
In this method is where you init @var instance variables.Did you read the "Pick-Axe" Ruby Pragmatic Programmer's Guide ?? It's basic Ruby 101 ...
-
Current issue at hand…
In the code bellow the references have to be “$” (constant) or else the script won’t work.
1st Problem
I have tried to use “@”& “@@” but it doesn’t seem to work… I should not use a constant as reference but right now I am lost in how to not use them.2nd Problem
When using this following code:… This code is similar to the one been used by the following here;
http://forums.sketchucation.com/viewtopic.php?f=180&t=25498#p218970module Renderiza module Resballiza class SuGame $x ||= 600 $z ||= 800 if $z <=> 800 $z = $z - 100 end if $z <= -200 $z = 800 $x = rand(600) end def nextFrame( view ) $ball.move! $t #<<<---- using the move! there return ( Time.now() - $start ) <3 end def stop() puts 'emptying trash' end $ball = Sketchup.active_model.selection[0] @move = Geom;;Vector3d.new($x,0,$z) $t = Geom;;Transformation.translation(@move) $start = Time.now() end # of class SuGame view = Sketchup.active_model().active_view() view.animation = SuGame.new end #module Resballiza end #module Renderiza
Continuation of problem #2…
When the animation is started the object is position doesn’t travel down like it should with only one click. I still have to keep clicking the ‘exec’ button for it to move.
There is something about this “move!” method because if you replace that with “transform!” like it was originally written by the other guys then the object is position changes over time. But there has to be something that will still enable me to use the move! method because I really like that it uses the global axis of sketchup instead of the local axis of the object the transform! uses.
-
Hi,
Here is a video update about the progress of the game so far;
I need to find an alternative solution for playing sound effects since the Sketchup "UI.play_sound" can't seem to handle simultaneous sounds to overlay each other.
The current script is based on Scott Lininger's "Prince IO" but a lot of things are different. For example the collision is base on a javascript code to compare distances and not sketchup raytrace.
If you want to test the current alpha version of the game you can download it here for testing.
https://www.dropbox.com/sh/w9m7du0fnhkgwv0/bIqndmMs1S
Thanks
-
Does it a special install or more files to install than Resballiza.rb ?
You have not an only zip file ?
I have run it, I have the Menu Inside the Menu Plugins,Resballiza Demo level, but nothing happen ?
tested under V7 -
@unknownuser said:
Does it a special install or more files to install than Resballiza.rb ?
You have not an only zip file ?
I have run it, I have the Menu Inside the Menu Plugins,Resballiza Demo level, but nothing happen ?
tested under V7Apart from the "resballiza.rb" file being in the plugins directory of sketchup you also need to have the folder included in the link named "resballiza". If you have the "resballiza.rb" and resballiza folder with all the files inside the plugins directory it should work unless there is incompatibilities with a version of sketchup lower than 8. I will see if I can find the problem.
Thanks
-
@unknownuser said:
So it's normal if I had onl the RB!
Ok I will made a new test when I have some free times!
But It's some painful to download file one by one!
A one Zip file will be a lot of better!Ok I have included the zip and just in case saved the sketchup file of the level in version 6. Also for the time being the sounds are disabled until problem is fixed.
Thanks
-
So it's normal if I had only the RB!
Ok I will made a new test when I have some free times!
But It's some painful to download file one by one!
A one Zip file will be a lot of better! -
Thanks for the ZIp file!
All works fine now! (tested on V7)
Have you a test (or other thing) for be sure there is not a fully horizontal line of balls ? -
Well good question…
There are 10 white balls that will each reset a value of 100 of each other in the z axis when they reach the bottom of the screen.Examples of reset value in z axis;
ballZa = 900 ;
ballZb = 1000 ;
ballZc = 1100 ;
ballZd = 1200 ;
ect…There is a possibility that after a period of time they will be near parallel of one another but to create horizontal line will be unlikely since the x axis is generated randomly. Not saying is not impossible...I guess I will have to test it and see if it happens.
-
Impossible is always probable :Murphy's law!
-
I hope Murphy is right because solving the sound effect problem its beginning to look impossible. I will try to work on other parts of the game until eureka shows at the door.
Advertisement