Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Yagl Pong...Why doesn't it work.
#1
I've been trying to use Yagl to make a simple pong game, I'm basing it on this:

Code:
'THE PONG EXAMPLE...
'---
SCREEN 7, 0, 1, 0
x = 50: y = 50
x2 = 130: y2 = 150
pspeed = 5
xadj = 1: yadj = 1
delay = 1
DO
press$ = INKEY$
LINE (0, 0)-(320, 200), 0, BF
CIRCLE (x, y), 7
PAINT (x, y), 4, 15
LINE (x2, y2)-(x2 + 30, y2 + 7), 1, BF
LINE (x2, y2)-(x2 + 30, y2 + 7), 8, B
LOCATE 1, 1: PRINT score
PCOPY 1, 0
IF y <= 20 THEN yadj = 1
IF y >= 180 THEN yadj = -1
IF x >= 300 THEN xadj = -1
IF x <= 20 THEN xadj = 1

IF press$ = "," AND x2 > 1 THEN x2 = x2 - pspeed
IF press$ = "." AND x2 < 290 THEN x2 = x2 + pspeed
x = x + xadj
y = y + yadj
IF y > y2 - 7 AND y2 < y2 + 2 AND x < x2 + 30 AND x > x2 THEN
yadj = -1: score = score + 1
END IF

IF y > y2 + 10 THEN
FOR i = 1 TO 100
PRINT "GAME OVER!!"
PCOPY 1, 0
NEXT
END
END IF
FOR i = 1 TO delay: NEXT
LOOP UNTIL press$ = "q"

'---

This is what i have:

Code:
'The Main Libary
#include "yaglwrapper.bi"

'Screen/Window Commands
#Define Yagl_CLS(c) YaglGfxDevice_clear(c)
#Define Yagl_Screen(X,Y,Bit,Full) YaglGfxDevice_setScreenMode(X,Y,Bit,Full)    
#define Yagl_SetWindowTitle(Title) YaglGfxDevice_setWindowTitle(title)  
#define Yagl_SwapBuffers YaglGfxDevice_swapBuffers  
#define Yagl_WindowCloseButton YaglGfxDevice_wasWindowCloseButtonPressed

'KeyBoard commands
#define Yagl_GetKey YaglKeyboard_getKey  
#define Yagl_KeyPress(ScanCode) YaglKeyboard_isKeyPressed(ScanCode)

'Mouse Commands
#define Yagl_MouseLeft YaglMouse_isLeftButtonPressed  
#define Yagl_MouseRight YaglMouse_isRightButtonPressed  
#define Yagl_MouseMiddle YaglMouse_isMiddleButtonPressed  
#define Yagl_MouseX YaglMouse_getX
#define Yagl_MouseY YaglMouse_getY
#define Yagl_MouseZ YaglMouse_getZ
#define Yagl_SetMouse(x,y) YaglMouse_setPosition(x,y)
#define Yagl_HideMouse YaglGfxDevice_hideMouseCursor    
#define Yagl_ShowMouse YaglGfxDevice_ShowMouseCursor  

' Font Commands
#define Yagl_CreateFont YaglGfxDevice_createFont
#define Yagl_LoadFont(font, filename) YaglGfxFont_loadFont(font, filename)
#define Yagl_FontSize(font,size) YaglGfxFont_setSize(font, size)
#define Yagl_Print(text,x,y,colour,font,blend_factor) YaglGfxDevice_printAt(text,x,y,colour,font,blend_factor)
#define Yagl_DestroyFont(font) YaglGfxDevice_destroyFont(font)
#define Yagl_DestroyAllFonts YaglGfxDevice_destroyAllFonts

'  Drawing Commands
#define yagl_Line(x1,y1,x2,y2,color,blendfactor) YaglGfxDevice_line(x1,y1,x2,y2,color,blendfactor)    
#define Yagl_Box(x1,y1,x2,y2,color,blendfactor) YaglGfxDevice_Box(x1,y1,x2,y2,color,blendfactor)      
#define Yagl_SolidBox(x1,y1,x2,y2,color,blendfactor) YaglGfxDevice_SolidBox(x1,y1,x2,y2,color,blendfactor)      
#define Yagl_ClippingRegion(clip_min_x,clip_min_y,clip_max_x,clip_max_y) YaglGfxDevice_setClippingRegion(clip_min_x,clip_min_y,clip_max_x,clip_max_y)  

