mousepick
Blitz3D Forums/Blitz3D Beginners Area/mousepick
| ||
I am creating a dice game and I am using the mousepick example from DungeonTrigger (well I did tweak it a bit) to select which dice was clicked to get the face value. That all works. For some reason I cannot get the machine to count the number of clicks and force a reroll before continuing. I am willing to email a RAR of models and code but I don't think my posting my (NOT CLEANED UP) code here would do the trick. Naytheless:; The Dice Thing Example ; by Ralph Wm Dunn aka Rook Zimbabwe ; Created in Blitz 3D ; Dice Model created by R Dunn in JTEdit ; Dice Artwork created by R Dunn in PaintShop Pro ; mousepick routines inspired by DUNGEONTRIGGER routines from Blitz Basic Website ; www.blitzbasic.com Graphics3D 800,600,0,2 ; set screen size SetBuffer BackBuffer() SeedRnd(MilliSecs()) camera=CreateCamera() ; create something to see with PositionEntity camera,6,6,0 RotateEntity camera,40,55,0 light=CreateLight() ; I will dispense with the biblical reference RotateEntity light,45,0,0 ; move the light a bit to create shadows on the model AmbientLight 44,44,41 ; turn on a bit of background light so the shadow isn't so dark ; load roll button rollbutton=LoadAnimMesh("wedge2.x") ScaleEntity rollbutton,1.7,1.7,1.7 UpdateNormals rollbutton EntityPickMode rollbutton,3 RotateEntity rollbutton,33,60,0 PositionEntity rollbutton,6,-2.5,6 EntityFX rollbutton,0 ; Load table table=LoadMesh("board1.x") UpdateNormals table EntityFX table,0 RotateEntity table,0,0,0 PositionEntity table,-3,-.9,5.25 ScaleEntity table,.015,.015,.015 ; Load mesh die1=LoadMesh("sixdie.x") UpdateNormals die1 EntityPickMode die1,3 EntityFX die1,0 ;NameEntity die1,dice1 ; Load mesh die2=LoadMesh("sixdie.x") UpdateNormals die2 EntityPickMode die2,3 EntityFX die2,0 ;NameEntity die2,dice2 ; Load mesh die3=LoadMesh("sixdie.x") UpdateNormals die3 EntityPickMode die3,3 EntityFX die3,0 ;NameEntity die3,dice3 ; Load mesh die4=LoadMesh("sixdie.x") UpdateNormals die4 EntityPickMode die4,3 EntityFX die4,0 ;NameEntity die4,dice4 dice1=Rand(5)+1 dice2=Rand(5)+1 dice3=Rand(5)+1 dice4=Rand(5)+1 numofdice=4 While Not KeyDown( 1 ) If kkgn=0 Then numofdice=numofdice + 4 ;=-=-=-=-=-=-=-=-=-=-=-=-=> SETS UP MOUSE PICK x=MouseX() y=MouseY() kkgn=numofdice - (anue+bnue+cnue+nue) x=MouseX() y=MouseY() e=CameraPick(camera,x,y) If e<>entity# If entity Then EntityColor entity,255,255,255 entity#=e EndIf If entity# EntityColor entity,255,240,60 ; 60 COLOR=Golden Yellow selected=entity ; Did this to show what the computer thought the address was If MouseDown(1) ; push L/mousebutton and get the number showing on the die Select entity Case die1 numb=dice1 : nue=1 Case die2 numb=dice2 : anue=1 Case die3 numb=dice3 : bnue=1 Case die4 numb=dice4 : cnue=1 Case rollbutton : dice1=Rand(5)+1 : dice2=Rand(5)+1 : dice3=Rand(5)+1 : dice4=Rand(5)+1 Default End Select EndIf EndIf ; rotation coords for each number on dice ; DICE 1 If dice1=1 Then xs#=90 : ys#=0 : zs#=0 If dice1=2 Then xs#=180 : ys#=0 : zs#=0 If dice1=3 Then xs#=0 : ys#=0 : zs#=90 If dice1=4 Then xs#=180 : ys#=0 : zs#=90 If dice1=5 Then xs#=0 : ys#=90 : zs#=0 If dice1=6 Then xs#=270: ys#=0 : zs#=0 ; show what dice 1 is and position it on the screen RotateEntity die1,xs#,ys#,zs# PositionEntity die1,0,0,4 ; DICE 2 If dice2=1 Then xs#=90 : ys#=0 : zs#=0 If dice2=2 Then xs#=180 : ys#=0 : zs#=0 If dice2=3 Then xs#=0 : ys#=0 : zs#=90 If dice2=4 Then xs#=180 : ys#=0 : zs#=90 If dice2=5 Then xs#=0 : ys#=90 : zs#=0 If dice2=6 Then xs#=270: ys#=0 : zs#=0 RotateEntity die2,xs#,ys#,zs# PositionEntity die2,-1.5,0,3 ; DICE 3 If dice3=1 Then xs#=90 : ys#=0 : zs#=0 If dice3=2 Then xs#=180 : ys#=0 : zs#=0 If dice3=3 Then xs#=0 : ys#=0 : zs#=90 If dice3=4 Then xs#=180 : ys#=0 : zs#=90 If dice3=5 Then xs#=0 : ys#=90 : zs#=0 If dice3=6 Then xs#=270: ys#=0 : zs#=0 RotateEntity die3,xs#,ys#,zs# PositionEntity die3,0,0,5.5 ; DICE 4 If dice4=1 Then xs#=90 : ys#=0 : zs#=0 If dice4=2 Then xs#=180 : ys#=0 : zs#=0 If dice4=3 Then xs#=0 : ys#=0 : zs#=90 If dice4=4 Then xs#=180 : ys#=0 : zs#=90 If dice4=5 Then xs#=0 : ys#=90 : zs#=0 If dice4=6 Then xs#=270: ys#=0 : zs#=0 RotateEntity die4,xs#,ys#,zs# PositionEntity die4,1,0,7 RenderWorld tat=dice1+dice2+dice3+dice4 Text 0,40," Total: "+tat Text 0,10,"D1: "+dice1 Text 0,20,"D2: "+dice2 Text 55,10,"D3: "+dice3 Text 55,20,"D4: "+dice4 tat=dice1+dice2+dice3+dice4 Text 0,40,"Total: "+tat Text 0,60,"Selected: "+selected Text 0,80,"DIE1: "+numb Text 75,100,"Num of Dice: "+ kkgn Flip Wend EndIf this helps anyone I am still willing... my email is in my signature line. Please no SPAM! : ) Rook Zimbabwe |
| ||
OK I put a page on my website called files.html so if you go here: [http]http://www.silverimports.com/files.html[/http] You should be able to DL it... 298k or thereabouts... Just the code and textures and models. |
| ||
Could you explain what the prob is a bit more clearly. The dice jiggle around when I click on roll. What's not working, exactly? |
| ||
maybe use Mousehit instead of Mousedown? |
| ||
But I cannot change the variable types... No matter where or how I have encoded the instruction. Look: foo = 4 if (thing) then foo = foo - 1 ;take away from foo if foo = 0 then rerollflag = true ; goes to reroll setup if rerollflag = true then foo = 4 (more stuff) That is what I think I need to do. I may be having this problem because of SELECT I will try mousehit though... |
| ||
OK mousehit worked... the dice no longer spin so I can now (sometime) create a throw animation for them (how I wil do that I don't know) but here is the conumdrum:x=MouseX() y=MouseY() e=CameraPick(camera,x,y) If e<>entity# If entity Then EntityColor entity,255,255,255 entity#=e EndIf If entity# EntityColor entity,255,240,60 ; 60 COLOR=Golden Yellow selected=entity ; Did this to show what the computer thought the address was If MouseHit(1) ; push L/mousebutton and get the number showing on the die Select entity Case die1 numb=dice1 : nue=1 Case die2 numb=dice2 : anue=1 Case die3 numb=dice3 : bnue=1 Case die4 numb=dice4 : cnue=1 Case rollbutton : dice1=Rand(5)+1 : dice2=Rand(5)+1 : dice3=Rand(5)+1 : dice4=Rand(5)+1 Default End Select EndIf EndIf kkgn=numofdice - (anue+bnue+cnue+nue) If kkgn<=0 Then kkgn=kkgn + 4 If numofdice<=0 Then numofdice = 4Even when I finally got the variables kkgn and numofdice to reset they don't go down again... Is there someway to refresh variables that I know nothing about or is this a child of the SELCT process??? |
| ||
Yep... That fixed it (well I had to do a lot of other little tweaks to recurse data a bit. Code is still messy. Interesting thing programming without gosub or goto. I used to love "spagetti code" : ) Thank you to everyone who had constructive advice, while you are not in the will you will get a nod if anything comes of this! -Rookster Rook |