Highlighting Function

BlitzPlus Forums/BlitzPlus Beginners Area/Highlighting Function

Siopses(Posted 2007) [#1]
I made this function-
Function Highlight()
If ImageRectOverlap(mouse,MouseX(),MouseY(),300,250,205,31) Then
DrawImage new1,200,200,0
EndIf
End Function

And it doesn't work for what I want it to do, infact it doesn't work at all.


Réno(Posted 2007) [#2]
Did not test, but it should work ( I never used ImageRectOverlap ) :

Global new1%=0
Global mouse%=0

new1=LoadImage blabla...
mouse=LoadImage blabla...

Function Highlight(a1%,a2%,a3%,a4%,a5%,a6%,a7%)
    If ImageRectOverlap(a1,a2,a3,a4,a5,a6,a7)
        DrawImage new1,200,200,0
    EndIf
End Function

;in game
Highlight(mouse,MouseX(),MouseY(),300,250,205,31)



Siopses(Posted 2007) [#3]
Much thanks, Reno; I just got one more question, what are the a1,a2,a3,a4,a5,a6 for? Just wondering. Also, If this
is my code

Then lets say I want to have the program loop me to the part the mouse is on (for example, new game) when the
collision's detected and MouseDown then how would I do
that with a While/Wend loop?


CS_TBL(Posted 2007) [#4]
use (code) (/code) or (codebox) (/codebox) tags for your code

-replace the ( ) with [ ] when you do-


Siopses(Posted 2007) [#5]
Could you show me a example?


CS_TBL(Posted 2007) [#6]
o_O

If I do that you can't see the tags.. :P

Erhm, it's forum-codes eh, not Blitz-code! I'm talking about pasting code here..

See?

Print "w000t"

and -between tags-

Print "w000t"



Siopses(Posted 2007) [#7]
Ok, fine I'll work it out by myself


Siopses(Posted 2007) [#8]
Can someone please tell me what "undefined label" means,
it keeps on coming up with my label even though I got
the .label thing. Any suggestions?


Réno(Posted 2007) [#9]
For the function, read the doc online or hightlight a word and type twice F1 in BLITZ IDE.

"undefined label" ? Show your code...


Siopses(Posted 2007) [#10]
Here's the code


NOTE: Just a work-in-progress ok?
Happy?====> EDITED TWICE


CS_TBL(Posted 2007) [#11]
again:

Do us a favour: and put your code between (code) (/code) tags (replace () with [] ) .. it reads so much better, and indenting is preserved)


Réno(Posted 2007) [#12]
You are right...use the forum tags when posting !

Siopses
>It seems that we can't use Goto and the label outside the function. Find another way to do that !


Siopses(Posted 2007) [#13]
O.k thanks for the information, but how am I supposed to make a function to make it possible to simply click on the
(for example) 'new game' image to go to a new game.


CS_TBL(Posted 2007) [#14]
Goto is evil anyway, it's the highway to Italian Pasta, use functions all the way.

Here's pseudocode, I'm kinda used to event-based code and apps, I ditched Graphics modes ever since I started out with B+ :P

If MouseX()>=NewGameImageX1 and MouseX()<=NewGameImageX2 and
MouseY()>=NewGameImageY1 and MouseY()<=NewGameImageY2

^ if this is true, then your pointer is in the new game image

next, check for a key/mouse/joystick trigger, et voila: you may now call a function called Game().

In this Game() runs your game!


Ok, enough chaos for now, and perhaps you can't make soup from it still :P .. I've a bloody deadline to make ._.


Réno(Posted 2007) [#15]
Here is a very basic of what I do :


event%=0

cls

select event

    ;screen to click on NEWGAME
    case 0

    if "click is true"
        event=1
    endif

    ;screen that show level info
    case 1

    drawimage blabla

    if "time or loop">"5 seconds"
        event=2
    endif

    ;in game
    case 2

    "your game loop"

end select

flip




Siopses(Posted 2007) [#16]
I don't quite understand programming events yet.


Réno(Posted 2007) [#17]
"event" is just the name of the variable... nothing to go with the BLITZplus event system...


Siopses(Posted 2007) [#18]
I know, what I mean is the set-up of an event. Like CASE
and every thing else.


CS_TBL(Posted 2007) [#19]
truly: this is just too funny :P

You replaced all your () with [] in your source. I mentioned before that I was talking forum-codes, not Blitz-code.

So, I meant that you put your sourcecode between forumcode tags, namely: (code) and (/code) or (codebox) and (/codebox). The reason I say 'replace () with []' is because I can't type (code) or (codebox) because it then makes a codebox .. and the command disappears from a post then.

So, leave your blitzsourcecode as it is, but put it between tags! It reads a lot better for the people who try to help you.


About your code: it's not the right way to do this thing. You never make functions like those to check for specific menu items (well, obviously you could, but you want to learn proper code, do you?)
In your example you're linking the technical concept of 'a menu' with the actual visual implementation, which is not something you should do. What you should try to do is:
- make code that displays *any* menu, of any size with any amount of menu choices, anywhere on the screen
- define your menu content (newgame, options, quit etc.) somewhere else, but *not in the menu code!*

So, how to start?

Divide your menu into two parts:
- a technical list, which is purely a list of menu options. Note that you should know the length of this list. How you'll be implementing that is up to you. I'd put it in a bank orso, but you could also make some global array$ and a global value for the length of this array.. it's just that I don't like globals .. :P You could also store the amount of menu items in the first array item.. then you only need one array! Anyway, that's up to you again.

- make a visual displayer for this technical list. This displayer should of course be able to display any list you made, as long as the list technically works the same.
This displayer should have properties like: x, y, width, height, itemheight, maxitems, currentoption .. and another bunch o' stuff.

Probably a lot of stuff for -I estimate :P- a beginner, but you gotta start somewhere, eh..

Best tip I can give tho is to start slowly, a game is about the most tricky thing one can make. Start easy/slowly with small dull things, learn bit by bit, try to learn to think ahead, try to envision what will happen when you code into a certain direction instead of another direction.


Siopses(Posted 2007) [#20]
Thanks for the information, but I seriously have no clue what
you mean when you say So, I meant that you put your sourcecode between forumcode tags, namely: (code) and (/code) or (codebox) and (/codebox).


CS_TBL(Posted 2007) [#21]
ok, plan B:

[code]
Graphics 640,480
Print "OMFG!"
End
[/code]

Did you ever use any forum before? Regular forums for news/reactions etc.?


CS_TBL(Posted 2007) [#22]
[ c o d e ]
Print "if it works, you should only need to move the spaces in these tags"
[/ c o d e ]


Siopses(Posted 2007) [#23]
Just forget about okay I don't need this damn forum's help anyway.


Senzak(Posted 2007) [#24]
ok, to make a codebox, just use
[code] to start it
and
[/code] to end it

it produces this effect:
This is in a codebox


details at:
http://www.digit-life.com/forum/help/code.html


Andy_A(Posted 2007) [#25]
I can't run without the pics, but does not generate any errors from "Check for errors F7" in "Program" menu.

Graphics 800,600

;Images
COE=LoadImage("cube_of_evil.bmp")
hand=LoadImage("hand.bmp")
title=LoadImage("title.bmp")
Xbound=LoadImage("X-boundary")
Ybound=LoadImage("Y-boundary")
mouse=LoadImage("mouse.bmp")
new0=LoadImage("newgame.bmp")
highscore0=LoadImage("highscore.bmp")
Global highscore1=LoadImage("highscore1.bmp")
options0=LoadImage("options.bmp")
Global options1=LoadImage("options1.bmp")
Global neww=LoadImage("newgame1.bmp")

;Fonts
fntArial=LoadFont("Arial",48,False,True,False)
fntbroadway=LoadFont("Broadway",36,False,False,False)
fntgameover=LoadFont("Chiller",48,True,True,False)

;================
Global ExitFlag% ;<- added this
;================

While Not KeyDown(1)
;	SetFont fntArial ;this font is not used here
	Color 0,0,255
;menu
	SetFont fntbroadway
	Cls 
	DrawImage title,200,0
	DrawImage new0,300,250,0
	DrawImage highscore0,300,300,0
	DrawImage options0,300,350,0
	DrawImage mouse,MouseX(),MouseY()
	HighlightNewGame(mouse,MouseX(),MouseY(),300,250,205,31)
	HighlightHighScore(mouse,MouseX(),MouseY(),300,300,205,31)
	HighlightOptions(mouse,MouseX(),MouseY(),300,350,205,31)
	Delay 25
	Flip
;============================	
	If ExitFlag = 1 Then Exit ;<- added this
;============================
Wend

End



Function HighlightNewGame(a1%,a2%,a3%,a4%,a5%,a6%,a7%)
	If ImageRectOverlap(a1,a2,a3,a4,a5,a6,a7)
		DrawImage neww,300,250,0
	End If 
End Function

Function HighlightHighScore(a1%,a2%,a3%,a4%,a5%,a6%,a7%)
	If ImageRectOverlap(a1,a2,a3,a4,a5,a6,a7)
		DrawImage highscore1,300,300,0
	End If
End Function 

Function HighlightOptions(a1%,a2%,a3%,a4%,a5%,a6%,a7%)
	If ImageRectOverlap(a1,a2,a3,a4,a5,a6,a7)
		DrawImage options1,300,350,0
	End If
End Function 

Function Click1(HighlightNewGame)
	If MouseDown(1) And HighlightNewGame = 1 Then
;		Goto .newgame   ;this label does not exist outside of this function as far as Blitz is concerned
;===================
		NewGame()    ;changed label to function and added ExitFlag
		ExitFlag = 1
;===================
	End If
End Function

;========================== ;changed your label into a function
Function NewGame()
	Text 400,300,"NEW GAME"
	Delay 5000
End Function
;==========================

To make codebox like the one above do the following:

STEP 1:
[-code] <---- copy this

paste into Blitz forum window

erase minus sign from what you pasted into Blitz forum window

STEP 2:
Paste your code right after where you pasted step 1 (or skip this if editing an existing post)

STEP3:
[/code] <---- copy this

erase minus sign from what you pasted into Blitz forum window

paste into Blitz forum window immediately after your pasted or edited source code

See forum codes here: http://www.blitzbasic.com/faq/faq_entry.php?id=2

[Edited to reflect Senzak's make bold suggestion - but it didn't work :\ ]


Senzak(Posted 2007) [#26]
it's easier to demonstrate the concept if you bold the word code (using [b] and [/b]), then it doesn't create the codebox


CS_TBL(Posted 2007) [#27]
I think it's too late anyway, judging his last reply .. :P


Senzak(Posted 2007) [#28]
yeah, that's too bad though......


Siopses(Posted 2007) [#29]
Thank you, Senzak for putting it into understandable words.
Also thanks to Andy_A, and to CS_TBL look at my past coding now! ;) All my current programing problems have now been
resolved, Thank you all!


Siopses(Posted 2007) [#30]
Hold that thought, the coding that Andy_A edited for me does
not work, As Reno said: "It seems that we can't use Goto and the label outside the function. Find another way to do that !"
I don't think that the program will work this way :(


Andy_A(Posted 2007) [#31]
"Goto" was commented out since labels are not seen when outside of a function.

Modified snippet uses function called "NewGame"


Siopses(Posted 2007) [#32]
It doesn't even work when I ran it, I think I'll forget about this project.


b32(Posted 2007) [#33]
Maybe try this then?



Siopses(Posted 2007) [#34]
That's all right, thanks! :)


Siopses(Posted 2007) [#35]
Sorry, for some odd reason StringHeight(i$) is not working,
it says "function stringheight not found."


b32(Posted 2007) [#36]
That could be a b3d function then, maybe replace it with 30 (size of the font) ?


Neo Genesis10(Posted 2007) [#37]
Odd. If you're using BlitzPlus there shouldn't be an issue with using StringHeight. I'm fairly sure that function is available, as its even listed in the current online manuals for it.


Siopses(Posted 2007) [#38]
Could I post this into Blitz Plus Bug's?


b32(Posted 2007) [#39]
Yes, I don't think it should be missing. I tried it with the demo, and the command is recognized.