Welcome, Guest |
You have to register before you can post on our site.
|
Online Users |
There are currently 181 online users. » 0 Member(s) | 178 Guest(s) Applebot, Bing, Google
|
Latest Threads |
.tap file code not execut...
Forum: Help & Support
Last Post: Zoran
04-28-2025, 10:59 AM
» Replies: 4
» Views: 345
|
Exit from more than one l...
Forum: Wishlist
Last Post: Duefectu
04-23-2025, 10:06 PM
» Replies: 3
» Views: 300
|
put small ASM programs li...
Forum: How-To & Tutorials
Last Post: Zoran
04-18-2025, 02:02 PM
» Replies: 6
» Views: 1,607
|
Creating +3 Menus - Loadi...
Forum: Help & Support
Last Post: merlinkv
04-16-2025, 02:08 PM
» Replies: 6
» Views: 557
|
Randomize not very random...
Forum: Help & Support
Last Post: Zoran
04-08-2025, 10:40 AM
» Replies: 4
» Views: 893
|
Scope rules
Forum: Bug Reports
Last Post: Zoran
04-04-2025, 09:46 AM
» Replies: 2
» Views: 339
|
Using constants not allow...
Forum: Bug Reports
Last Post: baltasarq
03-19-2025, 10:00 PM
» Replies: 8
» Views: 1,069
|
404 page not found
Forum: Documentation
Last Post: boriel
03-08-2025, 07:16 PM
» Replies: 5
» Views: 2,888
|
Spectrum keywords codes
Forum: Bug Reports
Last Post: boriel
03-08-2025, 11:00 AM
» Replies: 1
» Views: 421
|
ZXodus][Engine
Forum: ZX Basic Compiler
Last Post: boriel
02-19-2025, 11:43 PM
» Replies: 69
» Views: 213,817
|
|
|
New release 1.2.9-s785 |
Posted by: boriel - 02-21-2012, 06:02 PM - Forum: Bug Reports
- No Replies
|
 |
Okay, a new beta release with *important* fixes :!:
- ! Fixed some array copying operations bugs detected by britlion
- ! Fixed line error reporting, which was wrong under some circunstances.
- ! Fixed $+offset expression in ASM (was not allowed with the newer preprocessor)
You can download (as always) from <!-- m --><a class="postlink" href="http://www.boriel.com/files/zxb">http://www.boriel.com/files/zxb</a><!-- m -->
|
|
|
Re-Dim (*solved*) |
Posted by: britlion - 02-20-2012, 04:42 PM - Forum: Bug Reports
- Replies (9)
|
 |
Boriel, can I use Dim in a SUB to reinitialise a global array?
DIM grid (3,3) as uByte
SUB reinitialiseGrid ()
DIM grid (3,3) as uByte => { {0,1,2,3}, {4,5,6,7}, {8,9,10,11}, {12,13,14,15} }
END SUB
Is that legal, or is it trying to make a local variable?
|
|
|
Fractal |
Posted by: britlion - 02-18-2012, 07:32 PM - Forum: Gallery
- Replies (14)
|
 |
Just for fun.
Incidentally, if I change the float types to fixed, it crashes. Has something gone wrong with fixed type maths?
EDIT: Updated with fixed and exit for, so if people use it here, they get the best version.
Code: #define width 256
#define height 192
DIM x,y as FIXED
DIM xstart,xstep,ystart,ystep as FIXED
DIM xend,yend as FIXED
DIM z,zi,newz,newzi as FIXED
DIM colour as byte
DIM iter as uInteger
DIM col as uInteger
DIM i,k as uByte
DIM j as uInteger
dim inset as uByte
xstart=-1.6
xend=0.65
ystart=-1.15
yend=-ystart
iter=24
xstep=(xend-xstart)/width
ystep=(yend-ystart)/height
'Main loop
x=xstart
y=ystart
border 0
paper 0
ink 7
CLS
for i=0 to ( height -1 )/2 +1
for j=0 to width -1
z=0
zi=0
inset=1
for k=0 to iter
';z^2=(a+bi)*(a+bi) = a^2+2abi-b^2
newz=(z*z)-(zi*zi)+x
newzi=2*z*zi+y
z=newz
zi=newzi
if (z*z)+(zi*zi) > 4 then
inset=0
colour=k
exit for
END IF
next k
if NOT inset then
if colour BAND 1 THEN
plot j,i
plot j,192-i
END IF
end if
x=x+xstep
next j
y=y+ystep
x=xstart
print at 23,0;CAST(uinteger,i)*200/height;"%"
next i
BEEP 1,1
PAUSE 0
(This will take a long time. Even if you push an emulator to top speed)
|
|
|
A new site for ZX Basic? |
Posted by: boriel - 02-18-2012, 11:59 AM - Forum: ZX Basic Compiler
- Replies (8)
|
 |
Well, I've been thinking about it for a Long time, but don't know whether it will be worth the hassle or not...
This site is a mix of many things (ZX BASIC, XSPF Player, Captcha plugin, spam...). The wiki is separated, etc...
I was thinking on moving all ZX Stuff to a different exclusive site (zxbasic.net). This site will continue working, but if the other works, this will eventually be closed as read-only.
|
|
|
Line of sight |
Posted by: slenkar - 02-15-2012, 06:56 PM - Forum: How-To & Tutorials
- Replies (28)
|
 |
To see if 2 game characters can see each other you need 2 functions
distance:
Code: Function distance (x1 as Integer, y1 as Integer, x2 as Integer, y2 as Integer) as Integer
Dim x as Integer
x=ABS(x1-x2)
Dim y as Integer
y=ABS(y1-y2)
Return Sqr((x^2)+(y^2))
End Function
line:
Code: Function line(X1 as Integer,Y1 as Integer,X2 as Integer,Y2 as Integer) as Integer
'creates a line of individual co-ords from X1,Y1 to X2,Y2 at any angle
Dim dist as Integer
dist=distance(X1,Y1,X2,Y2)
dim bresiter as Integer
For bresiter=0 To dist
bresx(bresiter)=0
bresy(bresiter)=0
Next
Dim steep as Integer
if Abs(Y2-Y1) > Abs(X2-X1) then
steep=1
else
steep=0
end if
PRINT AT 1,0 ; PAPER 1 ; INK 0 ; "steep "+STR(steep)
If steep =1 Then
Dim Temp as Integer
Temp=X1
X1=Y1
Y1=Temp
Temp=X2
X2=Y2
Y2=Temp
End If
Dim DeltaX as Integer
DeltaX=Abs(X2-X1)
Dim DeltaY as Integer
DeltaY=Abs(Y2-Y1)
Dim IError as Integer
IError=0
Dim DeltaError as Integer
DeltaError=DeltaY
Dim x as Integer
x=X1 'Start at X1,Y1
Dim y as Integer
y=Y1
Dim XStep as Integer
Dim YStep as Integer
If X1<X2 Then
XStep=1
Else
XStep=-1
end if
If Y1<Y2 Then
YStep=1
Else
YStep=-1 'Direction
end if
Dim iter as Integer
iter=1
While x<>X2
x=x+XStep 'Move in X
IError=IError+DeltaError 'Add to counter
If (IError SHL 1)>DeltaX then 'Would it overflow?
y=y+YStep 'Move in Y
IError=IError-DeltaX 'Overflow/wrap the counter
End if
If steep then
bresx(iter)=y
bresy(iter)=x
Else
bresx(iter)=x
bresy(iter)=y
End If
iter=iter+1
If iter>dist then
'Print at 3,0;PAPER 1;INK 0;"bresenham over distance "+STR(dist)
Return dist
End If
Wend
Return dist
End Function
create 2 arrays to hold the x and y coordinates of the line
Code: Dim bresx(350) as Integer
Dim bresy(350) as Integer
The size of the arrays should be the distance of the longest line you intend to create
a line going across the screen of the speccy is about 322 in length
You have 2 characters on a playing field that has x and y coordinates
you call the line function:
one character is at 1,1
the other is at 100,95
Code: Dim dist as Integer
dist=line(1,1,100,95)
then finally you go through the co-ordinates on the line to check if anything is in the way, like walls or other characters
Code: Dim can_see:UByte
can_see=1
for x=0 to dist
if wall_in_way(bresx(x),bresy(x)) then
can_see=0
end if
next
if can_see =1 then
'yes they can see each other
end if
if can_see =0 then
'no they can not see each other
end if
|
|
|
191 plots causes crash |
Posted by: slenkar - 02-14-2012, 01:58 PM - Forum: Help & Support
- Replies (2)
|
 |
Code: Function distance (x1 as Integer, y1 as Integer, x2 as Integer, y2 as Integer) as Integer
Dim x as Integer
x=Abs(x1-x2)
Dim y as Integer
y=Abs(y1-y2)
Return x+y
End Function
Dim bresx(0 to 255) as Integer
Dim bresy(0 to 191) as Integer
Function line(X1 as Integer,Y1 as Integer,X2 as Integer,Y2 as Integer) as Integer
'Draws a line of individual pixels from X1,Y1 to X2,Y2 at any angle
Dim dist as Integer
dist=distance(X1,Y1,X2,Y2)
dim bresiter as Integer
For bresiter=0 To dist
bresx(bresiter)=0
bresy(bresiter)=0
Next
Dim steep as Integer
if Abs(Y2-Y1) > Abs(X2-X1) then
steep=1
else
steep=0
end if
PRINT AT 1,0 ; PAPER 1 ; INK 0 ; "steep "+STR(steep)
If steep =1 Then
Dim Temp as Integer
Temp=X1
X1=Y1
Y1=Temp
Temp=X2
X2=Y2
Y2=Temp
End If
Dim DeltaX as Integer
DeltaX=Abs(X2-X1)
Dim DeltaY as Integer
DeltaY=Abs(Y2-Y1)
Dim IError as Integer
IError=0
Dim DeltaError as Integer
DeltaError=DeltaY
Dim x as Integer
x=X1 'Start at X1,Y1
Dim y as Integer
y=Y1
Dim XStep as Integer
Dim YStep as Integer
If X1<X2 Then
XStep=1
Else
XStep=-1
end if
If Y1<Y2 Then
YStep=1
Else
YStep=-1 'Direction
end if
Dim iter as Integer
iter=1
While x<>X2
x=x+XStep 'Move in X
IError=IError+DeltaError 'Add to counter
If (IError SHL 1)>DeltaX then 'Would it overflow?
y=y+YStep 'Move in Y
IError=IError-DeltaX 'Overflow/wrap the counter
End if
If steep then
bresx(iter)=y
bresy(iter)=x
Else
bresx(iter)=x
bresy(iter)=y
End If
iter=iter+1
If iter>dist then
Print at 3,0;PAPER 1;INK 0;"bresenham over distance "+STR(dist)
Return dist
End If
Wend
Return dist
End Function
Dim dist as Integer
dist=line(1,1,100,95)-1
PRINT AT 0,0 ; PAPER 1 ; INK 0 ; "dist "+STR(dist)
for x=0 to dist
Plot bresx(x),bresy(x)
next
'PRINT AT 2,0 ; PAPER 1 ; INK 0 ; "bresx "+STR(bresx(108))
'PRINT AT 3,0 ; PAPER 1 ; INK 0 ; "bresx "+STR(bresx(57))
'PRINT AT 4,0 ; PAPER 1 ; INK 0 ; "bresx "+STR(bresx(18))
'PRINT AT 5,0 ; PAPER 1 ; INK 0 ; "bresy "+STR(bresy(108))
'PRINT AT 6,0 ; PAPER 1 ; INK 0 ; "bresy "+STR(bresy(59))
'PRINT AT 7,0 ; PAPER 1 ; INK 0 ; "bresy "+STR(bresy(1))
'main loop
100 LET j$ = INKEY$
GOTO 100
Im implementing a bresenham thingy for line of sight calculations,
whenever the length of the line exceeds 191 the screen gets corrupted,
191 just happens to be the height of the screen, but I dont see the relation.
|
|
|
|