Marvellous, it even better.
Thanks for your quick answer.
François
Thanks for your quick answer.
François
This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.
Show posts Menu
LOCAL DIM myArray[10];
FUNCTION BuildSequence: pLevel
// These values are defined LOCAL:
// pLevel
DIM tSequence[pLevel+2];
FOR i = 0 TO pLevel+1
tSequence[i] = RND(7);
NEXT
RETURN tSequence
ENDFUNCTION
Quoteyou could always do if X>320 or X<0 then dx=-dx to change direction (do the same for DY).This would definitely save the ANIMCOLL and improve performance... but in the next version, the bombs will bounce on the black and green boxes as well --> using pictures as masks and ANIMCOLL is easier than playing with all coordinate combinations... But I think that when I will consider the collisions between bombs... this will become unavoidable!
QuoteIf you look in the samples folder that comes with GLBasic, you'll find a QSIN and QCOS function that does faster calculations than the normal COS/SIN.
QuoteI'm not sure if it make sense to store precalculated values for SIN etc. I made some tests some time ago and the usage of SIN/COS within the loops was always faster then using precalc. values in arrays.Ok, thanks for the tips. It will make the code easier, and combined with the newt tips, should have a positive impact on performance.
QuoteNot sure if you are using your sin tables all the time to calculate the movement or not, but if you are then try working out the DX and DY offset at the start only and when you want to change direction, then just INC x,dx and INC y,dy... you could always do if X>320 or X<0 then dx=-dx to change direction (do the same for DY).I think you spot a good point! dx and dy should indeed be constant as long as there is no collision with the border. I will adapt my code!
QuoteYou could also ensure you redraw as little as possible, eg: use LOADBMP to load in the game screen and then only add in your bombs on top.
Quoteyou don't have to use LOADBMP within the game loop, just load the picture one time e.g. at start of sub Play()
LOADBMP "resources/home.png";
was indeed misplaced, but has no effect when playing the game. It only affects the drawing of the main manu; So, this does not explain the low performance.QuoteThere are four ANIMCOLL statements for each bomp. Is this really necessary? Perhaps you can save some of them.Unfortunatelly, yes as I need to check collision with all borders.
SETSCREEN 320, 240, 0; // Set the screen size (not full screen)
LIMITFPS 60; // Limit to 60 frames per second
ALLOWESCAPE TRUE; // Disable instant Esc function
GLOBAL gDevice$ = PLATFORMINFO$("DEVICE");
//IF gDevice$ = "POCKETPC" OR gDevice$ = "F200"
// SYSTEMPOINTER FALSE; // device with touchscreen!
//ELSE
// SYSTEMPOINTER TRUE; // device without touchscreen --> simulate pen with the mouse!
//ENDIF
LoadMedia(); // Call function to load media files
// Boucle principale.
// Quitter la boucle --> quitter le jeu et revenir au menu GP2X
WHILE TRUE
// Affichage et gestion de l'écran de démarrage
LOCAL touchedMenu, highlightedMenu;
LOCAL isMenuSelected = FALSE, dpad = FALSE, pen = FALSE;
LOADBMP "resources/home.bmp";
DrawHomeMenu(0);
SHOWSCREEN;
WHILE isMenuSelected = FALSE
touchedMenu = GetTouchedHomeMenu();
IF pen = FALSE AND touchedMenu > -1
// L'utilisateur vient tout juste de pointer un menu avec le stylet/la souris
highlightedMenu = touchedMenu;
pen = TRUE
ELSEIF pen = TRUE AND touchedMenu = -1
// L'utilisateur vient de relacher la pression sur un menu avec son stylet.
isMenuSelected = TRUE;
pen = FALSE;
ELSEIF dpad = FALSE AND (KEY(200) OR KEY(208))
IF KEY(200) THEN highlightedMenu = MAX(0, highlightedMenu-1); // up arrow
IF KEY(208) THEN highlightedMenu = MIN(4, highlightedMenu+1); // down arrow
dpad = TRUE;
ELSEIF KEY(200) = 0 AND KEY(208) = 0
dpad = FALSE;
ENDIF
DrawHomeMenu(highlightedMenu);
SHOWSCREEN;
// les boutons 'SELECT' (15) et 'B' (45) provoquent
// la sélection du menu en surbrillance.
IF KEY(45) OR KEY(15) THEN isMenuSelected = TRUE;
// Le bouton 'HOME' (F200) permet de quitter le jeu.
IF KEY(28)
isMenuSelected = TRUE;
highlightedMenu = 4;
ENDIF
WEND
IF highlightedMenu = 4 THEN END // Quit game
WEND
END // End the program
FUNCTION LoadMedia:
LOADANIM "resources/font-15px.png", 0, 15, 15;
LOADANIM "resources/home-menu.png", 1, 180, 30;
LOADANIM "resources/pause-menu.png", 2, 180, 30;
LOADANIM "resources/bombs-20px.png", 10, 20, 20;
ENDFUNCTION
FUNCTION DrawHomeMenu: tSelectedMenu
LOCAL offset;
FOR i = 0 TO 4
offset = 0;
IF tSelectedMenu = i THEN offset = 1;
DRAWANIM 1, 2*i+offset, (320-180)/2, 60+30*i;
NEXT
ENDFUNCTION
FUNCTION DrawPauseMenu: tSelectedMenu
LOCAL offset;
FOR i = 0 TO 1
offset = 0;
IF tSelectedMenu = i THEN offset = 1;
DRAWANIM 1, 2*i+offset, (320-180)/2, 60+30*i;
NEXT
ENDFUNCTION
FUNCTION GetTouchedHomeMenu:
LOCAL retval = -1;
MOUSESTATE mx, my, b1, b2;
IF b1 = 1 // pushed
FOR i = 0 TO 4
IF IsPointInRect(mx,my, (320-180)/2, 60+30*i, 180, 30) THEN retval = i;
NEXT
ENDIF
RETURN retval;
ENDFUNCTION
FUNCTION IsPointInRect: px,py, rx,ry,rw,rh
LOCAL retval = FALSE;
IF px > rx AND px < rx + rw AND py > ry AND py < ry + rh
retval = TRUE;
ENDIF
RETURN retval;
ENDFUNCTION
IF py en.dify=0-RND(3)
ELSE
en.dify=RND(3)
ENDIF
There is a chance that the speed of the enemy is 0... and it will stay in memory, but outside the screen...IF py en.dify=-(1+RND(2))
ELSE
en.dify=1+RND(2)
ENDIF
Voilà !
SETSCREEN 320,240,1
LIMITFPS 60
SETTRANSPARENCY RGB(0,0,0)
LOADSPRITE "player.bmp",0
GLOBAL px= 320/2 - 32/2
GLOBAL py= 240/2 - 32/2
WHILE KEY(01)=FALSE
DrawTheScreen()
WEND
END
FUNCTION DrawTheScreen:
DRAWSPRITE 0,px,py
SHOWSCREEN
ENDFUNCTION
I loaded the following files on my GP2X in a folder /Projects/MyFirstGame/