'Bitmaps and blitting
#define Yagl_CreateSurface YaglGfxDevice_createSurface()
#Define Yagl_LoadSurfaceFile(filename) YaglGfxSurface_loadFile(filename)
#define Yagl_LoadSurfaceMemory(someSurf,aSurf,x,y,FORMAT) YaglGfxSurface_loadFromMemory(someSurf,aSurf,x,y,FORMAT)
#define Yagl_Blit(x,y,surface,BlitMODE,blend_factor) YaglGfxDevice_blit(x,y,surface,BlitMODE,blend_factor)
#define Yagl_Blit2(x,y,src_min_x,src_min_y,src_max_x,src_max_y, surface, BLIT_MODE,blend_factor ) YaglGfxDevice_blit(x,y,src_min_x,src_min_y,src_max_x,src_max_y, surface, BLIT_MODE,blend_factor )
#define Yagl_BlitScaled YaglGfxDevice_blitScaled(x,y,scale_x,scale_y,surface,BLIT_MODE,blend_factor)
#define Yagl_BlitScaled2(x,y,scale_x,scale_y,src_min_x,src_min_y,src_max_x,src_max_y,surface,BLIT_MODE,blend_factor) YaglGfxDevice_blitScaled(x,y,scale_x,scale_y,src_min_x,src_min_y,src_max_x,src_max_y,surface,BLIT_MODE,blend_factor)
#define Yagl_BlitRotated(x,y,angle,surface,BLIT_MODE,blend_factor) YaglGfxDevice_blitRotated(x,y,angle,surface,BLIT_MODE,blend_factor)
#define Yagl_BlitRotated2(x,y,angle,src_min_x,src_min_y,src_max_x,src_max_y,surface,BLIT_MODE,blend_factor) YaglGfxDevice_blitRotated(x,y,angle,src_min_x,src_min_y,src_max_x,src_max_y,surface,BLIT_MODE,blend_factor)
#define Yagl_BlitRotatedScale(x,y,angle,scale_x,scale_y,surface,BLIT_MODE,blend_factor) YaglGfxDevice_blitRotatedScaled(x,y,angle,scale_x,scale_y,surface,BLIT_MODE,blend_factor)
#define Yagl_BlitRotatedScale2(x,y,angle,scale_x,scale_y,src_min_x,src_min_y,src_max_x,src_max_y,surface,BLIT_MODE,blend_factor) YaglGfxDevice_blitRotatedScaled(x,y,angle,scale_x,scale_y,src_min_x,src_min_y,src_max_x,src_max_y,surface,BLIT_MODE,blend_factor)
#define Yagl_DestroySurface(surface) YaglGfxDevice_destroySurface(surface)
#define Yagl_DestroyAllSurfaces YaglGfxDevice_destroyAllSurfaces()

option explicit

Yagl_Screen(320,240,24,0)

DIM as integer x = 50
DIM as integer y = 50
DIM as integer x2 = 130
DIM as integer y2 = 150
DIM as integer pspeed = 5
DIM as integer xadj = 1
DIM as integer yadj = 1
DIM key as integer
DIM Score as integer

DO
key = Yagl_getKey
Yagl_CLS(0)

Yagl_SolidBox(x-6,y-6,y+6,x+6,rgb(255,100,50),1.0) 'pong

yagl_SolidBox(x2,y2,x2 + 30,y2 + 6,rgb(155,155,255), 1.0) 'paddle
yagl_Box(x2,y2,x2 + 30,y2 + 6,rgb(100,255,200),.90) 'paddle

IF y <= 20 THEN yadj = 1
IF y >= 180 THEN yadj = -1
IF x >= 300 THEN xadj = -1
IF x <= 20 THEN xadj = 1

IF key = YAGL_KEY_LEFT AND x2 > 1 THEN x2 = x2 - pspeed

IF key = YAGL_KEY_RIGHT AND x2 < 290 THEN x2 = x2 + pspeed


x = x + xadj
y = y + yadj

IF y > y2 - 6 AND y2 < y2 + 2 AND x < x2 + 30 AND x > x2 THEN
yadj = -1
score = score + 1
END IF

