TGC Codebase Backup



snake 2d with 3d graphics by Antidote

8th Mar 2005 16:01
Summary

a 2d snake with enemy in 3d graphics



Description

this is basically just snake



Code
                                    ` This code was downloaded from The Game Creators
                                    ` It is reproduced here with full permission
                                    ` http://www.thegamecreators.com
                                    
                                    begin:

autocam off
level=1
time=10000
score=0

gosub _load_game
gosub _load_snake
gosub _load_enemy
gosub _load_blobs
gosub _make_map
gosub _set_collision_on
gosub _set_variables
gosub _load_sound
gosub _game_loop

_game_loop:

 sync on : hide mouse
 sync rate 60

 do

 position camera 0,280,0
 point camera 0,0,0

 x#=object position x(1)
 z#=object position z(1)

 move object 1, speed#
 gosub _move_enemy

 if speed#>2.0 then speed#=2.0

 if controlkey()=1 then turn_radius=8.0
 if controlkey()=0 then turn_radius=4.0

 if leftkey()=1 then ya#=wrapvalue(ya#-turn_radius) : gosub _enemy_ai
 if rightkey()=1 then ya#=wrapvalue(ya#+turn_radius) : gosub _enemy_ai

 gosub _turn

 gosub _collision
 gosub _tail_affect
 gosub _detect_defeat
 gosub _timer

 set cursor 500,1
 print "SCORE : ";score

 sync

 loop

_turn:
 ca#=curveangle(ca#, ya#, 15.0)
 yrotate object 1,ca#
return

_load_snake:
 make object cube 1,10
 color object 1,rgb(0,255,100)
 position object 1,0,5,0
return

_load_enemy:

  make object cube 2,10
  color object 2,rgb(255,0,100)

  position object 2, 0, 5, 160
  point object 2,object position x(1), 5, object position z(1)

return

_move_enemy:
 espeed#=level/2
 if object exist(2)=1 then move object 2,espeed#
 if espeed#>2.0 then espeed#=2.0
return

_load_blobs:
 for b=3 to 22
  make object sphere b,10
  color object b,rgb(255,255,0)
  disable object zdepth b
  bpos=rnd(400)-200
  if bpos<=0 then position object b,bpos+(level*10),0,rnd(200)-100
  if bpos>0 then position object b,bpos-(level*10),0,rnd(200)-100
 next b
return

_delete_blobs:
 for b=3 to 22
  if object exist(b)=1 then delete object b
 next b
return

_timer:
 set cursor 1,1
 print "TIME REMAINING : ";time
 dec time
 if time<=0 then end
return

_make_map:

 if matrix exist(1)=0 then make matrix 1,480,480,48,48
 position matrix 1,-240,0,-240

 for a=100 to 101
  if object exist(a)=0 then make object box a,600,0,20
  color object a,rgb(255,0,0)
 next a

 position object 100,0,5,160
 position object 101,0,5,-160

 for a=102 to 103
  if object exist(a)=0 then make object box a,20,0,300
  color object a,rgb(255,0,0)
 next a

 position object 102,220-level*10,5,0
 position object 103,-220+level*10,5,0

 if object exist(104)=0 then make object box 104,100,0,10
 position object 104,0,5,-20
 color object 104,rgb(0,100,255)

return

_set_collision_on:
 for c=1 to 200
   if object exist(c)=1 then set object collision on c
 next c
 return

_set_variables:
 length=4
 start_tail=400
 turn_radius=4.0
 speed#=0.5
return

_collision:

 if object exist(2)=1
  if object collision(1,2) then goto _death
 endif

 for a=100 to 103
  if object collision(1,a) then goto _death
 next a

 if object collision(1,3) then position object 3,600,0,0 : inc length,6 : inc speed#,0.2 : play sound 1 : inc score,10
 if object collision(1,4) then position object 4,600,0,0 : inc length,6 : inc speed#,0.2 : play sound 1 : inc score,10
 if object collision(1,5) then position object 5,600,0,0 : inc length,6 : inc speed#,0.2 : play sound 1 : inc score,10
 if object collision(1,6) then position object 6,600,0,0 : inc length,6 : inc speed#,0.2 : play sound 1 : inc score,10
 if object collision(1,7) then position object 7,600,0,0 : inc length,6 : inc speed#,0.2 : play sound 1 : inc score,10
 if object collision(1,8) then position object 8,600,0,0 : inc length,6 : inc speed#,0.2 : play sound 1 : inc score,10
 if object collision(1,9) then position object 9,600,0,0 : inc length,6 : inc speed#,0.2 : play sound 1 : inc score,10
 if object collision(1,10) then position object 10,600,0,0 : inc length,6 : inc speed#,0.2 : play sound 1 : inc score,10
 if object collision(1,11) then position object 11,600,0,0 : inc length,6 : inc speed#,0.2 : play sound 1 : inc score,10
 if object collision(1,12) then position object 12,600,0,0 : inc length,6 : inc speed#,0.2 : play sound 1 : inc score,10
 if object collision(1,13) then position object 13,600,0,0 : inc length,6 : inc speed#,0.2 : play sound 1 : inc score,10
 if object collision(1,14) then position object 14,600,0,0 : inc length,6 : inc speed#,0.2 : play sound 1 : inc score,10
 if object collision(1,15) then position object 15,600,0,0 : inc length,6 : inc speed#,0.2 : play sound 1 : inc score,10
 if object collision(1,16) then position object 16,600,0,0 : inc length,6 : inc speed#,0.2 : play sound 1 : inc score,10
 if object collision(1,17) then position object 17,600,0,0 : inc length,6 : inc speed#,0.2 : play sound 1 : inc score,10
 if object collision(1,18) then position object 18,600,0,0 : inc length,6 : inc speed#,0.2 : play sound 1 : inc score,10
 if object collision(1,19) then position object 19,600,0,0 : inc length,6 : inc speed#,0.2 : play sound 1 : inc score,10
 if object collision(1,20) then position object 20,600,0,0 : inc length,6 : inc speed#,0.2 : play sound 1 : inc score,10
 if object collision(1,21) then position object 21,600,0,0 : inc length,6 : inc speed#,0.2 : play sound 1 : inc score,10
 if object collision(1,22) then position object 22,600,0,0 : inc length,6 : inc speed#,0.2 : play sound 1 : inc score,10

 if object exist(2)=1
  if object collision(2,104) then delete object 2 : inc score,50
 endif
return

_tail_affect:

 make object cube start_tail,5
 color object start_tail,rgb(0,255,100)
 position object start_tail, x#, 5, z#

 inc start_tail
 if object exist(start_tail-length)=1 then delete object (start_tail-length)
return

_detect_defeat:
 if length>=124 then : level = level + 1 : gosub _delete_blobs : gosub _set_variables : gosub _load_blobs : length=4 : gosub _delete_enemy : gosub _load_enemy : position object 1,0,5,0 : gosub _delete_tail : gosub _make_map

_enemy_ai:
 if object exist(2)=1 then point object 2, x#, 5, z#
return

_delete_enemy:
 if object exist(2)=1 then delete object 2
return

_delete_tail:
 for t=399 to 10400
  if object exist(t)=1 then delete object t
 next t
 return

_load_sound:
 load sound "pop.wav",1
return

_load_game:
 set cursor 300,220
 print "SNAKE"
 suspend for key
return

_death:
 end