Hi folks.
Here is a lovely little game originally by Roger Isaac in 2004 .. :)
It had almost got lost in the sands of time, which would be a pity.
So I've modified it a bit - to give myself the slightest chance of completing it. ::)
It's a pretty, sliding square puzzle. It starts looking like a difficult jigsaw puzzle, and you have to move the squares around to make up the original picture.
I'm hopeless at knowing how to do these sort of puzzles, so I've modified the game so that if you press the SpaceBar, the full picture shows to give you an idea of which pieces go where.
Pressing F1 brings up some Help text for a few seconds.
Many thanks to Roger if he's still around. :) I hope people like it.
Another winner for Creative Basic I think.
Best wishes, :)
Graham
Ok guys, I have a couple of programming questions about this program .. ::) I'm very puzzled.
Here's the subroutine to draw the background gradient ..
sub DrawBack
'draw the background
for loop = 1 to 2
dxfill MainWindow, rgb(0, 0, 0) :' clear to black
for y = 0 to 255 :' gradient fill
rect MainWindow, 0, y, 800, 1, rgb(0, 0, 255-y)
rect MainWindow, 0, 599 - y, 800, 1, rgb(0, 255-y, 0)
next y
rect MainWindow, 78, 74, 643, 451, rgb(0, 0, 0), 1 :' tile grid
dxflip MainWindow
next loop
return
It works fine - but my question is How :o ..
Why does it have a 'loop' variable (which does not get used in the loop), and why do the same statements twice? Particularly since the first statement clears the screen to Black.
Without the FOR - NEXT loop, or if the 'loop' variable is 1, the thing falls apart in flickers.
Then there is the question that if the main window is 800 x 600, and the DX CreateScreen is for 800 x 600 - how on earth does the whole screen get the gradient? My screen resolution for example is 1024 x 768.
The two Rect statements are only for 0 to 800 by 1 pixel high - running 255 pixels from the top and from the bottom. Very strange. :P
It works, but I can't for the life of me see how. I'd never have thought of doing that ..
All the best, :)
Graham
Graham,
Why is the code so highly indented in the code window,
but not when copied and pasted.
Speaking of copying. When I do a Ctrl-Leftclick to copy
the code, it copies the whole reply?
Bill
Hi Bill,
You need to click at the top and then Shift-Left click instead of Cntrl-Left click .. that should work :)
Graham
Graham,
Your way works, but it does not copy as a block.
I have to drag the mouse "down" and highlight all
the lines; then copy.
Bill
Hi Bill,
Yep, that will work as well.
The reason for the horrible indenting, is that I have my Tabs set to 2 characters in the IDE, so of course to place text well across the page, I enter maybe 10 Tabs.
Looks fine in the IDE, but copied into Wordpad or Notepad, each Tab fleshes out to 8 characters - normal for word processors, but it places the text too far across the screen.
If you copy the text and paste it back into the IDE, it looks normal again .. ::)
Not much can be done about that. I don't fancy entering lots of spaces instead.
I've been playing with the code, but not got very far.
In the CREATESCREEN(w,wW,wH,32) statement, specifying the bits per pixel value, makes it fullscreen.
The rect w, 78, 74, 643, 451, rgb(0, 0, 0), 1 statement puts a black box on the screen, but how the size values fit in I don't know, nor why the colour value on the end is set to 1 rather than 0. Another puzzle.
I'm sure there's probably another way to do the gradient which might be easier to understand.
I'll keep playing with it .. :)
Graham
Well, here's my attempt at a background gradient, which has two parts - the upper half and the lower half of the screen.
It's a bit longer than the routine in Slidey, but I think a bit easier to follow.
def w:window
def textW,textH:int
def rdel1,gdel1,bdel1:float
def rdel2,gdel2,bdel2:float
def a$:string
type colour
def red:int
def grn:int
def blu:int
endtype
def c1,c2,c3,c4:colour
wW = 800
wH = 600
WINDOW w,0,0,wW,wH,@NOAUTODRAW|@NOCAPTION,0,"",mainwindow
CREATESCREEN(w,wW,wH,32)
drawmode w,@transparent
setfont w,"Arial",10,600
frontpen w,rgb(100,190,250)
a$ = "DX Gradient Test"
GETTEXTSIZE w,a$,textW,textH
' top start and end colours ..
c1.red = 0: c1.grn = 0: c1.blu = 180
c2.red = 0: c2.grn = 0: c2.blu = 0
' increments
rdel1=(c2.red - c1.red)/wH*2
gdel1=(c2.grn - c1.grn)/wH*2
bdel1=(c2.blu - c1.blu)/wH*2
' bottom start and end colours ..
c3.red = 0: c3.grn = 0: c3.blu = 0
c4.red = 0: c4.grn = 180: c4.blu = 0
' increments
rdel2=(c4.red - c3.red)/wH*2
gdel2=(c4.grn - c3.grn)/wH*2
bdel2=(c4.blu - c3.blu)/wH*2
run = 1
WAITUNTIL run = 0
CLOSEWINDOW w
END
mainwindow:
SELECT @CLASS
CASE @IDDXUPDATE
Update
CASE @IDCLOSEWINDOW
run = 0
CASE @IDCHAR
SELECT @code
case 27
CASE ASC("Q")
CASE ASC("q")
run = 0
ENDSELECT
ENDSELECT
RETURN
sub update
DrawGrad
move w,(wW-textW)/2,300
print w,a$
dxflip w
return
sub DrawGrad
' draw the background gradient
def ih:int
def r,g,b:float
' top start values
r = c1.red
g = c1.grn
b = c1.blu
' top vertical shading ..
for ih = 0 to wH/2
line w,0,ih,wW,ih,rgb(r,g,b)
r = r + rdel1
g = g + gdel1
b = b + bdel1
next ih
' bottom start values
r = c3.red
g = c3.grn
b = c3.blu
' bottom vertical shading ..
for ih = wH/2 to wH
line w,0,ih,wW,ih,rgb(r,g,b)
r = r + rdel2
g = g + gdel2
b = b + bdel2
next ih
rect w, 80, 70, 640, 450, 0, 0 :' black rectangle
return
Since it's Roger's program, I'll leave his original version as is .. :) It works OK.
Best wishes, :)
Graham