Basic course for newbies

Página 2/11
1 | | 3 | 4 | 5 | 6 | 7

Por NYYRIKKI

Enlighted (5918)

imagem de NYYRIKKI

20-12-2013, 21:55

edoz wrote:

Cool Topic. I will follow it ! So far everything is clear to me Smile .. I hope to learn more about the poke and peek also. And maybe some assembly ?

But this part is a bit complex Wink Please explain Big smile

Sure...

FORI=2TO8                     'What i understand.. count from 2 till 8 in I
     XD(I)=SGN(5-I)           'Then set a array in XD with SGN ? What is SGN

SGN()-function returns the SIGN of a number... So 0 will return 0, positive number will return +1 and negative number will return -1

     YD(8-I)=XD(I)             ' No idea .. but set YD(8-I) the value of XD(I)
NEXT
SWAP YD(0),YD(8)          'Then SWAP something ?

Yes, this may be a bit hard to understand, but it is just simple math... The idea of all until this point is to fill XD & YD tables with X & Y offset values related to the weird kind of number returned by STICK()-function. In the end the table will look like this:

STICK() XD	YD
0	 0	 0	Don't move
1	 0	-1	Up
2	+1	-1	Up, Right
3	+1	 0	Right
4	+1	+1	Down, Right
5	 0	+1	Down
6	-1	+1	Down, Left
7	-1	 0	Left
8	-1	-1	Up, Left

SPRITE$(0)="0HH0"        'SomeHex value used for the sprite ?

Actually it is ASCII string. (See the $-sign) When you convert the ASCII to binary, it looks like this:

00110000
01001000
01001000
00110000

-> It is representing a simple ball.

FORI=0TO1                   'Loop something 1 time ?
     S=STICK(J)
     I=-STRIG(J)             'What is strig ?

No, we actually loop until variable "I" gets value "1". The STRIG()-funtion return joystick button / SPACE-key status. If button is pressed it will return "-1" otherways it will return "0". We take this number, change the sign and put it to "I" This means that we loop until button is pressed.

Por NYYRIKKI

Enlighted (5918)

imagem de NYYRIKKI

21-12-2013, 00:03

I try to be a bit more beginner friendly although the comments are still missing...

I now decoded this:

10 FORI=2TO8:XD(I)=SGN(5-I):YD(8-I)=XD(I):NEXT:SWAPYD(0),YD(8): SCREEN2,1:SPRITE$(0)="0HH0":FORI=0TO1:S=STICK(J):I=-STRIG(J): X=X+XD(S):Y=Y+YD(S): PUTSPRITE0,(X,Y),8:NEXT

...to very traditional text book version:

10 SCREEN 2,1
20 FOR I=0 TO 7
30 READ D$
40 S$=S$+CHR$(VAL("&B"+D$))
50 NEXT I
60 SPRITE$(0)=S$
70 S=STICK(J)
80 IF S=1 THEN Y=Y-1
90 IF S=2 THEN Y=Y-1:X=X+1
100 IF S=3 THEN X=X+1
110 IF S=4 THEN Y=Y+1:X=X+1
120 IF S=5 THEN Y=Y+1
130 IF S=6 THEN Y=Y+1:X=X-1
140 IF S=7 THEN X=X-1
150 IF S=8 THEN Y=Y-1:X=X-1
160 PUT SPRITE 0,(X,Y),8
170 IF STRIG(J)=0 THEN GOTO 70
180 END
190 DATA 00110000
200 DATA 01001000
210 DATA 01001000
220 DATA 00110000
230 DATA 00000000
240 DATA 00000000
250 DATA 00000000
260 DATA 00000000

... at least when I was child the examples were like this. Smile

Por Vampier

Prophet (2397)

imagem de Vampier

21-12-2013, 06:35

hi Jack!

Por Manuel

Ascended (18788)

imagem de Manuel

21-12-2013, 07:39

Vampier - you don't like more people joining in?