IF y > y2 + 10 THEN END
Yagl_SetWindowTitle("Score: "& score)
Yagl_SwapBuffers
Sleep 10
LOOP UNTIL key = YAGL_KEY_ESCAPE OR Yagl_WindowCloseButton
END

Why doesn't it work? The pong ball box just goes all wierd.
url=http://www.sloganizer.net/en/][Image: style4,TheDarkJay.png][/url]
Reply
#2
that looks all crazy Smile. as the box goes wild after a change of direction ( that is aftera collision with the rectangle ) i guess your x, y, x2 and y2 values go out of bounds. i will check it if i find the time
quote="NecrosIhsan"]
[Image: yagl1.png]
[/quote]
Reply
#3
Quote:that looks all crazy Smile. as the box goes wild after a change of direction ( that is aftera collision with the rectangle ) i guess your x, y, x2 and y2 values go out of bounds. i will check it if i find the time

That's the problem...The box should just bounce off the paddle instead of going through it, bouncing around and changing size....

EDIT: I've added some more things to the top bit. It's a custom header of mine to shorten the amount of typing i have to do

Code:
'The Main Libary
#include "yaglwrapper.bi"

'Screen/Window Commands
#Define Yagl_CLS(c) YaglGfxDevice_clear(c)
#Define Yagl_Screen(X,Y,Bit,Full) YaglGfxDevice_setScreenMode(X,Y,Bit,Full)    
#define Yagl_SetWindowTitle(Title) YaglGfxDevice_setWindowTitle(title)  
#define Yagl_SwapBuffers YaglGfxDevice_swapBuffers  
#define Yagl_WindowCloseButton YaglGfxDevice_wasWindowCloseButtonPressed

'KeyBoard commands
#define Yagl_GetKey YaglKeyboard_getKey  
#define Yagl_KeyPress(ScanCode) YaglKeyboard_isKeyPressed(ScanCode)

'Mouse Commands
#define Yagl_MouseLeft YaglMouse_isLeftButtonPressed  
#define Yagl_MouseRight YaglMouse_isRightButtonPressed  
#define Yagl_MouseMiddle YaglMouse_isMiddleButtonPressed  
#define Yagl_MouseX YaglMouse_getX
#define Yagl_MouseY YaglMouse_getY
#define Yagl_MouseZ YaglMouse_getZ
#define Yagl_SetMouse(x,y) YaglMouse_setPosition(x,y)
#define Yagl_HideMouse YaglGfxDevice_hideMouseCursor    
#define Yagl_ShowMouse YaglGfxDevice_ShowMouseCursor  

' Font Commands
#define Yagl_CreateFont YaglGfxDevice_createFont
#define Yagl_LoadFont(font, filename) YaglGfxFont_loadFont(font, filename)
#define Yagl_FontSize(font,size) YaglGfxFont_setSize(font, size)
#define Yagl_Print(text,x,y,colour,font,blend_factor) YaglGfxDevice_printAt(text,x,y,colour,font,blend_factor)
#define Yagl_DestroyFont(font) YaglGfxDevice_destroyFont(font)
#define Yagl_DestroyAllFonts YaglGfxDevice_destroyAllFonts

'  Drawing Commands
#define yagl_Line(x1,y1,x2,y2,color,blendfactor) YaglGfxDevice_line(x1,y1,x2,y2,color,blendfactor)    
#define Yagl_Box(x1,y1,x2,y2,color,blendfactor) YaglGfxDevice_Box(x1,y1,x2,y2,color,blendfactor)      
#define Yagl_SolidBox(x1,y1,x2,y2,color,blendfactor) YaglGfxDevice_SolidBox(x1,y1,x2,y2,color,blendfactor)      
#define Yagl_ClippingRegion(clip_min_x,clip_min_y,clip_max_x,clip_max_y) YaglGfxDevice_setClippingRegion(clip_min_x,clip_min_y,clip_max_x,clip_max_y)  

