Page 1 of 1

How to set text color in text mode?

Posted: Wed Jan 10, 2024 6:28 pm
by KaiLikesToCode
My code sets to color to render the player as a text character and the enemy.

Code: Select all

SETUP:
	COLOR 1,0
    X = 5
    Y = 5
	EX = 14
	EY = 14
	MS = 1
    CLS
    SCREEN 3
	GOTO GAME
GAME:
	IF INT(EX) = INT(X) AND INT(EY) = INT(Y) THEN GOTO GAMEOVER

	TILE X,Y,96
	
    V=JOY(0)
	IF V AND 8 THEN Y = Y - MS
	IF V AND 4 THEN Y = Y + MS
	IF V AND 2 THEN X = X - MS
	IF V AND 1 THEN X = X + MS
	IF Y>38 THEN Y = Y + MS
	IF Y<2 THEN Y = Y - MS
	IF X<2 THEN Y = Y + MS
	IF X>38 THEN Y = Y - MS
	COLOR 5
    TILE X,Y,16
	COLOR 1
	TILE EX, EY, 96
	
	GOSUB ENEMYMOVE
	COLOR 2
	TILE EX, EY, 5
	COLOR 1

	SLEEP 7
    GOTO GAME
ENEMYMOVE:
	IF X<EX THEN EX = EX - 0.3
	IF Y<EY THEN EY = EY - 0.3
	IF X>EX THEN EX = EX + 0.3
	IF Y>EY THEN EY = EY + 0.3

	RETURN
GAMEOVER:
	CLS
	PRINT "YOU LOSE!"
	SLEEP 100
	SCREEN 0
	COLOR 1,6
	CLS
Still, the player is not a different color (neither is the enemy)

Re: How to set text color in text mode?

Posted: Wed Jan 10, 2024 9:24 pm
by TomXP411
That will make the text white on black.

if you want the player and opponent to be different colors, you'll need a different COLOR command before printing each character

10 COLOR 3,0
20 LOCATE 5,5
30 PRINT "\XD1"
40 COLOR 7,0
50 LOCATE 5,10
60 PRINT "\XD7"

Re: How to set text color in text mode?

Posted: Wed Jan 10, 2024 9:33 pm
by DragWx
COLOR is for PRINT.

For TILE, you need to add one more parameter after the tile number: the "attribute" value, which will determine the color of the tile.

In text mode, the "attribute" byte works like this: the high 4 bits are the background color, and the low 4 bits are the foreground color for that tile. For example, the hexadecimal value $37 is equivalent to COLOR 7, 3, and the value $AF is equivalent to COLOR 15, 10.