Calculator Community > Grammer
Grammer Routines
(1/1)
Yeong:
Post useful routines here. I'll start first. XD
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: ---://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
--- End code ---
Xeda112358:
A very simple routine for moving an object in relation to key presses looks something like this:
--- Code: ---
X+geKey(3 ;right arrow
-getKey(2 ;leftArrow
If <96 ;tests if it is in bounds
→X
Y+geKey(1 ;Down arrow
-getKey(4 ;Up Arrow
If <64
→Y
--- End code ---
The 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 :)
Xeda112358:
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: ---G'+B→G'
G+Ɵ'
If Ɵ' ;this means 32-bits were exceeded D:
-1→G' ;This is negative 1, not minus 1
→G
--- End code ---
To subtract without going below zero:
--- Code: ---G'-B→G'
G--Ɵ' ;this is minus negative Ɵ'
If Ɵ' ;this means 32-bits were exceeded D:
0→G'
→G
--- End code ---
Navigation
[0] Message Index
Go to full version