'Bitmaps and blitting
#define Yagl_CreateSurface YaglGfxDevice_createSurface()
#Define Yagl_LoadSurfaceFile(filename) YaglGfxSurface_loadFile(filename)
#define Yagl_LoadSurfaceMemory(someSurf,aSurf,x,y,FORMAT) YaglGfxSurface_loadFromMemory(someSurf,aSurf,x,y,FORMAT)
#define Yagl_Blit(x,y,surface,BlitMODE,blend_factor) YaglGfxDevice_blit(x,y,surface,BlitMODE,blend_factor)
#define Yagl_Blit2(x,y,src_min_x,src_min_y,src_max_x,src_max_y, surface, BLIT_MODE,blend_factor ) YaglGfxDevice_blit(x,y,src_min_x,src_min_y,src_max_x,src_max_y, surface, BLIT_MODE,blend_factor )
#define Yagl_BlitScaled YaglGfxDevice_blitScaled(x,y,scale_x,scale_y,surface,BLIT_MODE,blend_factor)
#define Yagl_BlitScaled2(x,y,scale_x,scale_y,src_min_x,src_min_y,src_max_x,src_max_y,surface,BLIT_MODE,blend_factor) YaglGfxDevice_blitScaled(x,y,scale_x,scale_y,src_min_x,src_min_y,src_max_x,src_max_y,surface,BLIT_MODE,blend_factor)
#define Yagl_BlitRotated(x,y,angle,surface,BLIT_MODE,blend_factor) YaglGfxDevice_blitRotated(x,y,angle,surface,BLIT_MODE,blend_factor)
#define Yagl_BlitRotated2(x,y,angle,src_min_x,src_min_y,src_max_x,src_max_y,surface,BLIT_MODE,blend_factor) YaglGfxDevice_blitRotated(x,y,angle,src_min_x,src_min_y,src_max_x,src_max_y,surface,BLIT_MODE,blend_factor)
#define Yagl_BlitRotatedScale(x,y,angle,scale_x,scale_y,surface,BLIT_MODE,blend_factor) YaglGfxDevice_blitRotatedScaled(x,y,angle,scale_x,scale_y,surface,BLIT_MODE,blend_factor)
#define Yagl_BlitRotatedScale2(x,y,angle,scale_x,scale_y,src_min_x,src_min_y,src_max_x,src_max_y,surface,BLIT_MODE,blend_factor) YaglGfxDevice_blitRotatedScaled(x,y,angle,scale_x,scale_y,src_min_x,src_min_y,src_max_x,src_max_y,surface,BLIT_MODE,blend_factor)
#define Yagl_DestroySurface(surface) YaglGfxDevice_destroySurface(surface)
#define Yagl_DestroyAllSurfaces YaglGfxDevice_destroyAllSurfaces()
url=http://www.sloganizer.net/en/][Image: style4,TheDarkJay.png][/url]
Reply
#4
Does no-one know??? :???:
url=http://www.sloganizer.net/en/][Image: style4,TheDarkJay.png][/url]
Reply
#5
that code isnt pleasant to read..
Reply
#6
you mean the first bit? That's a custom header to shorten the amount of typing i have to do

Take this bit :

Code:
'The Main Libary
#include "yaglwrapper.bi"

'Screen/Window Commands
#Define Yagl_CLS(c) YaglGfxDevice_clear(c)
#Define Yagl_Screen(X,Y,Bit,Full) YaglGfxDevice_setScreenMode(X,Y,Bit,Full)    
#define Yagl_SetWindowTitle(Title) YaglGfxDevice_setWindowTitle(title)    
#define Yagl_SwapBuffers YaglGfxDevice_swapBuffers    
#define Yagl_WindowCloseButton YaglGfxDevice_wasWindowCloseButtonPressed

'KeyBoard commands
#define Yagl_GetKey YaglKeyboard_getKey    
#define Yagl_KeyPress(ScanCode) YaglKeyboard_isKeyPressed(ScanCode)

'Mouse Commands
#define Yagl_MouseLeft YaglMouse_isLeftButtonPressed    
#define Yagl_MouseRight YaglMouse_isRightButtonPressed    
#define Yagl_MouseMiddle YaglMouse_isMiddleButtonPressed  
#define Yagl_MouseX YaglMouse_getX
#define Yagl_MouseY YaglMouse_getY
#define Yagl_MouseZ YaglMouse_getZ
#define Yagl_SetMouse(x,y) YaglMouse_setPosition(x,y)
#define Yagl_HideMouse YaglGfxDevice_hideMouseCursor    
#define Yagl_ShowMouse YaglGfxDevice_ShowMouseCursor  

