### Author Topic: Grammer Routines  (Read 2362 times)

0 Members and 1 Guest are viewing this topic.

#### Yeong

• Not a bridge
• LV12 Extreme Poster (Next: 5000)
•            • • Posts: 3739
• Rating: +278/-12
• Survivor of Apocalypse ##### Grammer Routines
« on: January 26, 2012, 06:39:12 pm »
Post useful routines here. I'll start first. This is the tilemapping routine/walking routine with scrolling map. This is barely optimized, but have fun. Maybe useful for the RPG programming, you know. Code: [Select]
://M=Map data  T=Tile data  W'=Width of Tilemap://H'= Height of the Tilemap  X'= Tilemap X offset://Y'= Tilemap Y offset  X= Sprite X coord(in 8s)://Y=Sprite Y coord  S= Sprite data://F'= Sprite direction (sprite data is in order of://down, up, left, and right)://T'= Tile # (from the map data. Good for handling events)::.TILE:ClrDraw:Pt-Change(0,M,T,W',X',Y',0:Pt-On(0,S+F'*8,Y*8,X,1,8:Y+Y':*W':+X'+X:→T':DispGraph:End::.MOVE:getKey→H:F':If H=1:0:If H=4:1:If H=2:2:If H=3:3:→F':0→G:X':If H=2 *!(M+T'-1) *X' *X=6  ://M+T'-1 is the tile # character will stand if possible. (order your tiles)://so if I put (M+T'-1)<4, you'll move when tile number is 0~3.:1→G X'-1:If H=3 *!(M+T'+1) *X=6 *W'≠X'+12:1→G X'+1:If W'<X'+12:X':→X':X:If H=2 *!(M+T'-1) *!G:-1:If H=3 *!(M+T'+1) *!G:+1:If  >11:X:→X:0→G:Y':If H=4 *!(M+T'-W') *Y' *Y=4:1→G Y'-1→Y':If H=1 *!(M+T'+W') *Y=4 *H'≠Y'+8:1→G Y'+1→Y':If H'<Y'+8:Y':→Y':Y:If H=4 *!(M+T'-W') *!G:-1:If H=1 *!(M+T'+W') *!G:+1:If  >7:Y:→Y:End
« Last Edit: January 26, 2012, 06:49:35 pm by TBO_Yeong »
Sig wipe!

#### Xeda112358

• they/them
• Moderator
• LV12 Extreme Poster (Next: 5000)
•            • • Posts: 4659
• Rating: +718/-6
• Calc-u-lator, do doo doo do do do. ##### Re: Grammer Routines
« Reply #1 on: January 29, 2012, 10:43:22 am »
A very simple routine for moving an object in relation to key presses looks something like this:
Code: [Select]
X+geKey(3      ;right arrow-getKey(2      ;leftArrowIf <96         ;tests if it is in bounds→XY+geKey(1      ;Down arrow-getKey(4      ;Up ArrowIf <64→YThe reason for why If >95 works for both directions is because if X reaches 0 and is decremented, it becomes 65535. So  by testing If >95, you are checking for negative going off screen in both directions EDIT: Edited for optimisation « Last Edit: February 05, 2012, 09:16:02 pm by Xeda112358 »

#### Xeda112358

• they/them
• Moderator
• LV12 Extreme Poster (Next: 5000)
•            • • Posts: 4659
• Rating: +718/-6
• Calc-u-lator, do doo doo do do do. ##### Re: Grammer Routines
« Reply #2 on: February 01, 2012, 09:49:03 pm »
Here is a small routine for adding a 16-bit number to a 32-bit number (that does not exceed maximum or minimum value):

To add GG'+B (does not exceed FFFFFFFF):
Code: [Select]
G'+B→G'G+Ɵ'If Ɵ'         ;this means 32-bits were exceeded D:-1→G'         ;This is negative 1, not minus 1→GTo subtract without going below zero:
Code: [Select]
G'-B→G'G--Ɵ'       ;this is minus negative Ɵ'If Ɵ'       ;this means 32-bits were exceeded D:0→G'→G