home *** CD-ROM | disk | FTP | other *** search
/ Programming Tool Box / SIMS_2.iso / tool / grafik / canimate / game.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1995-02-27  |  14.6 KB  |  449 lines

  1. VERSION 2.00
  2. Begin Form Form1 
  3.    Caption         =   "CANIMATE.VBX Sample Program"
  4.    ClientHeight    =   3465
  5.    ClientLeft      =   2685
  6.    ClientTop       =   1575
  7.    ClientWidth     =   6810
  8.    ForeColor       =   &H00000000&
  9.    Height          =   3990
  10.    Left            =   2625
  11.    LinkTopic       =   "Form1"
  12.    ScaleHeight     =   3465
  13.    ScaleWidth      =   6810
  14.    Top             =   1110
  15.    Width           =   6930
  16.    Begin Stage Stage1 
  17.       BackColor       =   &H00404040&
  18.       Height          =   3525
  19.       Interval        =   50
  20.       Left            =   -15
  21.       MaxDepth        =   0
  22.       Picture         =   GAME.FRX:0000
  23.       Playback        =   0   'False
  24.       PlaybackBufferSize=   0
  25.       Record          =   0   'False
  26.       Top             =   0
  27.       Width           =   6855
  28.       Begin CSPlayer BackTree 
  29.          CollideEvents   =   0   'False
  30.          CollideID       =   0
  31.          CycleEvents     =   0   'False
  32.          Cycling         =   0   'False
  33.          Frame           =   0
  34.          FrameRow        =   0
  35.          Height          =   1740
  36.          Interval        =   0
  37.          Left            =   4365
  38.          Moving          =   0   'False
  39.          NormalDepth     =   0
  40.          Picture         =   GAME.FRX:CF1A
  41.          TargetEvents    =   0   'False
  42.          TargetX         =   0
  43.          TargetY         =   0
  44.          TargetZ         =   0
  45.          Text            =   ""
  46.          TextColor       =   &H00000000&
  47.          Top             =   1575
  48.          TransparentColor=   &H00FFFFFF&
  49.          Width           =   1155
  50.          XFrames         =   0
  51.          XMoveAmount     =   0
  52.          YFrames         =   0
  53.          YMoveAmount     =   0
  54.          ZMoveAmount     =   0
  55.          ZPosition       =   2
  56.       End
  57.       Begin CSPlayer FrontTree 
  58.          CollideEvents   =   0   'False
  59.          CollideID       =   0
  60.          CycleEvents     =   0   'False
  61.          Cycling         =   0   'False
  62.          Frame           =   0
  63.          FrameRow        =   0
  64.          Height          =   1740
  65.          Interval        =   0
  66.          Left            =   1620
  67.          Moving          =   0   'False
  68.          NormalDepth     =   0
  69.          Picture         =   GAME.FRX:E074
  70.          TargetEvents    =   0   'False
  71.          TargetX         =   0
  72.          TargetY         =   0
  73.          TargetZ         =   0
  74.          Text            =   ""
  75.          TextColor       =   &H00000000&
  76.          Top             =   1725
  77.          TransparentColor=   &H00FFFFFF&
  78.          Width           =   1095
  79.          XFrames         =   0
  80.          XMoveAmount     =   0
  81.          YFrames         =   0
  82.          YMoveAmount     =   0
  83.          ZMoveAmount     =   0
  84.          ZPosition       =   0
  85.       End
  86.       Begin CSPlayer cloud 
  87.          CollideEvents   =   0   'False
  88.          CollideID       =   0
  89.          CycleEvents     =   0   'False
  90.          Cycling         =   0   'False
  91.          Frame           =   0
  92.          FrameRow        =   0
  93.          Height          =   540
  94.          Index           =   0
  95.          Interval        =   3
  96.          Left            =   2280
  97.          Moving          =   -1  'True
  98.          NormalDepth     =   0
  99.          Picture         =   GAME.FRX:F1CE
  100.          TargetEvents    =   -1  'True
  101.          TargetX         =   7000
  102.          TargetY         =   0
  103.          TargetZ         =   0
  104.          Text            =   ""
  105.          TextColor       =   &H00000000&
  106.          Top             =   120
  107.          TransparentColor=   &H00FF0000&
  108.          Width           =   1200
  109.          XFrames         =   0
  110.          XMoveAmount     =   50
  111.          YFrames         =   3
  112.          YMoveAmount     =   0
  113.          ZMoveAmount     =   0
  114.          ZPosition       =   1
  115.       End
  116.       Begin CSPlayer Fire 
  117.          CollideEvents   =   0   'False
  118.          CollideID       =   1
  119.          CycleEvents     =   0   'False
  120.          Cycling         =   -1  'True
  121.          Frame           =   0
  122.          FrameRow        =   0
  123.          Height          =   360
  124.          Interval        =   2
  125.          Left            =   3120
  126.          Moving          =   0   'False
  127.          NormalDepth     =   0
  128.          Picture         =   GAME.FRX:111C8
  129.          TargetEvents    =   0   'False
  130.          TargetX         =   0
  131.          TargetY         =   0
  132.          TargetZ         =   0
  133.          Text            =   ""
  134.          TextColor       =   &H00000000&
  135.          Top             =   2970
  136.          TransparentColor=   &H00FF0000&
  137.          Width           =   630
  138.          XFrames         =   2
  139.          XMoveAmount     =   0
  140.          YFrames         =   0
  141.          YMoveAmount     =   0
  142.          ZMoveAmount     =   0
  143.          ZPosition       =   0
  144.       End
  145.       Begin CSPlayer Player1 
  146.          CollideEvents   =   -1  'True
  147.          CollideID       =   0
  148.          CycleEvents     =   0   'False
  149.          Cycling         =   0   'False
  150.          Frame           =   0
  151.          FrameRow        =   0
  152.          Height          =   1455
  153.          Interval        =   0
  154.          Left            =   210
  155.          Moving          =   0   'False
  156.          NormalDepth     =   0
  157.          Picture         =   GAME.FRX:11482
  158.          TargetEvents    =   -1  'True
  159.          TargetX         =   6800
  160.          TargetY         =   1845
  161.          TargetZ         =   0
  162.          Text            =   ""
  163.          TextColor       =   &H00000000&
  164.          Top             =   1845
  165.          TransparentColor=   &H0000FF00&
  166.          Width           =   690
  167.          XFrames         =   2
  168.          XMoveAmount     =   0
  169.          YFrames         =   4
  170.          YMoveAmount     =   0
  171.          ZMoveAmount     =   0
  172.          ZPosition       =   1
  173.       End
  174.       Begin CSPlayer Bird 
  175.          CollideEvents   =   0   'False
  176.          CollideID       =   0
  177.          CycleEvents     =   0   'False
  178.          Cycling         =   -1  'True
  179.          Frame           =   0
  180.          FrameRow        =   0
  181.          Height          =   345
  182.          Interval        =   0
  183.          Left            =   465
  184.          Moving          =   -1  'True
  185.          NormalDepth     =   0
  186.          Picture         =   GAME.FRX:15E7C
  187.          TargetEvents    =   -1  'True
  188.          TargetX         =   4000
  189.          TargetY         =   50
  190.          TargetZ         =   0
  191.          Text            =   ""
  192.          TextColor       =   &H00000000&
  193.          Top             =   900
  194.          TransparentColor=   &H00FFFFFF&
  195.          Width           =   540
  196.          XFrames         =   3
  197.          XMoveAmount     =   0
  198.          YFrames         =   2
  199.          YMoveAmount     =   0
  200.          ZMoveAmount     =   0
  201.          ZPosition       =   0
  202.       End
  203.    End
  204.    Begin CSPlayer cloud 
  205.       CollideEvents   =   0   'False
  206.       CollideID       =   0
  207.       CycleEvents     =   0   'False
  208.       Cycling         =   0   'False
  209.       Frame           =   0
  210.       FrameRow        =   2
  211.       Height          =   540
  212.       Index           =   2
  213.       Interval        =   3
  214.       Left            =   0
  215.       Moving          =   -1  'True
  216.       NormalDepth     =   0
  217.       Picture         =   GAME.FRX:166D6
  218.       TargetEvents    =   -1  'True
  219.       TargetX         =   7000
  220.       TargetY         =   0
  221.       TargetZ         =   0
  222.       Text            =   ""
  223.       TextColor       =   &H00000000&
  224.       Top             =   100
  225.       TransparentColor=   &H00FF0000&
  226.       Width           =   1200
  227.       XFrames         =   0
  228.       XMoveAmount     =   50
  229.       YFrames         =   3
  230.       YMoveAmount     =   0
  231.       ZMoveAmount     =   0
  232.       ZPosition       =   1
  233.    End
  234.    Begin CSPlayer cloud 
  235.       CollideEvents   =   0   'False
  236.       CollideID       =   0
  237.       CycleEvents     =   0   'False
  238.       Cycling         =   0   'False
  239.       Frame           =   0
  240.       FrameRow        =   1
  241.       Height          =   540
  242.       Index           =   1
  243.       Interval        =   3
  244.       Left            =   5000
  245.       Moving          =   -1  'True
  246.       NormalDepth     =   0
  247.       Picture         =   GAME.FRX:186D0
  248.       TargetEvents    =   -1  'True
  249.       TargetX         =   7000
  250.       TargetY         =   0
  251.       TargetZ         =   0
  252.       Text            =   ""
  253.       TextColor       =   &H00000000&
  254.       Top             =   80
  255.       TransparentColor=   &H00FF0000&
  256.       Width           =   1200
  257.       XFrames         =   0
  258.       XMoveAmount     =   50
  259.       YFrames         =   3
  260.       YMoveAmount     =   0
  261.       ZMoveAmount     =   0
  262.       ZPosition       =   1
  263.    End
  264. Dim LastKey As Integer   ' What was the last key processed?
  265. Dim LastDir As Integer   ' Which direction (also a key)
  266. Dim KeyLeft As Integer   ' Is the left key down
  267. Dim KeyRight As Integer  ' Is the right key down
  268. Dim KeyUp As Integer     ' Is the Up key down
  269. Sub Bird_AtTarget ()
  270. Dim NewX As Integer
  271. Dim NewY As Integer
  272. 'We just pick a random location within limits and head
  273. '  there next
  274. NewX = Int(7000 * Rnd)
  275. NewY = Int(1000 * Rnd)
  276. 'See if our new location is to the left or right and use
  277. '  the appropriate row of animation
  278. If Bird.TargetX > NewX Then
  279.   Bird.FrameRow = 1
  280.   Bird.FrameRow = 0
  281.   End If
  282. Bird.TargetX = NewX
  283. Bird.TargetY = NewY
  284. Bird.Moving = True
  285. End Sub
  286. Sub cloud_AtTarget (Index As Integer)
  287. 'The target was set at design time to be just off the right
  288. '  edge of the screen. So evertime a cloud arrives there,
  289. '  Move it back to left of stage and start it moving again
  290. 'This is an example of beginning and ending movement off
  291. '  stage for smoothe entries and exits
  292. Cloud(Index).Move 0 - Cloud(Index).Width, 0
  293. Cloud(Index).Moving = True
  294. End Sub
  295. Sub Form_Load ()
  296. 'Save Interval and pause game on any message box!
  297. SaveI = Stage1.Interval
  298. Stage1.Interval = 0
  299. MsgBox "Use Left/Right/Up Arrows to Move, Esc to Pause"
  300. Stage1.Interval = SaveI
  301. End Sub
  302. Sub Player1_AtTarget ()
  303. 'If a key is still down, act on it; we may just be at
  304. '  the bottom or top of a jump
  305. If KeyLeft = True Then
  306.     Stage1_KeyDown (37)
  307.     End If
  308. If KeyRight = True Then
  309.     Stage1_KeyDown (39)
  310.     End If
  311. 'If neither left or right is down, select the standing
  312. '  still bitmap and quit cycling
  313. If KeyLeft = False And KeyRight = False Then
  314.     Player1.FrameRow = 0
  315.     Player1.Cycling = False
  316.     End If
  317. 'This checks for the up key to enable "hopping". We can't
  318. '  jump again at the top, only the bottom
  319. If KeyUp = True And Player1.Top = 1845 Then
  320.     Stage1_KeyDown (38)
  321.     End If
  322. 'If we are at the top of a jump we descend back down
  323. If Player1.Top <> 1845 Then
  324.     Player1.TargetY = 1845
  325.     Player1.Moving = True
  326.     End If
  327. End Sub
  328. Sub Player1_Collide (ID As Integer)
  329. 'The only collision is fire - start the "OUCH" sequence
  330. '  and set cycle events on so we will return to normal
  331. '  play after going through the sequence
  332. Player1.FrameRow = 3
  333. Player1.CycleEvents = True
  334. End Sub
  335. Sub Player1_Cycle ()
  336. 'The only time we get this event is after stepping in the
  337. '  fire and playing the "OUCH" bitmaps
  338. 'Turn the event off
  339. Player1.CycleEvents = False
  340. 'See which sequence to do next
  341. If KeyRight = True Then Player1.FrameRow = 1
  342. If KeyLeft = True Then Player1.FrameRow = 2
  343. 'If we are still, we also stop cycling. NOTE - we know it
  344. '  is on or we never would have gotten this event. That's
  345. '  why we turn it off here and don't bother turning it on
  346. '  for left or right
  347. If KeyLeft = False And KeyRight = False Then
  348.     Player1.FrameRow = 0
  349.     Player1.Cycling = False
  350.     End If
  351. End Sub
  352. Sub Stage1_KeyChar (WP As Integer)
  353. 'Save Interval to pause game on Esc
  354. If (WP <> 27) Then Exit Sub
  355. SaveI = Stage1.Interval
  356. Stage1.Interval = 0
  357. MsgBox "Game Paused; OK to continue"
  358. Stage1.Interval = SaveI
  359. 'Reset all key states
  360. KeyLeft = False
  361. KeyRight = False
  362. KeyUp = False
  363. End Sub
  364. Sub Stage1_KeyDown (WP As Integer)
  365. 'IMPORTANT: KeyDown does not repeat - otherwise we
  366. '  would get flooded with events. So we use state
  367. '  logic to track which keys are down, and aim at the
  368. '  far edge of the stage for left and right
  369. 'KeyUp will stop the player if needed, and AtTarget (player
  370. '  event) will keep it moving after jumps
  371. 'We check the key stroke, but through a series of
  372. ' If statements in case we want to change it so
  373. ' that multiple things happen (especially for up
  374. ' arrow - we want to keep moving in the same
  375. ' direction we have been)
  376. ' <- = 37
  377. ' -> = 39
  378. '  ^ = 38
  379. 'Let's eliminate keys we don't care about
  380. If WP < 37 Or WP > 39 Then Exit Sub
  381. 'First, let's check for an up arrow hit
  382. If WP = 38 Then
  383.     KeyUp = True
  384.     ' "Normal" TargetY is 1845, which places the guy on
  385.     '   the grass. Not a magic number, just where it
  386.     '   happens to be.
  387.     Player1.TargetY = 1845 - (Player1.Height / 2)
  388.     ' Now we want to jump in the direction we are moving
  389.     WP = LastKey
  390.     ' If not jumping, aim at normal level
  391.     Player1.TargetY = 1845
  392. End If
  393. 'On left and right we aim for the far end of the stage
  394. '  unless the up arrow is down, in which we aim nearby
  395. '  so that the slope will be right
  396. 'Next, let's check for right
  397. If WP = 39 Then
  398.     KeyRight = True
  399.     Player1.FrameRow = 1
  400.     Player1.TargetX = (Stage1.Width - Player1.Width)
  401.     If KeyUp = True Then
  402.       Player1.TargetX = Player1.Left + Player1.Width
  403.     End If
  404. End If
  405. 'Last, we check for left
  406. If WP = 37 Then
  407.     KeyLeft = True
  408.     Player1.FrameRow = 2
  409.     Player1.TargetX = 0
  410.     If KeyUp = True Then
  411.       Player1.TargetX = Player1.Left - Player1.Width
  412.     End If
  413. End If
  414. ' Save key (direction actually) for next time
  415. LastKey = WP
  416. ' Make sure we are moving
  417. Player1.Moving = True
  418. ' If going left or right, use cell animation
  419. If Player1.FrameRow <> 0 Then Player1.Cycling = True
  420. End Sub
  421. Sub Stage1_KeyUp (WP As Integer)
  422. 'See KeyDown for key# explanation and some overall logic
  423. '  explanation
  424. 'Let's elimate keys we don't care about
  425. If WP < 37 Or WP > 39 Then Exit Sub
  426. 'We need to update key state variables and stop motion
  427. '  by setting Targets to current location. NOTE: Setting
  428. '  target will allow player's AtTarget logic to work. If
  429. '  you wanted to prevent that, you would set Moving False
  430. '  for the player. We want the logic to run.
  431. 'First, let's check for an up arrow released
  432. If WP = 38 Then
  433.     KeyUp = False
  434.     Player1.TargetY = 1845
  435. End If
  436. 'Next, let's check for right
  437. If WP = 39 Then
  438.     KeyRight = False
  439.     Player1.FrameRow = 0
  440.     Player1.TargetX = Player1.Left
  441. End If
  442. 'Last, we check for left
  443. If WP = 37 Then
  444.     KeyLeft = False
  445.     Player1.FrameRow = 0
  446.     Player1.TargetX = Player1.Left
  447. End If
  448. End Sub
  449.