sketchucation logo sketchucation
    • Login
    ℹ️ Licensed Extensions | FredoBatch, ElevationProfile, FredoSketch, LayOps, MatSim and Pic2Shape will require license from Sept 1st More Info

    Making a SketchUp game named "Resballiza"

    Scheduled Pinned Locked Moved Developers' Forum
    27 Posts 4 Posters 2.4k Views 4 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • renderizaR Offline
      renderiza
      last edited by

      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

      [url=https://www.sketchupcode.com/:z3kqsidd]My Extensions ...[/url:z3kqsidd]

      1 Reply Last reply Reply Quote 0
      • pilouP Offline
        pilou
        last edited by

        Cool game 😄
        Black Ball can't move over the horizontal middle line ?
        Bon courage! ☀

        Frenchy Pilou
        Is beautiful that please without concept!
        My Little site :)

        1 Reply Last reply Reply Quote 0
        • pilouP Offline
          pilou
          last edited by

          error 404 😉

          Frenchy Pilou
          Is beautiful that please without concept!
          My Little site :)

          1 Reply Last reply Reply Quote 0
          • renderizaR Offline
            renderiza
            last edited by

            @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/-D3fdDBkZW

            Thanks

            [url=https://www.sketchupcode.com/:z3kqsidd]My Extensions ...[/url:z3kqsidd]

            1 Reply Last reply Reply Quote 0
            • renderizaR Offline
              renderiza
              last edited by

              The link is fixed....thanks for letting me know. 👍

              Just drop the files inside a folder and done.

              [url=https://www.sketchupcode.com/:z3kqsidd]My Extensions ...[/url:z3kqsidd]

              1 Reply Last reply Reply Quote 0
              • Dan RathbunD Offline
                Dan Rathbun
                last edited by

                @unknownuser said:

                transform! Vs move!

                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 or ComponentInstance

                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 and Model.active_path. See ModelObserver.onActivePathChanged for more information.

                I'm not here much anymore.

                1 Reply Last reply Reply Quote 0
                • Dan RathbunD Offline
                  Dan Rathbun
                  last edited by

                  Oh.. and the toplevel namespace (module) should be YOUR company or author name.

                  Not something common like "Game"... maybe Renderiza or RiveraR ??

                  I'm not here much anymore.

                  1 Reply Last reply Reply Quote 0
                  • renderizaR Offline
                    renderiza
                    last edited by

                    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!

                    [url=https://www.sketchupcode.com/:z3kqsidd]My Extensions ...[/url:z3kqsidd]

                    1 Reply Last reply Reply Quote 0
                    • Dan RathbunD Offline
                      Dan Rathbun
                      last edited by

                      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 an initialize() method ??

                      When you call a class' public class constructor method new(), it creates the instance, THEN calls the instance's copy of the initialize() 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 ...

                      I'm not here much anymore.

                      1 Reply Last reply Reply Quote 0
                      • renderizaR Offline
                        renderiza
                        last edited by

                        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#p218970

                        module 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.

                        [url=https://www.sketchupcode.com/:z3kqsidd]My Extensions ...[/url:z3kqsidd]

                        1 Reply Last reply Reply Quote 0
                        • renderizaR Offline
                          renderiza
                          last edited by

                          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.

                          Dropbox

                          favicon

                          (www.dropbox.com)

                          Thanks

                          [url=https://www.sketchupcode.com/:z3kqsidd]My Extensions ...[/url:z3kqsidd]

                          1 Reply Last reply Reply Quote 0
                          • pilouP Offline
                            pilou
                            last edited by

                            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

                            Frenchy Pilou
                            Is beautiful that please without concept!
                            My Little site :)

                            1 Reply Last reply Reply Quote 0
                            • renderizaR Offline
                              renderiza
                              last edited by

                              @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 V7

                              Apart 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

                              [url=https://www.sketchupcode.com/:z3kqsidd]My Extensions ...[/url:z3kqsidd]

                              1 Reply Last reply Reply Quote 0
                              • renderizaR Offline
                                renderiza
                                last edited by

                                @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

                                [url=https://www.sketchupcode.com/:z3kqsidd]My Extensions ...[/url:z3kqsidd]

                                1 Reply Last reply Reply Quote 0
                                • pilouP Offline
                                  pilou
                                  last edited by

                                  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!

                                  Frenchy Pilou
                                  Is beautiful that please without concept!
                                  My Little site :)

                                  1 Reply Last reply Reply Quote 0
                                  • pilouP Offline
                                    pilou
                                    last edited by

                                    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 ?

                                    Frenchy Pilou
                                    Is beautiful that please without concept!
                                    My Little site :)

                                    1 Reply Last reply Reply Quote 0
                                    • renderizaR Offline
                                      renderiza
                                      last edited by

                                      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.

                                      [url=https://www.sketchupcode.com/:z3kqsidd]My Extensions ...[/url:z3kqsidd]

                                      1 Reply Last reply Reply Quote 0
                                      • pilouP Offline
                                        pilou
                                        last edited by

                                        Impossible is always probable :Murphy's law! 💚

                                        Frenchy Pilou
                                        Is beautiful that please without concept!
                                        My Little site :)

                                        1 Reply Last reply Reply Quote 0
                                        • renderizaR Offline
                                          renderiza
                                          last edited by

                                          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.

                                          [url=https://www.sketchupcode.com/:z3kqsidd]My Extensions ...[/url:z3kqsidd]

                                          1 Reply Last reply Reply Quote 0
                                          • Dan RathbunD Offline
                                            Dan Rathbun
                                            last edited by

                                            @unknownuser said:

                                            I hope Murphy is right because solving the sound effect problem its beginning to look impossible. ...

                                            Did you try the <embed> tag yet?

                                            See: http://sketchucation.com/forums/viewtopic.php?f=180&t=48260&p=433470#p433470

                                            It is not impossible.. we are having you the obvious simple possibilities first (because they are likely to be cross-platform, and because the system specific solutions are very advanced programming exercises.)

                                            I'm not here much anymore.

                                            1 Reply Last reply Reply Quote 0
                                            • 1
                                            • 2
                                            • 1 / 2
                                            • First post
                                              Last post
                                            Buy SketchPlus
                                            Buy SUbD
                                            Buy WrapR
                                            Buy eBook
                                            Buy Modelur
                                            Buy Vertex Tools
                                            Buy SketchCuisine
                                            Buy FormFonts

                                            Advertisement