Author Topic: SCI Tetris  (Read 430 times)

0 Members and 1 Guest are viewing this topic.

Offline robbo007

SCI Tetris
« on: October 20, 2025, 12:39:21 PM »
Hi guys,
I'm trying to compile SCI Tetris using the SCI0 template I'm using. It seems to get stuck on this when running. The title screen script works. Its just the game room that locks up. Anyone got it working?

Code: [Select]
;; todo: encapsulate this in a procedure
    (= next (Random 0 6))
    (= n (Random 0 6))
(for ((= t 0)) (< t 4) ((++ t))
(= [ax t] (mod [figures (+ t (* n 4))] 2))
    (= [ay t] (/   [figures (+ t (* n 4))] 2))
    (+= [ax t] 4) ; move it to the centre
)
(= next (Random 0 6))
(for ((= t 0)) (< t 4) ((++ t))
(= [nx t] (mod [figures (+ t (* next 4))] 2))
    (= [ny t] (/   [figures (+ t (* next 4))] 2))
)


GameRoom Script:

Code: [Select]
;;; Sierra Script 1.0 - (do not remove this comment)
; Tetris
(script# 524)
(include sci.sh)
(include game.sh)
(use main)
(use controls)
(use cycle)
(use game)
(use feature)
(use obj)
;(use inv)
;(use door)
;(use jump)
;(use dpath)

(public
rm524 0
)

(local
HEIGHT = 20
WIDTH = 10
[field 200] ; default value is zero
[figures 28] = [1 3 5 7 ; I
2 4 5 7 ; Z
3 5 4 6 ; S
3 5 4 7 ; T
2 3 5 7 ; L
3 5 7 6 ; J
2 3 4 5 ; O
   ]
[ax 4]
[bx 4]
[ay 4]
[by 4]
[nx 4]
[ny 4]

dx = 0
rotate = 0
colorNum = 1
n = 0
delay = 30

[displayString 80]

offsetx = 119
offsety = 12

elapsedTime = 0
lastFrameTime = 0

next = 0

clear = 0
cleared = 0
)


(instance block0 of Prop
(properties
view 617
x -10
y -10
loop 0
cel 0
priority 15
)
)
(instance block1 of Prop
(properties
view 617
x -10
y -10
loop 0
cel 0
priority 15
)
)
(instance block2 of Prop
(properties
view 617
x -10
y -10
loop 0
cel 0
priority 15
)
)
(instance block3 of Prop
(properties
view 617
x -10
y -10
loop 0
cel 0
priority 15
)
)

(instance block4 of View
(properties
view 617
x -10
y -10
loop 0
cel 0
priority 15
)
)

(instance rosella of Act
(properties
view 618
x 260
y 165
loop 1
priority 15
)
)


(instance rm524 of Rm
(properties
picture 524
)

(method (init &tmp i)
(super init:)
(self setScript: RoomScript)

    (block0 init:)
    (block1 init:)
    (block2 init:)
    (block3 init:)
   
    ;; todo: encapsulate this in a procedure
    (= next (Random 0 6))
    (= n (Random 0 6))
(for ((= i 0)) (< i 4) ((++ i))
(= [ax i] (mod [figures (+ i (* n 4))] 2))
    (= [ay i] (/   [figures (+ i (* n 4))] 2))
    (+= [ax i] 4) ; move it to the centre
)
(= next (Random 0 6))
(for ((= i 0)) (< i 4) ((++ i))
(= [nx i] (mod [figures (+ i (* next 4))] 2))
    (= [ny i] (/   [figures (+ i (* next 4))] 2))
)

(= gSpeed 1)
(= lastFrameTime (GetTime))

(gTheMusic prevSignal: 0  stop: number: 100 loop: -1 play:)
(rosella init: setCycle: Fwd cycleSpeed: 10)
)
)

(procedure (check &tmp i [tempString 500]) ; checks for collision returns 1 if true
(for ((= i 0)) (< i 4) ((++ i))
(if
(or (< [ax i] 0) ; left side check 0
(>= [ax i] WIDTH) ; right side check
(>= [ay i] HEIGHT)
)
(return 1)
else
(if [field (+ [ax i] (* [ay i] WIDTH))]
(if (== [ay i] 1)
((ScriptID DYING_SCRIPT) caller: 800)
(gGame setScript: (ScriptID DYING_SCRIPT))
)
(return 1) ; check with field
)
)
)
(return 0) ; no collision
)

(procedure (refresh)
; 10 lines cleared, level up!
(if (> clear (* gLevel 10))
(++ gLevel)
(= clear 0)
(rosella cycleSpeed: (- 10 gLevel))
(SL doit:)
)

(DrawPic gRoomNumber)
(Display {Tetris} dsCOORD 206 12 dsCOLOUR clWHITE dsFONT 100)
(Display {Tetris} dsCOORD 205 11 dsCOLOUR clBLACK dsFONT 100)
(Display {Tetris} dsCOORD 204 10 dsCOLOUR clMAROON dsFONT 100)
(Display "Controls:" dsFONT 4 dsCOLOR clSILVER dsCOORD 205 40)
(Display "____W____Rotate" dsFONT 4 dsCOLOR clSILVER dsCOORD 205 50)
(Display "__A___D__Move Left/Right" dsFONT 4 dsCOLOR clSILVER dsCOORD 205 60)
(Display "____S____Move Down" dsFONT 4 dsCOLOR clSILVER dsCOORD 205 70)

(Display {Score:} dsFONT 4 dsCOLOR clBLACK dsCOORD 21 11)
(Display {Score:} dsFONT 4 dsCOLOR clSILVER dsCOORD 20 10)
(Format @displayString {%d} gScore)
(Display @displayString dsFONT 100 dsCOLOR clBLACK dsCOORD 21 21 dsALIGN alRIGHT dsWIDTH 90)
(Display @displayString dsFONT 100 dsCOLOR clWHITE dsCOORD 20 20 dsALIGN alRIGHT dsWIDTH 90)

(Display {Highest:} dsFONT 4 dsCOLOR clBLACK dsCOORD 21 41)
(Display {Highest:} dsFONT 4 dsCOLOR clSILVER dsCOORD 20 40)
(Format @displayString {%d} gMaxScore)
(Display @displayString dsFONT 100 dsCOLOR clBLACK dsCOORD 21 51 dsALIGN alRIGHT dsWIDTH 90)
(Display @displayString dsFONT 100 dsCOLOR clWHITE dsCOORD 20 50 dsALIGN alRIGHT dsWIDTH 90)

(Display {Next:} dsFONT 4 dsCOLOR clBLACK dsCOORD 21 96)
(Display {Next:} dsFONT 4 dsCOLOR clSILVER dsCOORD 20 95)

(Display {Lines Cleared:} dsFONT 4 dsCOLOR clBLACK dsCOORD 206 96)
(Display {Lines Cleared:} dsFONT 4 dsCOLOR clSILVER dsCOORD 205 95)
(Format @displayString {%d} cleared)
(Display @displayString dsCOLOR clBLACK dsCOORD 206 96 dsALIGN alRIGHT dsWIDTH 90)
(Display @displayString dsCOLOR clWHITE dsCOORD 205 95 dsALIGN alRIGHT dsWIDTH 90)
)


(instance RoomScript of Script
(properties)

(method (handleEvent pEvent)
    (switch (pEvent type?)
      (evKEYBOARD
        (if (== (pEvent message?) KEY_w)
        (= rotate 1)
              (pEvent claimed: 1)
)
(if (== (pEvent message?) KEY_a)
        (= dx -1)
              (pEvent claimed: 1)
)
(if (== (pEvent message?) KEY_d)
        (= dx 1)
              (pEvent claimed: 1)
)
(if (== (pEvent message?) KEY_s)
        (= delay 1)
              (pEvent claimed: 1)
)
)
)
)

(method (doit &tmp i cx cy x y j row count)
;;; timer stuff ;;;
(= elapsedTime (- (GetTime) lastFrameTime))
;(Format @displayString "elapsed: %d" elapsedTime )
    ;(Display @displayString dsCOORD 160 20 dsCOLOUR clRED dsFONT 999)

;;;; move ;;;;
(for ((= i 0)) (< i 4) ((++ i))
(= [bx i] [ax i]) ; store previous position
(= [by i] [ay i])
(+= [ax i] dx) ; move left or right
)
(if (check) ; stop and move back to previous position
(for ((= i 0)) (< i 4) ((++ i))
(= [ax i] [bx i])
(= [ay i] [by i])
)

)


;;;; rotate ;;;;
(if rotate
(= cx [ax 1]) ; center of rotation
(= cy [ay 1])
(for ((= i 0)) (< i 4) ((++ i)) ; rotate the blocks
(= x (- [ay i] cy))
(= y (- [ax i] cx))
(= [ax i] (- cx x))
(= [ay i] (+ cy y))
)
(if (check) ; can't rotate this way, move back to previous
(for ((= i 0)) (< i 4) ((++ i))
(= [ax i] [bx i])
(= [ay i] [by i])
)
)
)

;;;; tick ;;;;
(if (> elapsedTime delay)
(= lastFrameTime (GetTime))
(for ((= i 0)) (< i 4) ((++ i))
(= [bx i] [ax i]) ; store previous position
(= [by i] [ay i])
(++ [ay i]) ; move down one block
)
(if (check) ; did we hit something?
(for ((= i 0)) (< i 4) ((++ i))
;(FormatPrint {x: %d y: %d index: %d} [bx i] [by i] (+ [bx i] (* [by i] WIDTH)))
(= [field (+ [bx i] (* [by i] WIDTH))] colorNum)
)
(= colorNum (Random 1 6))
(= n next)
(= next (Random 0 6))
(for ((= i 0)) (< i 4) ((++ i))
(= [ax i] (mod [figures (+ i (* n 4))] 2))
    (= [ay i] (/   [figures (+ i (* n 4))] 2))
    (+= [ax i] 4) ; move it to the centre
)

(for ((= i 0)) (< i 4) ((++ i))
(= [nx i] (mod [figures (+ i (* next 4))] 2))
    (= [ny i] (/   [figures (+ i (* next 4))] 2))
)
)
)

;;;; check lines ;;;;
(= row (- HEIGHT 1))
(for ((= i (- HEIGHT 1))) (> i 0) ((-- i))
(= count 0)
(for ((= j 0)) (< j WIDTH) ((++ j))
(if [field (+ j (* i WIDTH))]
(++ count)
)
(=
[field (+ j (* row WIDTH))]
[field (+ j (* i WIDTH))]
)
)
(if (< count WIDTH)
(-- row)
(refresh) ; clear the screen
)
)
(+= clear row) ; cleared this level
(+= cleared row) ; cleared in total
(switch row
(4 (+= gScore (* 1200 gLevel)))
(3 (+= gScore (* 300 gLevel)))
(2 (+= gScore (* 100 gLevel)))
(1 (+= gScore (* 40 gLevel)))
)

;(Format @displayString "Row: %d" row )
    ;(Display @displayString dsCOORD 250 180 dsCOLOUR clRED dsFONT 4)

(= dx 0)
(= rotate 0)
(= delay (- 33 (* gLevel 3)))

    ;;;; draw the set blocks ;;;;
    (for ((= i 0)) (< i HEIGHT) ((++ i))
    (for ((= j 0)) (< j WIDTH) ((++ j))
    ;(Format @displayString "X" )
    ;(Display @displayString dsCOORD (* j 8) (* i 8) dsCOLOUR clRED dsFONT 4)
    (if [field (+ j (* i WIDTH))]
    (block4 init: loop: [field (+ j (* i WIDTH))] posn: (+ offsetx (* j 8)) (+ offsety (* i 8)))
    (gAddToPics add: block4 eachElementDo: #init doit:)
)
)
)
   
    (block0 loop: colorNum posn: (+ offsetx (* [ax 0] 8)) (+ offsety (* [ay 0] 8)))
    (block1 loop: colorNum posn: (+ offsetx (* [ax 1] 8)) (+ offsety (* [ay 1] 8)))
    (block2 loop: colorNum posn: (+ offsetx (* [ax 2] 8)) (+ offsety (* [ay 2] 8)))
    (block3 loop: colorNum posn: (+ offsetx (* [ax 3] 8)) (+ offsety (* [ay 3] 8)))
   
    (block4 init: colorNum posn: (+ 50 (* [nx 0] 8)) (+ 110 (* [ny 0] 8)))
    (gAddToPics add: block4 eachElementDo: #init doit:)
    (block4 init: colorNum posn: (+ 50 (* [nx 1] 8)) (+ 110 (* [ny 1] 8)))
    (gAddToPics add: block4 eachElementDo: #init doit:)
    (block4 init: colorNum posn: (+ 50 (* [nx 2] 8)) (+ 110 (* [ny 2] 8)))
    (gAddToPics add: block4 eachElementDo: #init doit:)
    (block4 init: colorNum posn: (+ 50 (* [nx 3] 8)) (+ 110 (* [ny 3] 8)))
    (gAddToPics add: block4 eachElementDo: #init doit:)

   
   
    (super doit:)
)
)



Offline troflip

Re: SCI Tetris
« Reply #1 on: October 20, 2025, 01:09:37 PM »
That code looks fine, all the array accesses are within the bounds of the arrays. Are you sure it's stuck there?
Check out my website: http://icefallgames.com
Groundhog Day Competition

Offline Collector

Re: SCI Tetris
« Reply #2 on: October 20, 2025, 02:27:08 PM »
Is there some reason that you are trying to use a different SCI0 template? This is a fan game that comes with its source. It compiles just fine with the resources and scripts it came with.
KQII Remake Pic

Offline robbo007

Re: SCI Tetris
« Reply #3 on: October 20, 2025, 04:30:42 PM »
That code looks fine, all the array accesses are within the bounds of the arrays. Are you sure it's stuck there?

If I put the (setdebug) after (= lastFrameTime (GetTime)) in the init part it does not reach it. It gets stuck before this. It seems to get stuck in a loop of the section of code I mentioned earlier.

I've checked the main.sc of the fan game and it does not appear to have anything important apart from the variable gLevel = 1, the games.sh does not seem to contain any changes. I was going to add this to a room I've created which is an arcade room at the "Kaos HomeBrew Klub". To promote some of the fan stuff. I think Rainer did an amazing job.

I'm not sure why that init part was making the room stick when running.


Offline troflip

Re: SCI Tetris
« Reply #4 on: October 20, 2025, 06:22:48 PM »
Can you stick some Prints in there that print the value of t? Something in that block of code must be corrupting it, which would suggest that incorrect byte code is being generated when compiled.

What interpreter version are you running it on? Are you sure the compiler is generating the byte code for that version?
What happens if you run it using scummvm?
Check out my website: http://icefallgames.com
Groundhog Day Competition

Offline Kawa

Re: SCI Tetris
« Reply #5 on: October 20, 2025, 06:26:46 PM »
Are you by chance compiling this on Phil's original SCI Companion from 2016?

Offline robbo007

Re: SCI Tetris
« Reply #6 on: October 20, 2025, 06:39:28 PM »
Are you by chance compiling this on Phil's original SCI Companion from 2016?

Correct. I'm not using your folk of SC to compile it.
Quote
Can you stick some Prints in there that print the value of t? Something in that block of code must be corrupting it, which would suggest that incorrect byte code is being generated when compiled.

What interpreter version are you running it on? Are you sure the compiler is generating the byte code for that version?
What happens if you run it using scummvm?
I will stick some prints to see where it gets too and repost


Offline Kawa

Re: SCI Tetris
« Reply #7 on: October 20, 2025, 06:47:20 PM »
A certain corned beef sandwich told me that this is because of a bug involving arithmetic on arrays that wasn't fixed until '18.

Offline robbo007

Re: SCI Tetris
« Reply #8 on: October 21, 2025, 04:56:17 AM »
With pickles?

Is this fix available for the SCI0 template? Or is it built into the code in the SC 2016? Could it be patched if so?
Thanks,

Offline Kawa

Re: SCI Tetris
« Reply #9 on: October 21, 2025, 05:51:00 AM »
The problem is in SCI Companion's compiler, nothing about the templates is wrong. Use my fork and it should work.

Offline robbo007

Re: SCI Tetris
« Reply #10 on: October 21, 2025, 09:21:49 AM »
ahh ok.. Yes, your fork works for the SCI Tetris but unfortunately breaks some of my other rooms.  I'll have to see what I do.
Thanks,

Offline troflip

Re: SCI Tetris
« Reply #11 on: October 21, 2025, 01:10:52 PM »
The problem is in SCI Companion's compiler, nothing about the templates is wrong. Use my fork and it should work.

Did I ever pull that change into the main branch of SCI Companion? Do you have a link to the change?
Check out my website: http://icefallgames.com
Groundhog Day Competition

Offline Kawa

Re: SCI Tetris
« Reply #12 on: October 21, 2025, 01:55:50 PM »
Did I ever pull that change into the main branch of SCI Companion? Do you have a link to the change?
You kept it in the experimental branch.

Offline robbo007

Re: SCI Tetris
« Reply #13 on: October 23, 2025, 06:02:24 AM »
Thanks to sluicebox for the fix. I've updated the expresions based on his fix.

Quote
You can work around at least some of these compiler bugs in the older version, this particular problem is with the "+=" expressions. (Or -=, *=, /=, etc).

You can avoid this problem by expanding all of those lines like this:

(+= [ax t] 4)

becomes:

(= [ax t] (+ [ax t] 4))

Code: [Select]
;;; Sierra Script 1.0 - (do not remove this comment)
;**
;** Logics for room 524 -- SCI Tetris mini game. Code by Rainer De Temple.
;**
;** Leisure Suit Larry 4 - Never say Nontoonyt (AKA The Missing Floppies)
;**        Copyright 2025
;** by Robbbo
;**
;** Last Update: October 23rd, 2025
;**
(script# 524)
(include sci.sh)
(include game.sh)
(use main)
(use controls)
(use cycle)
(use game)
(use feature)
(use obj)
(use inv)
(use door)
(use jump)
(use dpath)

(public
rm524 0
)

(local
HEIGHT = 20
WIDTH = 10
[field 200] ; default value is zero
[figures 28] = [1 3 5 7 ; I
2 4 5 7 ; Z
3 5 4 6 ; S
3 5 4 7 ; T
2 3 5 7 ; L
3 5 7 6 ; J
2 3 4 5 ; O
   ]
[ax 4]
[bx 4]
[ay 4]
[by 4]
[nx 4]
[ny 4]

dx = 0
rotate = 0
colorNum = 1
n = 0
delay = 30

[displayString 80]

offsetx = 119
offsety = 12

elapsedTime = 0
lastFrameTime = 0

next = 0

clear = 0
cleared = 0
)


(instance block0 of Prop
(properties
view 617
x -10
y -10
loop 0
cel 0
priority 15
)
)
(instance block1 of Prop
(properties
view 617
x -10
y -10
loop 0
cel 0
priority 15
)
)
(instance block2 of Prop
(properties
view 617
x -10
y -10
loop 0
cel 0
priority 15
)
)
(instance block3 of Prop
(properties
view 617
x -10
y -10
loop 0
cel 0
priority 15
)
)

(instance block4 of View
(properties
view 617
x -10
y -10
loop 0
cel 0
priority 15
)
)

(instance alLowe of Act
(properties
view 618
x 260
y 165
loop 1
priority 15
)
)


(instance rm524 of Rm
(properties
picture 524
)

(method (init &tmp i)
(super init:)
(self setScript: RoomScript)

    (block0 init:)
    (block1 init:)
    (block2 init:)
    (block3 init:)
   
    ;; todo: encapsulate this in a procedure
    (= next (Random 0 6))
    (= n (Random 0 6))
(for ((= i 0)) (< i 4) ((= i (+ i 1)))
(= [ax i] (mod [figures (+ i (* n 4))] 2))
    (= [ay i] (/   [figures (+ i (* n 4))] 2))
    (= [ax i] (+ [ax i] 4)) ; move it to the centre
)
(= next (Random 0 6))
(for ((= i 0)) (< i 4) ((= i (+ i 1)))
(= [nx i] (mod [figures (+ i (* next 4))] 2))
    (= [ny i] (/   [figures (+ i (* next 4))] 2))
)
(= gSpeed 1)
(= lastFrameTime (GetTime))
(gTheMusic prevSignal: 0  stop: number: 100 loop: -1 play:)
(alLowe init: setCycle: Fwd cycleSpeed: 10)

)
)

(procedure (check &tmp i [tempString 500]) ; checks for collision returns 1 if true
(for ((= i 0)) (< i 4) ((= i (+ i 1)))
(if
(or (< [ax i] 0) ; left side check 0
(>= [ax i] WIDTH) ; right side check
(>= [ay i] HEIGHT)
)
(return 1)
else
(if [field (+ [ax i] (* [ay i] WIDTH))]
(if (== [ay i] 1)
((ScriptID DYING_SCRIPT) caller: 729)
(gGame setScript: (ScriptID DYING_SCRIPT))
)
(return 1) ; check with field
)
)
)
(return 0) ; no collision
)

(procedure (refresh)
; 10 lines cleared, level up!
(if (> clear (* gLevel 10))
(= gLevel (+ gLevel 1))
(= clear 0)
(alLowe cycleSpeed: (- 10 gLevel))
(SL doit:)
)

(DrawPic gRoomNumber)
(Display {Tetris} dsCOORD 206 12 dsCOLOUR clWHITE dsFONT 100)
(Display {Tetris} dsCOORD 205 11 dsCOLOUR clBLACK dsFONT 100)
(Display {Tetris} dsCOORD 204 10 dsCOLOUR clMAROON dsFONT 100)
(Display "Controls:" dsFONT 4 dsCOLOR clSILVER dsCOORD 205 40)
(Display "____W____Rotate" dsFONT 4 dsCOLOR clSILVER dsCOORD 205 50)
(Display "__A___D__Move Left/Right" dsFONT 4 dsCOLOR clSILVER dsCOORD 205 60)
(Display "____S____Move Down" dsFONT 4 dsCOLOR clSILVER dsCOORD 205 70)

(Display {Score:} dsFONT 4 dsCOLOR clBLACK dsCOORD 21 11)
(Display {Score:} dsFONT 4 dsCOLOR clSILVER dsCOORD 20 10)
(Format @displayString {%d} gScore)
(Display @displayString dsFONT 100 dsCOLOR clBLACK dsCOORD 21 21 dsALIGN alRIGHT dsWIDTH 90)
(Display @displayString dsFONT 100 dsCOLOR clWHITE dsCOORD 20 20 dsALIGN alRIGHT dsWIDTH 90)

(Display {Highest:} dsFONT 4 dsCOLOR clBLACK dsCOORD 21 41)
(Display {Highest:} dsFONT 4 dsCOLOR clSILVER dsCOORD 20 40)
(Format @displayString {%d} gMaxScore)
(Display @displayString dsFONT 100 dsCOLOR clBLACK dsCOORD 21 51 dsALIGN alRIGHT dsWIDTH 90)
(Display @displayString dsFONT 100 dsCOLOR clWHITE dsCOORD 20 50 dsALIGN alRIGHT dsWIDTH 90)

(Display {Next:} dsFONT 4 dsCOLOR clBLACK dsCOORD 21 96)
(Display {Next:} dsFONT 4 dsCOLOR clSILVER dsCOORD 20 95)

(Display {Lines Cleared:} dsFONT 4 dsCOLOR clBLACK dsCOORD 206 96)
(Display {Lines Cleared:} dsFONT 4 dsCOLOR clSILVER dsCOORD 205 95)
(Format @displayString {%d} cleared)
(Display @displayString dsCOLOR clBLACK dsCOORD 206 96 dsALIGN alRIGHT dsWIDTH 90)
(Display @displayString dsCOLOR clWHITE dsCOORD 205 95 dsALIGN alRIGHT dsWIDTH 90)
)


(instance RoomScript of Script
(properties)

(method (handleEvent pEvent)
    (switch (pEvent type?)
      (evKEYBOARD
        (if (== (pEvent message?) KEY_w)
        (= rotate 1)
              (pEvent claimed: 1)
)
(if (== (pEvent message?) KEY_a)
        (= dx -1)
              (pEvent claimed: 1)
)
(if (== (pEvent message?) KEY_d)
        (= dx 1)
              (pEvent claimed: 1)
)
(if (== (pEvent message?) KEY_s)
        (= delay 1)
              (pEvent claimed: 1)
)
)
)
)

(method (doit &tmp i cx cy x y j row count)
;;; timer stuff ;;;
(= elapsedTime (- (GetTime) lastFrameTime))

;;;; move ;;;;
(for ((= i 0)) (< i 4) ((= i (+ i 1)))
(= [bx i] [ax i]) ; store previous position
(= [by i] [ay i])
(= [ax i] (+ [ax i] dx)) ; move left or right
)
(if (check) ; stop and move back to previous position
(for ((= i 0)) (< i 4) ((= i (+ i 1)))
(= [ax i] [bx i])
(= [ay i] [by i])
)
)

;;;; rotate ;;;;
(if rotate
(= cx [ax 1]) ; center of rotation
(= cy [ay 1])
(for ((= i 0)) (< i 4) ((= i (+ i 1))) ; rotate the blocks
(= x (- [ay i] cy))
(= y (- [ax i] cx))
(= [ax i] (- cx x))
(= [ay i] (+ cy y))
)
(if (check) ; can't rotate this way, move back to previous
(for ((= i 0)) (< i 4) ((= i (+ i 1)))
(= [ax i] [bx i])
(= [ay i] [by i])
)
)
)

;;;; tick ;;;;
(if (> elapsedTime delay)
(= lastFrameTime (GetTime))
(for ((= i 0)) (< i 4) ((= i (+ i 1)))
(= [bx i] [ax i]) ; store previous position
(= [by i] [ay i])
(= [ay i] (+ [ay i] 1)) ; move down one block
)
(if (check) ; did we hit something?
(for ((= i 0)) (< i 4) ((= i (+ i 1)))
(= [field (+ [bx i] (* [by i] WIDTH))] colorNum)
)
(= colorNum (Random 1 6))
(= n next)
(= next (Random 0 6))
(for ((= i 0)) (< i 4) ((= i (+ i 1)))
(= [ax i] (mod [figures (+ i (* n 4))] 2))
    (= [ay i] (/   [figures (+ i (* n 4))] 2))
    (= [ax i] (+ [ax i] 4)) ; move it to the centre
)

(for ((= i 0)) (< i 4) ((= i (+ i 1)))
(= [nx i] (mod [figures (+ i (* next 4))] 2))
    (= [ny i] (/   [figures (+ i (* next 4))] 2))
)
)
)

;;;; check lines ;;;;
(= row (- HEIGHT 1))
(for ((= i (- HEIGHT 1))) (> i 0) ((= i (- i 1)))
(= count 0)
(for ((= j 0)) (< j WIDTH) ((= j (+ j 1)))
(if [field (+ j (* i WIDTH))]
(= count (+ count 1))
)
(=
[field (+ j (* row WIDTH))]
[field (+ j (* i WIDTH))]
)
)
(if (< count WIDTH)
(= row (- row 1))
(refresh) ; clear the screen
)
)
(= clear (+ clear row)) ; cleared this level
(= cleared (+ cleared row)) ; cleared in total
(switch row
(4 (= gScore (+ gScore (* 1200 gLevel))))
(3 (= gScore (+ gScore (* 300 gLevel))))
(2 (= gScore (+ gScore (* 100 gLevel))))
(1 (= gScore (+ gScore (* 40 gLevel))))
)

(= dx 0)
(= rotate 0)
(= delay (- 33 (* gLevel 3)))

    ;;;; draw the set blocks ;;;;
    (for ((= i 0)) (< i HEIGHT) ((= i (+ i 1)))
    (for ((= j 0)) (< j WIDTH) ((= j (+ j 1)))
    (if [field (+ j (* i WIDTH))]
    (block4 init: loop: [field (+ j (* i WIDTH))] posn: (+ offsetx (* j 8)) (+ offsety (* i 8)))
    (gAddToPics add: block4 eachElementDo: #init doit:)
)
)
)
   
    (block0 loop: colorNum posn: (+ offsetx (* [ax 0] 8)) (+ offsety (* [ay 0] 8)))
    (block1 loop: colorNum posn: (+ offsetx (* [ax 1] 8)) (+ offsety (* [ay 1] 8)))
    (block2 loop: colorNum posn: (+ offsetx (* [ax 2] 8)) (+ offsety (* [ay 2] 8)))
    (block3 loop: colorNum posn: (+ offsetx (* [ax 3] 8)) (+ offsety (* [ay 3] 8)))
   
    (block4 init: colorNum posn: (+ 50 (* [nx 0] 8)) (+ 110 (* [ny 0] 8)))
    (gAddToPics add: block4 eachElementDo: #init doit:)
    (block4 init: colorNum posn: (+ 50 (* [nx 1] 8)) (+ 110 (* [ny 1] 8)))
    (gAddToPics add: block4 eachElementDo: #init doit:)
    (block4 init: colorNum posn: (+ 50 (* [nx 2] 8)) (+ 110 (* [ny 2] 8)))
    (gAddToPics add: block4 eachElementDo: #init doit:)
    (block4 init: colorNum posn: (+ 50 (* [nx 3] 8)) (+ 110 (* [ny 3] 8)))
    (gAddToPics add: block4 eachElementDo: #init doit:)

    (super doit:)
)
)

Offline cosmicr

Re: SCI Tetris
« Reply #14 on: October 23, 2025, 06:12:47 PM »
I am honoured you're using my code :) BTW I had no idea what I was doing back then (and now too) so I'm not surprised if it causes problems lol

Is this for a boss key or something special in your LSL game? I love the idea!
« Last Edit: October 23, 2025, 06:27:39 PM by cosmicr »


SMF 2.0.19 | SMF © 2021, Simple Machines
Simple Audio Video Embedder

Page created in 0.019 seconds with 17 queries.