Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Yagl Mouse Click
#1
I've made this simple little thing for Yagl. It is a box bouncing around the screen. The idea is to click on it. It gets faster everytime you do and it vanishes to some random location.

Code:
#include "YaglWrapper.bi"
DECLARE SUB DrawBox(PlayerX as integer, PlayerY as integer, HalfPlayerBoxSize as short)
RANDOMIZE TIMER

option explicit

'Simple Drawing Example

Const Scr_Width = 500
Const Scr_Height = 500
Const Scr_BITDEPTH = 24
Const Scr_Mode = 0

'Set The ScreenMode
if( YaglGfxDevice_setScreenMode( Scr_Width, Scr_Height, Scr_BITDEPTH, Scr_Mode ) = 0 ) then
   print "couldn't initialize screen mode"
   system
end if

dim font as YaglGfxFont

font = YaglGfxDevice_createFont( )
if( font = 0 ) then end

if( YaglGfxFont_loadFont( font, "font.ttf" ) = 0 ) then end
YaglGfxFont_setSize( font, 16 )

DIM MouseX as integer
DIM MouseY as integer
DIM MouseButton as integer

Dim PlayerX as integer 'Center Player On
Dim PlayerY as integer
Dim HalfPlayerBoxSize as short 'Half Size of player box

PlayerX = (int(rnd * Scr_Height)+HalfPlayerBoxSize)
PlayerY = (int(rnd * Scr_Width)+HalfPlayerBoxSize)
HalfPlayerBoxSize = (int(rnd * 10)+5)

DIM xadj as integer
DIM yadj as integer
xadj = 1
yadj = 1

DIM fpc as long
DIM t as long
DIM fps as long
DIM lastfps as long
DIM speed as double
speed = 1

DIM score as long
fpc = timer+1
WHILE(YaglKeyBoard_isKeyPressed( YAGL_KEY_ESCAPE ) = 0 and YaglGfxDevice_wasWindowCloseButtonPressed() = 0 )
t = timer
fps += 1

'Draw The Box and the background
YaglGfxDevice_clear(rgb(100,100,100))
DrawBox(PlayerX, PlayerY, HalfPlayerBoxSize)

PlayerX += xadj
PlayerY += yadj

IF PlayerY - HalfPlayerBoxSize <= 0 THEN yadj = speed
IF PlayerY + HalfPlayerBoxSize >= Scr_Height THEN yadj = -speed
IF PlayerX + HalfPlayerBoxSize >= Scr_Width THEN xadj = -speed
IF PlayerX - HalfPlayerBoxSize <= 0 THEN xadj = speed

MouseX = YaglMouse_getX()
MouseY = YaglMouse_getY()

IF MouseY >= PlayerY - HalfPlayerBoxSize AND MouseY <= PlayerY + HalfPlayerBoxSize THEN
IF MouseX >= PlayerX - HalfPlayerBoxSize AND MouseX <= PlayerX + HalfPlayerBoxSize THEN
IF YaglMouse_isLeftButtonPressed() THEN
Score += 1
speed += 0.5
PlayerY = (int(rnd * Scr_Height)+HalfPlayerBoxSize)
PlayerX = (int(rnd * Scr_Width)+HalfPlayerBoxSize)

if (int(rnd*3)+1) = 2 then
Xadj = speed
Yadj = speed
else
Xadj = -speed
Yadj = -speed
end if

END IF
END IF
END IF

sleep 20,1

YaglGfxDevice_setWindowTitle ( " Yagl Mouse And Basic Drawing Demo " )

if timer >= fpc then
  fpc = timer+1
  if fps <= 50 then YaglGfxDevice_printAt( "FPS: " + str(fps), 5, 20, &hffffff, font, 1.0 )
  lastfps = fps
  fps = 0
Else
if lastfps <= 50 then YaglGfxDevice_printAt( "FPS: " + str(lastfps), 5, 20, &hffffff, font, 1.0 )
END IF

YaglGfxDevice_printAt( "Score: " + str(score), 5, 1, &hffffff, font, 1.0 )
YaglGfxdevice_SwapBuffers()
WEND

SUB DrawBox(PlayerX as integer, PlayerY as integer, HalfPlayerBoxSize as short)
'Use blending for a nice effect
YaglGfxDevice_SolidBox(PlayerX-HalfPlayerBoxSize,PlayerY-HalfPlayerBoxSize,PlayerX+HalfPlayerBoxSize,PlayerY+HalfPlayerBoxSize,rgb(255,55,55),1.0)
YaglGfxDevice_Box(PlayerX-HalfPlayerBoxSize,PlayerY-HalfPlayerBoxSize,PlayerX+HalfPlayerBoxSize,PlayerY+HalfPlayerBoxSize,0,0.70)
YaglGfxDevice_Box(PlayerX-HalfPlayerBoxSize+1,PlayerY-HalfPlayerBoxSize+1,PlayerX+HalfPlayerBoxSize-1,PlayerY+HalfPlayerBoxSize-1,0,0.55)
YaglGfxDevice_Box(PlayerX-HalfPlayerBoxSize+2,PlayerY-HalfPlayerBoxSize+2,PlayerX+HalfPlayerBoxSize-2,PlayerY+HalfPlayerBoxSize-2,0,0.40)
YaglGfxDevice_Box(PlayerX-HalfPlayerBoxSize+3,PlayerY-HalfPlayerBoxSize+3,PlayerX+HalfPlayerBoxSize-3,PlayerY+HalfPlayerBoxSize-3,0,0.15)
END SUB

The Source Code and Binaries can be downloaded here:
http://www.sitesled.com/members/fallenange.../MouseClick.zip

And YAGL can be found here
http://goddess.selfip.com/yagl

The FPS limit is set by the Sleep 20 command (1000/20 = 50) NOT YAGL!

What do you think?
url=http://www.sloganizer.net/en/][Image: style4,TheDarkJay.png][/url]
Reply
#2
funky Smile
quote="NecrosIhsan"]
[Image: yagl1.png]
[/quote]
Reply
#3
Quote:The FPS limit is set by the Sleep 20 command (1000/20 = 50) NOT YAGL!
It's kind of sad we have to add that to avoid people going mental..
Silly people Tongue

Gonna try it now TDJ..


EDIT: Haha, evil little box!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)