Por ericb59

Paragon (1071)

imagem de ericb59

21-12-2013, 09:04

@ NYYRIKKI : I love this Code ! If you would make a topic to share BASIC TRICK and TIPS like that I would be fan !

Por edoz

Prophet (2441)

imagem de edoz

21-12-2013, 10:16

FORI=0TO1:S=STICK(J):I=-STRIG(J): X=X+XD(S):Y=Y+YD(S): PUTSPRITE0,(X,Y),8:NEXT

So this part is more or less like a Do Until/Loop


Do Until I=1

     S=STICK(J)
     X=X+XD(S)
     Y=Y+YD(S)

     PUTSPRITE0,(X,Y),8

     I=-STRIG(J)    'IF I=1 EXIT LOOP
Loop

Por edoz

Prophet (2441)

imagem de edoz

21-12-2013, 10:22

About the old school code:

I think I understand it, but what about this part ?

20 FOR I=0 TO 7
30 READ D$
40 S$=S$+CHR$(VAL("&B"+D$))
50 NEXT I

So you have a loop from 0 to 7, so 8 steps to read all the DATA Items into S$. But before you read in the data into S$ you convert the binary data to a STRING Value ?

190 DATA 00110000
200 DATA 01001000
210 DATA 01001000
220 DATA 00110000
230 DATA 00000000
240 DATA 00000000
250 DATA 00000000
260 DATA 00000000

Por NYYRIKKI

Enlighted (5918)

imagem de NYYRIKKI

21-12-2013, 12:51

@Vampier: Come on... We have the same goal: Let's teach people MSX-BASIC! If you want to make the "Vampiers ultimate guide to coding MSX-BASIC" then I also suggest that you use WIKI or if you want even more control, make a www-page...

edoz wrote:

FORI=0TO1:S=STICK(J):I=-STRIG(J): X=X+XD(S):Y=Y+YD(S): PUTSPRITE0,(X,Y),8:NEXT

So this part is more or less like a Do Until/Loop


Do Until I=1

     S=STICK(J)
     X=X+XD(S)
     Y=Y+YD(S)

     PUTSPRITE0,(X,Y),8

     I=-STRIG(J)    'IF I=1 EXIT LOOP
Loop

Yes, MSX-BASIC just doesn't have DO UNTIL or LOOP-commands... To be more exact this is DO UNTIL I=>1

edoz wrote:

About the old school code:

I think I understand it, but what about this part ?

20 FOR I=0 TO 7
30 READ D$
40 S$=S$+CHR$(VAL("&B"+D$))
50 NEXT I

So you have a loop from 0 to 7, so 8 steps to read all the DATA Items into S$. But before you read in the data into S$ you convert the binary data to a STRING Value ?

Yes. In MSX-BASIC the normal 8x8 sprites are defined with 8-byte long strings. So what happens here is that I read binary string -> convert the binary string to number value -> convert the number to character -> insert the character to S$-string. After the loop I define the sprite outlook with generated S$-string.

In this example in DATA-lines the 0's represent transparent color and 1's represent red color.

Por wolf_

Ambassador_ (9956)

imagem de wolf_

21-12-2013, 14:25

Whoever adds code: let's add it to the Wiki in an organized way. That way things can be found back more easily because it's all categorized. This thread could be used to noodle around though, but without organizing things in an orderly fashion, the thread will sooner or later disappear in thread-history.

Por edoz

Prophet (2441)

imagem de edoz

21-12-2013, 14:53

Ok, Clear! I just looked to an old book and this one is also FUN:

10 COLOR,1,1:SCREEN2:FORF=1TO96STEP.5:Y1=F*SIN(F):X1=F*COS(F):Y2=100-Y1:X2=125-X1:C=RND(1)*13+2:PSET(X1+125,Y1+100),C:PSET(x2,y2),C:NEXTF:GOTO10

Página 2/11
1 | | 3 | 4 | 5 | 6 | 7