i have been wondering how to mkae the heightmap code work with my current fps setup. i found the heightmap code in some other tutorial then the FPS one i was using, but i thought i could figure out how to apply it since i figured out how to add jumping/gravity.
heightmap:
mapsize =500 `TERRAIN SIZE.
segments= 64 `# OF SEGMENTS IN MATRIX
make matrix 1,mapsize,mapsize,segments,segments `MATRIX TO MOLD INTO TERRAIN
load image "heightmap.bmp",1 `HEIGHTMAP
size=128 `HEIGHTMAP DEMENSION
load image "sand.bmp",2 `TERRAIN TEXTURE
prepare matrix texture 1,2,1,1 `APPLY TEXTURE TO TERRAIN
cls `RESET SCREEN
paste image 1,0,0 `PASTE IMAGE TO SCREEN
modifier=size/segments `Since our image has more pixels than we have segments, we need
`to make sure we can account for that difference, by getting every
`height after 2 pixels(256/128=2) rather than every pixel.
for x = 0 to segments
for y = 0 to segments
pixelcolor#=rgbr(point(x*modifier,y*modifier)) `This will return the color value.
set matrix height 1,x,y,pixelcolor#/6 `With the color value, we then set the
next x `matrix height according to that color.
next y
update matrix 1 `Finally, we must update our matrix to show the changes that've taken
`place.
FPS (thanks ruccus):
`FPS GAME
`CREATED BY TIKKI
`STARTED ON 7/31/2007
`BASIC SYSTEM SETUP
SYNC ON:SYNC RATE 0:HIDE MOUSE
`PLAYER
MAKE OBJECT SPHERE 1,10:COLOR OBJECT 1,RGB(000,255,000)
HIDE OBJECT 1
`ENEMY
MAKE OBJECT SPHERE 2,50:COLOR OBJECT 2,RGB(255,000,000):POSITION OBJECT 2,130,0,0
`VULTURE
LOAD OBJECT "VULTURE.X",3:POSITION OBJECT 3,0,0,150
`AMMO BOX
MAKE OBJECT BOX 4,15,10,50:COLOR OBJECT 4,RGB(000,255,255):POSITION OBJECT 4,-40,0,0
`GROUND
MAKE OBJECT PLAIN 5,300,300
ROTATE OBJECT 5,90,0,0
POSITION OBJECT 5,0,-20,0
`COLLISION DETECTOR FOR GUN
MAKE OBJECT PLAIN 9999,1,1 `MAKES THE DETECTOR
MAKE MESH FROM OBJECT 1,9999 `WE NEED A MESH TO CREATE A LIMB
DELETE OBJECT 9999 `DELETES THE UNNECESSARY OBJECT. ITS NOT NECESSARY BECAUSE WE RECREATED IT IN MESH FORM
ADD LIMB 1,1,1 `ADDS A LIMB (LIKE AN ARM, LEG, HEAD, ETC.
OFFSET LIMB 1,1,0,0,500 `THE DISTANCE TO CHECK BETWEEN
DELETE MESH 1 `DELETES THE NOT NEEDED MESH, SINCE WE CONVERTED IT INTO A LIMB
HIDE LIMB 1,1 `HIDES LIMB 1 ON OBJECT 1
`COLLISION DETECTOR FOR GROUND
MAKE OBJECT PLAIN 9998,1,1 `MAKES THE DETECTOR
POSITION OBJECT 9998, OBJECT POSITION X(1),OBJECT POSITION Y(1)-500,OBJECT POSITION Z(1)
`SOME VARIABLES
ENEMYHP#=100
AMMO#=100
MAXAMMO#=110
CLIPS#=3
MAXCLIPS#=3
RELOAD#=0
gravity# = 0
gravrate# = 0.5
jumping = 0
jumpspeed# = -5
groundDistance# = 0
onGround = 1
x# = 0
y# = 0
z# = 0
`MOVEMENT
DO
POSITION CAMERA OBJECT POSITION X(1),OBJECT POSITION Y(1),OBJECT POSITION Z(1)`sets the camera at the player
`ARROWS
IF UPKEY()=1 THEN MOVE OBJECT 1,2
IF DOWNKEY()=1 THEN MOVE OBJECT 1,-2
IF RIGHTKEY()=1 THEN MOVE OBJECT RIGHT 1,2
IF LEFTKEY()=1 THEN MOVE OBJECT LEFT 1,2
`WASD MOVEMENT
IF KEYSTATE(17)=1 THEN MOVE OBJECT 1,2
IF KEYSTATE(31)=1 THEN MOVE OBJECT 1,-2
IF KEYSTATE(30)=1 THEN MOVE OBJECT LEFT 1,2
IF KEYSTATE(32)=1 THEN MOVE OBJECT RIGHT 1,2
`JUMP/GRAVITY
`Store player positions
x# = OBJECT POSITION X(1)
y# = OBJECT POSITION Y(1)
z# = OBJECT POSITION Z(1)
`Get distance to ground
groundDistance# = INTERSECT OBJECT(5,x#,y#,z#,x#,-2000,z#)
IF groundDistance# <= OBJECT SIZE Y(1) / 2
`If theyre on or below the ground, reset their data, and reposition them on the surface.
onGround = 1
gravity# = 0
jumping = 0
MOVE OBJECT UP 1,(OBJECT SIZE Y(1) / 2)-groundDistance#
ELSE
onGround = 0
ENDIF
`Jump Routine
IF onGround = 1 AND jumping = 0 AND SPACEKEY() = 1
jumping = 1
gravity# = jumpspeed#
ENDIF
`Handle Gravity
MOVE OBJECT DOWN 1,gravity#
INC gravity#,gravrate#
`DETECT IF MOUSE IS CLICKED, AND ANYTHING IS BETWEEN US
IF MOUSECLICK()=1 AND KEYSTATE(19)=0 AND Ammo#>0 AND RELOAD#=0
DEC Ammo#,1`IF LEFT MOUSE IS PRESSED, "R" IS NOT PRESSED, AMMO IS NOT EMPTY, AND YOU ARE NOT RELOADING, SHOOT THE BULLET
IF OBJECT EXIST(2)=1 AND Ammo#>0
IF INTERSECT OBJECT (2, LIMB POSITION X(1,1), LIMB POSITION Y(1,1), LIMB POSITION Z(1,1), OBJECT POSITION X(1),OBJECT POSITION Y(1), OBJECT POSITION Z(1))>0
DEC EnemyHP#,1
ENDIF : ENDIF : ENDIF
`ENEMY HP
IF EnemyHP#=0 AND OBJECT EXIST(2)=1
DELETE OBJECT 2
ENDIF
`RELOAD
IF MOUSECLICK()=0 AND KEYSTATE(19)=1 AND AMMO#<MAXAMMO# AND CLIPS#>0 THEN RELOAD#=1
IF RELOAD#=1 THEN INC RTIME#,.01
IF RTIME#>=1 THEN AMMO#=MAXAMMO# : DEC CLIPS#,1 : RTIME#=0 : RELOAD#=0
IF CLIPS#>MAXCLIPS# THEN CLIPS#=MAXCLIPS#
`DRAW TEXT
TEXT 10,10, "AMMO: " +Str$(AMMO#)+"/"+Str$(MAXAMMO#)
TEXT 10,24, "AMMO CLIPS: " +Str$(CLIPS#)+"/"+Str$(MAXCLIPS#)
TEXT 10,36, "RELOADING: " +Str$(RELOAD#)
TEXT 10,50, "RELOAD TIME: " +STR$(RTIME#)+"/1"
TEXT 10,64,"ENEMY HP: " +Str$(ENEMYHP#)
CIRCLE SCREEN WIDTH()/2,SCREEN HEIGHT()/2,5 `CROSSHAIR
`CHECK COLLISION WITH AMMO BOX
IF OBJECT EXIST(4)
IF INTERSECT OBJECT (4, OBJECT POSITION X(1),OBJECT POSITION Y(1)-25,OBJECT POSITION Z(1),OBJECT POSITION X(1),OBJECT POSITION Y(1),OBJECT POSITION Z(1))>0
INC CLIPS#,1
INC AMMO#,(MAXAMMO#-AMMO#)
DELETE OBJECT 4
ENDIF : ENDIF
REMSTART
MOUSE LOOK
Time to explain. Ok, first we are defining two variables, CAMX# and CAMY#.
We are making these variables equal the integers the MOUSEMOVEX() and MOUSEMOVEY() commands return.
These two MOUSEMOVE commands return the difference between the current and last position of the mouse,
allowing us to determine if it’s moving left, right, up or down.
We then multiply that value by .1 since the speed would be too great if we didn’t.
Next, we check if the CAMX values are greater than 90 or 270 and less than 135 or 225.
These IF statements restrict the player from fully rotating the camera all the way around, to add some realism.
Finally, we rotate the camera and object on the appropriate axis by the variables.
REMEND
CAMY#=CAMY#+MOUSEMOVEX()*.1
CAMX#=CAMX#+MOUSEMOVEY()*.1
IF CAMX#>90 AND CAMX#<135 THEN CAMX#=90
IF CAMX#>270 AND CAMX#<225 THEN CAMX#=90
YROTATE CAMERA CAMY#
XROTATE CAMERA CAMX#
YROTATE OBJECT 1,CAMY#
XROTATE OBJECT 1,CAMX#
SYNC
LOOP
the only problen i see is this: groundDistance# = INTERSECT OBJECT(5,x#,y#,z#,x#,-2000,z#)
because a matrix isnt an OBJECT sooooo, its not checking for the matrixes number. how could i work around that? will i need a whole new jumping/gravity code?
i tried SPARKY's .dll, but after i installed it EXACTLY as the readme said, still NO commands work. i get errors.
thanks!
RAWR!