TGC Codebase Backup



Water with reflections by Attila

20th Jun 2005 17:16
Summary

This example show how to make water with a ball swimming on it and giving reflections. The rar-file contains all neccessary media and the source code.



Description

The programm creates a pool with water and ball floating on it. The ball moves slowly on the water and is reflected in the water.



Code
                                    ` This code was downloaded from The Game Creators
                                    ` It is reproduced here with full permission
                                    ` http://www.thegamecreators.com
                                    
                                    Rem Project: _reflections
rem (c) 2005 - R. Bannier
Rem Created: 20.06.2005

set display mode 1024,768,16

sync on
sync rate 0
set ambient light 30
backdrop on
color backdrop rgb(128,128,255)
hide mouse

make object box 1, 100,1,100
load image "water2.bmp",1
texture object 1,1
ghost object on 1
position object 1, 50,0,50

make object box 2, 100,1,100
load image "water1.bmp",2
texture object 2,2
ghost object on 2
position object 2, 50,-.1,50

load object "horizont.x",3
load image "horizont.bmp",3
texture object 3,3
scale object 3, 8000,8000,8000
position object 3, 50,-40,50

make matrix 11, 120,120,4,4
load image "plates.bmp",11
prepare matrix texture 11,11,1,1
set matrix wireframe off 11
position matrix 11, 0,-15,0

make matrix 2, 100,100,2,2
load image "water2.bmp",2
prepare matrix texture 2,2,1,1
set matrix wireframe off 2
position matrix 2, 0,-6,0
ghost matrix on 2

make matrix 3, 100,100,2,2
load image "water1.bmp",3
prepare matrix texture 3,3,1,1
set matrix wireframe off 3
position matrix 3, 0,-5,0
ghost matrix on 3

load image "ground.bmp",12
make object box 10, 25,10,120
position object 10, 0,0,50
texture object 10, 12

make object box 11, 25,10,120
position object 11, 100,0,50
texture object 11, 12

make object box 12, 100,10,25
position object 12, 50,0,0
texture object 12, 12

make object box 13, 100,10,25
position object 13, 50,0,100
texture object 13, 12

x#=70
z#=80
y#=2.6
r#=22
speed#=.05

load image "ball.bmp",20
make object sphere 20, 5
texture object 20,20
position object 20, x#,y#,z#
yrotate object 20,180

make object sphere 21, 5
texture object 21,20
position object 21, x#,-1*y#,z#
ghost object on 21
yrotate object 21,180

`              Lights
make light 1
set spot light 1, 15,30
position light 1,20,50,110
color light 1,255,255,255

make light 2
set spot light 2, 15,30
position light 2,20,50,110
color light 2,-255,-255,-255

position camera 25,10,75
point camera x#,0,z#

while -1
   scroll object texture 1, .0005, 0
   scroll object texture 2, -.0002, 0

   scroll object texture 20, .005, 0
   scroll object texture 21, .005, 0

   nz#=z#
   nx#=x#
   dz#=cos(r#)
   dy#=cos(90-r#)
   z#=nz#+Speed#*dz#
   x#=nx#+Speed#*dy#

   position object 20, x#,y#,z#
   position object 21, x#,-1*y#,z#
   if x# < 15 or x# > 85 or z# < 15 or z# > 85
      r#=r#+75
   endif
   if r# > 360
      r#=r#-360
   endif
   point camera x#,0,z#
   point light 1,x#,0,z#
   point light 2,x#,0,z#
   sync
endwhile
end