' Font Commands
#define Yagl_CreateFont YaglGfxDevice_createFont
#define Yagl_LoadFont(font, filename) YaglGfxFont_loadFont(font, filename)
#define Yagl_FontSize(font,size) YaglGfxFont_setSize(font, size)
#define Yagl_Print(text,x,y,colour,font,blend_factor) YaglGfxDevice_printAt(text,x,y,colour,font,blend_factor)
#define Yagl_DestroyFont(font) YaglGfxDevice_destroyFont(font)
#define Yagl_DestroyAllFonts YaglGfxDevice_destroyAllFonts

'  Drawing Commands
#define yagl_Line(x1,y1,x2,y2,color,blendfactor) YaglGfxDevice_line(x1,y1,x2,y2,color,blendfactor)    
#define Yagl_Box(x1,y1,x2,y2,color,blendfactor) YaglGfxDevice_Box(x1,y1,x2,y2,color,blendfactor)        
#define Yagl_SolidBox(x1,y1,x2,y2,color,blendfactor) YaglGfxDevice_SolidBox(x1,y1,x2,y2,color,blendfactor)      
#define Yagl_ClippingRegion(clip_min_x,clip_min_y,clip_max_x,clip_max_y) YaglGfxDevice_setClippingRegion(clip_min_x,clip_min_y,clip_max_x,clip_max_y)    

'Bitmaps and blitting
#define Yagl_CreateSurface YaglGfxDevice_createSurface()
#Define Yagl_LoadSurfaceFile(filename) YaglGfxSurface_loadFile(filename)
#define Yagl_LoadSurfaceMemory(someSurf,aSurf,x,y,FORMAT) YaglGfxSurface_loadFromMemory(someSurf,aSurf,x,y,FORMAT)
#define Yagl_Blit(x,y,surface,BlitMODE,blend_factor) YaglGfxDevice_blit(x,y,surface,BlitMODE,blend_factor)
#define Yagl_Blit2(x,y,src_min_x,src_min_y,src_max_x,src_max_y, surface, BLIT_MODE,blend_factor ) YaglGfxDevice_blit(x,y,src_min_x,src_min_y,src_max_x,src_max_y, surface, BLIT_MODE,blend_factor )
#define Yagl_BlitScaled YaglGfxDevice_blitScaled(x,y,scale_x,scale_y,surface,BLIT_MODE,blend_factor)
#define Yagl_BlitScaled2(x,y,scale_x,scale_y,src_min_x,src_min_y,src_max_x,src_max_y,surface,BLIT_MODE,blend_factor) YaglGfxDevice_blitScaled(x,y,scale_x,scale_y,src_min_x,src_min_y,src_max_x,src_max_y,surface,BLIT_MODE,blend_factor)
#define Yagl_BlitRotated(x,y,angle,surface,BLIT_MODE,blend_factor) YaglGfxDevice_blitRotated(x,y,angle,surface,BLIT_MODE,blend_factor)
#define Yagl_BlitRotated2(x,y,angle,src_min_x,src_min_y,src_max_x,src_max_y,surface,BLIT_MODE,blend_factor) YaglGfxDevice_blitRotated(x,y,angle,src_min_x,src_min_y,src_max_x,src_max_y,surface,BLIT_MODE,blend_factor)
#define Yagl_BlitRotatedScale(x,y,angle,scale_x,scale_y,surface,BLIT_MODE,blend_factor) YaglGfxDevice_blitRotatedScaled(x,y,angle,scale_x,scale_y,surface,BLIT_MODE,blend_factor)
#define Yagl_BlitRotatedScale2(x,y,angle,scale_x,scale_y,src_min_x,src_min_y,src_max_x,src_max_y,surface,BLIT_MODE,blend_factor) YaglGfxDevice_blitRotatedScaled(x,y,angle,scale_x,scale_y,src_min_x,src_min_y,src_max_x,src_max_y,surface,BLIT_MODE,blend_factor)
#define Yagl_DestroySurface(surface) YaglGfxDevice_destroySurface(surface)
#define Yagl_DestroyAllSurfaces YaglGfxDevice_destroyAllSurfaces()

And replace it with

Code:
#include "yaglCustom.bi"
url=http://www.sloganizer.net/en/][Image: style4,TheDarkJay.png][/url]
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)