Hi there, I wrote a long program and I have noticed an important bug that comes from DarkBasic pro: I believe it concern the FOR Next statements because in my program there is this code:
FOR Z = V_ENNEMISA_E TO V_ENNEMISZ_E-2 STEP 3
IF AI Entity Exist ( Z ) + 1
IF TIMER() - V_TIR_ENNEMIS_E >= 500 AND AI Get Entity Can Fire(Z) = 1 : DEC V_VIES_JOUEUR_#,0.1 : PLAY SOUND Z+2 : HIDE OBJECT Z+0 : V_TIR_ENNEMIS_E = TIMER() : ELSE : SHOW OBJECT Z+0 : ENDIF
ENDIF
NEXT Z
(the important command in this code is 'HIDE OBJECT Z+0')
the aim of the above code is to make the enemies ( 3 eyeballs) flash on and off: they should appear and disapear alternately
BUT in fact, when I run the program there is only one of the 3 eyeballs that flash on and off ! and yet the FOR NEXT loop affect every eyeball in the scene !
I haven't tried to reproduce this error on smaller code.
here is the full program and attached to this post a zip file containing my program and all its media:
REM * Titre : programmer1
REM * Auteur : programmeur prog'
REM * Date : 01/ 06/ 2009
REM ;
REM ###################################################################################
REM |PROG PRINCIPAL "_prog.dba" ; "_prog-PRO.dbpro"///////////////////////////////////|
REM ################################################################################### #
IF FILE EXIST("util.txt")=1 THEN f_Util()
f_INITIALISER()
REM Débuter PROGRAMME PRINCIPAL ; déclarer les variables ;
REM VARIABLES CONTROLES LIBRES :
GLOBAL V_Joueur_# as float : V_Joueur_#= 0
GLOBAL V_TailleJoueur_# as float : V_TailleJoueur_#=2
GLOBAL V_OldJoueur_X_# as float : V_OldJoueur_X_#= 2.5
GLOBAL V_OldJoueur_Y_# as float : V_OldJoueur_Y_#= 2.0
GLOBAL V_OldJoueur_Z_# as float : V_OldJoueur_Z_#= 2.5
GLOBAL V_Joueur_X_# as float : V_Joueur_X_#= V_OldJoueur_X_#
GLOBAL V_Joueur_Y_# as float : V_Joueur_Y_#= V_OldJoueur_Y_#
GLOBAL V_Joueur_Z_# as float : V_Joueur_Z_#= V_OldJoueur_Z_#
GLOBAL V_Joueur_Vitesse_# : V_Joueur_Vitesse_#= 2.5
GLOBAL V_Camera_Vitesse_# : V_Camera_Vitesse_#= 6.0
GLOBAL V_Avance_# : V_Avance_#= 0.0
GLOBAL V_Droite_# : V_Droite_#= 0.0
GLOBAL V_Recul_# : V_Recul_#= 0.0
GLOBAL V_Gauche_# : V_Gauche_#= 0.0
GLOBAL V_OldCameraY_#
GLOBAL V_OldCameraX_#
GLOBAL V_CameraY_#
GLOBAL V_CameraX_#
GLOBAL V_CameraTest_X_#
REM SCORE JOUEUR:
GLOBAL V_VIES_JOUEUR_# = 3.0
REM NIVEAU, CHEMINS ET NOM$
GLOBAL V_Niveau_E = 4
GLOBAL V_NiveauZ_E = 4
GLOBAL V_Niveau_JEU_E = 1
GLOBAL V_Niveau_JEU_$ : V_Niveau_JEU_$ = "1"
GLOBAL V_PartNiveau_E = 2
REM ENNEMIS
GLOBAL V_ENNEMISA_E
GLOBAL V_ENNEMISZ_E
GLOBAL V_NbreEnnemis_E
GLOBAL V_ENNEMISTYPE_E
GLOBAL V_TIR_ENNEMIS_E
GLOBAL V_FX_ENNEMIS_E
GLOBAL V_TIR_ENNEMISZ_E
GLOBAL V_FX_ENNEMISZ_E
GLOBAL V_MOUCHE_ENNEMIS_E
GLOBAL V_FXA_E = 1000
REM VARIABLE D'USAGE ET DE LECTURE
GLOBAL V_LECTURE1_# : GLOBAL V_LECTURE2_# : GLOBAL V_LECTURE3_#
GLOBAL V_LECTURE1_$
GLOBAL Y=1
REM IMAGES :
GLOBAL V_TexturesZ_E = 10
REM ARME JOUEUR:
GLOBAL V_ARME_JOUEUR_E
REM V_VISEUR_E:
GLOBAL V_VISEUR_E
REM TIRER JOUEUR :
GLOBAL V_GACHETTE_E
GLOBAL V_TIR_UN_E = TIMER()
GLOBAL V_INTERVALLE_TIR_E
GLOBAL V_SON_E = 0
GLOBAL V_TIR_X_EE
GLOBAL V_TIR_X_# : GLOBAL V_TIR_Y_# : GLOBAL V_TIR_Z_#
REM SYNC TEMPS:
global V_BOUCLE1=0
global V_SYNC1=0
global V_TEMPS_ZERO1=0
REM MENUS 1 :
` To make the code easier to read I will make my menu options into
` readable constants
#constant cMENU1OPT1 1
#constant cMENU1OPT2 2
#constant cMENU1OPT3 3
#constant cMENU_OPTIONS_1_OPT1 4
#constant cMENU_OPTIONS_1_OPT2 5
REM LE MENU PRINCIPAL 1 :
global V_Menu_PRINCIPAL_1_E
REM LE MENU OPTIONS 1 :
GLOBAL V_MENU_OPTIONS_1_E
REM MENUS 2 :
GLOBAL V_FIN_MENU_PRINCIPAL_E
global V_Premier_spriteE : V_Premier_spriteE=500 : ` numéro de sprite correspondant au titre
` Menu Type. This holds the information about each individual menu
type tMenu
title$
Columns
Options
firstSprite
endtype
` Option Type. This holds the information about each individual option
type tOption
MenuId
title$
value
x
y
endtype
` We also need some global variables to support the system.
type tMenuVar
CurMenu
CurOption
Initialised
font$
fontSize
mouse
mousedown
endtype
global gMenuVar as tMenuVar
` These variables don't need to be declared here
` but they have been so that they are visible in the Debug window
global txt$
global x
global y
global NumRows
global rows#
GLOBAL V_Animer_SpriteE
GLOBAL V_Animer_Sprite_OldE
REM EXPLOSIONS :
`set the first object used by the system
GLOBAL ex_first = 50000
`set the max number of objects the system can use
GLOBAL ex_max = 50
`a counter to incerement throught he objects
GLOBAL ex_counter = 0
`an array to determine if the object / explosion is alive
GLOBAL DIM ex_alive(ex_max)
`the curent frame of the explosion is held in an array
GLOBAL DIM ex_frame(ex_max)
`the first image number of the current explosion effect
GLOBAL DIM ex_first_image(ex_max)
`a frame skip delay to slow down the animation
GLOBAL DIM ex_delay(ex_max)
REM LUMIERE:
GLOBAL A3= 1
GLOBAL B3= 1
// GOTO Declarer_Variables_aGOT
// Declarer_Variables_zGOT:
REM DEROULEMENT DU PROGRAMME ENTIER:
F_DEROULEMENT1()
REM ___ F I N ____/////////////////
FINIR_TOUT:
END
REMSTART
; NOTER | Enregistrer sousI | Enregistrer sousII | Répertoire à structurer | INCLURE dans l'éxecutable | LIRE comme suit |
;
|***********************************************************|
NOTER; |************---------------------------------------||
|*********************************************************|||
-FONCTIONS préfixe 'f_'
-VARIABLES préfixe majuscule 'V_' = globale ; 'v_' = locale ; SUFFIXE Variables _E ; _# ; _$ (Entier ; réel ; caractères)
-numéroter variables globales 1,2 etc pour les différencier des locales déclarées dans des fonctions;
-TABLEAUX préfixes majuscule 'T_' = GLOBAL ; 't_' = LOCAL ; SUFFIXE Tableaux _E ; _# ; _$
-TYPES préfixes 'TYP_'
-ETIQUETTES suffixe majuscule '_GOT' = GOTO ; '_GOS' = GOSUB / de A à Z : zGOT:
-CHEMINS "\" séparateur ; ".." dossier parent ;
-COLONNES PUIS LIGNES / LARGEUR puis HAUTEUR
|-------------------------------------------------------|
Enregistrer sousI '_Préférences.txt'; |----------------||
|-----------------------------------------------------|||
>enregistrer sous '_Préférences.txt'
>enregistrer sous '\Bin32\Données_0a\_Préférences.txt' (<-préf. par défaut)
>Fichier '_Préférences.txt' ; contenu;
-résolution largeur. hauteur. profondeur. Vsync. Anti-aliasing;
1024
-
768
-
32
-
1
-
1
-Langue, 1 français, 2 Anglais;
1
-Qualité / performances 1=très bas, 2=bas, 3=Bon, 4=Très Bon, 5=Max élevé;
4
-Typo texte (s'assurer que la typo est installée sur votre disque dur) sinon laisser ARIAL;
Arial
-Taille Texte: 1,2 ou 3 pour améliorer la définition utilisée par les lettres du texte;
1
-demander confirmation avant de quitter le programme grâce à touche ECHAP ; 0=non ;1=oui ;
0
|--------------------------------------------------------|
Enregistrer sousII _initialisation.txt; |---------------||
|------------------------------------------------------|||
>enregistrer sous '\Bin32\Données_0a\_initialisation.txt'
>Fichier '_initialisation.txt' ; contenu;
-fréquence d'images/seconde;
60
-Titre de barre de titre;
programme darkbasicpro
-Titre jeu;
"programme1"
-Auteur;
"programmeur prog'"
-année;
(c)2009
-Message d'erreur de base;
"erreur"
http://inudge.net/inudge#/2l9l CREATE MUSIC
REMEND
Rem ***** Included Source File *****
REM * Titre : programmer1
REM * Auteur : programmeur prog'
REM * Date : 01/ 06/ 2009
REM ;
REM ###################################################################################
REM |***** Included Source File ***** "_prog.dba" ; "_prog-PRO.dbpro" "F_fonctions1.dba"///////////////////////////////////|
REM ################################################################################### #
REM /////// CONTROLES LIBRES/////////////
FUNCTION f_CONTROLES()
REM AVANT / ARRIERE
IF UPKEY()=1 THEN INC V_Avance_#,0.1 ELSE V_Avance_#= 0
IF DOWNKEY()=1 THEN INC V_Recul_#,0.1 ELSE V_Recul_#= 0
IF V_Avance_# > V_Recul_#
IF V_Recul_#>0 THEN DEC V_Recul_#, 0.1
ENDIF
IF V_Avance_# < V_Recul_#
IF V_Avance_#>0 THEN DEC V_Avance_#, 0.1
ENDIF
REM DROITE / GAUCHE
IF RIGHTKEY()=1 THEN INC V_Droite_#,0.1 ELSE V_Droite_#= 0
IF LEFTKEY()=1 THEN INC V_Gauche_#,0.1 ELSE V_Gauche_#= 0
IF V_Droite_# > V_Gauche_#
IF V_Gauche_#>0 THEN DEC V_Gauche_#, 0.1
ENDIF
IF V_Droite_# < V_Gauche_#
IF V_Droite_#>0 THEN DEC V_Droite_#, 0.1
ENDIF
REM PEAUFINE LE MOUVEMENT :
IF V_Avance_# > 0 OR V_Recul_# > 0 OR V_Droite_# > 0 OR V_Gauche_# > 0
// V_Joueur_Vitesse_# = CURVEVALUE(8,0.5,2)
IF f_Sync_TEMPS1(10) = 1 THEN INC V_Joueur_Vitesse_#,0.3
ELSE:
V_Joueur_Vitesse_# = 0.2
ENDIF
IF V_Joueur_Vitesse_# > 5.0 THEN V_Joueur_Vitesse_# = 5.0
REM Enregistre coordonnées joueur axe xyz
V_OldJoueur_X_# = CAMERA POSITION X()
V_OldJoueur_Y_# = CAMERA POSITION Y()
V_OldJoueur_Z_# = CAMERA POSITION Z()
V_OldCameraY_# = CAMERA ANGLE Y()
V_OldCameraX_# = CAMERA ANGLE X()
REM CAMERA / SOURIS
// V_CameraY_# = WrapValue(V_CameraY_#+MousemoveX()*V_Camera_Vitesse_#)
// V_CameraX_# = WrapValue(V_CameraX_#+MousemoveY()*V_Camera_Vitesse_#)
// V_CameraZ_# = Camera angle Z()
REM CONTROLES souris MODIFIES
V_CameraX_# = V_CameraX_#+((mousemovey()+0.0)/V_Camera_Vitesse_#)
V_CameraY_# = V_CameraY_#+((mousemovex()+0.0)/V_Camera_Vitesse_#)
V_CameraZ_# = Camera angle Z()
// rotate camera camera angle x()+((mousemovey()+0.0)/2.0),camera angle y()+((mousemovex()+0.0)/2.0),0
REM MOUVEMENT DE HAUT EN BAS :
// V_Joueur_Y_# = V_Joueur_Y_#+MOUSEMOVEZ()/80
REM REM V_Joueur_Y_# = CAMERA POSITION Y()+MOUSEMOVEZ()*32
// POSITION CAMERA CAMERA POSITION X(),V_Joueur_Y_#,CAMERA POSITION Z()
POSITION CAMERA CAMERA POSITION X(),V_Joueur_Y_#,CAMERA POSITION Z()
// POSITION CAMERA CAMERA POSITION X(),CURVEVALUE( V_Joueur_Y_#, V_OldJoueur_Y_#, 12 ),CAMERA POSITION Z()
// Position Camera CURVEVALUE( V_Joueur_X_#, V_OldJoueur_X_#, 12 ),V_Joueur_Y_#,CURVEVALUE( V_Joueur_Z_#, V_OldJoueur_Z_#, 12 )
Rem Controle DEPLACEMENT pour camera
IF V_Avance_#>0 AND V_Gauche_#=0 AND V_Droite_#=0
// XROTATE CAMERA 0
MOVE CAMERA V_Joueur_Vitesse_#
V_Joueur_X_# = CAMERA POSITION X()
REM REM V_Joueur_Y_# = CAMERA POSITION Y()
V_Joueur_Z_# = CAMERA POSITION Z()
ENDIF
IF V_Recul_#>0 AND V_Gauche_#=0 AND V_Droite_#=0
// XROTATE CAMERA 0
MOVE CAMERA 0-V_Joueur_Vitesse_#
V_Joueur_X_# = CAMERA POSITION X()
REM REM V_Joueur_Y_# = CAMERA POSITION Y()
V_Joueur_Z_# = CAMERA POSITION Z()
ENDIF
IF V_Gauche_#>0 AND V_Avance_#=0 AND V_Recul_#=0
YROTATE CAMERA CAMERA ANGLE Y()-90
MOVE CAMERA V_Joueur_Vitesse_#
V_Joueur_X_# = CAMERA POSITION X()
// V_Joueur_Y_# = CAMERA POSITION Y()
V_Joueur_Z_# = CAMERA POSITION Z()
ENDIF
IF V_Droite_#>0 AND V_Avance_#=0 AND V_Recul_#=0
YROTATE CAMERA CAMERA ANGLE Y()+90
MOVE CAMERA V_Joueur_Vitesse_#
V_Joueur_X_# = CAMERA POSITION X()
// V_Joueur_Y_# = CAMERA POSITION Y()
V_Joueur_Z_# = CAMERA POSITION Z()
ENDIF
REM DIAGONALES: AVANCER.
IF V_Gauche_#>0 AND V_Avance_#>0
YROTATE CAMERA CAMERA ANGLE Y()-45
MOVE CAMERA V_Joueur_Vitesse_#
V_Joueur_X_# = CAMERA POSITION X()
REM REM V_Joueur_Y_# = CAMERA POSITION Y()
V_Joueur_Z_# = CAMERA POSITION Z()
ENDIF
IF V_Droite_#>0 AND V_Avance_#>0
YROTATE CAMERA CAMERA ANGLE Y()+45
MOVE CAMERA V_Joueur_Vitesse_#
V_Joueur_X_# = CAMERA POSITION X()
REM REM V_Joueur_Y_# = CAMERA POSITION Y()
V_Joueur_Z_# = CAMERA POSITION Z()
ENDIF
REM DIAGONALES: RECULER.
IF V_Gauche_#>0 AND V_Recul_#>0 AND V_Avance_#=0
YROTATE CAMERA CAMERA ANGLE Y()+45
MOVE CAMERA 0-V_Joueur_Vitesse_#
V_Joueur_X_# = CAMERA POSITION X()
REM REM V_Joueur_Y_# = CAMERA POSITION Y()
V_Joueur_Z_# = CAMERA POSITION Z()
ENDIF
IF V_Droite_#>0 AND V_Recul_#>0 AND V_Avance_#=0
YROTATE CAMERA CAMERA ANGLE Y()-45
MOVE CAMERA 0-V_Joueur_Vitesse_#
V_Joueur_X_# = CAMERA POSITION X()
REM REM V_Joueur_Y_# = CAMERA POSITION Y()
V_Joueur_Z_# = CAMERA POSITION Z()
ENDIF
V_CameraTest_X_#=WrapValue(V_CameraX_#-180)
if V_CameraTest_X_# > 270 then V_CameraX_#=90
if V_CameraTest_X_# < 90 then V_CameraX_#=270
YRotate camera CurveANGLE(V_CameraY_#,V_OldCameraY_#,6)
XRotate camera CurveAngle(V_CameraX_#,V_OldCameraX_#,6)
// POSITION CAMERA CAMERA POSITION X(),CURVEVALUE( V_Joueur_Y_#, V_OldJoueur_Y_#, 12 ),CAMERA POSITION Z()
// Position Camera V_Joueur_X_#,V_Joueur_Y_#,V_Joueur_Z_#
Position Camera CURVEVALUE( V_Joueur_X_#, V_OldJoueur_X_#, 12 ),CURVEVALUE( V_Joueur_Y_#, V_OldJoueur_Y_#, 12 ),CURVEVALUE( V_Joueur_Z_#, V_OldJoueur_Z_#, 12 )
// Position Camera V_Joueur_X_#,V_Joueur_Y_#,V_Joueur_Z_#
Rem REPositionne Camera :
// f_CollisionGlissante(V_OldJoueur_X_#,V_OldJoueur_Y_#,V_OldJoueur_Z_#,V_Joueur_X_#,V_Joueur_Y_#,V_Joueur_Z_#,V_TailleJoueur_#,V_Niveau_E)
IF SC_SPHERESLIDE(V_Niveau_E,V_OldJoueur_X_#,V_OldJoueur_Y_#,V_OldJoueur_Z_#,V_Joueur_X_#,V_Joueur_Y_#,V_Joueur_Z_#,V_TailleJoueur_#,0) > 0
V_Joueur_X_# = sc_getCollisionSlideX()
V_Joueur_Y_# = sc_getCollisionSlideY()
V_Joueur_Z_# = sc_getCollisionSlideZ()
POSITION CAMERA CURVEVALUE( V_Joueur_X_#, V_OldJoueur_X_#, 12 ),CURVEVALUE( V_Joueur_Y_#, V_OldJoueur_Y_#, 12 ),CURVEVALUE( V_Joueur_Z_#, V_OldJoueur_Z_#, 12 )
// Position Camera V_Joueur_X_#,V_Joueur_Y_#,V_Joueur_Z_#
REM Sliding Collision with Sparky's Collision dll
REM By RUCCUS ----- Email/MSN: [email protected]
ENDIF
Rem Position Listener
Position Listener V_Joueur_X_#,V_Joueur_Y_#,V_Joueur_Z_#
Rotate Listener 0,V_CameraY_#,0
ENDFUNCTION
REM ////// INITIER /////////////////
FUNCTION f_INITIALISER()
AUTOCAM OFF : SYNC ON : SYNC RATE GET DISPLAY REFRESH RATE( )
// SET DISPLAY MODE 1920,1080,32,1,4,0 : BACKDROP ON : HIDE MOUSE
SET DISPLAY MODE 1024,768,32,1 : BACKDROP ON : HIDE MOUSE
EXIT PROMPT "Merci d'avoir testé ce programme : appuyer sur ECHAP pour Quitter / THE END, ESCAPE TO QUIT", "TIREUR D'ELITE : "
rem SHOW MOUSE
RANDOMIZE TIMER()
AI START
SET DIR "BIN"
ENDFUNCTION
REM /////// SCENE //////////////////
FUNCTION f_PREPARE_SCENE()
SET DIR V_Niveau_JEU_$
HIDE MOUSE : SET TEXT SIZE SCREEN WIDTH()/50
// OPEN TO READ 1,"tout.txt" : READ STRING 1,V_LECTURE1_$ : V_PartNiveau_E = VAL(V_LECTURE1_$) : CLOSE FILE 1
OPEN FILE BLOCK "a.a",1,"monmotdepasse111"
PERFORM CHECKLIST FOR FILE BLOCK DATA 1
FOR Z=1 TO CHECKLIST QUANTITY()
IF RIGHT$(CHECKLIST STRING$(Z),4)=".bmp"
LOAD IMAGE FROM BLOCK 1,CHECKLIST STRING$(Z),V_TexturesZ_E
INC V_TexturesZ_E,1
ENDIF
NEXT Z
REM VISEUR:
V_VISEUR_E = V_TexturesZ_E
LOAD IMAGE "VISEUR.BMP",V_VISEUR_E : SPRITE 1,SCREEN WIDTH() /2,SCREEN HEIGHT() /2,V_VISEUR_E : SIZE SPRITE 1,(SCREEN WIDTH()*0.8333333)/100*2,(SCREEN HEIGHT()*1.481481481)/100*2 : SPRITE 1,(SCREEN WIDTH() /2)-SPRITE WIDTH(1) /2,(SCREEN HEIGHT() /2)-SPRITE HEIGHT(1) /2,V_VISEUR_E
REM (16/1080)*100 = 1.481481481 %
SET SPRITE DIFFUSE 1,255,255,0
// DO
// AI ADD CONTAINER V_Niveau_JEU_E : AI SET CONTAINER ACTIVE V_Niveau_JEU_E,0
LOAD OBJECT FROM BLOCK 1,"1col.x",V_NiveauZ_E : SC_SETUPCOMPLEXOBJECT V_NiveauZ_E,0,2 : SC_allowObjectScaling V_NiveauZ_E : SCALE OBJECT V_NiveauZ_E,100,100,100 : SC_updateObject V_NiveauZ_E : EXCLUDE OBJECT ON V_NiveauZ_E
AI ADD OBSTACLE FROM LEVEL V_NiveauZ_E, 0, 0, 1, 1 : AI COMPLETE OBSTACLES 0
INC V_NiveauZ_E,1
LOAD OBJECT FROM BLOCK 1,"1.x",V_NiveauZ_E : SET OBJECT LIGHT V_NiveauZ_E, 0 : EXCLUDE OBJECT ON V_NiveauZ_E
INC V_NiveauZ_E,1
LOAD OBJECT FROM BLOCK 1,"1gfx1.x",V_NiveauZ_E : SET OBJECT LIGHT V_NiveauZ_E, 0 : EXCLUDE OBJECT ON V_NiveauZ_E
INC V_NiveauZ_E,1
LOAD OBJECT FROM BLOCK 1,"1gfx2.x",V_NiveauZ_E : SET OBJECT LIGHT V_NiveauZ_E, 0 : EXCLUDE OBJECT ON V_NiveauZ_E
INC V_NiveauZ_E,1
LOAD OBJECT FROM BLOCK 1,"1info.x",V_NiveauZ_E : EXCLUDE OBJECT ON V_NiveauZ_E
INC V_NiveauZ_E,1
REM PASSER AU NIVEAU SUPERIEUR :
// INC V_Niveau_JEU_E,1
REM QITTER LA BOUCLE A LA FIN:
// IF FILE EXIST(STR$(V_Niveau_JEU_E)+"col.x")=0 THEN EXIT
// IF 0 = GET FILE BLOCK DATA EXISTS( 1, STR$(V_Niveau_JEU_E)+"col.x" ) THEN EXIT
// IF V_Niveau_JEU_E > V_PartNiveau_E THEN EXIT
// LOOP
V_Niveau_JEU_E = 1
// AI SET CONTAINER ACTIVE V_Niveau_JEU_E,1
// AI DEBUG SHOW OBSTACLE BOUNDS 0,-5
AI COMPLETE OBSTACLES 0
V_ENNEMISA_E = V_NiveauZ_E
V_ENNEMISZ_E = V_ENNEMISA_E
REM LIRE OBJET 1INFO.X !
f_LIRE_OBJETS()
DIM shootTimer(V_NbreEnnemis_E) as float
V_ARME_JOUEUR_E = V_ENNEMISZ_E
EXCLUDE OBJECT OFF V_Niveau_E+1
REM LE JOUEUR :
MAKE OBJECT SPHERE 2,4 : HIDE OBJECT 2
AI ADD FRIENDLY 2,1 : AI Set Entity Control 2, 0
// AI ADD PLAYER 2000,0 : AI SET PLAYER POSITION 80,50
REM DECAL:
MAKE OBJECT SPHERE 3,1
// V_Niveau_JEU_$ = "1"
// IF FILE EXIST(V_Niveau_JEU_$+".dbo") = 0
// LOAD OBJECT V_Niveau_JEU_$+".x",V_Niveau_E : SAVE OBJECT V_Niveau_JEU_$+".dbo",V_Niveau_E : DELETE OBJECT V_Niveau_E : LOAD OBJECT V_Niveau_JEU_$+".dbo",V_Niveau_E
// ELSE
// LOAD OBJECT V_Niveau_JEU_$+".dbo",V_Niveau_E
// ENDIF
//
// SET OBJECT LIGHT V_Niveau_E, 0
REM Met le niveau dans le groupe 0 avec collision complexe polygone (type 0) 2 facesPerNode
// SC_SETUPCOMPLEXOBJECT V_Niveau_E,0,2 : SC_allowObjectScaling V_Niveau_E : SCALE OBJECT V_Niveau_E,100,100,100 : SC_updateObject V_Niveau_E
// REM CHARGER 5 NIVEAUX EN TOUT....
POSITION CAMERA V_Joueur_X_#,V_Joueur_Y_#,V_Joueur_Z_#
REM CREER UNE ARME:
LOAD OBJECT "Arme.x",V_ARME_JOUEUR_E : POSITION OBJECT V_ARME_JOUEUR_E,V_Joueur_X_#,V_Joueur_Y_#,V_Joueur_Z_# : SCALE OBJECT V_ARME_JOUEUR_E,100,100,100 : TEXTURE OBJECT V_ARME_JOUEUR_E,V_TexturesZ_E-1 : DISABLE OBJECT ZDEPTH V_ARME_JOUEUR_E
LOAD SOUND "Arme1.wav",1 : CLONE SOUND 2,1 : CLONE SOUND 3,1
DELETE FILE BLOCK 1
SET DIR ".."
// `then we need to prepare the explosions with this function
prepare_explosions()
ENDFUNCTION
REM TIRER JOUEUR /////////////////////
FUNCTION f_TIRER_JOUEUR()
IF V_SON_E = 3 THEN V_SON_E = 1
IF MOUSECLICK() = 1 THEN INC V_GACHETTE_E,1
IF MOUSECLICK() = 0 THEN V_GACHETTE_E = 0
IF V_GACHETTE_E = 1 AND TIMER() - V_TIR_UN_E >= 125 : INC V_SON_E,1 : PLAY SOUND V_SON_E : V_TIR_UN_E = TIMER()
MOVE CAMERA 10000 : V_TIR_X_EE = SC_multipleRayCast( V_Niveau_E, OBJECT POSITION X (V_ARME_JOUEUR_E), OBJECT POSITION Y (V_ARME_JOUEUR_E), OBJECT POSITION Z (V_ARME_JOUEUR_E), CAMERA POSITION X(), CAMERA POSITION Y(), CAMERA POSITION Z(), 0 ) :
V_TIR_X_# = SC_getStaticCollisionX() : V_TIR_Y_# = SC_getStaticCollisionY() : V_TIR_Z_# = SC_getStaticCollisionZ()
REM DECAL:
POSITION OBJECT 3,V_TIR_X_#,V_TIR_Y_#,V_TIR_Z_#
V_TIR_X_EE = SC_rayCastGroup( 1, OBJECT POSITION X (V_ARME_JOUEUR_E), OBJECT POSITION Y (V_ARME_JOUEUR_E), OBJECT POSITION Z (V_ARME_JOUEUR_E),V_TIR_X_#,V_TIR_Y_#,V_TIR_Z_#, 0 )
// IF V_TIR_X_EE>0 : HIDE OBJECT V_TIR_X_EE : HIDE OBJECT V_TIR_X_EE-1 : HIDE OBJECT V_TIR_X_EE+1 : ENDIF
REM L'adversaire est composé de 3 objets: 2èME pour les collisions, 1 pour l'apparence, 3 pour les effets spéciaux
IF V_TIR_X_EE>0
spawn_explosion(OBJECT POSITION X(V_TIR_X_EE),OBJECT POSITION Y(V_TIR_X_EE),OBJECT POSITION Z(V_TIR_X_EE),RND(19)+1,OBJECT SIZE(V_TIR_X_EE)*3.5)
POSITION OBJECT V_TIR_X_EE,OBJECT POSITION X(V_TIR_X_EE)+1000000,OBJECT POSITION Y(V_TIR_X_EE)-20,OBJECT POSITION Z(V_TIR_X_EE)+1000000
POSITION OBJECT V_TIR_X_EE-1,OBJECT POSITION X(V_TIR_X_EE-1)+1000000,OBJECT POSITION Y(V_TIR_X_EE-1)-20,OBJECT POSITION Z(V_TIR_X_EE-1)+1000000
POSITION OBJECT V_TIR_X_EE+1,OBJECT POSITION X(V_TIR_X_EE+1)+1000000,OBJECT POSITION Y(V_TIR_X_EE+1)-20,OBJECT POSITION Z(V_TIR_X_EE+1)+1000000
SC_removeObject V_TIR_X_EE : AI Kill Entity V_TIR_X_EE-1 : AI Add Neutral V_TIR_X_EE-1 :`` AI Set Entity Control V_TIR_X_EE-1, 0 : AI Entity Move To Cover V_TIR_X_EE-1, CAMERA POSITION X(),CAMERA POSITION Z() : AI Set Entity Attack Distance V_TIR_X_EE-1, 1
DEC V_NbreEnnemis_E,1
PLAY SOUND V_TIR_X_EE-1+RND(1)
ENDIF
MOVE CAMERA -10000 : ENDIF
POSITION MOUSE SCREEN WIDTH() /2,SCREEN HEIGHT() /2
ENDFUNCTION
REM ////////////////////////
REM LIRE OBJETS ///////
FUNCTION f_LIRE_OBJETS()
PERFORM CHECKLIST FOR OBJECT LIMBS V_Niveau_E+4
FOR Z=2 TO CHECKLIST QUANTITY()-1
V_LECTURE1_$ = LIMB NAME$(V_Niveau_E+4,Z)
IF LEFT$(V_LECTURE1_$,8)="ennemisa"
V_ENNEMISTYPE_E = RND(1)+1
LOAD OBJECT FROM BLOCK 1,"ENNEMISA"+STR$(V_ENNEMISTYPE_E)+".x",V_ENNEMISZ_E : POSITION OBJECT V_ENNEMISZ_E,LIMB POSITION X(V_Niveau_E+4,Z),LIMB POSITION Y(V_Niveau_E+4,Z),LIMB POSITION Z(V_Niveau_E+4,Z)
YROTATE OBJECT V_ENNEMISZ_E,RND(359)
LOAD OBJECT FROM BLOCK 1,"ENNEMISB"+STR$(V_ENNEMISTYPE_E)+".x",V_ENNEMISZ_E+1 : YROTATE OBJECT V_ENNEMISZ_E+1, OBJECT ANGLE Y(V_ENNEMISZ_E) : POSITION OBJECT V_ENNEMISZ_E+1,LIMB POSITION X(V_Niveau_E+4,Z),LIMB POSITION Y(V_Niveau_E+4,Z),LIMB POSITION Z(V_Niveau_E+4,Z)
HIDE OBJECT V_ENNEMISZ_E+1 : EXCLUDE OBJECT ON V_ENNEMISZ_E+1
LOAD OBJECT FROM BLOCK 1,"ENNEMISC"+STR$(V_ENNEMISTYPE_E)+".x",V_ENNEMISZ_E+2 : YROTATE OBJECT V_ENNEMISZ_E+2, OBJECT ANGLE Y(V_ENNEMISZ_E) : POSITION OBJECT V_ENNEMISZ_E+1,LIMB POSITION X(V_Niveau_E+4,Z),LIMB POSITION Y(V_Niveau_E+4,Z),LIMB POSITION Z(V_Niveau_E+4,Z)
GHOST OBJECT ON V_ENNEMISZ_E+2 : SET OBJECT CULL V_ENNEMISZ_E+2,0 :`` HIDE OBJECT V_ENNEMISZ_E+2
REM SC_setupComplexObject V_ENNEMISZ_E , 1 , 2
SC_setupObject V_ENNEMISZ_E+1, 1, 0
REM COLOR OBJECT V_ENNEMISZ_E,RGB(255,0,0) :
AI ADD ENEMY V_ENNEMISZ_E,0
REM ENTITY SPEED = 16
AI SET ENTITY SPEED V_ENNEMISZ_E,25 : AI SET ENTITY AGGRESSIVE V_ENNEMISZ_E : AI Set Entity View Range V_ENNEMISZ_E, 100000
AI Set Entity Position V_ENNEMISZ_E,LIMB POSITION X(V_Niveau_E+4,Z),LIMB POSITION Z(V_Niveau_E+4,Z) : AI Set Entity Angle Y V_ENNEMISZ_E, OBJECT ANGLE Y(V_ENNEMISZ_E)
// LOAD OBJECT FROM BLOCK 1,"ENNEMISC"+STR$(V_ENNEMISTYPE_E)+".x",V_ENNEMISZ_E+V_FXA_E : GHOST OBJECT ON V_ENNEMISZ_E+V_FXA_E :`` HIDE OBJECT V_ENNEMISZ_E+V_FXA_E
LOAD 3DSOUND "EXPLOSION1.wav",V_ENNEMISZ_E : LOAD 3DSOUND "EXPLOSION2.wav",V_ENNEMISZ_E+1
LOAD 3DSOUND "TIR_ENNEMI.wav",V_ENNEMISZ_E+2
INC V_ENNEMISZ_E,3
INC V_NbreEnnemis_E,1
ENDIF
NEXT Z
ENDFUNCTION
REM //////////////////////
FUNCTION f_POSITIONNER_ENNEMIS()
FOR Z = V_ENNEMISA_E TO V_ENNEMISZ_E-2 STEP 3
IF AI Entity Exist ( Z ) = 1 THEN POSITION OBJECT Z,AI GET ENTITY X(Z),OBJECT POSITION Y(Z),AI GET ENTITY Z(Z) : YROTATE OBJECT Z, AI Get Entity Angle Y(Z)-180
// REM MOUVEMENT DE HAUT EN BAS :
// RR# = WRAPVALUE(RR#+1.0)
// REM POSITION CAMERA CAMERA POSITION X(),0+(COS(RR#)*20),CAMERA POSITION Z()
// POSITION OBJECT Z,AI GET ENTITY X(Z),0+(COS(RR#)*2),AI GET ENTITY Z(Z) : YROTATE OBJECT Z, AI Get Entity Angle Y(Z)-180
POSITION OBJECT Z+1,OBJECT POSITION X (Z),OBJECT POSITION Y (Z),OBJECT POSITION Z (Z) : YROTATE OBJECT Z+1,OBJECT ANGLE Y (Z)
POSITION OBJECT Z+2,OBJECT POSITION X (Z),OBJECT POSITION Y (Z),OBJECT POSITION Z (Z) : YROTATE OBJECT Z+2,OBJECT ANGLE Y (Z)
REM POSITIONNE LES SONS 3D:
POSITION SOUND Z,OBJECT POSITION X (Z),OBJECT POSITION Y (Z),OBJECT POSITION Z (Z)
POSITION SOUND Z+1,OBJECT POSITION X (Z),OBJECT POSITION Y (Z),OBJECT POSITION Z (Z)
POSITION SOUND Z+2,OBJECT POSITION X (Z),OBJECT POSITION Y (Z),OBJECT POSITION Z (Z)
// AI Set Entity Control Z,0 : AI Entity Move To Cover Z, CAMERA POSITION X(), CAMERA POSITION Z()
NEXT Z
ENDFUNCTION
REM //////////////////////
REM //////////////////////
FUNCTION f_POSITIONNER_JOUEUR()
AI Set Entity Position 2, CAMERA POSITION X(), CAMERA POSITION Z()
ENDFUNCTION
REM /////////////////////
REM /////////////////////
FUNCTION f_TIRER_ENNEMIS()
FOR Z = V_ENNEMISA_E TO V_ENNEMISZ_E-2 STEP 3
IF AI Entity Exist ( Z ) + 1
IF TIMER() - V_TIR_ENNEMIS_E >= 500 AND AI Get Entity Can Fire(Z) = 1 : DEC V_VIES_JOUEUR_#,0.1 : PLAY SOUND Z+2 : HIDE OBJECT Z+0 : V_TIR_ENNEMIS_E = TIMER() : ELSE : SHOW OBJECT Z+0 : ENDIF
ENDIF
NEXT Z
ENDFUNCTION
REM /////////////////////
REM /////////////////////
FUNCTION f_SCORE()
IF V_NbreEnnemis_E <= 0 THEN END
IF V_VIES_JOUEUR_# <= 0 THEN END
ENDFUNCTION
REM /////////////////////
FUNCTION f_NETTOYER()
ENDFUNCTION
FUNCTION f_QUITTER()
ENDFUNCTION
FUNCTION f_INTRO()
ENDFUNCTION
REM ///////// intervalle de temps en millisecondes /////////////
FUNCTION f_Sync_TEMPS1(V_T1)
IF V_SYNC1>0
DEC V_SYNC1,1
V_BOUCLE1 = 0
ENDIF
IF V_BOUCLE1 = 0 THEN V_TEMPS_ZERO1 = TIMER()
IF TIMER()-V_TEMPS_ZERO1 => V_T1 : V_SYNC1 = 1 : ENDIF
IF V_BOUCLE <=90000 THEN INC V_BOUCLE1,1
// PRINT TIMER()
// PRINT V_BOUCLE1
// PRINT V_TEMPS_ZERO1
// print V_SYNC1
ENDFUNCTION V_SYNC1
REM /////////////////////////////////
Rem ***** Included Source File *****
REM * Titre : programmer1
REM * Auteur : programmeur prog'
REM * Date : 01/ 06/ 2009
REM ;
REM ###################################################################################
REM |***** Included Source File ***** "_prog.dba" ; "_prog-PRO.dbpro"///////////////////////////////////|
REM ################################################################################### #
REM ////////// UTILITAIRES ////////////
FUNCTION f_Util()
V_Niveau_JEU_$ = SAVE FILE DIALOG(GET DIR$(),".","NUMERO DU NIVEAU: 1,2,3... ")
SYNC
WAIT 350
IF FILE EXIST(V_Niveau_JEU_$+".X") = 1 AND FILE EXIST(V_Niveau_JEU_$+".DBO") = 0
V_LECTURE1_$ = SAVE FILE DIALOG(GET DIR$(),"","NOMBRE TEXTURES : 1,2,3... ")
// V_LECTURE3_$ = ""
V_Niveau_E = 1
LOAD OBJECT V_Niveau_JEU_$+".x",V_Niveau_E
SAVE OBJECT V_Niveau_JEU_$+".dbo",V_Niveau_E : DELETE OBJECT V_Niveau_E
ENDIF
DIM T_CARTEZ_E(1) AS INTEGER
LOAD BITMAP "1A.BMP",1 : SET CURRENT BITMAP 1 : V_LECTURE1_#=BITMAP WIDTH(1) : V_LECTURE2_#=BITMAP HEIGHT(1)
DIM T_CARTEA_E(V_LECTURE1_#-1,V_LECTURE2_#-1) : T_CARTEZ_E(0) = V_LECTURE1_# : T_CARTEZ_E(1) = V_LECTURE2_#
LOCK PIXELS
FOR V_COL_E=0 TO V_LECTURE1_#-1
FOR V_LIN_E=0 TO V_LECTURE2_#-1
T_CARTEA_E(V_COL_E,V_LIN_E)=RGBR(POINT(V_COL_E,V_LIN_E))
NEXT V_LIN_E
NEXT V_COL_E
SAVE ARRAY "1A",T_CARTEA_E() : SAVE ARRAY "1Z",T_CARTEZ_E()
UNLOCK PIXELS
DELETE BITMAP 1
UNDIM T_CARTEA_E() : DIM T_CARTEA_E(V_LECTURE1_#-1,V_LECTURE2_#-1)
LOAD ARRAY "1A",T_CARTEA_E()
CREATE BITMAP 1,V_LECTURE1_#,V_LECTURE2_# : SET CURRENT BITMAP 1
FOR V_COL_E=0 TO V_LECTURE1_#-1
FOR V_LIN_E=0 TO V_LECTURE2_#-1
rem T_CARTEA_E(V_COL_E,V_LIN_E)=RGBR(POINT(V_COL_E,V_LIN_E))
dot V_COL_E,V_LIN_E,rgb(T_CARTEA_E(V_COL_E,V_LIN_E),0,0)
NEXT V_LIN_E
NEXT V_COL_E
DO
COPY BITMAP 1,0
// SET CURSOR 0,0
// FOR C=0 TO V_LECTURE1_#-15
// PRINT C
// NEXT C
SYNC
LOOP
// LOAD BITMAP "1B.BMP",1 : SET CURRENT BITMAP 1 : V_LECTURE1_#=BITMAP WIDTH(1) : V_LECTURE2_#=BITMAP HEIGHT(1)
// GLOBAL DIM T_CARTEB_E(V_LECTURE1_#,V_LECTURE2_#)
// LOCK PIXELS
// FOR V_COL_E=0 TO V_LECTURE1_#
// FOR V_LIN_E=0 TO V_LECTURE2_#
// T_CARTEB_E(V_COL_E,V_LIN_E)=RGBR(POINT(V_COL_E,V_LIN_E))
// NEXT V_LIN_E
// NEXT V_COL_E
// SAVE ARRAY "CB",T_CARTEB_E(0)
// DIM T_lecture_E(1) : T_lecture_E(0)=V_LECTURE1_# : T_lecture_E(1)=V_LECTURE2_# : SAVE ARRAY "CD",T_lecture_E(0)
// UNLOCK PIXELS : DELETE BITMAP 1
END
ENDFUNCTION
REM
`#######################################################
`|"F_Deroulement.dba" |///////////////////////////////////|
`# (c) prog' ########################################### #############################
FUNCTION F_DEROULEMENT1()
f_INTRO()
f_MENU()
REM CLEARMENU()
Jouer_zGot:
f_PREPARE_SCENE()
REM f_NETTOYER()
REM f_QUITTER()
JOUER_LA_SCENE_Zgot:
REM BOUCLE DE JEU ////////////////////////
DO
SET CURSOR 0,0 : PRINT "ENNEMIS RESTANTS / ENEMIES LEFT : ";V_NbreEnnemis_E;" - VIES / LIFES : ";V_VIES_JOUEUR_#
SET CURSOR 0,20
REM PRINT AI Get Entity Is Moving (V_ENNEMISZ_E-3)
REM PRINT AI Get Entity Is Moving (2000)
PRINT V_TIR_X_EE
PRINT V_TIR_ENNEMISZ_E
PRINT V_FX_ENNEMISZ_E
print V_NbreEnnemis_E
// PRINT V_niveauz_E
// FOR Z=2 TO CHECKLIST QUANTITY()-1
//
// PRINT LIMB NAME$(V_Niveau_E+4,Z)
// IF LIMB NAME$(V_Niveau_E+4,Z)="ennemiesa"
//
// ENDIF
//
// NEXT Z
// CONTROL CAMERA USING ARROWKEYS 0,0.1,1
f_TIRER_JOUEUR()
f_CONTROLES()
f_POSITIONNER_ENNEMIS()
f_POSITIONNER_JOUEUR()
f_TIRER_ENNEMIS()
f_SCORE()
POSITION OBJECT V_ARME_JOUEUR_E,CAMERA POSITION X(),CAMERA POSITION Y(),CAMERA POSITION Z() : YROTATE OBJECT V_ARME_JOUEUR_E, CAMERA ANGLE Y() : XROTATE OBJECT V_ARME_JOUEUR_E,CAMERA ANGLE X()
// IF Sync_TEMPS1(1) = 1 THEN f_CONTROLES()
// IF f_Sync_TEMPS1(1000) = 1 THEN TURN OBJECT RIGHT 200,6
// POSITION MOUSE SCREEN WIDTH()/2,SCREEN HEIGHT()/2
// SC_setupObject V_ENNEMISA_E+7, 1, 0
// SC_setupObject V_ENNEMISA_E+1, 1, 0
// SC_setupObject V_ENNEMISA_E+4, 1, 0
FOR Z = V_ENNEMISA_E TO V_ENNEMISZ_E-2 STEP 3
IF OBJECT POSITION Y(Z+1) >-10
SC_setupObject Z+1, 1, 0
ENDIF
NEXT Z
update_explosions()
AI UPDATE
SYNC
LOOP
ENDFUNCTION
`EXPLOSION DEMO CODE, TGC NEWSLETTER NOVEMBER 2006.
//
//
// `prepare the display and camera for use
// SET DISPLAY MODE 1024,768,32,1
// HIDE MOUSE
// BACKDROP ON
// COLOR BACKDROP RGB(0,0,0)
// AUTOCAM OFF
// POSITION CAMERA 0.0,0.0,-639.0
// POINT CAMERA 0.0,0.0,0.0
// SYNC ON
// SYNC RATE 60
//
// `load and set up a skybox
// LOAD OBJECT "media\skybox\skybox01.x",50
// SET OBJECT TEXTURE 50,2,1
// SCALE OBJECT 50,200000,200000,200000
// SET OBJECT CULL 50,0
// SET OBJECT LIGHT 50,0
//
//
//
//
// `first we need to call the explosion variable setup, this is a subroutine
// GOSUB init_explosion_variables
//
// `then we need to prepare the explosions with this function
// prepare_explosions()
// `the explosions are now ready for use in the demo.
//
//
//
//
// `an input delay counter to stop explosions spawning too fast when holding down a key
// in_delay = 0
//
//
//
// `MAIN LOOP, the explosion system should be updated in a loop with sync
// REPEAT
// `this part of the code spawns explosion effects depending on the key being pressed
// IF in_delay > 0 : in_delay = in_delay - 1 : ENDIF
// IF in_delay = 0
// IF KEYSTATE(2) = 1 : spawn_explosion(RND(1024.0)-512.0,RND(768.0)-384.0,0.0,1,RND(128.0)+128.0) : in_delay = 10 : ENDIF
// IF KEYSTATE(3) = 1 : spawn_explosion(RND(1024.0)-512.0,RND(768.0)-384.0,0.0,2,RND(128.0)+128.0) : in_delay = 10 :ENDIF
// IF KEYSTATE(4) = 1 : spawn_explosion(RND(1024.0)-512.0,RND(768.0)-384.0,0.0,3,RND(128.0)+128.0) : in_delay = 10 :ENDIF
// IF KEYSTATE(5) = 1 : spawn_explosion(RND(1024.0)-512.0,RND(768.0)-384.0,0.0,4,RND(128.0)+128.0) : in_delay = 10 :ENDIF
// IF KEYSTATE(6) = 1 : spawn_explosion(RND(1024.0)-512.0,RND(768.0)-384.0,0.0,5,RND(128.0)+128.0) : in_delay = 10 :ENDIF
// IF KEYSTATE(7) = 1 : spawn_explosion(RND(1024.0)-512.0,RND(768.0)-384.0,0.0,6,RND(128.0)+128.0) : in_delay = 10 :ENDIF
// IF KEYSTATE(8) = 1 : spawn_explosion(RND(1024.0)-512.0,RND(768.0)-384.0,0.0,7,RND(128.0)+128.0) : in_delay = 10 :ENDIF
// IF KEYSTATE(9) = 1 : spawn_explosion(RND(1024.0)-512.0,RND(768.0)-384.0,0.0,8,RND(128.0)+128.0) : in_delay = 10 :ENDIF
// IF KEYSTATE(10) = 1 : spawn_explosion(RND(1024.0)-512.0,RND(768.0)-384.0,0.0,9,RND(128.0)+128.0) : in_delay = 10 :ENDIF
// IF KEYSTATE(11) = 1 : spawn_explosion(RND(1024.0)-512.0,RND(768.0)-384.0,0.0,10,RND(128.0)+128.0) : in_delay = 10 :ENDIF
//
// IF KEYSTATE(16) = 1 : spawn_explosion(RND(1024.0)-512.0,RND(768.0)-384.0,0.0,11,RND(128.0)+128.0) : in_delay = 10 : ENDIF
// IF KEYSTATE(17) = 1 : spawn_explosion(RND(1024.0)-512.0,RND(768.0)-384.0,0.0,12,RND(128.0)+128.0) : in_delay = 10 :ENDIF
// IF KEYSTATE(18) = 1 : spawn_explosion(RND(1024.0)-512.0,RND(768.0)-384.0,0.0,13,RND(128.0)+128.0) : in_delay = 10 :ENDIF
// IF KEYSTATE(19) = 1 : spawn_explosion(RND(1024.0)-512.0,RND(768.0)-384.0,0.0,14,RND(128.0)+128.0) : in_delay = 10 :ENDIF
// IF KEYSTATE(20) = 1 : spawn_explosion(RND(1024.0)-512.0,RND(768.0)-384.0,0.0,15,RND(128.0)+128.0) : in_delay = 10 :ENDIF
// IF KEYSTATE(21) = 1 : spawn_explosion(RND(1024.0)-512.0,RND(768.0)-384.0,0.0,16,RND(128.0)+128.0) : in_delay = 10 :ENDIF
// IF KEYSTATE(22) = 1 : spawn_explosion(RND(1024.0)-512.0,RND(768.0)-384.0,0.0,17,RND(128.0)+128.0) : in_delay = 10 :ENDIF
// IF KEYSTATE(23) = 1 : spawn_explosion(RND(1024.0)-512.0,RND(768.0)-384.0,0.0,18,RND(128.0)+128.0) : in_delay = 10 :ENDIF
// IF KEYSTATE(24) = 1 : spawn_explosion(RND(1024.0)-512.0,RND(768.0)-384.0,0.0,19,RND(128.0)+128.0) : in_delay = 10 :ENDIF
// IF KEYSTATE(25) = 1 : spawn_explosion(RND(1024.0)-512.0,RND(768.0)-384.0,0.0,20,RND(128.0)+128.0) : in_delay = 10 :ENDIF
// ENDIF
//
// `update the explosions in the main update loop
// `============================================
// update_explosions()
// `============================================
//
//
// `screen text / information
// SET CURSOR 10,10 : PRINT "press keys 1-0 and Q-P for different explosions"
// SET CURSOR 10,25 : PRINT "press escape to quit this demo"
// SET CURSOR 10,40 : PRINT "framerate ";SCREEN FPS();" FPS"
// `turn the skybox object
// TURN OBJECT LEFT 50,0.05
// SYNC
// UNTIL ESCAPEKEY() = 1
`###################################################################
`### EVERYTHING BELOW THIS POINT IS PART OF THE EXPLOSION SYSTEM ###
`###################################################################
// `prepare the variables for the explosion system
// init_explosion_variables:
// `set the first object used by the system
// GLOBAL ex_first = 50000
// `set the max number of objects the system can use
// GLOBAL ex_max = 50
// `a counter to incerement throught he objects
// GLOBAL ex_counter = 0
// `an array to determine if the object / explosion is alive
// GLOBAL DIM ex_alive(ex_max)
// `the curent frame of the explosion is held in an array
// GLOBAL DIM ex_frame(ex_max)
// `the first image number of the current explosion effect
// GLOBAL DIM ex_first_image(ex_max)
// `a frame skip delay to slow down the animation
// GLOBAL DIM ex_delay(ex_max)
// RETURN
`preapre the media for the explosions
FUNCTION prepare_explosions()
LOAD IMAGE "media\expl01.png",10,1
split_image(10,6,5,50101)
LOAD IMAGE "media\expl02.png",10,1
split_image(10,6,5,50201)
LOAD IMAGE "media\expl03.png",10,1
split_image(10,6,5,50301)
LOAD IMAGE "media\expl04.png",10,1
split_image(10,6,5,50401)
LOAD IMAGE "media\expl05.png",10,1
split_image(10,6,5,50501)
LOAD IMAGE "media\expl06.png",10,1
split_image(10,6,5,50601)
LOAD IMAGE "media\expl07.png",10,1
split_image(10,6,5,50701)
LOAD IMAGE "media\expl08.png",10,1
split_image(10,6,5,50801)
LOAD IMAGE "media\expl09.png",10,1
split_image(10,6,5,50901)
LOAD IMAGE "media\expl10.png",10,1
split_image(10,6,5,51001)
LOAD IMAGE "media\expl11.png",10,1
split_image(10,6,5,51101)
LOAD IMAGE "media\expl12.png",10,1
split_image(10,6,5,51201)
LOAD IMAGE "media\expl13.png",10,1
split_image(10,6,5,51301)
LOAD IMAGE "media\expl14.png",10,1
split_image(10,6,5,51401)
LOAD IMAGE "media\expl15.png",10,1
split_image(10,6,5,51501)
LOAD IMAGE "media\expl16.png",10,1
split_image(10,6,5,51601)
LOAD IMAGE "media\expl17.png",10,1
split_image(10,6,5,51701)
LOAD IMAGE "media\expl18.png",10,1
split_image(10,6,5,51801)
LOAD IMAGE "media\expl19.png",10,1
split_image(10,6,5,51901)
LOAD IMAGE "media\expl20.png",10,1
split_image(10,6,5,52001)
IF IMAGE EXIST(10) = 1 : DELETE IMAGE 10 : ENDIF
FOR j = 1 TO ex_max
MAKE OBJECT PLAIN ex_first+j,100,100
DISABLE OBJECT ZWRITE ex_first+j
`the following line causes the explosions to be drawn on top of
`all the other stuff in your scene, rem it out if not needed.
DISABLE OBJECT ZDEPTH ex_first+j
GHOST OBJECT ON ex_first+j,3
SET OBJECT LIGHT ex_first+j,0
HIDE OBJECT ex_first+j
NEXT j
ENDFUNCTION
`spawn an explosion
FUNCTION spawn_explosion(x#,y#,z#,explosion_type,size#)
IF ex_counter = ex_max : ex_counter = 0 : ENDIF
ex_counter = ex_counter +1
ex_alive(ex_counter) = 1
ex_frame(ex_counter) = 1
ex_delay(ex_counter) = 2
SELECT explosion_type
CASE 1 : ex_first_image(ex_counter) = 50100 : ENDCASE
CASE 2 : ex_first_image(ex_counter) = 50200 : ENDCASE
CASE 3 : ex_first_image(ex_counter) = 50300 : ENDCASE
CASE 4 : ex_first_image(ex_counter) = 50400 : ENDCASE
CASE 5 : ex_first_image(ex_counter) = 50500 : ENDCASE
CASE 6 : ex_first_image(ex_counter) = 50600 : ENDCASE
CASE 7 : ex_first_image(ex_counter) = 50700 : ENDCASE
CASE 8 : ex_first_image(ex_counter) = 50800 : ENDCASE
CASE 9 : ex_first_image(ex_counter) = 50900 : ENDCASE
CASE 10 : ex_first_image(ex_counter) = 51000 : ENDCASE
CASE 11 : ex_first_image(ex_counter) = 51100 : ENDCASE
CASE 12 : ex_first_image(ex_counter) = 51200 : ENDCASE
CASE 13 : ex_first_image(ex_counter) = 51300 : ENDCASE
CASE 14 : ex_first_image(ex_counter) = 51400 : ENDCASE
CASE 15 : ex_first_image(ex_counter) = 51500 : ENDCASE
CASE 16 : ex_first_image(ex_counter) = 51600 : ENDCASE
CASE 17 : ex_first_image(ex_counter) = 51700 : ENDCASE
CASE 18 : ex_first_image(ex_counter) = 51800 : ENDCASE
CASE 19 : ex_first_image(ex_counter) = 51900 : ENDCASE
CASE 20 : ex_first_image(ex_counter) = 52000 : ENDCASE
ENDSELECT
POSITION OBJECT ex_first+ex_counter,x#,y#,z#
SET OBJECT TO CAMERA ORIENTATION ex_first+ex_counter
ZROTATE OBJECT ex_first+ex_counter,RND(359)
TEXTURE OBJECT ex_first+ex_counter,ex_first_image(ex_counter)+ex_frame(ex_counter)
SCALE OBJECT ex_first+ex_counter,size#,size#,size#
SHOW OBJECT ex_first+ex_counter
ENDFUNCTION
`update the explosions
FUNCTION update_explosions()
FOR j = 1 TO ex_max
IF ex_alive(j) = 1
IF ex_delay(j) > 0 : ex_delay(j) = ex_delay(j) - 1 : ENDIF
IF ex_delay(j) = 0
ex_frame(j) = ex_frame(j) + 1
TEXTURE OBJECT ex_first+j,ex_first_image(j)+ex_frame(j)
SET OBJECT TO CAMERA ORIENTATION ex_first+j
ex_delay(j) = 2
ENDIF
IF ex_frame(j) = 30
ex_alive(j) = 0
HIDE OBJECT ex_first+j
ENDIF
ENDIF
NEXT j
ENDFUNCTION
`kill off all the active explosions
FUNCTION engine_kill_all_explosions()
FOR j = 1 TO ex_max
ex_alive(j) = 0
ex_frame(j) = 0
HIDE OBJECT ex_first+j
NEXT j
ENDFUNCTION
`Steve's Famous image splitter function to chop the images up
FUNCTION split_image(baseImage,imgX,imgY,firstImg)
baseSprite = 1
WHILE SPRITE EXIST(baseSprite) = 1
INC baseSprite
ENDWHILE
SPRITE baseSprite,0,0,baseImage
memNo = 1
WHILE MEMBLOCK EXIST(memNo) = 1
INC memNo
ENDWHILE
MAKE MEMBLOCK FROM IMAGE memNo,baseImage
iW = (MEMBLOCK DWORD(memNo,0))
iH = (MEMBLOCK DWORD(memNo,4))
iD = (MEMBLOCK DWORD(memNo,8))
imgWidth = iW / imgX
imgHeight = iH / imgY
mbSize = ((imgWidth * imgHeight) + 3) * 4
memNo2 = memNo + 1
WHILE MEMBLOCK EXIST(memNo2) = 1
INC memNo2
ENDWHILE
MAKE MEMBLOCK memNo2, mbSize
WRITE MEMBLOCK DWORD memNo2,0,imgWidth
WRITE MEMBLOCK DWORD memNo2,4,imgHeight
WRITE MEMBLOCK DWORD memNo2,8,iD
FOR imagesY = 1 TO imgY
FOR imagesX = 1 TO imgX
img = ((imagesY -1) * imgX) + imagesX
NewByte = 12
FOR rows = 1 TO imgHeight
FOR cols = 1 TO imgWidth
offSet1 = (imagesY - 1) * imgWidth * imgHeight * imgX
offset2 = (iW * (rows - 1))
offset3 = imgWidth * (imagesX - 1)
offset4 = cols - 1
imgDword = (offset1 + offset2 + offset3 + offset4 + 3) * 4
WRITE MEMBLOCK DWORD memNo2,NewByte, MEMBLOCK DWORD(memNo,imgDWord)
INC NewByte,4
NEXT cols
NEXT rows
NewByte = 12
MAKE IMAGE FROM MEMBLOCK (img + firstImg - 1),memNo2
NEXT imagesX
NEXT imagesY
DELETE MEMBLOCK memNo
DELETE MEMBLOCK memNo2
DELETE SPRITE BaseSprite
DELETE IMAGE baseImage
ENDFUNCTION 0
Rem ***** Included Source File *****
FUNCTION f_MENU()
cls 0
SHOW MOUSE
InitMenu()
REM MENU PRINCIPAL 1 :
V_Menu_PRINCIPAL_1_E = MakeMenu("TIREUR D'ELITE : MENU PRINCIPAL / MAIN MENU",1,V_Premier_spriteE)
` Add some options, using the function provided.
makeoption("JOUER / PLAY GAME!", cMENU1OPT1)
makeoption("OPTIONS", cMENU1OPT2)
makeoption("QUITTER / EXIT", cMENU1OPT3)
REM MENU OPTIONS 1 :
V_Menu_OPTIONS_1_E = MakeMenu("TIREUR D'ELITE : MENU OPTIONS / OPTIONS MENU",1,V_Premier_spriteE)
` Add some options, using the function provided.
makeoption("DEFINITION DE L'IMAGE / SCREEN RESOLUTION", cMENU_OPTIONS_1_OPT1)
makeoption("RETOUR / BACK", cMENU_OPTIONS_1_OPT2)
REM FAIT DU MENU PRINCIPAL LE MENU EN COURS :
setMenu(V_Menu_PRINCIPAL_1_E)
do
opt = showMenu()
` Delete the last menu after returning...
clearMenu()
IF V_FIN_MENU_PRINCIPAL_E = 1 THEN EXIT
` process my options. Check the value returned,
` and take the appropriate action.
f_ProcessMyOptions(opt)
loop
ENDFUNCTION
function f_processMyOptions(opt)
` **********************************************************
` This function simply looks at the option selected by the user
` and carries out the request.
` **********************************************************
select opt
` ********** Menu 1...
case cMENU1OPT1
cls
REM clearMenu()
V_FIN_MENU_PRINCIPAL_E = 1
endcase
case cMENU1OPT2
cls
setMenu(V_Menu_OPTIONS_1_E)
// center text screen width() / 2, screen height() / 2, "OPTIONS"
// sync
// wait 3000
REM setMenu(Menu2)
endcase
case cMENU1OPT3
end
endcase
case cMENU_OPTIONS_1_OPT1
endcase
case cMENU_OPTIONS_1_OPT2
setMenu(V_Menu_PRINCIPAL_1_E)
endcase
endselect
endfunction
remstart
TODO: 1;REMPLACER FLECHE/CURSEUR PAR UN SPRITE 2;FIXER LA TAILLE DU TEXTE PUIS ADAPTER LA TAILLE DES SPRITES SELON LA RESOLUTION ECRAN 3;AJOUTER SONS, SABLIER,ANIMATIONS ARRIERE-PLAN
TODO : global V_Premier_spriteE : V_Premier_spriteE=500 ; déclarer cette variable et l'utiliser dans MakeMenu("My example Menu",1,V_Premier_spriteE)
todo: adjust size of text with screen resolution while avoiding too big sprites (to limit the memory used by sprites): sprites height should be 8, 16, 32, 64 or 128 pixels in size and then stretched according to screen resolution
-to replace the cursor with a custom one, should be a sprite pasted at mouse x,y screen coordinates (I think about cross hairs, for an FPS)
-to add some nice sounds effects
Self-Contained Code
by Steve Vink
This example illustrates how to make self-contained, reusable code.
It utilises Functions, Types, and Arrays.
remend
`*******************************************************
` Supporting Data structures
` Our menu system requires various components to "live"
`*******************************************************
`*******************************************************
` Function: InitMenu()
` This function initialises all of the required data,
` and brings our self-contained menu system to life
`*******************************************************
function InitMenu()
` We will make life easier for the programmer implementing our menu system.
` If this function is not called, the code will fail.
` More often than not, no error will be generated.
` So every Make... function will call this one.
` If we have already initialised, we will quickly skip over this code.
If gMenuVar.Initialised <> 1
` Make the Menu and Option arrays
` Because I use 0 as a special value in my programs, I add an empty element
` after creation. It also makes it easier to count!
dim gMenu() as tMenu
add to queue gMenu()
dim gOption() as tOption
add to queue gOption()
gMenuVar.curMenu = 0
gMenuVar.Initialised = 1
gMenuVar.Font$ = "Arial"
gMenuVar.FontSize = 24
gMenuVar.FontSize = SCREEN WIDTH()/33
gMenuVar.FontSize = SCREEN WIDTH()/48
REM SET TEXT TO BOLD
SET TEXT TO BOLDITALIC
gMenuVar.mouse = 999
gMenuVar.mouseDown = 0
endif
endfunction
`*******************************************************
` Function: MakeMenu()
` This function creates one menu
` We will return the menu number to the user for future reference.
` We will also assist the programmer by making this new menu
` the current menu
`*******************************************************
function MakeMenu(title$, columns, firstSprite)
` Make sure the menu system has been initialised.
` As this is reusable code, it's essential to make it
` as robust as possible.
InitMenu()
` Add a new menu to our array
add to queue gMenu()
gMenu().title$ = title$
gMenu().columns = columns
gMenu().firstSprite = firstSprite
` Set the current menu
curMenu = array count(gMenu())
SetMenu(curMenu)
` Return the new menu ID!
endfunction curMenu
`*******************************************************
` Function: MakeOption()
` This function creates one option
` We will return the option id to the user for future reference.
` We will add the option to the current menu
`*******************************************************
function MakeOption(title$, value)
` If the current menu is 0, we haven't actually made one yet!
` To make our code robust, and help the programmer,
` we will check this and make a menu if necessary
` Because MakeMenu() will ensure the system is initialised
` we won't be duplicating the effort here.
if gMenuVar.curMenu = 0
mnu = MakeMenu("Menu 1", 1, 100)
endif
` Add a new option to our array
add to queue gOption()
gOption().menuId = gMenuVar.curMenu
gOption().title$ = title$
gOption().value = value
` Update the menu option count...
inc gMenu(gMenuVar.curMenu).options, 1
` Set the current option
curOption = array count(gOption())
SetOption(curOption)
` Return the new option ID!
endfunction curOption
`*******************************************************
` Function: SetMenu()
` This function sets the id of the current menu
` At a glance, it does very little. But it's still important
` to write this code as a function
` 1. It is called from several places, including our own menu code
` 2. We need to hide the data from the programmer.
` 3. In the future this may become a more complex procedure
`
` The function returns the menu id. The user can interrogate this
` to ensure the request was successful.
` If an invalid menu reference is passed, the return value will differ.
`*******************************************************
function setMenu(menu)
if menu <= array count(gMenu())
gMenuVar.curMenu = menu
endif
endfunction gMenuVar.curMenu
`*******************************************************
` Function: SetOption()
` This function sets the id of the current option
` At a glance, it does very little. But it's still important
` to write this code as a function
` 1. It is called from several places, including our own menu code
` 2. We need to hide the data from the programmer.
` 3. In the future this may become a more complex procedure
`
` The function returns the option id. The user can interrogate this
` to ensure the request was successful.
` If an invalid option reference is passed, the return value will differ.
`*******************************************************
function setOption(option)
if option <= array count(gOption())
gMenuVar.curOption = option
endif
endfunction gMenuVar.curOption
`*******************************************************
` Function: showMenu()
` This function is the main driver of our self-contained code
` It will construct the menu, display it and receive the feedback
`*******************************************************
function showMenu()
` Work out how we need to format the menu
` Based on number of options and number of columns
` We will do this every time, because it's possible
` that the menu layout has changed
cls rgb(0,0,0)
` Set the font for the menu. Font is a System-wide parameter
set text size gMenuVar.FontSize
set text font gMenuVar.Font$
`Create the Menu Title Image
makeTextImage(gMenu(gMenuVar.curMenu).title$, gMenu(gMenuVar.curMenu).firstSprite,0)
width = text width(gMenu(gMenuVar.curMenu).title$) : height = text height(gMenu(gMenuVar.curMenu).title$)
sprite gMenu(gMenuVar.curMenu).firstSprite, (screen width() / 2) - (width / 2), (gMenuVar.fontsize / 2),gMenu(gMenuVar.curMenu).firstSprite
rows# = (gMenu(gMenuVar.curMenu).options) / ((gMenu(gMenuVar.curMenu).columns) * 1.0)
Numrows = int(rows#)
if NumRows < rows# then inc NumRows
` Work out the centre position of each menu option...
OptionPosition = 0 : ` Use this to track our position in our options array
for n = 1 to NumRows
y = (gMenuVar.fontsize * 2) + ((screen height() / (NumRows + 1)) * n)
for m = 1 to gMenu(gMenuVar.curMenu).columns
x = screen width() / (gMenu(gMenuVar.curMenu).columns + 1) * m
option = ((n-1) * (gMenu(gMenuVar.curMenu).columns)) + m
if option <= gMenu(gMenuVar.curMenu).options
` Find next option for this menu...
while gOption(OptionPosition).menuId <> gMenuVar.curMenu
inc OptionPosition, 1
endwhile
` Now we have the next option, update x and y
gOption(OptionPosition).x = x
gOption(OptionPosition).y = y
` Now we need to make the text image...
MakeTextImage(gOption(OptionPosition).title$, gMenu(gMenuVar.curMenu).firstSprite + option,1)
` Make and position the sprite...
width = text width(gOption(OptionPosition).title$) + 8 : height = text height(gOption(OptionPosition).title$) + 8
sprite gMenu(gMenuVar.curMenu).firstSprite + option, gOption(OptionPosition).x - (width / 2), gOption(OptionPosition).y - (height / 2),gMenu(gMenuVar.curMenu).firstSprite + option
endif
inc OptionPosition, 1
next m
next n
makeBackground()
` Process the menu. Once we return from here, we simply need to pass the selected option back
` to the main program for the developer to react to.
value = processMenu()
endfunction value
`*******************************************************
` Function: processMenu()
` Once the menu is on-screen, we have to respond to the feedback
` That all happens here...
`*******************************************************
function processMenu()
` Firstly, make a hidden sprite. We use this to work out if our mouse is over an option...
mouse = gMenu(gMenuVar.curMenu).firstSprite
while image exist(mouse) = 1
inc mouse
endwhile
get image gMenuVar.mouse,1,1,2,2
SET SPRITE gMenuVar.mouse,1,0
REM sprite gMenuVar.mouse, mousex(), mousey(), gMenuVar.mouse
V_Animer_Sprite_OldE = 0
V_Animer_SpriteE = 0
value = 0
SPRITE gMenuVar.mouse, mousex(), mousey(), gMenuVar.mouse
HIDE sprite gMenuVar.mouse
while value = 0
paste image 1000,1,1
sprite gMenuVar.mouse, mousex(), mousey(), gMenuVar.mouse
` The following code is a safety check
` The user must release the mouse and press again
` between options
` Otherwise, you may process multiple requests.
if mouseclick() = 0 and gMenuVar.mousedown = 1
gMenuVar.mousedown = 0
endif
` If mouse clicked, check which option...
if mouseclick() = 1 and gMenuVar.mousedown = 0
gMenuVar.mousedown = 1
hit = sprite COLLISION(gMenuVar.mouse, 0)
` If hit is greater than 0, we were over a sprite when we clicked...
if hit > 0 AND hit <> V_Premier_spriteE
option = hit - gMenu(gMenuVar.curMenu).firstsprite
` Animer_le_sprite cliqué; JOUER UN SON.... >>>>
` STRETCH SPRITE Hit,100,125
SET SPRITE DIFFUSE V_Animer_SpriteE, 255, 255, 255
` PASTE SPRITE Hit, SPRITE X(Hit), SPRITE Y(Hit)
` SYNC : WAIT 10 : SYNC : WAIT 10 : SYNC
` find the corresponding array element for this option...
checked = 0
for n = 1 to array count(gOption())
if gOption(n).MenuId = gMenuVar.curMenu then inc checked, 1
if checked = option
value = gOption(n).value
exit
endif
next n
endif : ` end checking which option clicked.
endif : ` End processing collision occurred
` toucher Sprites avec souris;
V_Animer_SpriteE = SPRITE COLLISION(gMenuVar.mouse, 0)
` Animer sprite;
IF V_Animer_SpriteE > 0 AND V_Animer_SpriteE <> V_Premier_spriteE
` Animer_le_sprite touché; JOUER UN SON.... >>>>
IF V_Animer_SpriteE <> V_Animer_Sprite_OldE
` STRETCH SPRITE V_Animer_SpriteE,125,105
SET SPRITE DIFFUSE V_Animer_SpriteE, 255, 255, 0
V_Animer_Sprite_OldE = V_Animer_SpriteE
ENDIF
ENDIF
` Redimensionner Sprite précédemment touché mais qui ne l'est plus.
IF V_Animer_Sprite_OldE > 0 AND V_Animer_SpriteE <> V_Premier_spriteE
IF V_Animer_SpriteE <> V_Animer_Sprite_OldE
` STRETCH SPRITE V_Animer_Sprite_OldE,100,100
SET SPRITE DIFFUSE V_Animer_Sprite_OldE, 255, 255, 255
V_Animer_Sprite_OldE = 0
ENDIF
ENDIF
REM set cursor 0,0
REM print V_Animer_SpriteE
SYNC
ENDWHILE
delete sprite gMenuVar.mouse
delete image gMenuVar.mouse
endfunction value
`*******************************************************
` Function: clearMenu()
` This function clears the current menu
` It will delete sprites and images, but
` leave the data in the arrays intact, for the next use.
`*******************************************************
function clearMenu()
` Delete Menu Header...
delete sprite gMenu(gMenuVar.curMenu).firstSprite
delete image gMenu(gMenuVar.curMenu).firstSprite
for n = 1 to gMenu(gMenuVar.curMenu).options
delete sprite gMenu(gMenuVar.curMenu).firstSprite + n
delete image gMenu(gMenuVar.curMenu).firstSprite + n
next n
endfunction
`*******************************************************
` Function: MakeTextImage()
` This function creates an image from a text string
` We will use it for our buttons and menu titles
`*******************************************************
function MakeTextImage(txt$, img, border)
if txt$ = "" then txt$ = "Error!"
width = text width(txt$) + 8 : height = text height(txt$) + 8
` Get a free bitmap to make our image...
break
bitmap = 1
while bitmap exist(bitmap) = 1
inc bitmap,1
endwhile
create bitmap bitmap, width, height
if border = 1
line 1,1,width,1
line 1,1,1,height
line width-1,height-1,width-1,1
line width-1,height-1,1,height-1
endif
center text width / 2,4,txt$
get image img,1,1, width, height,1
delete bitmap bitmap
endfunction
`*******************************************************
` Function: MakeBackground()
` This function creates a background image using memblock trickery
` As nice as it would be to cover the detail of this,
` we'll leave it for another day!
`*******************************************************
function makeBackground()
if image exist(1000) = 0
sw = screen width()
sh = screen height()
` Make a memblock...
make memblock from bitmap 1, 0
for n = 1 to sh
hOffset = 12 + ((n-1) * 4 * sw)
for m = 1 to sw
if (n < 5 or n > (sh - 5)) or (m < 5 or m > (sw - 5))
red = 0 : green = 255 : blue = 0
else
red = 255 * n/(sh * 1.0) : green = 0: blue = 255 - (255 * n/(sh * 1.0))
endif
write memblock byte 1, hOffset + (4 * (m-1)), blue
write memblock byte 1, hOffset + (4 * (m-1)) + 1, green
write memblock byte 1, hOffset + (4 * (m-1)) + 2, red
write memblock byte 1, hOffset + (4 * (m-1)) + 3, 255
next m
next n
make image from memblock 1000, 1
endif
endfunction
I think that
FOR NEXT don't work properly, what do you think ? can you help me please ?