Are you interested?
Yes
 100%  [ 11 ]
No
 0%  [ 0 ]
Total Votes : 11

Hello, I thought about an ICE tutorial where I would create a small game (I don't know which yet; maybe Doodle Jump) and explain what I do so that others can learn ICE better. I would go from drawing rectangles to using sprites, arrays, pointers, calculate intersections and maybe a few other things.

EDIT:
You will need the clibs version 9.0 (not higher)
I think this is a great idea!
That’s an awesome idea (: if you want any help I’m here... on June 7th when school ends for me Smile

I think the hardest part (for me) was figuring out that ICE only supports positive int. Creates a lot of problems Razz lists were also kinda hard for me to figure out.

Edit: I forgot about sprites (mostly figuring out pointers)
Thank you;
I will try to explain things how I learned them, because I got ICE from a friend and I had to figure out how things work by my self until I found Cemetech after about one year. So I didn´t know all these technical terms and I think this could help others to understand what they mean. (I hope my English is understandable Wink )
If you have any supplements let me know or post it here.
Why ICE?
I really like ICE because it is a very nice way to create asm programs oncalc. It's much faster than Ti-Basic and you have much more possibilities like using the whole screen.

To create an ICE program you need the ICE compiler. I would also recommend Cesium to you because your source code won't be deleted after a reset (of course you have to archive it).
The documentation and the command list could be also helpful.



The program begins with an imaginary "i" (2nd, i) and the name of the program. To use the whole screen, you need det(0) to begin and det(1) to return to the normal state.
The screen goes from (0,0) top, left to (320,240) bottom, right
Code:
[i]DJUMP
det(0)

[i] code

det(1)

The [i] can be also used for comments.





Until now, the program will be executed in less than a second.
Let's insert a pause.

Code:
[i]DJUMP
det(0)

Pause

det(1)


Can we draw a rectangle?

Code:
[i]DJUMP
det(0)

det(41,5,5,30,40)

Pause

det(1)


A filled one?

Code:
[i]DJUMP
det(0)

det(42,5,5,30,40)

Pause

det(1)


You may have noticed that we use many det( ´s; det(x tells the compiler to use the command number x. You can see all commands by pressing trace in the program editor.

Let's change the color!

Code:
[i]DJUMP
det(0)
det(2,7)
det(42,5,5,30,40)

Pause

det(1)

You can press graph to see how you can get the color code, or you can use this program.


Let's create a variable (we can do this very similar to Ti-Basic)

Code:
[i]TEST
ClrHome
5→A
Disp A
Pause


Code:
[i]TEST
ClrHome
5→A
3→AA
Disp A+AA
Pause

We can use up to 10 characters per variable and up to 85 variables!


We will try to make an animation:

Code:
[i]DJUMP
det(0)

[i] At first we need a loop instead of the pause, so we can do things while the program runs
[i] We can also use getKey just like in basic (only the keycode is different)
Repeat KEY=9
getKey→KEY

det(2,7)
det(42,5,5,30,40)

End
det(1)


We use A to let the rectangle move.

Code:
[i]DJUMP
det(0)
0→A

Repeat KEY=9
getKey→KEY

det(2,7)
det(42,A,5,30,40)

A+1→A
End
det(1)


It's a bit fast, but we can't use A+0.5→A, because we can only use positive integers. We can do it like this

Code:
[i]DJUMP
det(0)
0→A

Repeat KEY=9
getKey→KEY

det(2,7)
det(42,A/2,5,30,40)

A+1→A
End
det(1)


Let's let the rectangle move instead of drawing a thick line

Code:
[i]DJUMP
det(0)
0→A

Repeat KEY=9
getKey→KEY

det(5,255)    //overdraws the whole screen
det(2,7)
det(42,A/2,5,30,40)
det(10)

A+1→A
End
det(1)

det(10) switches our canvas. Until now, we have drawn on one canvas, but we can also draw on the first one and show it with det(10). Then we can draw on the second one until we switch again. This makes our game smoothly. You can use det(9, to change the draw mode.

Now you should be able to make small animations. Very Happy
Maybe I should add this small program which shows you the key codes.
Use double clear to exit.

Code:
[i]KEYCODE
Repeat KEY=15 and A=15
If KEY:KEY→A:End

If getKey→KEY
ClrHome
Disp KEY
End
End
Ah okay, did I unterstand correctly?
Drawing at the two screenbuffers and swaping them every frame
doesn`t cause anymore this diagonal line from the upper left corner to the bottom right corner of the screen?
Yes; double buffering is used to make your game non-flickering. I don't know why this diagonal line sometimes arises, but it's much better with double buffering.
Let's move the rectangle around.
Code:
[i]DJUMP
det(0)
50→PX→PY   // P means position

Repeat getKey(15)  // getKey(x) is 1 when the key x is pressed in this moment
det(5,255)
det(2,7)
det(42,PX,PY,30,40)
det(10)

If getKey(2):PX-3→PX:End
If getKey(3):PX+3→PX:End
End
det(1)


Now we want the rectangle to fall down. This means we have to simulate the increasing falling speed.

Code:
[i]DJUMP
det(0)
50→PX→PY
0→SPEED

Repeat getKey(15)
det(5,255)
det(2,7)
det(42,PX,PY,30,40)
det(10)


SPEED+1→SPEED
SPEED+PY→PY
If getKey(2):PX-3→PX:End
If getKey(3):PX+3→PX:End
End
det(1)


Well, that was a bit fast...

Code:
SPEED+1→SPEED
SPEED/3+PY→PY


And we could write that shorter...

Code:
SPEED+1→SPEED/3+PY→PY


Now we want the rectangle to have a negative speed when the program starts... But we can't use negative numbers (here). We can do it like this:

Code:
SPEED/3+PY-10→PY
When SPEED is less than 30 it will "fall" up, otherwise down.


I think it should be able to bounce too.

Code:
[i]DJUMP
det(0)
50→PX→PY
15→SPEED  // if we want to jump not so high, we can change SPEED (30 would be no speed)

Repeat getKey(15)
det(5,255)
det(2,7)
det(42,PX,PY,30,40)
det(10)


SPEED+1→SPEED/3+PY-10→PY
If PY >=200  // Screen bottom minus rectangle height
0→SPEED
200→PY   // We don´t want to jump trough the ground!
End

If getKey(2):PX-3→PX:End
If getKey(3):PX+3→PX:End
End
det(1)


I will go on another time Wink
Until now, we can jump around on the ground. But we have to change a few things:

At first, we should change the center of the rectangle, so we can calculate intersections easier.
Code:
det(42,PX-15,PY-40,30,40)
Now PX is in the middle of the rectangle and PY is at the bottom.



Code:
If PY >=240   // We have to optimize the bounce too...
0→SPEED
240→PY
End



And here's our problem: If we jump too high, we will get respawned at the ground. I'll tell you why.
The numbers in our variables are between 0 and 16777215.
If we are higher than 16777215, we will start at 0 again.
So 16777216 is 0 and -1 is 16777215.
If we jump too high, we will be at 16777215 instead of -1 and get respawned to 240 because of our "If PY >=240"-loop.

So we have to change something; I think this is the best way:

Code:
det(42,PX-15,340-PY-40,30,40)  // later I will write that shorter, but it´s easier to understand

If PY is 0, we are at 340, so we fell down and died.Sad
If PY is 340 we are at 0 and if PY is 500 we are at -160, so we can jump as high as we want without getting respawned from our loop. We could say we "changed our coordinate system" to (0,340) top, left and (320,100) bottom right.


To draw that, we need to use another command: det(36
The difference between clip and noclip is that when you draw something noclip it will be faster, but you can only draw inside the screen. It’s a bit like the variables. (Try to jump out of the screen on one side, then you will see)
When we draw something clip everything what is outside the clip region will be not drawn. With det(43 we can define the clip region.


Code:
[i]DJUMP
det(0)
160→PX  // our new positions
200→PY
45→SPEED    //We have to change the jump direction, because we "changed our coordinate system"

det(43,0,0,320,240)  // define clip region (whole screen)
Repeat getKey(15)
det(5,255)
det(2,7)
det(36,PX-15,340-PY-40,30,40)
det(10)


SPEED-1→SPEED/3+PY-10→PY  // Speed has to decrease now
If PY<100    //our "new bottom" is at 100  (340-100=240)
70→SPEED  // right direction
100→PY  // our "new bottom"...
End

If getKey(2):PX-3→PX:End
If getKey(3):PX+3→PX:End
End
det(1)

Hey, it works. But there’s one thing left...

Code:
max(SPEED,1)-1→SPEED/3+PY-10→PY  // If SPEED is lower than 0, it would start from 16777215


That were a few things to change, but now we can jump higher than the screen Very Happy
(If you have any questions, please tell me!)
Before we can insert platforms, we need to understand how pointers and arrays work.
We can use L1 to L6 similar to Basic. Instead of L1(X) we write *{L1+X}

Code:
[i]TEST
0→*{L1}
5→*{L1+1}

ClrHome
Disp *{L1}
Disp *{L1+1}
Pause


This seems a bit strange now, but I will explain it:
Each of L1 to L6 has a size limit of 2000 bytes.
One byte can hold numbers from 0 to 255.
Two bytes can hold numbers from 0 to 55535.
Three bytes can hold numbers from 0 to 16777215, so the variables are three byte numbers.

To write into one byte you use *{L1+X}
To write into two bytes you use **{L1+X}
To write into three bytes you use ***{L1+X}

Here's an example

Code:
[i]TEST
8→*{L1}
589→**{L1+1}
348927→***{L1+3}
558927→***{L1+6}


ClrHome
Disp *{L1}
Disp **{L1+1}
Disp ***{L1+3}
Disp {L1+6}  // instead of ***{L1+X} you can also write {L1+X}
Pause

You have to be careful to overwrite nothing: The first one uses the 0th byte; the second one uses byte 1 and 2, the third one 3 to 5 and the fourth one 6 to 8.


If we want to use more than 6 arrays or more than 2000 bytes you can also allocate memory:

Code:
[i]TEST
Alloc(3000)→ARRAY  // now we can use 3000 bytes instead of 2000
8→*{ARRAY}
589748→{ARRAY+1}

ClrHome
Disp *{ARRAY}
Disp {ARRAY+1}
Pause


ARRAY and L1 are pointers. This means they hold the number of the byte you want read.
For example, ARRAY could be a pointer to the 13648278th byte in your RAM. So ARRAY would be 13648278.
With *{ARRAY} you can read it, with *{ARRAY+1} you read the next byte. (You could also write *{13648278} and *{13648279}, but that's no good way.)
A short digression:
In the beginning I said we can't use negative numbers, but that's not completely true.
We can use negative numbers, but only for addition, subtraction and multiplication. Here are a few examples:
If a number is too high, it starts from 0 again; so we always have the remainder of x/16777216
(16777216 = 256³; three bytes)


"-5 + 7"
-5 is 16777211 (256³ - 5) and 7 is still 7.
Our new therm is: 16777211+7 = 16777218
16777218 is too high, so it means 2 (remainder(16777218, 256³) = 2)

"-5 + -3"
-5 is 16777211, -3 is 16777213
16777211 + 16777213 = 33554424
remainder(33554424, 256³) = 16777208 means -8

"-2 * 3"
means 16777214 * 3 = 50331642
remainder(50331642, 256³) = 16777210; means -6

"-2 * -3"
remainder(16777214 * 16777213, 256³) = 6

"-10 / 5"
means 16777206 / 5 = 3355441 ! Dividing doesn't work!

Comparisons do not work either:
"-5 < 4" (true)
means: "16777211 < 4" (false)
You could write: "-5 +10 < 4 +10" (true)


"max(" and "min(" also doesn't work; that's why I wrote max(SPEED,1)-1 instead of max(SPEED-1,0)

Maybe I'll talk more about that later (for example about "cos(" and "sin(" ) but I think that would be too much for now.
The last two posts were a bit hard to understand, but when you understand arrays and pointers we can go on.

At first, we will create one platform:
Code:
[i]DJUMP
det(0)
160→PX
200→PY
45→SPEED

// We store all variables for the platform in an array
Alloc(4)→PLATF
160→**{PLATF}   // position x (we need two bytes because x can be up to 320)
200→**{PLATF+2}   // position y (same goes for y)


det(43,0,0,320,240)
Repeat getKey(15)
det(5,255)
det(36,**{PLATF},**{PLATF+2},40,10)  // draw our new platform

det(2,7)
det(36,PX-15,340-PY-40,30,40)
det(10)


max(SPEED,1)-1→SPEED/3+PY-10→PY
If PY<100
70→SPEED
100→PY
End

If getKey(2):PX-3→PX:End
If getKey(3):PX+3→PX:End
End
det(1)


We have to change the center and "the coordinate system"

Code:
det(36,**{PLATF}-20,340-**{PLATF+2},40,10)



Let's insert a few more platforms:

Code:
[i]DJUMP
det(0)
160→PX
200→PY
45→SPEED

Alloc(40)→PLATF     // We create 10 platforms so we need to allocate 40 bytes.
For(Z,0,9)
PLATF+Z*4→ID    // Four bytes for each platform...
randInt(25,295)→**{ID}   // They shouldn't be all at the same place
130+Z*35→**{ID+2}
End


det(43,0,0,320,240)
Repeat getKey(15)
det(5,255)
det(2,237)  // we draw them in another color
For(Z,0,9)
PLATF+Z*4→ID
det(36,**{ID}-20,340-**{ID+2},40,10)
End

det(2,7)
det(36,PX-15,340-PY-40,30,40)
det(10)


max(SPEED,1)-1→SPEED/3+PY-10→PY
If PY<100
70→SPEED
100→PY
End

If getKey(2):PX-3→PX:End
If getKey(3):PX+3→PX:End
End
det(1)


Now we have to add the intersection.
We can do this by checking if (PX,PY) is inside the platform.

Code:
[i]DJUMP
det(0)

Lbl CREATE VARIABLES  // we can use labels to structure our source code
160→PX
200→PY
45→SPEED

Alloc(40)→PLATF
For(Z,0,9)
PLATF+Z*4→ID
randInt(25,295)→**{ID}
130+Z*35→**{ID+2}
End



Lbl GAME LOOP
det(43,0,0,320,240)
Repeat getKey(15)

det(5,255)
det(2,237)
For(Z,0,9)
PLATF+Z*4→ID
det(36,**{ID}-20,340-**{ID+2},40,10)

If PX+15>=**{ID}-20 and PX-15<= **{ID}+20 and PY<=**{ID+2} and PY>=**{ID+2}-10   // intersection check
53→SPEED
**{ID+2}→PY
End
End

det(2,7)
det(36,PX-15,340-PY-40,30,40)
det(10)




max(SPEED,1)-1→SPEED/3+PY-10→PY
If PY<100
70→SPEED
100→PY
End

If getKey(2):PX-3→PX:End
If getKey(3):PX+3→PX:End
End
det(1)


We don't need the ground bounce anymore...

Code:
[i]DJUMP
det(0)

Lbl CREATE VARIABLES
160→PX
60→PY  // we want to jump into the screen
60→SPEED

Alloc(40)→PLATF
For(Z,0,9)
PLATF+Z*4→ID
randInt(25,295)→**{ID}
130+Z*35→**{ID+2}
End
160→**{PLATF}  // the first platform should be in the middle



Lbl GAME LOOP
det(43,0,0,320,240)
Repeat getKey(15) or PY<50  // quits if we are too deep
det(5,255)
det(2,237)
For(Z,0,9)
PLATF+Z*4→ID
det(36,**{ID}-20,340-**{ID+2},40,10)

If PX+15>=**{ID}-20 and PX-15<= **{ID}+20 and PY<=**{ID+2} and PY>=**{ID+2}-10
max(53,SPEED)→SPEED   // we only want to speed up
**{ID+2}→PY
End
End


det(2,7)
det(36,PX-15,340-PY-40,30,40)
det(10)



max(SPEED,1)-1→SPEED/3+PY-10→PY
If getKey(2):PX-3→PX:End
If getKey(3):PX+3→PX:End
End
det(1)
Now we insert the camera movement and that we can't jump out of the screen.

Code:
[i]DJUMP
det(0)

Lbl CREATE VARIABLES
160→PX
60→PY
60→SPEED

Alloc(40)→PLATF
For(Z,0,9)
PLATF+Z*4→ID
randInt(25,295)→**{ID}
130+Z*35→**{ID+2}
End
160→**{PLATF}



Lbl GAME LOOP
det(43,0,0,320,240)
Repeat getKey(15) or PY<50

0→CAMERA:If PY>220:4→CAMERA:End    // calculate camera movement
PY-CAMERA→PY   // move rectangle


det(5,255)
det(2,237)
For(Z,0,9)
PLATF+Z*4→ID
**{ID+2}-CAMERA→**{ID+2}     // move platforms
det(36,**{ID}-20,340-**{ID+2},40,10)

If PX+15>=**{ID}-20 and PX-15<= **{ID}+20 and PY<=**{ID+2} and PY>=**{ID+2}-10
max(53,SPEED)→SPEED
**{ID+2}→PY
End
End


det(2,7)
det(36,PX-15,340-PY-40,30,40)
det(10)



max(SPEED,1)-1→SPEED/3+PY-10→PY
If getKey(2):PX-3→PX:End
If getKey(3):PX+3→PX:End
remainder(PX+275,290)+15→PY   // we don't want to be able to jump out of the screen
End
det(1)


The line "remainder(PX+275,290)+15→PY" means the following:
Our screen is 320 pixel width, minus our rectangle width it's 290.
So we can use: remainder(PX,290)→PX
Now every time we jump out of the screen we come in on the other side.

But we have to shift that "border" 15 pixels: remainder(PX-15,290)+15→PX
"PX-15" could be a negative number, so we write:
remainder(PX+290-15,290)+15→PY (same as: remainder(PX+275,290)+15→PY)


Our camera also works, but we could make it a bit better...

Code:
max(PY-220,0)→CAMERA

Well... we have to write it a bit different because PY-200 could be a negative number:

Code:
max(PY,220)-220→CAMERA

That's better, but we want to slow it down.

Code:
max(PY,220)-220→A
A/30→CAMERA

We could use also the SPEED in our calculation, so we can't jump out of the screen.

Code:
max(PY,220)-220→A
SPEED*A/30→CAMERA

We try different numbers out until it is good...

Code:
[i]DJUMP
det(0)

Lbl CREATE VARIABLES
160→PX
60→PY
60→SPEED

Alloc(40)→PLATF
For(Z,0,9)
PLATF+Z*4→ID
randInt(25,295)→**{ID}
130+Z*35→**{ID+2}
End
160→**{PLATF}



Lbl GAME LOOP
det(43,0,0,320,240)
Repeat getKey(15) or PY<50

Lbl CAMERA
max(PY,220)-220→A     // calculate camera movement
SPEED*A/300→CAMERA
max(130,PY)-PY→A     // the camera also should be alble to move downwards (maximal 8pxl per frame)
If A and SPEED<30:0-min(A/4,8)→CAMERA:End
PY-CAMERA→PY


det(5,255)
det(2,237)
For(Z,0,9)
PLATF+Z*4→ID
**{ID+2}-CAMERA→**{ID+2}
det(36,**{ID}-20,340-**{ID+2},40,10)

If PX+15>=**{ID}-20 and PX-15<= **{ID}+20 and PY<=**{ID+2} and PY>=**{ID+2}-10
max(53,SPEED)→SPEED
**{ID+2}→PY
End
End


det(2,7)
det(36,PX-15,340-PY-40,30,40)
det(10)



max(SPEED,1)-1→SPEED/3+PY-10→PY
If getKey(2):PX-3→PX:End
If getKey(3):PX+3→PX:End
remainder(PX+275,290)+15→PY
End
det(1)

Feel free to ask if you have any questions.
Now we want the platforms to respawn when they are too deep.
Code:
[i]DJUMP
det(0)

Lbl CREATE VARIABLES
160→PX
60→PY
60→SPEED
0→SCORE   // We could also insert a score

Alloc(40)→PLATF
For(Z,0,9)
PLATF+Z*4→ID
randInt(25,295)→**{ID}
130+Z*35→**{ID+2}
End
160→**{PLATF}



Lbl GAME LOOP
det(74,2,2)    // change font size
det(43,0,0,320,240)
Repeat getKey(15) or PY<50

Lbl CAMERA
max(PY,220)-220→A
SPEED*A/300→CAMERA
SCORE+CAMERA→SCORE     // increase score

max(130,PY)-PY→A
If A and SPEED<30:0-min(A/4,8)→CAMERA:End
PY-CAMERA→PY


det(5,255)
det(2,237)
For(Z,0,9)
PLATF+Z*4→ID
**{ID+2}-CAMERA→**{ID+2}
det(36,**{ID}-20,340-**{ID+2},40,10)

If PX+15>=**{ID}-20 and PX-15<= **{ID}+20 and PY<=**{ID+2} and PY>=**{ID+2}-10
max(53,SPEED)→SPEED
**{ID+2}→PY
End

If **{ID+2}>50000   // When the platform is too deep it is at 16777215 instead of -1
PLATF+remainder(Z+9,10)*4→A   // gets the pointer for highest platform (platform Z-1)
randInt(25,295)→**{ID}     // new position x
**{A+2}+35→**{ID+2}    // respawn it 35 pixels above platform A
End
End


det(2,7)
det(36,PX-15,340-PY-40,30,40)

det(19,5,5)    // set text xy
det(15,SCORE/100,1)    // writes SCORE/100; at least 1 char
det(10)



max(SPEED,1)-1→SPEED/3+PY-10→PY
If getKey(2):PX-3→PX:End
If getKey(3):PX+3→PX:End
remainder(PX+275,290)+15→PY
End
det(1)
To insert sprites, we will use a subprogram:
Code:
[i]DJUMP
det(0)
AsmComp(DJUMPSPR)  // name of subprogram
...


And this is DJUMPSPR:

Code:
Alloc(9)→SPR  // we want to save the sprite-pointer into a string

[i] Player
DefineSprite(30,40,"FFFFFFFFFFFFFFFFFFFF00000000000000000000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF000000E4E4E4E4E5E6E6E6E6E6000000FFFFFFFFFFFFFFFFFFFFFFFF0000E4E4E4E5E6E6E6E6E6E6E6E6E6E6E6E60000FFFFFFFFFFFFFFFFFF00E4E4E4E5E6E6E6E6E6E6E6E6E6E5E4E4E4E6E6E600FFFFFFFFFFFFFF00E4E4E4E5E6E6E6E6E6E6E6E6E6E6E6E6E6E5E4E4E6E600FFFFFFFFFF00E4E4E4E5E6E6E6E6E6E6E6E6E6E6E6E6E6E6E6E6E5E4E6E600FFFFFFFF00E4E4E4E5E6E6000000E6E6E6E6E6E6000000E6E6E6E5E4E600FFFFFF00E4E4E4E5E6E6009F9F9F00E6E6E6E6009F9F9F00E6E6E5E4E6E600FFFF00E4E4E4E5E6E6009F000000E6E6E6E60000009F00E6E6E6E5E4E600FFFF00E4E4E4E5E6E6009F000000E6E6E6E60000009F00E6E6E6E5E4E600FF00E4E4E4E5E6E6E6E6000000E6E6E6E6E6E6000000E6E6E6E6E5E4E6E60000E4E4E4E5E6E6E6E6E6E6E6E6E6E6E6E6E6E6E6E6E6E6E6E6E6E5E4E60000E4E4E4E5E6E6E6E6E6E6E6E6E6E6E6E6E6E6E6E6E6E6E6E6E6E5E4E60000E4E4E4E5E6E6E6E6E6E6E6E6E6E6E6E6E6E6E6E6E6E6E6E6E6E5E4E60000E4E4E4E5E6E6E6E6E6E6E6E6E6E6E6E6E6E6E6E6E6E6E6E6E6E5E4E60000E4E4E4E5E6E6E6E6E6E6E6E6E6E6E6E6E6E6E6E6E6E6E6E6E6E5E4E60000E4E4E4E5E6E6E6E6E6E6E6E6E6E6E6E6E6E6E6E6E6E6E6E6E6E5E4E60000E4E4E4E5E6E6E6E6E6E6E6E6E6E6E6E6E6E6E6E6E6E6E6E6E6E5E4E60000E4E4E4E5E6E6E6E6E6E6E6E6E6E6E6E6E6E6E6E6E6E6E6E6E6E5E4E60000E4E4E4E5E6E6E6E6E6E6E6E6E6E6E6E6E6E6E6E6E6E6E6E6E6E5E4E60000E4E4E4E4E5E6E6E6E6E6E6E6E6E6E6E6E6E6E6E6E6E6E6E6E5E4E4E6000000E4E4E4E4E4E4E4E4E4E4E4E4E4E4E5E6E6E6E6E6E6E6E6E6E6E60000002A0000000000000000000000000000000000000000000000000000FF00002A2A2A00FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF00002A00FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF2A00FF00002A00FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF2A00FF00002A00FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF2A00FF00002A00FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF2A00FF00002A2A00FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF2A2A00FF00002A2A2A00FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF0000FFFF0000002A2A2A2A2A2A00FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF00000000000000000000000000000000000000000000000000000000000000FF000000FFFFFFFFFF000000FFFFFFFFFF000000FFFFFFFFFF000000FFFFFF002A00FFFFFFFFFF002A00FFFFFFFFFF002A00FFFFFFFFFF002A00FFFFFF4A2A00FFFFFFFFFF2A2A00FFFFFFFFFF2A2A00FFFFFFFFFF2A2A00FFFFFF4A2A00FFFFFFFFFF2A2A00FFFFFFFFFF2A2A00FFFFFFFFFF2A2A00FFFFFF4A2A000000FFFFFF2A2A000000FFFFFF2A2A000000FFFFFF2A2A000000FF4A2A2A2A2A00FFFF2A2A2A2A2A00FFFF2A2A2A2A2A00FFFF2A2A2A2A2A004A2A2A2A2A00FFFF2A2A2A2A2A00FFFF2A2A2A2A2A00FFFF2A2A2A2A2A00FF00000000FFFFFFFF00000000FFFFFFFF00000000FFFFFFFF00000000FF")→{SPR}
// "DefineSprite(" creates a Sprite and returns a pointer (3 bytes) which we store in {SPR}.
// You can imagine a sprite like an array which holds all needed information.

// We need two sprites for the player (both directions).
DefineSprite(30,40)→{SPR+3}  // At first we need to "allocate" memory and write the size into the "new array"
det(64,{SPR},{SPR+3})   // flips {SPR} and saves it into {SPR+3}


[i] Platform
DefineSprite(40,10,"FFFFFF00000000000000000000000000000000000000000000000000000000000000000000FFFFFFFFFF00EDEDEDEDEDEDEDEDEDEDEDEDEDEDEDEDEDEDEDEDEDEDEDEDEDEDEDEDEDEDEDEDEDED00FFFFFF00EDEDEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEDED00FF00EDEDEEEDEDEDEDEDEDEDEDEDEDEDEDEDEDEDEDEDEDEDEDEDEDEDEDEDEDEDEDEDEDEDEDEEEDED0000EDEDEDEDEDEDEDEDEDEDEDEDEDEDEDEDEDEDEDEDEDEDEDEDEDEDEDEDEDEDEDEDEDEDEDEDEDED0000EDEEEEEDEDEDEDEDEDEDEDEDEDEDEDEDEDEDEDEDEDEDEDEDEDEDEDEDEDEDEDEDEDEDEDEEEEED0000EDEDEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEDED00FF00EDEDEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEDED00FFFFFF00EDEDEDEDEDEDEDEDEDEDEDEDEDEDEDEDEDEDEDEDEDEDEDEDEDEDEDEDEDEDEDEDEDED00FFFFFFFFFF00000000000000000000000000000000000000000000000000000000000000000000FFFFFF")→{SPR+6}



Now we insert the sprites:

Code:
[i]DJUMP
det(0)
AsmComp(DJUMPSPR)


Lbl CREATE VARIABLES
160→PX
60→PY
60→SPEED
0→DIRECTION     // direction for the sprite (0 is right 3 is left)
0→SCORE

Alloc(40)→PLATF
For(Z,0,9)
PLATF+Z*4→ID
randInt(25,295)→**{ID}
130+Z*35→**{ID+2}
End
160→**{PLATF}



Lbl GAME LOOP
det(74,2,2)
det(75,255)  // set transparent color for the sprites
det(43,0,0,320,240)
Repeat getKey(15) or PY<50

Lbl CAMERA
max(PY,220)-220→A
SPEED*A/300→CAMERA
SCORE+CAMERA→SCORE

max(130,PY)-PY→A
If A and SPEED<30:0-min(A/4,8)→CAMERA:End
PY-CAMERA→PY


det(5,255)
det(2,237)
For(Z,0,9)
PLATF+Z*4→ID
**{ID+2}-CAMERA→**{ID+2}
det(58,{SPR+6},**{ID}-20,340-**{ID+2})   // draw platform sprite

If PX+15>=**{ID}-20 and PX-15<= **{ID}+20 and PY<=**{ID+2} and PY>=**{ID+2}-10
max(53,SPEED)→SPEED
**{ID+2}→PY
End

If **{ID+2}>50000
PLATF+remainder(Z+9,10)*4→A
randInt(25,295)→**{ID}
**{A+2}+35→**{ID+2}
End
End


det(2,7)
det(58,{SPR+DIRECTION},PX-15,300-PY)   // draw player sprite

det(19,5,5)
det(15,SCORE/100,1)
det(10)



max(SPEED,1)-1→SPEED/3+PY-10→PY
If getKey(2):PX-3→PX:3→DIRECTION:End   // change direction
If getKey(3):PX+3→PX:0→DIRECTION:End
remainder(PX+275,290)+15→PY
End
det(1)


There's one thing left: The trousers are transparent, so we can use a colored rectangle to give it a color.

Code:
...
det(2,7)
det(36,PX-15,321-PY,30,10)    // insert the rectangle
det(58,{SPR+DIRECTION},PX-15,300-PY)
...

To create your own sprites, you can use my Designer, which also contains a color picker and key values.
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 1 of 1
» All times are UTC - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement