1 |
80 |
olivier.gi |
#include "msp430x20x3.h"
|
2 |
|
|
#include "spacewar.h"
|
3 |
|
|
|
4 |
|
|
//************************************************************
|
5 |
|
|
// externals
|
6 |
|
|
//
|
7 |
|
|
|
8 |
|
|
extern int bzsin(char);
|
9 |
|
|
|
10 |
|
|
//************************************************************
|
11 |
|
|
//
|
12 |
|
|
// update
|
13 |
|
|
//
|
14 |
|
|
// checks rockets buttons and fires its torpedoes
|
15 |
|
|
// updates rockets position
|
16 |
|
|
// updates torpedos position
|
17 |
|
|
//
|
18 |
|
|
/* Description:
|
19 |
|
|
Generates the x, y vectors for the rocket at present angle. Checks the A to D
|
20 |
|
|
passed into function for any keys pressed. The A to D resistors are selected
|
21 |
|
|
to generate values in between the ranges checked. If you push multiple buttons
|
22 |
|
|
strange results will occure. If no keys are pressed the fire flaag clears.
|
23 |
|
|
Rotate counter clockwise increments the angle variable. Rotate clockwise
|
24 |
|
|
decrements the angle variable. If the thrust key is pressed a scaled
|
25 |
|
|
value of xsize and ysize is added into the x and y velocity of the rocket
|
26 |
|
|
creating acceleration. If the fire button is pressed the fire flag is checked.
|
27 |
|
|
If no fire flag then a inactive torpedo is searched for. If a inactive torpedo
|
28 |
|
|
is found the torpedo is given the present position of the rocket plus an x,y
|
29 |
|
|
offset to get it past the nose of the rocket. The torpedo is given the present
|
30 |
|
|
velocity of the rocket plus additional speed based on xsize, ysize.
|
31 |
|
|
The rocket position is updated by adding a scaled velocity into position.
|
32 |
|
|
The position is masked to the DAC maximum. The torpedo positions are updated
|
33 |
|
|
by adding a scaled torpedo velocity into torpedo position. The torpedo
|
34 |
|
|
position is masked to the DAC maximum.
|
35 |
|
|
*/
|
36 |
|
|
void update(rkt_data *rkt, unsigned int new_a2d)
|
37 |
|
|
{
|
38 |
|
|
int i;
|
39 |
|
|
|
40 |
|
|
rkt->xsize = bzsin(rkt->ang + 64); // this returns the cosine
|
41 |
|
|
rkt->ysize = bzsin(rkt->ang); // this returns the sine
|
42 |
|
|
|
43 |
|
|
if(new_a2d > 0xD000){ // rkt rotate CCW ?
|
44 |
|
|
rkt->ang++; // yes
|
45 |
|
|
}
|
46 |
|
|
else { // no
|
47 |
|
|
if(new_a2d > 0xA000){ // rkt rotate CW ?
|
48 |
|
|
rkt->ang--; // yes
|
49 |
|
|
}
|
50 |
|
|
else { // no
|
51 |
|
|
if(new_a2d > 0x6000) { // is rkt thrusting
|
52 |
|
|
rkt->xvel += ((long) rkt->xsize << 6); // yes
|
53 |
|
|
rkt->yvel += ((long) rkt->ysize << 6);
|
54 |
|
|
}
|
55 |
|
|
else { // no
|
56 |
|
|
if(new_a2d > 0x2000) { // is rkt firing now ?
|
57 |
|
|
if((rkt->flags & fire_bit) == 0) { // did rkt fire last loop ?
|
58 |
|
|
for(i = 0; i < ammo; i++) { // no - look for a torp read to fire
|
59 |
|
|
if(rkt->pt_dx[i] == -1) {
|
60 |
|
|
rkt->flags |= fire_bit; // set firing flag
|
61 |
|
|
rkt->pt_dx[i] = rkt->xdisp + (rkt->xsize << 1); // load up a new torps data
|
62 |
|
|
rkt->pt_dy[i] = rkt->ydisp + (rkt->ysize << 1);
|
63 |
|
|
rkt->pt_vx[i] = (rkt->xvel >> 16) + (rkt->xsize >> 3);
|
64 |
|
|
rkt->pt_vy[i] = (rkt->yvel >> 16) + (rkt->ysize >> 3);
|
65 |
|
|
break;
|
66 |
|
|
}
|
67 |
|
|
}
|
68 |
|
|
}
|
69 |
|
|
} else {
|
70 |
|
|
rkt->flags &= ~fire_bit; // clear fire flag
|
71 |
|
|
}
|
72 |
|
|
}
|
73 |
|
|
}
|
74 |
|
|
}
|
75 |
|
|
|
76 |
|
|
rkt->xdisp = (rkt->xdisp + (rkt->xvel >> 16)) & max_dac; // update rkt x position
|
77 |
|
|
rkt->ydisp = (rkt->ydisp + (rkt->yvel >> 16)) & max_dac; // update rkt y position
|
78 |
|
|
|
79 |
|
|
for(i = 0; i < ammo; i++) {
|
80 |
|
|
if(rkt->pt_dx[i] != -1) {
|
81 |
|
|
rkt->pt_dx[i] = (rkt->pt_dx[i] + rkt->pt_vx[i]) & max_dac; // move torp x
|
82 |
|
|
rkt->pt_dy[i] = (rkt->pt_dy[i] + rkt->pt_vy[i]) & max_dac; // move torp x
|
83 |
|
|
}
|
84 |
|
|
}
|
85 |
|
|
}
|
86 |
|
|
|
87 |
|
|
|
88 |
|
|
|