Hello everyone, I used to programm in the past in DarkBasic Pro, a few months ago I purchased AppGameKit Basic and i'm getting mad with Text Commands.
I'm trying to do a game (2D) without external files. Only with Sprites created from simple colors and of course: text. My target is to do a Football Simulator (only text). But I have some troubles (text ID are arrays).
I now i'm using bad the command CreateText because it is in a loop. But my question is, it is posible to create text with an unique ID? The programm have a lot of lines but this is an example:
DO
GOSUB DisplayOnce
SYNC()
LOOP
DisplayOnce:
textoeligeonce$="Choose eleven players please:"
eligeonce=CreateText(textoeligeonce$)
SetTextAlignment(EligeOnce,1)
SetTextSize(EligeOnce,20)
SetTextPosition(EligeOnce,20+GetTextTotalWidth(EligeOnce)/2,5+GetTextTotalHeight(EligeOnce)/2)
FOR A=1 to 24
nombrejug$=Nombrejugador[A]
ListadoJugadores[A]=CreateText(nombrejug$)
SetTextAlignment(ListadoJugadores[A],1)
SetTextSize(ListadoJugadores[A],20)
SetTextPosition(ListadoJugadores[A],20+GetTextTotalWidth(EligeOnce)/2,(Margen*A)+GetTextTotalHeight(EligeOnce)/2)
NEXT A
RETURN
With this I can make a list of all the players. But this will create a lot of text. And If I want to delete some of it, it's is impossible. The new text will appear over the other. My first idea was to take out GOSUB DisplayOnce of the loop, but If I do that, I can't refresh it.
I now my Engligh is bad but I hope someone will understand my problem and call help me.
The all code if you want (you can press up, down and enter). As you can see, when you press enter, the new text appear over the oldest one. And it's no posibble to delete it.
// Project: Simulador Futbol
// Created: 2017-03-05
// show all errors
SetErrorMode(2)
// set window properties
SetWindowTitle( "Real Manager" )
SetWindowSize( 1024, 768, 0 )
SetWindowAllowResize( 0 ) // allow the user to resize the window
// set display properties
SetVirtualResolution( 1024, 768 ) // doesn't have to match the window
SetOrientationAllowed( 1, 1, 1, 1 ) // allow both portrait and landscape on mobile devices
SetScissor( 0,0,0,0 ) // use the maximum available screen space, no black borders
UseNewDefaultFonts( 1 ) // since version 2.0.22 we can use nicer default fonts
SetSyncRate( 60, 0 )
GOSUB IniciaVariables:
GOSUB Valoraciones
GOSUB Mapeado
GOSUB Dificultad
FUNCTION HacerBoton(X,Y,X2,Y2,texto$)
RatonX=GetRawMouseX()
RatonY=GetRawMouseY()
IF GetRawMouseLeftState()=1
IF RatonX>X-2 and RatonX<X2+2 and RatonY>Y-2 and RatonY<Y2+2
PulsarBoton(X,Y,X2,Y2,texto$)
ENDIF
ENDIF
Boton2=CreateSprite(0)
SetSpriteSize(Boton2,(X2-X)+4,(Y2-Y)+4)
SetSpritePosition(Boton2,X-2,Y-2)
SetSpriteColor(Boton2,190,190,190,255)
SetSpriteDepth(Boton2,12)
Boton=CreateSprite(0)
SetSpriteSize(Boton,X2-X,Y2-Y)
SetSpritePosition(Boton,X,Y)
SetSpriteColor(Boton,160,160,160,255)
SetSpriteDepth(Boton,11)
NumBoton=CreateText(texto$)
SetTextAlignment(numboton,1)
SetTextDepth(numboton,1)
SetTextColor(numboton,255,255,255,255)
SetTextSize(numboton,40)
SetTextPosition(NumBoton,(X+(X2-X)/2),(Y+(Y2-Y)/2)-GetTextTotalHeight(NumBoton)/2)
sync()
ENDFUNCTION
FUNCTION PulsarBoton(X,Y,X2,Y2,texto$)
BotonPuls=CreateSprite(0)
SetSpriteSize(BotonPuls,X2-X,Y2-Y)
SetSpritePosition(BotonPuls,X,Y)
SetSpriteColor(BotonPuls,100,100,100,255)
SetSpriteDepth(BotonPuls,10)
NumBotonPuls=CreateText(texto$)
SetTextAlignment(NumBotonPuls,1)
SetTextDepth(NumBotonPuls,1)
SetTextColor(NumBotonPuls,205,205,205,255)
SetTextSize(NumBotonPuls,40)
SetTextPosition(NumBotonPuls,(X+(X2-X)/2),(Y+(Y2-Y)/2)-GetTextTotalHeight(NumBotonPuls)/2)
sync()
sleep(400)
DeleteSprite(BotonPuls) : DeleteText(NumBotonPuls)
If Texto$="Fácil" THEN GOSUB DifFacil
If Texto$="Normal" THEN GOSUB DifNormal
If Texto$="Difícil" THEN GOSUB DifDificil
ENDFUNCTION
rem ----------------------------------------------------------------------------------------------------------
rem ----------------------------------------------------------------------------------------------------------
Valoraciones:
dim Nombrejugador[25] as String
Nombrejugador[1]="Keylor Navas"
Nombrejugador[2]="Carvajal"
Nombrejugador[3]="Pepe"
Nombrejugador[4]="Ramos"
Nombrejugador[5]="Varane"
Nombrejugador[6]="Nacho"
Nombrejugador[7]="Cristiano"
Nombrejugador[8]="Kroos"
Nombrejugador[9]="Benzemá"
Nombrejugador[10]="James"
Nombrejugador[11]="Gareth Bale"
Nombrejugador[12]="Marcelo"
Nombrejugador[13]="Kiko Casilla"
Nombrejugador[14]="Casemiro"
Nombrejugador[15]="Coentrão"
Nombrejugador[16]="Kovacic"
Nombrejugador[17]="Lucas Vázquez"
Nombrejugador[18]="Mariano"
Nombrejugador[19]="Modric"
Nombrejugador[20]="Marco Asensio"
Nombrejugador[21]="Álvaro Morata"
Nombrejugador[22]="Isco"
Nombrejugador[23]="Danilo"
Nombrejugador[25]="Rubén Yáñez"
dim Portero[25] as integer
Portero[1]=85
Portero[2]=5
Portero[3]=5
Portero[4]=10
Portero[5]=5
Portero[6]=5
Portero[7]=5
Portero[8]=5
Portero[9]=5
Portero[10]=5
Portero[11]=5
Portero[12]=5
Portero[13]=80
Portero[14]=5
Portero[15]=5
Portero[16]=5
Portero[17]=5
Portero[18]=5
Portero[19]=5
Portero[20]=5
Portero[21]=5
Portero[22]=5
Portero[23]=5
Portero[25]=75
dim Ataque[25] as integer
Ataque[1]=5
Ataque[2]=75
Ataque[3]=70
Ataque[4]=80
Ataque[5]=70
Ataque[6]=65
Ataque[7]=90
Ataque[8]=75
Ataque[9]=85
Ataque[10]=80
Ataque[11]=92
Ataque[12]=82
Ataque[13]=5
Ataque[14]=70
Ataque[15]=60
Ataque[16]=81
Ataque[17]=83
Ataque[18]=83
Ataque[19]=78
Ataque[20]=80
Ataque[21]=86
Ataque[22]=78
Ataque[23]=73
Ataque[25]=5
dim Defensa[25] as integer
Defensa[1]=85
Defensa[2]=5
Defensa[3]=5
Defensa[4]=10
Defensa[5]=5
Defensa[6]=5
Defensa[7]=5
Defensa[8]=5
Defensa[9]=5
Defensa[10]=5
Defensa[11]=5
Defensa[12]=5
Defensa[13]=80
Defensa[14]=5
Defensa[15]=5
Defensa[16]=5
Defensa[17]=5
Defensa[18]=5
Defensa[19]=5
Defensa[20]=5
Defensa[21]=5
Defensa[22]=5
Defensa[23]=5
Defensa[25]=75
dim Pase[25] as integer
Pase[1]=85
Pase[2]=5
Pase[3]=5
Pase[4]=10
Pase[5]=5
Pase[6]=5
Pase[7]=5
Pase[8]=5
Pase[9]=5
Pase[10]=5
Pase[11]=5
Pase[12]=5
Pase[13]=80
Pase[14]=5
Pase[15]=5
Pase[16]=5
Pase[17]=5
Pase[18]=5
Pase[19]=5
Pase[20]=5
Pase[21]=5
Pase[22]=5
Pase[23]=5
Pase[25]=75
dim Disparo[25] as integer
Disparo[1]=85
Disparo[2]=5
Disparo[3]=5
Disparo[4]=10
Disparo[5]=5
Disparo[6]=5
Disparo[7]=5
Disparo[8]=5
Disparo[9]=5
Disparo[10]=5
Disparo[11]=5
Disparo[12]=5
Disparo[13]=80
Disparo[14]=5
Disparo[15]=5
Disparo[16]=5
Disparo[17]=5
Disparo[18]=5
Disparo[19]=5
Disparo[20]=5
Disparo[21]=5
Disparo[22]=5
Disparo[23]=5
Disparo[25]=75
dim Titular[11] as integer
dim ListadoJugadores[24] as integer
dim Tit[11] as integer
RETURN
rem ----------------------------------------------------------------------------------------------------------
rem ----------------------------------------------------------------------------------------------------------
Dificultad:
textoelige$="Elige dificultad por favor:"
textodificultad=CreateText(textoelige$)
do
SetTextAlignment(textodificultad,1)
SetTextPosition(textodificultad,GetDeviceWidth()/2,50)
SetTextSize(textodificultad,30)
HacerBoton(50,120,GetDeviceWidth()-50,280,"Fácil")
HacerBoton(50,320,GetDeviceWidth()-50,480,"Normal")
HacerBoton(50,520,GetDeviceWidth()-50,680,"Difícil")
IF Dif>0 THEN exit
SYNC()
loop
FactorCorreccion=Dif*10
PorteroRival=Random(50+FactorCorreccion,60+FactorCorreccion)
DefensaRival=Random(50+FactorCorreccion,60+FactorCorreccion)
AtaqueRival=Random(50+FactorCorreccion,60+FactorCorreccion)
PaseRival=Random(50+FactorCorreccion,60+FactorCorreccion)
DisparoRival=Random(50+FactorCorreccion,60+FactorCorreccion)
RETURN
rem ----------------------------------------------------------------------------------------------------------
rem ----------------------------------------------------------------------------------------------------------
IniciaVariables:
Dif as integer
Subray as integer : Subray=1
numtitu as integer
RETURN
rem ----------------------------------------------------------------------------------------------------------
rem ----------------------------------------------------------------------------------------------------------
DifFacil:
Dif=1
RETURN
rem ----------------------------------------------------------------------------------------------------------
rem ----------------------------------------------------------------------------------------------------------
DifNormal:
Dif=2
RETURN
rem ----------------------------------------------------------------------------------------------------------
rem ----------------------------------------------------------------------------------------------------------
DifDificil:
Dif=3
RETURN
rem ----------------------------------------------------------------------------------------------------------
rem ----------------------------------------------------------------------------------------------------------
Mapeado:
Margen=30
MargenInf=GetDeviceHeight()-Margen
Interlineado=(MargenInf/24)
DO
GOSUB DisplayOnce
GOSUB DisplayTitulares
GOSUB Teclado
GOSUB BotonesOnce
tecla$=STR(GetRawLastKey())
Keylog=CreateText(tecla$)
SetTextPosition(Keylog,600,500)
SetTextSize(Keylog,100)
SYNC()
LOOP
RETURN
rem ----------------------------------------------------------------------------------------------------------
rem ----------------------------------------------------------------------------------------------------------
Subrayar:
SubIniY=GetTextY(ListadoJugadores[A])
IF GetSpriteExists(Subrayado)=1 THEN DeleteSprite(Subrayado)
Subrayado=CreateSprite(0)
SetSpriteSize(Subrayado,140,22)
SetSpritePosition(Subrayado,20,SubIniY)
SetSpriteColor(Subrayado,20,55,255,255)
RETURN
rem ----------------------------------------------------------------------------------------------------------
rem ----------------------------------------------------------------------------------------------------------
DisplayOnce:
textoeligeonce$="Elige once por favor:"
eligeonce=CreateText(textoeligeonce$)
SetTextAlignment(EligeOnce,1)
SetTextSize(EligeOnce,20)
SetTextPosition(EligeOnce,20+GetTextTotalWidth(EligeOnce)/2,5+GetTextTotalHeight(EligeOnce)/2)
FOR A=1 to 24
IF A=24
nombrejug$=Nombrejugador[25]
else
nombrejug$=Nombrejugador[A]
ENDIF
ListadoJugadores[A]=CreateText(nombrejug$)
SetTextAlignment(ListadoJugadores[A],1)
SetTextSize(ListadoJugadores[A],20)
SetTextPosition(ListadoJugadores[A],20+GetTextTotalWidth(EligeOnce)/2,(Margen*A)+GetTextTotalHeight(EligeOnce)/2)
IF A=Subray THEN GOSUB Subrayar
NEXT A
RETURN
rem ----------------------------------------------------------------------------------------------------------
rem ----------------------------------------------------------------------------------------------------------
DisplayTitulares:
textotitulares$="Formará equipo con el siguiente once:"
titulares=CreateText(textotitulares$)
SetTextAlignment(titulares,1)
SetTextSize(titulares,20)
SetTextPosition(titulares,200+GetTextTotalWidth(titulares)/2,5+GetTextTotalHeight(titulares)/2)
FOR A=1 to 11
B=Titular[A]
nombretit$=STR(A)+" . "+Nombrejugador[B]
Tit[A]=CreateText(nombretit$)
SetTextAlignment(Tit[A],1)
SetTextSize(Tit[A],20)
SetTextPosition(Tit[A],200+GetTextTotalWidth(titulares)/2,(Margen*A*2)+GetTextTotalHeight(EligeOnce)/2)
NEXT A
RETURN
rem ----------------------------------------------------------------------------------------------------------
rem ----------------------------------------------------------------------------------------------------------
Teclado:
IF GetRawKeyPressed(38)=1
dec Subray,1
IF Subray<1 THEN Subray=24
ENDIF
IF GetRawKeyPressed(40)=1
inc Subray,1
IF Subray>24 THEN Subray=1
ENDIF
IF GetRawKeyPressed(13)=1 and numtitu<12
inc numtitu,1
Titular[numtitu]=Subray
ENDIF
IF GetRawLastKey()>0 THEN SLEEP(200)
RETURN
rem ----------------------------------------------------------------------------------------------------------
rem ----------------------------------------------------------------------------------------------------------
BotonesOnce:
RETURN