OpenCores
URL https://opencores.org/ocsvn/openmsp430/openmsp430/trunk

Subversion Repositories openmsp430

[/] [openmsp430/] [trunk/] [fpga/] [actel_m1a3pl_dev_kit/] [software/] [spacewar/] [compar.c] - Blame information for rev 105

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 80 olivier.gi
#include <stdlib.h>
2
#include "spacewar.h"
3
 
4
//************************************************************
5
// externals
6
//
7
 
8
extern void reset_rkts(rkt_data *, rkt_data *);
9
 
10
//************************************************************
11
//
12
// compare torps
13
//
14
//    checks for collisions between rocket and torps
15
//
16
/* Description:
17
The function checks for collisions between a rocket and all the active
18
torpedoes for the other player.  The first structure passed is used for the
19
rocket.  The second structure passed is used for torpedoes.  The array of
20
torpedoes is scaned for active torpedoes.  If a torpedo's x position is not
21
equal to -1 it is active.  If active the absolute value of the difference
22
between torpedo and rocket x positions is compared to a constant collide.
23
If less the y positions are compared the same way.  If less a collision has
24
occured.  The rocket shield is decremented.
25
*/
26
void comp_torp(rkt_data *rkt, rkt_data *torps)
27
{
28
int i;
29
 
30
  for(i = 0 ; i < ammo; i++) {
31
    if(torps->pt_dx[i] != -1) {             // is this torp active ?
32
      if(abs(rkt->xdisp - torps->pt_dx[i]) < collide) { // yes - collide between rkt and torps
33
        if(abs(rkt->ydisp - torps->pt_dy[i]) < collide) {
34
          torps->pt_dx[i] = -1;             // remove torp from list
35
          rkt->shield--;                    // rkt loose one shield
36
        }
37
      }
38
    }
39
  }
40
}
41
 
42
//************************************************************
43
//
44
// compar
45
//
46
//    checks for collisions or hits and keeps score
47
//
48
/* Description:
49
Check for collisions between all objects.  First checks for a rocket to rocket
50
collision.  If rocket to rocket collision then decrement boths rockets shields
51
and reset rockets to initial positions.  Next check for rocket 1 to torpedos
52
of rocket 2 collisions.  If a hit decrement rocket 1 shields.  Finally check
53
for rocket 2 to torpedos of rocket 1 collisions.  If a hit decrement rocket 2
54
shields.
55
*/
56
void compar(rkt_data *rkt1, rkt_data *rkt2)
57
{
58
 
59
  if(abs(rkt1->xdisp - rkt2->xdisp) < collide) {  // check rkt1 collide with rkt2
60
    if(abs(rkt1->ydisp - rkt2->ydisp) < collide) {
61
      rkt1->shield--;                       // rkt1 loose one shield
62
      rkt2->shield--;                       // rkt2 loose one shield
63
      reset_rkts(rkt1, rkt2);               // reset rkt positons                        
64
    }
65
  }
66
 
67
  comp_torp(rkt1, rkt2);              // check for hit on rkt1 by tops from rkt2
68
  comp_torp(rkt2, rkt1);              // check for hit on rkt1 by tops from rkt2
69
 
70
}
71
 
72
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.