A top-down space game with a focus on exploration and collection Jack Townsend 200874711

Dependencies:   N5110 mbed

Fork of Space_Explorer by ELEC2645 (2015/16)

Committer:
The_Jackal
Date:
Fri May 13 13:30:32 2016 +0000
Revision:
0:7a4b26a3aef5
Child:
1:6a8aedb2ff69
Version 1.0.1; Operational at a basic level.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
The_Jackal 0:7a4b26a3aef5 1 //Include libraries
The_Jackal 0:7a4b26a3aef5 2 #include "mbed.h"
The_Jackal 0:7a4b26a3aef5 3 #include "N5110.h"
The_Jackal 0:7a4b26a3aef5 4 #include "time.h"
The_Jackal 0:7a4b26a3aef5 5 #define SENS 0.4
The_Jackal 0:7a4b26a3aef5 6 #define XCALI 0.5
The_Jackal 0:7a4b26a3aef5 7 #define YCALI 0.5
The_Jackal 0:7a4b26a3aef5 8
The_Jackal 0:7a4b26a3aef5 9 //set up serial connection
The_Jackal 0:7a4b26a3aef5 10 Serial pc(USBTX, USBRX);
The_Jackal 0:7a4b26a3aef5 11
The_Jackal 0:7a4b26a3aef5 12 //Set display pins
The_Jackal 0:7a4b26a3aef5 13 N5110 lcd(PTE26,PTA0,PTC4,PTD0,PTD2,PTD1,PTC3);
The_Jackal 0:7a4b26a3aef5 14
The_Jackal 0:7a4b26a3aef5 15 //Set tickers
The_Jackal 0:7a4b26a3aef5 16 Ticker ticker1;
The_Jackal 0:7a4b26a3aef5 17 Ticker ticker2;
The_Jackal 0:7a4b26a3aef5 18 Ticker ticker3;
The_Jackal 0:7a4b26a3aef5 19
The_Jackal 0:7a4b26a3aef5 20 //Set interrupts
The_Jackal 0:7a4b26a3aef5 21 InterruptIn Button1(PTB18);
The_Jackal 0:7a4b26a3aef5 22 InterruptIn Button2(PTB19);
The_Jackal 0:7a4b26a3aef5 23 InterruptIn Button3(PTC1);
The_Jackal 0:7a4b26a3aef5 24 InterruptIn Button4(PTC8);
The_Jackal 0:7a4b26a3aef5 25 InterruptIn JoyButton(PTB11);
The_Jackal 0:7a4b26a3aef5 26
The_Jackal 0:7a4b26a3aef5 27 //Set Analog Inputs
The_Jackal 0:7a4b26a3aef5 28 AnalogIn Pot(PTB10);
The_Jackal 0:7a4b26a3aef5 29 AnalogIn XJoy(PTB2);
The_Jackal 0:7a4b26a3aef5 30 AnalogIn YJoy(PTB3);
The_Jackal 0:7a4b26a3aef5 31
The_Jackal 0:7a4b26a3aef5 32 //Set Digital Outputs
The_Jackal 0:7a4b26a3aef5 33 DigitalOut rled(PTC10);
The_Jackal 0:7a4b26a3aef5 34 DigitalOut yled(PTC11);
The_Jackal 0:7a4b26a3aef5 35 DigitalOut gled(PTA1);
The_Jackal 0:7a4b26a3aef5 36
The_Jackal 0:7a4b26a3aef5 37 //Set Pwm Outputs
The_Jackal 0:7a4b26a3aef5 38 PwmOut flash(PTC2);
The_Jackal 0:7a4b26a3aef5 39 PwmOut Buzz(PTA2);
The_Jackal 0:7a4b26a3aef5 40
The_Jackal 0:7a4b26a3aef5 41 //Set up the seeds array
The_Jackal 0:7a4b26a3aef5 42 int seed[10][12] = {
The_Jackal 0:7a4b26a3aef5 43 {13, 15, 1, 9, 2, 3, 0, 14, 7, 6, 12, 5},
The_Jackal 0:7a4b26a3aef5 44 {10, 0, 15, 3, 7, 2, 11, 12, 9, 8, 14, 5},
The_Jackal 0:7a4b26a3aef5 45 {8, 12, 15, 9, 7, 13, 14, 3, 5, 1, 4, 10},
The_Jackal 0:7a4b26a3aef5 46 {15, 14, 0, 2, 10, 9, 1, 7, 11, 8, 5, 6},
The_Jackal 0:7a4b26a3aef5 47 {11, 7, 13, 0, 15, 4, 12, 10, 8, 2, 14, 9},
The_Jackal 0:7a4b26a3aef5 48 {7, 8, 3, 12, 9, 11, 2, 5, 15, 13, 1, 6},
The_Jackal 0:7a4b26a3aef5 49 {7, 9, 6, 12, 3, 4, 10, 13, 1, 11, 15, 5},
The_Jackal 0:7a4b26a3aef5 50 {0, 5, 1, 2, 7, 11, 14, 6, 4, 15, 8, 10},
The_Jackal 0:7a4b26a3aef5 51 {14, 7, 10, 1, 0, 4, 2, 8, 11, 15, 13, 9},
The_Jackal 0:7a4b26a3aef5 52 {5, 6, 12, 2, 9, 14, 8, 15, 13, 1, 10, 6},
The_Jackal 0:7a4b26a3aef5 53 };
The_Jackal 0:7a4b26a3aef5 54
The_Jackal 0:7a4b26a3aef5 55 //Set up the map data array
The_Jackal 0:7a4b26a3aef5 56 int mapdata [16][46][60] = {0};
The_Jackal 0:7a4b26a3aef5 57
The_Jackal 0:7a4b26a3aef5 58 //set up the screenframe array
The_Jackal 0:7a4b26a3aef5 59 int frame [1][48][84] = {0};
The_Jackal 0:7a4b26a3aef5 60
The_Jackal 0:7a4b26a3aef5 61 //Set up the sprite arrays
The_Jackal 0:7a4b26a3aef5 62 int objdata [5][12][12] = {{
The_Jackal 0:7a4b26a3aef5 63 //Station sprite
The_Jackal 0:7a4b26a3aef5 64 {0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0},
The_Jackal 0:7a4b26a3aef5 65 {0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0},
The_Jackal 0:7a4b26a3aef5 66 {0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0},
The_Jackal 0:7a4b26a3aef5 67 {0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 1},
The_Jackal 0:7a4b26a3aef5 68 {0, 0, 0, 1, 1, 1, 0, 1, 1, 1, 1, 1},
The_Jackal 0:7a4b26a3aef5 69 {0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1},
The_Jackal 0:7a4b26a3aef5 70 {1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 0, 0},
The_Jackal 0:7a4b26a3aef5 71 {0, 0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0},
The_Jackal 0:7a4b26a3aef5 72 {0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0},
The_Jackal 0:7a4b26a3aef5 73 {0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0},
The_Jackal 0:7a4b26a3aef5 74 {0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0},
The_Jackal 0:7a4b26a3aef5 75 {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
The_Jackal 0:7a4b26a3aef5 76 },
The_Jackal 0:7a4b26a3aef5 77
The_Jackal 0:7a4b26a3aef5 78 //Asteroid cluster sprite
The_Jackal 0:7a4b26a3aef5 79 { {0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0},
The_Jackal 0:7a4b26a3aef5 80 {0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0},
The_Jackal 0:7a4b26a3aef5 81 {1, 1, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0},
The_Jackal 0:7a4b26a3aef5 82 {0, 1, 1, 1, 1, 0, 0, 0, 1, 1, 1, 0},
The_Jackal 0:7a4b26a3aef5 83 {0, 0, 1, 1, 0, 0, 0, 0, 1, 0, 1, 1},
The_Jackal 0:7a4b26a3aef5 84 {1, 0, 0, 0, 1, 0, 0, 1, 1, 1, 0, 1},
The_Jackal 0:7a4b26a3aef5 85 {0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1},
The_Jackal 0:7a4b26a3aef5 86 {0, 0, 1, 0, 0, 1, 0, 1, 1, 1, 1, 1},
The_Jackal 0:7a4b26a3aef5 87 {0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0},
The_Jackal 0:7a4b26a3aef5 88 {0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0},
The_Jackal 0:7a4b26a3aef5 89 {0, 0, 1, 1, 0, 1, 0, 1, 0, 0, 0, 0},
The_Jackal 0:7a4b26a3aef5 90 {0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0}
The_Jackal 0:7a4b26a3aef5 91 },
The_Jackal 0:7a4b26a3aef5 92
The_Jackal 0:7a4b26a3aef5 93 //Planet sprite
The_Jackal 0:7a4b26a3aef5 94 { {0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0},
The_Jackal 0:7a4b26a3aef5 95 {0, 0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0},
The_Jackal 0:7a4b26a3aef5 96 {0, 1, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0},
The_Jackal 0:7a4b26a3aef5 97 {0, 1, 0, 1, 0, 0, 0, 1, 0, 0, 1, 0},
The_Jackal 0:7a4b26a3aef5 98 {1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 1},
The_Jackal 0:7a4b26a3aef5 99 {1, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1},
The_Jackal 0:7a4b26a3aef5 100 {1, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 1},
The_Jackal 0:7a4b26a3aef5 101 {1, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1},
The_Jackal 0:7a4b26a3aef5 102 {0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 0},
The_Jackal 0:7a4b26a3aef5 103 {0, 1, 0, 0, 1, 0, 1, 1, 0, 1, 1, 0},
The_Jackal 0:7a4b26a3aef5 104 {0, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 0},
The_Jackal 0:7a4b26a3aef5 105 {0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0}
The_Jackal 0:7a4b26a3aef5 106 },
The_Jackal 0:7a4b26a3aef5 107
The_Jackal 0:7a4b26a3aef5 108 //Gas cloud sprite
The_Jackal 0:7a4b26a3aef5 109 { {0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0},
The_Jackal 0:7a4b26a3aef5 110 {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
The_Jackal 0:7a4b26a3aef5 111 {0, 0, 1, 0, 0, 0, 1, 0, 0, 1, 0, 0},
The_Jackal 0:7a4b26a3aef5 112 {0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0},
The_Jackal 0:7a4b26a3aef5 113 {0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1},
The_Jackal 0:7a4b26a3aef5 114 {1, 0, 0, 1, 1, 1, 0, 1, 0, 0, 0, 0},
The_Jackal 0:7a4b26a3aef5 115 {0, 0, 0, 0, 1, 0, 0, 1, 0, 1, 0, 1},
The_Jackal 0:7a4b26a3aef5 116 {0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0},
The_Jackal 0:7a4b26a3aef5 117 {0, 0, 0, 1, 0, 0, 1, 0, 1, 0, 0, 0},
The_Jackal 0:7a4b26a3aef5 118 {0, 1, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0},
The_Jackal 0:7a4b26a3aef5 119 {0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0},
The_Jackal 0:7a4b26a3aef5 120 {0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0}
The_Jackal 0:7a4b26a3aef5 121 },
The_Jackal 0:7a4b26a3aef5 122
The_Jackal 0:7a4b26a3aef5 123 //Cargo icon
The_Jackal 0:7a4b26a3aef5 124 { {0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 0},
The_Jackal 0:7a4b26a3aef5 125 {0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 0},
The_Jackal 0:7a4b26a3aef5 126 {0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 1, 0},
The_Jackal 0:7a4b26a3aef5 127 {0, 0, 1, 1, 1, 1, 1, 1, 0, 0, 1, 0},
The_Jackal 0:7a4b26a3aef5 128 {0, 1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 0},
The_Jackal 0:7a4b26a3aef5 129 {0, 1, 0, 1, 1, 0, 1, 0, 1, 0, 1, 0},
The_Jackal 0:7a4b26a3aef5 130 {0, 1, 1, 0, 0, 1, 1, 1, 0, 0, 1, 0},
The_Jackal 0:7a4b26a3aef5 131 {0, 1, 1, 0, 0, 0, 1, 0, 0, 1, 0, 0},
The_Jackal 0:7a4b26a3aef5 132 {0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 0},
The_Jackal 0:7a4b26a3aef5 133 {0, 1, 0, 1, 1, 0, 1, 1, 0, 0, 0, 0},
The_Jackal 0:7a4b26a3aef5 134 {1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1},
The_Jackal 0:7a4b26a3aef5 135 {1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}
The_Jackal 0:7a4b26a3aef5 136 },
The_Jackal 0:7a4b26a3aef5 137 };
The_Jackal 0:7a4b26a3aef5 138
The_Jackal 0:7a4b26a3aef5 139 int ship [4][4][4] = {
The_Jackal 0:7a4b26a3aef5 140 { {0, 1, 1, 0},
The_Jackal 0:7a4b26a3aef5 141 {0, 1, 1, 0},
The_Jackal 0:7a4b26a3aef5 142 {1, 0, 0, 1},
The_Jackal 0:7a4b26a3aef5 143 {1, 1, 1, 1}
The_Jackal 0:7a4b26a3aef5 144 },
The_Jackal 0:7a4b26a3aef5 145
The_Jackal 0:7a4b26a3aef5 146 { {1, 1, 0, 0},
The_Jackal 0:7a4b26a3aef5 147 {1, 0, 1, 1},
The_Jackal 0:7a4b26a3aef5 148 {1, 0, 1, 1},
The_Jackal 0:7a4b26a3aef5 149 {1, 1, 0, 0}
The_Jackal 0:7a4b26a3aef5 150 },
The_Jackal 0:7a4b26a3aef5 151
The_Jackal 0:7a4b26a3aef5 152 { {1, 1, 1, 1},
The_Jackal 0:7a4b26a3aef5 153 {1, 0, 0, 1},
The_Jackal 0:7a4b26a3aef5 154 {0, 1, 1, 0},
The_Jackal 0:7a4b26a3aef5 155 {0, 1, 1, 0}
The_Jackal 0:7a4b26a3aef5 156 },
The_Jackal 0:7a4b26a3aef5 157
The_Jackal 0:7a4b26a3aef5 158 { {0, 0, 1, 1},
The_Jackal 0:7a4b26a3aef5 159 {1, 1, 0, 1},
The_Jackal 0:7a4b26a3aef5 160 {1, 1, 0, 1},
The_Jackal 0:7a4b26a3aef5 161 {0, 0, 1, 1}
The_Jackal 0:7a4b26a3aef5 162 },
The_Jackal 0:7a4b26a3aef5 163 };
The_Jackal 0:7a4b26a3aef5 164 //Set up ints and floats
The_Jackal 0:7a4b26a3aef5 165 int ZPos = 0;
The_Jackal 0:7a4b26a3aef5 166 int XPos = 0;
The_Jackal 0:7a4b26a3aef5 167 int YPos = 0;
The_Jackal 0:7a4b26a3aef5 168 int v = 0;
The_Jackal 0:7a4b26a3aef5 169 int i = 0;
The_Jackal 0:7a4b26a3aef5 170 int x = 0;
The_Jackal 0:7a4b26a3aef5 171 int y = 0;
The_Jackal 0:7a4b26a3aef5 172 int pixel = 0;
The_Jackal 0:7a4b26a3aef5 173 int s = 0;
The_Jackal 0:7a4b26a3aef5 174 int b = 0;
The_Jackal 0:7a4b26a3aef5 175 int joystate = 3;
The_Jackal 0:7a4b26a3aef5 176 int motion = 0;
The_Jackal 0:7a4b26a3aef5 177 int clear = 1;
The_Jackal 0:7a4b26a3aef5 178 int start = 1;
The_Jackal 0:7a4b26a3aef5 179 int cargo = 0;
The_Jackal 0:7a4b26a3aef5 180 int scan = 0;
The_Jackal 0:7a4b26a3aef5 181 int life = 3;
The_Jackal 0:7a4b26a3aef5 182 int g = 0;
The_Jackal 0:7a4b26a3aef5 183 double cash = 0;
The_Jackal 0:7a4b26a3aef5 184 int cost = 0;
The_Jackal 0:7a4b26a3aef5 185
The_Jackal 0:7a4b26a3aef5 186 //initialise isr variables
The_Jackal 0:7a4b26a3aef5 187 volatile int butx_flag[4] = {0};
The_Jackal 0:7a4b26a3aef5 188 volatile int butj_flag = 0;
The_Jackal 0:7a4b26a3aef5 189 volatile int refresh_flag = 0;
The_Jackal 0:7a4b26a3aef5 190
The_Jackal 0:7a4b26a3aef5 191 //Declare isrs
The_Jackal 0:7a4b26a3aef5 192
The_Jackal 0:7a4b26a3aef5 193 void but1_isr();
The_Jackal 0:7a4b26a3aef5 194 void but2_isr();
The_Jackal 0:7a4b26a3aef5 195 void but3_isr();
The_Jackal 0:7a4b26a3aef5 196 void but4_isr();
The_Jackal 0:7a4b26a3aef5 197 void butj_isr();
The_Jackal 0:7a4b26a3aef5 198 void refresh_isr();
The_Jackal 0:7a4b26a3aef5 199
The_Jackal 0:7a4b26a3aef5 200
The_Jackal 0:7a4b26a3aef5 201 //Declare Functions
The_Jackal 0:7a4b26a3aef5 202 //Generates map at init
The_Jackal 0:7a4b26a3aef5 203 void MapGen();
The_Jackal 0:7a4b26a3aef5 204 //Draws objects
The_Jackal 0:7a4b26a3aef5 205 void drawobj();
The_Jackal 0:7a4b26a3aef5 206 //Updates the screen with sprites
The_Jackal 0:7a4b26a3aef5 207 void ScreenDraw();
The_Jackal 0:7a4b26a3aef5 208 //Runs the game environment
The_Jackal 0:7a4b26a3aef5 209 void run1();
The_Jackal 0:7a4b26a3aef5 210 //Runs the ship menu
The_Jackal 0:7a4b26a3aef5 211 void run2();
The_Jackal 0:7a4b26a3aef5 212 //determines analog positions
The_Jackal 0:7a4b26a3aef5 213 void ain();
The_Jackal 0:7a4b26a3aef5 214 //refreshes the screen
The_Jackal 0:7a4b26a3aef5 215 void refresh();
The_Jackal 0:7a4b26a3aef5 216 //repositions the player if blocked
The_Jackal 0:7a4b26a3aef5 217 void reposition();
The_Jackal 0:7a4b26a3aef5 218 //Damage taken
The_Jackal 0:7a4b26a3aef5 219 void Damage();
The_Jackal 0:7a4b26a3aef5 220 //checks for collisions before moving
The_Jackal 0:7a4b26a3aef5 221 void collision_check();
The_Jackal 0:7a4b26a3aef5 222 //Draws the user interface + menu functions
The_Jackal 0:7a4b26a3aef5 223 int UI(int);
The_Jackal 0:7a4b26a3aef5 224 //reloads if a crash is detected
The_Jackal 0:7a4b26a3aef5 225 void crash();
The_Jackal 0:7a4b26a3aef5 226 //repair minigame
The_Jackal 0:7a4b26a3aef5 227 void repair();
The_Jackal 0:7a4b26a3aef5 228 //return to main game
The_Jackal 0:7a4b26a3aef5 229 void Return();
The_Jackal 0:7a4b26a3aef5 230 //resets the button flags
The_Jackal 0:7a4b26a3aef5 231 int reset(int);
The_Jackal 0:7a4b26a3aef5 232
The_Jackal 0:7a4b26a3aef5 233
The_Jackal 0:7a4b26a3aef5 234
The_Jackal 0:7a4b26a3aef5 235
The_Jackal 0:7a4b26a3aef5 236
The_Jackal 0:7a4b26a3aef5 237
The_Jackal 0:7a4b26a3aef5 238
The_Jackal 0:7a4b26a3aef5 239 int main()
The_Jackal 0:7a4b26a3aef5 240 {
The_Jackal 0:7a4b26a3aef5 241
The_Jackal 0:7a4b26a3aef5 242 //pc.printf("Main\n \n");
The_Jackal 0:7a4b26a3aef5 243 lcd.init(); //initialise display
The_Jackal 0:7a4b26a3aef5 244 srand(time(NULL)); //Set up rand function
The_Jackal 0:7a4b26a3aef5 245 JoyButton.rise(&butj_isr);
The_Jackal 0:7a4b26a3aef5 246 Button1.rise(&but1_isr);
The_Jackal 0:7a4b26a3aef5 247 Button2.rise(&but2_isr);
The_Jackal 0:7a4b26a3aef5 248 Button3.rise(&but3_isr);
The_Jackal 0:7a4b26a3aef5 249 Button4.rise(&but4_isr);
The_Jackal 0:7a4b26a3aef5 250 JoyButton.mode(PullDown);
The_Jackal 0:7a4b26a3aef5 251 Button1.mode(PullDown);
The_Jackal 0:7a4b26a3aef5 252 Button2.mode(PullDown);
The_Jackal 0:7a4b26a3aef5 253 Button3.mode(PullDown);
The_Jackal 0:7a4b26a3aef5 254 Button4.mode(PullDown);
The_Jackal 0:7a4b26a3aef5 255 lcd.printString("Jack",29,2);
The_Jackal 0:7a4b26a3aef5 256 lcd.printString("Townsend",17,3);
The_Jackal 0:7a4b26a3aef5 257 lcd.printString("2016 Leeds",12,4);
The_Jackal 0:7a4b26a3aef5 258 wait(3);
The_Jackal 0:7a4b26a3aef5 259 lcd.clear();
The_Jackal 0:7a4b26a3aef5 260 //pc.printf("Display initialised\n \n");
The_Jackal 0:7a4b26a3aef5 261 //pc.printf("Rand funct set\n \n");
The_Jackal 0:7a4b26a3aef5 262 UI(2);
The_Jackal 0:7a4b26a3aef5 263 }
The_Jackal 0:7a4b26a3aef5 264 int UI(int t)
The_Jackal 0:7a4b26a3aef5 265 {
The_Jackal 0:7a4b26a3aef5 266 switch(t) {
The_Jackal 0:7a4b26a3aef5 267 case 0:
The_Jackal 0:7a4b26a3aef5 268 s = 4;
The_Jackal 0:7a4b26a3aef5 269 for (x = 0; x < 12; x++) {
The_Jackal 0:7a4b26a3aef5 270 for (y = 0; y < 12; y++) {
The_Jackal 0:7a4b26a3aef5 271 pixel = objdata [s][y][x];
The_Jackal 0:7a4b26a3aef5 272 if(pixel == 0) {
The_Jackal 0:7a4b26a3aef5 273 lcd.clearPixel(x+67,y+3);
The_Jackal 0:7a4b26a3aef5 274 } else {
The_Jackal 0:7a4b26a3aef5 275 lcd.setPixel(x+67,y+3);
The_Jackal 0:7a4b26a3aef5 276 }
The_Jackal 0:7a4b26a3aef5 277 }
The_Jackal 0:7a4b26a3aef5 278 }
The_Jackal 0:7a4b26a3aef5 279 lcd.drawRect(67,16,11,28,0);
The_Jackal 0:7a4b26a3aef5 280 break;
The_Jackal 0:7a4b26a3aef5 281 case 1:
The_Jackal 0:7a4b26a3aef5 282 ticker2.detach();
The_Jackal 0:7a4b26a3aef5 283 ticker1.detach();
The_Jackal 0:7a4b26a3aef5 284 lcd.inverseMode();
The_Jackal 0:7a4b26a3aef5 285 lcd.clear();
The_Jackal 0:7a4b26a3aef5 286 joystate = 3;
The_Jackal 0:7a4b26a3aef5 287 lcd.drawRect(0,0,83,47,0);
The_Jackal 0:7a4b26a3aef5 288 lcd.drawRect(2,2,79,43,0);
The_Jackal 0:7a4b26a3aef5 289 wait(0.5);
The_Jackal 0:7a4b26a3aef5 290 lcd.printString("STATION:",5,1);
The_Jackal 0:7a4b26a3aef5 291 wait(1);
The_Jackal 0:7a4b26a3aef5 292 lcd.printString("Sell Cargo",5,3);
The_Jackal 0:7a4b26a3aef5 293 wait(0.5);
The_Jackal 0:7a4b26a3aef5 294 lcd.printString("Repair",5,4);
The_Jackal 0:7a4b26a3aef5 295 wait(0.5);
The_Jackal 0:7a4b26a3aef5 296 x = 0;
The_Jackal 0:7a4b26a3aef5 297 y = 0;
The_Jackal 0:7a4b26a3aef5 298 ticker1.attach(&ain, 0.125);
The_Jackal 0:7a4b26a3aef5 299 while(x == 0) {
The_Jackal 0:7a4b26a3aef5 300 lcd.drawRect(66,23,10,17,2);
The_Jackal 0:7a4b26a3aef5 301 wait(0.2);
The_Jackal 0:7a4b26a3aef5 302 switch(joystate) {
The_Jackal 0:7a4b26a3aef5 303 case 3:
The_Jackal 0:7a4b26a3aef5 304 lcd.printChar('<',66,3);
The_Jackal 0:7a4b26a3aef5 305 y = 3;
The_Jackal 0:7a4b26a3aef5 306 break;
The_Jackal 0:7a4b26a3aef5 307 case 1:
The_Jackal 0:7a4b26a3aef5 308 lcd.printChar('<',66,4);
The_Jackal 0:7a4b26a3aef5 309 y = 4;
The_Jackal 0:7a4b26a3aef5 310 break;
The_Jackal 0:7a4b26a3aef5 311 case 2:
The_Jackal 0:7a4b26a3aef5 312 x = 1;
The_Jackal 0:7a4b26a3aef5 313 break;
The_Jackal 0:7a4b26a3aef5 314 case 0:
The_Jackal 0:7a4b26a3aef5 315 x = 1;
The_Jackal 0:7a4b26a3aef5 316 break;
The_Jackal 0:7a4b26a3aef5 317 }
The_Jackal 0:7a4b26a3aef5 318 wait(0.2);
The_Jackal 0:7a4b26a3aef5 319 }
The_Jackal 0:7a4b26a3aef5 320 ticker1.detach();
The_Jackal 0:7a4b26a3aef5 321 switch(y) {
The_Jackal 0:7a4b26a3aef5 322 case 3:
The_Jackal 0:7a4b26a3aef5 323 cash = cash + cargo;
The_Jackal 0:7a4b26a3aef5 324 cargo = 0;
The_Jackal 0:7a4b26a3aef5 325 Return();
The_Jackal 0:7a4b26a3aef5 326 break;
The_Jackal 0:7a4b26a3aef5 327 case 4:
The_Jackal 0:7a4b26a3aef5 328 cost = 3 - life;
The_Jackal 0:7a4b26a3aef5 329 if(cash < 50*cost) {
The_Jackal 0:7a4b26a3aef5 330 lcd.clear();
The_Jackal 0:7a4b26a3aef5 331 lcd.printString("Can't afford!",5,4);
The_Jackal 0:7a4b26a3aef5 332 wait(2);
The_Jackal 0:7a4b26a3aef5 333 Return();
The_Jackal 0:7a4b26a3aef5 334 } else {
The_Jackal 0:7a4b26a3aef5 335 cash = cash - 50*cost;
The_Jackal 0:7a4b26a3aef5 336 life = 3;
The_Jackal 0:7a4b26a3aef5 337 lcd.clear();
The_Jackal 0:7a4b26a3aef5 338 lcd.printString("Repaired!",5,4);
The_Jackal 0:7a4b26a3aef5 339 wait(2);
The_Jackal 0:7a4b26a3aef5 340 Return();
The_Jackal 0:7a4b26a3aef5 341 }
The_Jackal 0:7a4b26a3aef5 342 }
The_Jackal 0:7a4b26a3aef5 343 break;
The_Jackal 0:7a4b26a3aef5 344 case 2:
The_Jackal 0:7a4b26a3aef5 345 lcd.inverseMode();
The_Jackal 0:7a4b26a3aef5 346 lcd.clear();
The_Jackal 0:7a4b26a3aef5 347 joystate = 3;
The_Jackal 0:7a4b26a3aef5 348 lcd.drawRect(0,0,83,47,0);
The_Jackal 0:7a4b26a3aef5 349 lcd.drawRect(2,2,79,43,0);
The_Jackal 0:7a4b26a3aef5 350 wait(0.2);
The_Jackal 0:7a4b26a3aef5 351 lcd.printString("SpacE",27,1);
The_Jackal 0:7a4b26a3aef5 352 wait(0.4);
The_Jackal 0:7a4b26a3aef5 353 lcd.printString("-EXPLORER-",12,2);
The_Jackal 0:7a4b26a3aef5 354 wait(2);
The_Jackal 0:7a4b26a3aef5 355 lcd.printString("Start",5,3);
The_Jackal 0:7a4b26a3aef5 356 wait(0.5);
The_Jackal 0:7a4b26a3aef5 357 lcd.printString("Help",5,4);
The_Jackal 0:7a4b26a3aef5 358 x = 0;
The_Jackal 0:7a4b26a3aef5 359 y = 0;
The_Jackal 0:7a4b26a3aef5 360 ticker1.attach(&ain, 0.125);
The_Jackal 0:7a4b26a3aef5 361 while(x == 0) {
The_Jackal 0:7a4b26a3aef5 362 lcd.drawRect(38,23,20,17,2);
The_Jackal 0:7a4b26a3aef5 363 wait(0.2);
The_Jackal 0:7a4b26a3aef5 364 switch(joystate) {
The_Jackal 0:7a4b26a3aef5 365 case 3:
The_Jackal 0:7a4b26a3aef5 366 lcd.printChar('<',40,3);
The_Jackal 0:7a4b26a3aef5 367 y = 3;
The_Jackal 0:7a4b26a3aef5 368 break;
The_Jackal 0:7a4b26a3aef5 369 case 1:
The_Jackal 0:7a4b26a3aef5 370 lcd.printChar('<',40,4);
The_Jackal 0:7a4b26a3aef5 371 y = 4;
The_Jackal 0:7a4b26a3aef5 372 break;
The_Jackal 0:7a4b26a3aef5 373 case 2:
The_Jackal 0:7a4b26a3aef5 374 x = 1;
The_Jackal 0:7a4b26a3aef5 375 break;
The_Jackal 0:7a4b26a3aef5 376 case 0:
The_Jackal 0:7a4b26a3aef5 377 x = 1;
The_Jackal 0:7a4b26a3aef5 378 break;
The_Jackal 0:7a4b26a3aef5 379 }
The_Jackal 0:7a4b26a3aef5 380 wait(0.2);
The_Jackal 0:7a4b26a3aef5 381 }
The_Jackal 0:7a4b26a3aef5 382 ticker1.detach();
The_Jackal 0:7a4b26a3aef5 383 wait(0.2);
The_Jackal 0:7a4b26a3aef5 384 b = rand()%10;
The_Jackal 0:7a4b26a3aef5 385 UI(y);
The_Jackal 0:7a4b26a3aef5 386 break;
The_Jackal 0:7a4b26a3aef5 387 case 3:
The_Jackal 0:7a4b26a3aef5 388 lcd.clear();
The_Jackal 0:7a4b26a3aef5 389 lcd.normalMode();
The_Jackal 0:7a4b26a3aef5 390 lcd.printString("Loading...",4,10);
The_Jackal 0:7a4b26a3aef5 391 i=0;
The_Jackal 0:7a4b26a3aef5 392 ticker3.attach(&crash, 2.5);
The_Jackal 0:7a4b26a3aef5 393 i=1;
The_Jackal 0:7a4b26a3aef5 394 MapGen();
The_Jackal 0:7a4b26a3aef5 395 //pc.printf("\nMap generated\n \n");
The_Jackal 0:7a4b26a3aef5 396 ScreenDraw();
The_Jackal 0:7a4b26a3aef5 397 //pc.printf("Loading complete!\n");
The_Jackal 0:7a4b26a3aef5 398 break;
The_Jackal 0:7a4b26a3aef5 399 case 4:
The_Jackal 0:7a4b26a3aef5 400 lcd.clear();
The_Jackal 0:7a4b26a3aef5 401 lcd.printString("The aim is to",1,2);
The_Jackal 0:7a4b26a3aef5 402 wait(0.5);
The_Jackal 0:7a4b26a3aef5 403 lcd.printString("mine asteroids",1,3);
The_Jackal 0:7a4b26a3aef5 404 wait(0.5);
The_Jackal 0:7a4b26a3aef5 405 lcd.printString("to earn points",1,4);
The_Jackal 0:7a4b26a3aef5 406 wait(3);
The_Jackal 0:7a4b26a3aef5 407 lcd.clear();
The_Jackal 0:7a4b26a3aef5 408 lcd.printString("Your ship is",1,2);
The_Jackal 0:7a4b26a3aef5 409 wait(0.5);
The_Jackal 0:7a4b26a3aef5 410 lcd.printString("controlled w/",1,3);
The_Jackal 0:7a4b26a3aef5 411 wait(0.5);
The_Jackal 0:7a4b26a3aef5 412 lcd.printString("the joystick",1,4);
The_Jackal 0:7a4b26a3aef5 413 wait(3);
The_Jackal 0:7a4b26a3aef5 414 lcd.clear();
The_Jackal 0:7a4b26a3aef5 415 lcd.printString("Pressing the",1,2);
The_Jackal 0:7a4b26a3aef5 416 wait(0.5);
The_Jackal 0:7a4b26a3aef5 417 lcd.printString("stick fires",1,3);
The_Jackal 0:7a4b26a3aef5 418 wait(0.5);
The_Jackal 0:7a4b26a3aef5 419 lcd.printString("your laser",1,4);
The_Jackal 0:7a4b26a3aef5 420 wait(3);
The_Jackal 0:7a4b26a3aef5 421 lcd.clear();
The_Jackal 0:7a4b26a3aef5 422 lcd.printString("You will need",1,2);
The_Jackal 0:7a4b26a3aef5 423 wait(0.5);
The_Jackal 0:7a4b26a3aef5 424 lcd.printString("to search to",1,3);
The_Jackal 0:7a4b26a3aef5 425 wait(0.5);
The_Jackal 0:7a4b26a3aef5 426 lcd.printString("find asteroids",1,4);
The_Jackal 0:7a4b26a3aef5 427 wait(3);
The_Jackal 0:7a4b26a3aef5 428 lcd.clear();
The_Jackal 0:7a4b26a3aef5 429 lcd.printString("Luckily, you",1,2);
The_Jackal 0:7a4b26a3aef5 430 wait(0.5);
The_Jackal 0:7a4b26a3aef5 431 lcd.printString("can fly any",1,3);
The_Jackal 0:7a4b26a3aef5 432 wait(0.5);
The_Jackal 0:7a4b26a3aef5 433 lcd.printString("distance...",1,4);
The_Jackal 0:7a4b26a3aef5 434 wait(3);
The_Jackal 0:7a4b26a3aef5 435 lcd.clear();
The_Jackal 0:7a4b26a3aef5 436 lcd.printString("in any",1,2);
The_Jackal 0:7a4b26a3aef5 437 wait(0.5);
The_Jackal 0:7a4b26a3aef5 438 lcd.printString("direction!",1,3);
The_Jackal 0:7a4b26a3aef5 439 wait(2);
The_Jackal 0:7a4b26a3aef5 440 lcd.printString("However...",1,4);
The_Jackal 0:7a4b26a3aef5 441 wait(2);
The_Jackal 0:7a4b26a3aef5 442 lcd.clear();
The_Jackal 0:7a4b26a3aef5 443 lcd.printString("You MUST",1,2);
The_Jackal 0:7a4b26a3aef5 444 wait(0.5);
The_Jackal 0:7a4b26a3aef5 445 lcd.printString("not fly into",1,3);
The_Jackal 0:7a4b26a3aef5 446 wait(0.5);
The_Jackal 0:7a4b26a3aef5 447 lcd.printString("any objects!",1,4);
The_Jackal 0:7a4b26a3aef5 448 wait(3);
The_Jackal 0:7a4b26a3aef5 449 lcd.clear();
The_Jackal 0:7a4b26a3aef5 450 lcd.printString("If you are",1,2);
The_Jackal 0:7a4b26a3aef5 451 wait(0.5);
The_Jackal 0:7a4b26a3aef5 452 lcd.printString("on the same",1,3);
The_Jackal 0:7a4b26a3aef5 453 wait(0.5);
The_Jackal 0:7a4b26a3aef5 454 lcd.printString("screen as...",1,4);
The_Jackal 0:7a4b26a3aef5 455 wait(3);
The_Jackal 0:7a4b26a3aef5 456 lcd.clear();
The_Jackal 0:7a4b26a3aef5 457 lcd.printString("a station,",1,2);
The_Jackal 0:7a4b26a3aef5 458 wait(0.5);
The_Jackal 0:7a4b26a3aef5 459 lcd.printString("you can dock",1,3);
The_Jackal 0:7a4b26a3aef5 460 wait(0.5);
The_Jackal 0:7a4b26a3aef5 461 lcd.printString("w/ button 4",1,4);
The_Jackal 0:7a4b26a3aef5 462 wait(3);
The_Jackal 0:7a4b26a3aef5 463 lcd.clear();
The_Jackal 0:7a4b26a3aef5 464 lcd.printString("You can sell",1,2);
The_Jackal 0:7a4b26a3aef5 465 wait(0.5);
The_Jackal 0:7a4b26a3aef5 466 lcd.printString("ore and get",1,3);
The_Jackal 0:7a4b26a3aef5 467 wait(0.5);
The_Jackal 0:7a4b26a3aef5 468 lcd.printString("repairs",1,4);
The_Jackal 0:7a4b26a3aef5 469 wait(3);
The_Jackal 0:7a4b26a3aef5 470 lcd.clear();
The_Jackal 0:7a4b26a3aef5 471 lcd.printString("On the right",1,2);
The_Jackal 0:7a4b26a3aef5 472 wait(0.5);
The_Jackal 0:7a4b26a3aef5 473 lcd.printString("will be your",1,3);
The_Jackal 0:7a4b26a3aef5 474 wait(0.5);
The_Jackal 0:7a4b26a3aef5 475 lcd.printString("cargo bar",1,4);
The_Jackal 0:7a4b26a3aef5 476 wait(3);
The_Jackal 0:7a4b26a3aef5 477 lcd.clear();
The_Jackal 0:7a4b26a3aef5 478 lcd.printString("It shows you",1,2);
The_Jackal 0:7a4b26a3aef5 479 wait(0.5);
The_Jackal 0:7a4b26a3aef5 480 lcd.printString("how full the",1,3);
The_Jackal 0:7a4b26a3aef5 481 wait(0.5);
The_Jackal 0:7a4b26a3aef5 482 lcd.printString("ship is",1,4);
The_Jackal 0:7a4b26a3aef5 483 wait(3);
The_Jackal 0:7a4b26a3aef5 484 lcd.clear();
The_Jackal 0:7a4b26a3aef5 485 lcd.printString("Now get out",1,2);
The_Jackal 0:7a4b26a3aef5 486 wait(0.5);
The_Jackal 0:7a4b26a3aef5 487 lcd.printString("there and",1,3);
The_Jackal 0:7a4b26a3aef5 488 wait(0.5);
The_Jackal 0:7a4b26a3aef5 489 lcd.printString("EXPLORE!",1,4);
The_Jackal 0:7a4b26a3aef5 490 wait(5);
The_Jackal 0:7a4b26a3aef5 491 UI(2);
The_Jackal 0:7a4b26a3aef5 492 break;
The_Jackal 0:7a4b26a3aef5 493 case 5:
The_Jackal 0:7a4b26a3aef5 494 lcd.clear();
The_Jackal 0:7a4b26a3aef5 495 lcd.refresh();
The_Jackal 0:7a4b26a3aef5 496 lcd.printString("BOOM!",29,2);
The_Jackal 0:7a4b26a3aef5 497 wait(1);
The_Jackal 0:7a4b26a3aef5 498 lcd.printString("Game over",20,4);
The_Jackal 0:7a4b26a3aef5 499 wait(4);
The_Jackal 0:7a4b26a3aef5 500 UI(2);
The_Jackal 0:7a4b26a3aef5 501
The_Jackal 0:7a4b26a3aef5 502
The_Jackal 0:7a4b26a3aef5 503 }
The_Jackal 0:7a4b26a3aef5 504 }
The_Jackal 0:7a4b26a3aef5 505 void but1_isr()
The_Jackal 0:7a4b26a3aef5 506 {
The_Jackal 0:7a4b26a3aef5 507 butx_flag[3] = 1;
The_Jackal 0:7a4b26a3aef5 508 pc.printf("4\n");
The_Jackal 0:7a4b26a3aef5 509 }
The_Jackal 0:7a4b26a3aef5 510 void but2_isr()
The_Jackal 0:7a4b26a3aef5 511 {
The_Jackal 0:7a4b26a3aef5 512 butx_flag[0] = 1;
The_Jackal 0:7a4b26a3aef5 513 pc.printf("1\n");
The_Jackal 0:7a4b26a3aef5 514 }
The_Jackal 0:7a4b26a3aef5 515 void but3_isr()
The_Jackal 0:7a4b26a3aef5 516 {
The_Jackal 0:7a4b26a3aef5 517 butx_flag[1] = 1;
The_Jackal 0:7a4b26a3aef5 518 pc.printf("2\n");
The_Jackal 0:7a4b26a3aef5 519 }
The_Jackal 0:7a4b26a3aef5 520 void but4_isr()
The_Jackal 0:7a4b26a3aef5 521 {
The_Jackal 0:7a4b26a3aef5 522 butx_flag[2] = 1;
The_Jackal 0:7a4b26a3aef5 523 pc.printf("3\n");
The_Jackal 0:7a4b26a3aef5 524 }
The_Jackal 0:7a4b26a3aef5 525
The_Jackal 0:7a4b26a3aef5 526 void Return()
The_Jackal 0:7a4b26a3aef5 527 {
The_Jackal 0:7a4b26a3aef5 528 XPos = 24;
The_Jackal 0:7a4b26a3aef5 529 YPos = 20;
The_Jackal 0:7a4b26a3aef5 530 lcd.normalMode();
The_Jackal 0:7a4b26a3aef5 531 lcd.clear();
The_Jackal 0:7a4b26a3aef5 532 start = 1;
The_Jackal 0:7a4b26a3aef5 533 ScreenDraw();
The_Jackal 0:7a4b26a3aef5 534 }
The_Jackal 0:7a4b26a3aef5 535
The_Jackal 0:7a4b26a3aef5 536 void crash()
The_Jackal 0:7a4b26a3aef5 537 {
The_Jackal 0:7a4b26a3aef5 538 lcd.clear();
The_Jackal 0:7a4b26a3aef5 539 srand(b*20);
The_Jackal 0:7a4b26a3aef5 540 UI(3);
The_Jackal 0:7a4b26a3aef5 541 }
The_Jackal 0:7a4b26a3aef5 542
The_Jackal 0:7a4b26a3aef5 543
The_Jackal 0:7a4b26a3aef5 544 void butj_isr()
The_Jackal 0:7a4b26a3aef5 545 {
The_Jackal 0:7a4b26a3aef5 546 if(cargo < 53) {
The_Jackal 0:7a4b26a3aef5 547 butj_flag = 1;
The_Jackal 0:7a4b26a3aef5 548 } else {
The_Jackal 0:7a4b26a3aef5 549 butj_flag = 0;
The_Jackal 0:7a4b26a3aef5 550 }
The_Jackal 0:7a4b26a3aef5 551 }
The_Jackal 0:7a4b26a3aef5 552
The_Jackal 0:7a4b26a3aef5 553 int reset(int s)
The_Jackal 0:7a4b26a3aef5 554 {
The_Jackal 0:7a4b26a3aef5 555 for(i=0; i<4; i++) {
The_Jackal 0:7a4b26a3aef5 556 butx_flag[i] = s;
The_Jackal 0:7a4b26a3aef5 557 }
The_Jackal 0:7a4b26a3aef5 558 }
The_Jackal 0:7a4b26a3aef5 559
The_Jackal 0:7a4b26a3aef5 560 void repair()
The_Jackal 0:7a4b26a3aef5 561 {
The_Jackal 0:7a4b26a3aef5 562 lcd.drawRect(0,0,60,48,2); //draws a blank rectangle to clear a specific area of screen
The_Jackal 0:7a4b26a3aef5 563 lcd.printString("DAMAGE",10,2);
The_Jackal 0:7a4b26a3aef5 564 lcd.printString("CRITICAL!",5,4);
The_Jackal 0:7a4b26a3aef5 565 wait(2);
The_Jackal 0:7a4b26a3aef5 566 reset(1);
The_Jackal 0:7a4b26a3aef5 567 lcd.clear();
The_Jackal 0:7a4b26a3aef5 568 lcd.printString("SYSTEMS:",2,0);
The_Jackal 0:7a4b26a3aef5 569 i=rand()%3+1; //generates a random number of faults (up to three)
The_Jackal 0:7a4b26a3aef5 570 for(y=0; y<i; y++) { //for these faults,
The_Jackal 0:7a4b26a3aef5 571 x=rand()%4+1; //generate a random fault number (out of 4 possible)
The_Jackal 0:7a4b26a3aef5 572 butx_flag[x-1] = 0; //set the appropriate flag to zero, depending on fault chosen
The_Jackal 0:7a4b26a3aef5 573 switch(x) { //displays the fault
The_Jackal 0:7a4b26a3aef5 574 case 1:
The_Jackal 0:7a4b26a3aef5 575 lcd.printString("!Reactor temp!",2,y+1);
The_Jackal 0:7a4b26a3aef5 576 break;
The_Jackal 0:7a4b26a3aef5 577 case 2:
The_Jackal 0:7a4b26a3aef5 578 lcd.printString("!Coolant leak!",2,y+1);
The_Jackal 0:7a4b26a3aef5 579 break;
The_Jackal 0:7a4b26a3aef5 580 case 3:
The_Jackal 0:7a4b26a3aef5 581 lcd.printString("!CO2 high!",2,y+1);
The_Jackal 0:7a4b26a3aef5 582 break;
The_Jackal 0:7a4b26a3aef5 583 case 4:
The_Jackal 0:7a4b26a3aef5 584 lcd.printString("!Hatch seal!",2,y+1);
The_Jackal 0:7a4b26a3aef5 585 break;
The_Jackal 0:7a4b26a3aef5 586 }
The_Jackal 0:7a4b26a3aef5 587 }
The_Jackal 0:7a4b26a3aef5 588 for(i=0; i<4; i++) { //loops until all flags are set to 1 by the user
The_Jackal 0:7a4b26a3aef5 589 if(butx_flag[i] != 1) {
The_Jackal 0:7a4b26a3aef5 590 i--;
The_Jackal 0:7a4b26a3aef5 591 }
The_Jackal 0:7a4b26a3aef5 592 wait(0.1);
The_Jackal 0:7a4b26a3aef5 593 pc.printf("Flags: %d %d %d %d\n",butx_flag[0], butx_flag[1], butx_flag[2], butx_flag[3]); //flag status for debugging
The_Jackal 0:7a4b26a3aef5 594 }
The_Jackal 0:7a4b26a3aef5 595
The_Jackal 0:7a4b26a3aef5 596
The_Jackal 0:7a4b26a3aef5 597 }
The_Jackal 0:7a4b26a3aef5 598
The_Jackal 0:7a4b26a3aef5 599 void collision_check()
The_Jackal 0:7a4b26a3aef5 600 {
The_Jackal 0:7a4b26a3aef5 601 switch(joystate) {
The_Jackal 0:7a4b26a3aef5 602 case 0:
The_Jackal 0:7a4b26a3aef5 603 for(y=-1; y<5; y++) {
The_Jackal 0:7a4b26a3aef5 604 if(lcd.getPixel(XPos-1,YPos+y) != 0) {
The_Jackal 0:7a4b26a3aef5 605 life--;
The_Jackal 0:7a4b26a3aef5 606 Damage();
The_Jackal 0:7a4b26a3aef5 607 }
The_Jackal 0:7a4b26a3aef5 608 }
The_Jackal 0:7a4b26a3aef5 609 break;
The_Jackal 0:7a4b26a3aef5 610 case 1:
The_Jackal 0:7a4b26a3aef5 611 for(x=-1; x<5; x++) {
The_Jackal 0:7a4b26a3aef5 612 if(lcd.getPixel(XPos+x,YPos+4) != 0) {
The_Jackal 0:7a4b26a3aef5 613 life--;
The_Jackal 0:7a4b26a3aef5 614 Damage();
The_Jackal 0:7a4b26a3aef5 615 }
The_Jackal 0:7a4b26a3aef5 616 }
The_Jackal 0:7a4b26a3aef5 617 break;
The_Jackal 0:7a4b26a3aef5 618 case 2:
The_Jackal 0:7a4b26a3aef5 619 for(y=-1; y<5; y++) {
The_Jackal 0:7a4b26a3aef5 620 if(lcd.getPixel(XPos+4,YPos+y) != 0) {
The_Jackal 0:7a4b26a3aef5 621 life--;
The_Jackal 0:7a4b26a3aef5 622 Damage();
The_Jackal 0:7a4b26a3aef5 623 }
The_Jackal 0:7a4b26a3aef5 624 }
The_Jackal 0:7a4b26a3aef5 625 break;
The_Jackal 0:7a4b26a3aef5 626 case 3:
The_Jackal 0:7a4b26a3aef5 627 for(x=-1; x<5; x++) {
The_Jackal 0:7a4b26a3aef5 628 if(lcd.getPixel(XPos+x,YPos-1) != 0) {
The_Jackal 0:7a4b26a3aef5 629 life--;
The_Jackal 0:7a4b26a3aef5 630 Damage();
The_Jackal 0:7a4b26a3aef5 631 }
The_Jackal 0:7a4b26a3aef5 632 }
The_Jackal 0:7a4b26a3aef5 633 break;
The_Jackal 0:7a4b26a3aef5 634 }
The_Jackal 0:7a4b26a3aef5 635 }
The_Jackal 0:7a4b26a3aef5 636
The_Jackal 0:7a4b26a3aef5 637
The_Jackal 0:7a4b26a3aef5 638 void Damage()
The_Jackal 0:7a4b26a3aef5 639 {
The_Jackal 0:7a4b26a3aef5 640 //Prevent tickers from interfering with the function
The_Jackal 0:7a4b26a3aef5 641 ticker1.detach();
The_Jackal 0:7a4b26a3aef5 642 ticker2.detach();
The_Jackal 0:7a4b26a3aef5 643 wait(0.5); //Allows user to react
The_Jackal 0:7a4b26a3aef5 644 if(life == 2) { //depending on the amount of life left, takes one life away per collision
The_Jackal 0:7a4b26a3aef5 645 gled = 1;
The_Jackal 0:7a4b26a3aef5 646 }
The_Jackal 0:7a4b26a3aef5 647 if(life == 1) {
The_Jackal 0:7a4b26a3aef5 648 yled = 1;
The_Jackal 0:7a4b26a3aef5 649 }
The_Jackal 0:7a4b26a3aef5 650 if(life == 0) { //when life becomes 0, the emergency repair minigame starts
The_Jackal 0:7a4b26a3aef5 651 rled = 1;
The_Jackal 0:7a4b26a3aef5 652 g++;
The_Jackal 0:7a4b26a3aef5 653 repair();
The_Jackal 0:7a4b26a3aef5 654 lcd.randomiseBuffer(); //generates static screens to simulate a software crash
The_Jackal 0:7a4b26a3aef5 655 lcd.refresh();
The_Jackal 0:7a4b26a3aef5 656 wait(0.2);
The_Jackal 0:7a4b26a3aef5 657 lcd.randomiseBuffer();
The_Jackal 0:7a4b26a3aef5 658 lcd.refresh();
The_Jackal 0:7a4b26a3aef5 659 wait(0.1);
The_Jackal 0:7a4b26a3aef5 660 lcd.clear();
The_Jackal 0:7a4b26a3aef5 661 lcd.printString("Rebooting...",2,0);
The_Jackal 0:7a4b26a3aef5 662 wait(0.2);
The_Jackal 0:7a4b26a3aef5 663 lcd.randomiseBuffer();
The_Jackal 0:7a4b26a3aef5 664 lcd.refresh();
The_Jackal 0:7a4b26a3aef5 665 wait(0.1);
The_Jackal 0:7a4b26a3aef5 666 lcd.clear();
The_Jackal 0:7a4b26a3aef5 667 lcd.printString("Rebooting...",2,0);
The_Jackal 0:7a4b26a3aef5 668 XPos = 24; //resets the player character position (avoids further collisions
The_Jackal 0:7a4b26a3aef5 669 YPos = 20;
The_Jackal 0:7a4b26a3aef5 670 wait(1.5);
The_Jackal 0:7a4b26a3aef5 671 lcd.clear();
The_Jackal 0:7a4b26a3aef5 672 reset(0);
The_Jackal 0:7a4b26a3aef5 673 switch(g) { //if g<2, the player is rewarded with one life. If g == 2, the player's ship explodes.
The_Jackal 0:7a4b26a3aef5 674 case 0:
The_Jackal 0:7a4b26a3aef5 675 case 1:
The_Jackal 0:7a4b26a3aef5 676 life++;
The_Jackal 0:7a4b26a3aef5 677 rled = 0;
The_Jackal 0:7a4b26a3aef5 678 ScreenDraw();
The_Jackal 0:7a4b26a3aef5 679 break;
The_Jackal 0:7a4b26a3aef5 680 case 2:
The_Jackal 0:7a4b26a3aef5 681 UI(5);
The_Jackal 0:7a4b26a3aef5 682 break;
The_Jackal 0:7a4b26a3aef5 683 }
The_Jackal 0:7a4b26a3aef5 684
The_Jackal 0:7a4b26a3aef5 685
The_Jackal 0:7a4b26a3aef5 686
The_Jackal 0:7a4b26a3aef5 687
The_Jackal 0:7a4b26a3aef5 688 }
The_Jackal 0:7a4b26a3aef5 689
The_Jackal 0:7a4b26a3aef5 690 ticker1.attach(&ain, 0.075); //tickers for the game are re-attached
The_Jackal 0:7a4b26a3aef5 691 ticker2.attach(&refresh_isr, 0.125);
The_Jackal 0:7a4b26a3aef5 692
The_Jackal 0:7a4b26a3aef5 693 }
The_Jackal 0:7a4b26a3aef5 694 void refresh()
The_Jackal 0:7a4b26a3aef5 695 {
The_Jackal 0:7a4b26a3aef5 696 lcd.refresh();
The_Jackal 0:7a4b26a3aef5 697 //pc.printf("tick\n");
The_Jackal 0:7a4b26a3aef5 698
The_Jackal 0:7a4b26a3aef5 699
The_Jackal 0:7a4b26a3aef5 700 if(motion == 1) {
The_Jackal 0:7a4b26a3aef5 701 switch(joystate) {
The_Jackal 0:7a4b26a3aef5 702 case 0:
The_Jackal 0:7a4b26a3aef5 703 XPos--;
The_Jackal 0:7a4b26a3aef5 704 break;
The_Jackal 0:7a4b26a3aef5 705 case 1:
The_Jackal 0:7a4b26a3aef5 706 YPos++;
The_Jackal 0:7a4b26a3aef5 707 break;
The_Jackal 0:7a4b26a3aef5 708 case 2:
The_Jackal 0:7a4b26a3aef5 709 XPos++;
The_Jackal 0:7a4b26a3aef5 710 break;
The_Jackal 0:7a4b26a3aef5 711 case 3:
The_Jackal 0:7a4b26a3aef5 712 YPos--;
The_Jackal 0:7a4b26a3aef5 713 break;
The_Jackal 0:7a4b26a3aef5 714 }
The_Jackal 0:7a4b26a3aef5 715 }
The_Jackal 0:7a4b26a3aef5 716 if(butj_flag == 0) {
The_Jackal 0:7a4b26a3aef5 717 collision_check();
The_Jackal 0:7a4b26a3aef5 718 }
The_Jackal 0:7a4b26a3aef5 719
The_Jackal 0:7a4b26a3aef5 720 switch(motion) {
The_Jackal 0:7a4b26a3aef5 721 case 0:
The_Jackal 0:7a4b26a3aef5 722 break;
The_Jackal 0:7a4b26a3aef5 723 case 1:
The_Jackal 0:7a4b26a3aef5 724 for(y=-1; y<5; y++) {
The_Jackal 0:7a4b26a3aef5 725 for(x=-1; x<5; x++) {
The_Jackal 0:7a4b26a3aef5 726 lcd.clearPixel(XPos+x,YPos+y);
The_Jackal 0:7a4b26a3aef5 727 }
The_Jackal 0:7a4b26a3aef5 728 }
The_Jackal 0:7a4b26a3aef5 729 for(y=0; y<4; y++) {
The_Jackal 0:7a4b26a3aef5 730 for(x=0; x<4; x++) {
The_Jackal 0:7a4b26a3aef5 731 pixel = ship [joystate][x][y];
The_Jackal 0:7a4b26a3aef5 732 if(pixel == 0) {
The_Jackal 0:7a4b26a3aef5 733 lcd.clearPixel(XPos+x,YPos+y);
The_Jackal 0:7a4b26a3aef5 734 } else {
The_Jackal 0:7a4b26a3aef5 735 lcd.setPixel(XPos+x,YPos+y);
The_Jackal 0:7a4b26a3aef5 736 }
The_Jackal 0:7a4b26a3aef5 737 }
The_Jackal 0:7a4b26a3aef5 738
The_Jackal 0:7a4b26a3aef5 739 }
The_Jackal 0:7a4b26a3aef5 740
The_Jackal 0:7a4b26a3aef5 741 break;
The_Jackal 0:7a4b26a3aef5 742 }
The_Jackal 0:7a4b26a3aef5 743
The_Jackal 0:7a4b26a3aef5 744 }
The_Jackal 0:7a4b26a3aef5 745
The_Jackal 0:7a4b26a3aef5 746 void ain()
The_Jackal 0:7a4b26a3aef5 747 {
The_Jackal 0:7a4b26a3aef5 748 if(XJoy.read() > (1+SENS) * XCALI) {
The_Jackal 0:7a4b26a3aef5 749 joystate = 0;
The_Jackal 0:7a4b26a3aef5 750 motion = 1;
The_Jackal 0:7a4b26a3aef5 751 } else if(XJoy.read() < (1-SENS) * XCALI) {
The_Jackal 0:7a4b26a3aef5 752 joystate = 2;
The_Jackal 0:7a4b26a3aef5 753 motion = 1;
The_Jackal 0:7a4b26a3aef5 754 } else if(YJoy.read() > (1+SENS) * YCALI) {
The_Jackal 0:7a4b26a3aef5 755 joystate = 3;
The_Jackal 0:7a4b26a3aef5 756 motion = 1;
The_Jackal 0:7a4b26a3aef5 757 } else if(YJoy.read() < (1-SENS) * YCALI) {
The_Jackal 0:7a4b26a3aef5 758 joystate = 1;
The_Jackal 0:7a4b26a3aef5 759 motion = 1;
The_Jackal 0:7a4b26a3aef5 760 } else {
The_Jackal 0:7a4b26a3aef5 761 motion = 0;
The_Jackal 0:7a4b26a3aef5 762 }
The_Jackal 0:7a4b26a3aef5 763
The_Jackal 0:7a4b26a3aef5 764 }
The_Jackal 0:7a4b26a3aef5 765 void refresh_isr()
The_Jackal 0:7a4b26a3aef5 766 {
The_Jackal 0:7a4b26a3aef5 767 refresh_flag = 1;
The_Jackal 0:7a4b26a3aef5 768 }
The_Jackal 0:7a4b26a3aef5 769 void run1()
The_Jackal 0:7a4b26a3aef5 770 {
The_Jackal 0:7a4b26a3aef5 771 pc.printf("Screen %d \n", ZPos);
The_Jackal 0:7a4b26a3aef5 772 if(start == 1) {
The_Jackal 0:7a4b26a3aef5 773 for(y=-1; y<5; y++) {
The_Jackal 0:7a4b26a3aef5 774 for(x=-1; x<5; x++) {
The_Jackal 0:7a4b26a3aef5 775 pixel = lcd.getPixel(XPos+x,YPos+y);
The_Jackal 0:7a4b26a3aef5 776 if(pixel == 0) {
The_Jackal 0:7a4b26a3aef5 777 } else {
The_Jackal 0:7a4b26a3aef5 778 reposition();
The_Jackal 0:7a4b26a3aef5 779 }
The_Jackal 0:7a4b26a3aef5 780 }
The_Jackal 0:7a4b26a3aef5 781 }
The_Jackal 0:7a4b26a3aef5 782
The_Jackal 0:7a4b26a3aef5 783 } else {
The_Jackal 0:7a4b26a3aef5 784 }
The_Jackal 0:7a4b26a3aef5 785 start = 0;
The_Jackal 0:7a4b26a3aef5 786 for(y=0; y<4; y++) {
The_Jackal 0:7a4b26a3aef5 787 for(x=0; x<4; x++) {
The_Jackal 0:7a4b26a3aef5 788 pixel = ship [joystate][x][y];
The_Jackal 0:7a4b26a3aef5 789 if(pixel == 0) {
The_Jackal 0:7a4b26a3aef5 790 lcd.clearPixel(XPos+x,YPos+y);
The_Jackal 0:7a4b26a3aef5 791 } else {
The_Jackal 0:7a4b26a3aef5 792 lcd.setPixel(XPos+x,YPos+y);
The_Jackal 0:7a4b26a3aef5 793 }
The_Jackal 0:7a4b26a3aef5 794 }
The_Jackal 0:7a4b26a3aef5 795
The_Jackal 0:7a4b26a3aef5 796 }
The_Jackal 0:7a4b26a3aef5 797 UI(0);
The_Jackal 0:7a4b26a3aef5 798 lcd.refresh();
The_Jackal 0:7a4b26a3aef5 799 ticker3.detach();
The_Jackal 0:7a4b26a3aef5 800 ticker1.attach(&ain, 0.075);
The_Jackal 0:7a4b26a3aef5 801 ticker2.attach(&refresh_isr, 0.125);
The_Jackal 0:7a4b26a3aef5 802 while(1) {
The_Jackal 0:7a4b26a3aef5 803 if(refresh_flag == 1) {
The_Jackal 0:7a4b26a3aef5 804 refresh_flag--;
The_Jackal 0:7a4b26a3aef5 805 refresh();
The_Jackal 0:7a4b26a3aef5 806 }
The_Jackal 0:7a4b26a3aef5 807 if(ZPos == seed[b][11]) {
The_Jackal 0:7a4b26a3aef5 808 if(butx_flag[3]) {
The_Jackal 0:7a4b26a3aef5 809 butx_flag[3] = 0;
The_Jackal 0:7a4b26a3aef5 810 wait(0.5);
The_Jackal 0:7a4b26a3aef5 811 UI(1);
The_Jackal 0:7a4b26a3aef5 812 }
The_Jackal 0:7a4b26a3aef5 813 }
The_Jackal 0:7a4b26a3aef5 814 if(XPos > 55) {
The_Jackal 0:7a4b26a3aef5 815 ZPos = ZPos++;
The_Jackal 0:7a4b26a3aef5 816 XPos = 6;
The_Jackal 0:7a4b26a3aef5 817 ticker1.detach();
The_Jackal 0:7a4b26a3aef5 818 ticker2.detach();
The_Jackal 0:7a4b26a3aef5 819 ScreenDraw();
The_Jackal 0:7a4b26a3aef5 820 } else if(XPos < 4) {
The_Jackal 0:7a4b26a3aef5 821 ZPos = ZPos--;
The_Jackal 0:7a4b26a3aef5 822 XPos = 54;
The_Jackal 0:7a4b26a3aef5 823 ticker1.detach();
The_Jackal 0:7a4b26a3aef5 824 ticker2.detach();
The_Jackal 0:7a4b26a3aef5 825 ScreenDraw();
The_Jackal 0:7a4b26a3aef5 826 } else if (YPos > 41) {
The_Jackal 0:7a4b26a3aef5 827 ZPos = ZPos + 4;
The_Jackal 0:7a4b26a3aef5 828 YPos = 4;
The_Jackal 0:7a4b26a3aef5 829 ticker1.detach();
The_Jackal 0:7a4b26a3aef5 830 ticker2.detach();
The_Jackal 0:7a4b26a3aef5 831 ScreenDraw();
The_Jackal 0:7a4b26a3aef5 832 } else if(YPos < 4) {
The_Jackal 0:7a4b26a3aef5 833 ZPos = ZPos - 4;
The_Jackal 0:7a4b26a3aef5 834 YPos = 41;
The_Jackal 0:7a4b26a3aef5 835 ticker1.detach();
The_Jackal 0:7a4b26a3aef5 836 ticker2.detach();
The_Jackal 0:7a4b26a3aef5 837 ScreenDraw();
The_Jackal 0:7a4b26a3aef5 838 }
The_Jackal 0:7a4b26a3aef5 839 if(butj_flag == 1) {
The_Jackal 0:7a4b26a3aef5 840 butj_flag = 0;
The_Jackal 0:7a4b26a3aef5 841 wait(0.05);
The_Jackal 0:7a4b26a3aef5 842 switch(joystate) {
The_Jackal 0:7a4b26a3aef5 843 case 0:
The_Jackal 0:7a4b26a3aef5 844 for(x=2; x<9; x++) {
The_Jackal 0:7a4b26a3aef5 845 if(lcd.getPixel(XPos-x,YPos+2)!= 0) {
The_Jackal 0:7a4b26a3aef5 846 cargo++;
The_Jackal 0:7a4b26a3aef5 847 }
The_Jackal 0:7a4b26a3aef5 848 lcd.setPixel(XPos-x,YPos+2);
The_Jackal 0:7a4b26a3aef5 849 mapdata[ZPos][XPos-x][YPos+2] = 0;
The_Jackal 0:7a4b26a3aef5 850 }
The_Jackal 0:7a4b26a3aef5 851 lcd.refresh();
The_Jackal 0:7a4b26a3aef5 852 wait(0.075);
The_Jackal 0:7a4b26a3aef5 853 for(x=2; x<9; x++) {
The_Jackal 0:7a4b26a3aef5 854 lcd.clearPixel(XPos-x,YPos+2);
The_Jackal 0:7a4b26a3aef5 855 }
The_Jackal 0:7a4b26a3aef5 856 lcd.refresh();
The_Jackal 0:7a4b26a3aef5 857 break;
The_Jackal 0:7a4b26a3aef5 858 case 2:
The_Jackal 0:7a4b26a3aef5 859 for(x=5; x<12; x++) {
The_Jackal 0:7a4b26a3aef5 860 if(lcd.getPixel(XPos+x,YPos+1)!= 0) {
The_Jackal 0:7a4b26a3aef5 861 cargo++;
The_Jackal 0:7a4b26a3aef5 862 }
The_Jackal 0:7a4b26a3aef5 863 lcd.setPixel(XPos+x,YPos+1);
The_Jackal 0:7a4b26a3aef5 864 mapdata[ZPos][XPos+x][YPos+1] = 0;
The_Jackal 0:7a4b26a3aef5 865 }
The_Jackal 0:7a4b26a3aef5 866 lcd.refresh();
The_Jackal 0:7a4b26a3aef5 867 wait(0.075);
The_Jackal 0:7a4b26a3aef5 868 for(x=5; x<12; x++) {
The_Jackal 0:7a4b26a3aef5 869 lcd.clearPixel(XPos+x,YPos+1);
The_Jackal 0:7a4b26a3aef5 870 }
The_Jackal 0:7a4b26a3aef5 871 lcd.refresh();
The_Jackal 0:7a4b26a3aef5 872 break;
The_Jackal 0:7a4b26a3aef5 873 case 1:
The_Jackal 0:7a4b26a3aef5 874 for(y=5; y<12; y++) {
The_Jackal 0:7a4b26a3aef5 875 if(lcd.getPixel(XPos+2,YPos+y)!= 0) {
The_Jackal 0:7a4b26a3aef5 876 cargo++;
The_Jackal 0:7a4b26a3aef5 877 }
The_Jackal 0:7a4b26a3aef5 878 lcd.setPixel(XPos+2,YPos+y);
The_Jackal 0:7a4b26a3aef5 879 mapdata[ZPos][XPos+2][YPos+y] = 0;
The_Jackal 0:7a4b26a3aef5 880 }
The_Jackal 0:7a4b26a3aef5 881 lcd.refresh();
The_Jackal 0:7a4b26a3aef5 882 wait(0.075);
The_Jackal 0:7a4b26a3aef5 883 for(y=5; y<12; y++) {
The_Jackal 0:7a4b26a3aef5 884 lcd.clearPixel(XPos+2,YPos+y);
The_Jackal 0:7a4b26a3aef5 885 }
The_Jackal 0:7a4b26a3aef5 886 lcd.refresh();
The_Jackal 0:7a4b26a3aef5 887 break;
The_Jackal 0:7a4b26a3aef5 888 case 3:
The_Jackal 0:7a4b26a3aef5 889 for(y=2; y<9; y++) {
The_Jackal 0:7a4b26a3aef5 890 if(lcd.getPixel(XPos+1,YPos-y)!= 0) {
The_Jackal 0:7a4b26a3aef5 891 cargo++;
The_Jackal 0:7a4b26a3aef5 892 }
The_Jackal 0:7a4b26a3aef5 893 lcd.setPixel(XPos+1,YPos-y);
The_Jackal 0:7a4b26a3aef5 894 mapdata[ZPos][XPos+1][YPos-y] = 0;
The_Jackal 0:7a4b26a3aef5 895 }
The_Jackal 0:7a4b26a3aef5 896 lcd.refresh();
The_Jackal 0:7a4b26a3aef5 897 wait(0.075);
The_Jackal 0:7a4b26a3aef5 898 for(y=2; y<9; y++) {
The_Jackal 0:7a4b26a3aef5 899 lcd.clearPixel(XPos+1,YPos-y);
The_Jackal 0:7a4b26a3aef5 900 }
The_Jackal 0:7a4b26a3aef5 901 lcd.refresh();
The_Jackal 0:7a4b26a3aef5 902 break;
The_Jackal 0:7a4b26a3aef5 903
The_Jackal 0:7a4b26a3aef5 904 }
The_Jackal 0:7a4b26a3aef5 905 for(y=0; y<0.5f*cargo; y++) {
The_Jackal 0:7a4b26a3aef5 906 for(x=0; x<10; x++) {
The_Jackal 0:7a4b26a3aef5 907 lcd.setPixel(x+68,44-y);
The_Jackal 0:7a4b26a3aef5 908 }
The_Jackal 0:7a4b26a3aef5 909 pc.printf("Cargo: %d \n", cargo);
The_Jackal 0:7a4b26a3aef5 910 }
The_Jackal 0:7a4b26a3aef5 911
The_Jackal 0:7a4b26a3aef5 912 }
The_Jackal 0:7a4b26a3aef5 913 }
The_Jackal 0:7a4b26a3aef5 914 }
The_Jackal 0:7a4b26a3aef5 915 void drawobj()
The_Jackal 0:7a4b26a3aef5 916 {
The_Jackal 0:7a4b26a3aef5 917 //pc.printf("Drawing object at:\n \n");
The_Jackal 0:7a4b26a3aef5 918 //pc.printf("x %1d y %1d \n", XPos, YPos);
The_Jackal 0:7a4b26a3aef5 919 //pc.printf("on screen %1d \n \n \n", ZPos);
The_Jackal 0:7a4b26a3aef5 920 for (y = 0; y < 12; y++) {
The_Jackal 0:7a4b26a3aef5 921 for (x = 0; x < 12; x++) {
The_Jackal 0:7a4b26a3aef5 922 mapdata [ZPos][XPos+x][YPos+y] = objdata [s][x][y];
The_Jackal 0:7a4b26a3aef5 923 }
The_Jackal 0:7a4b26a3aef5 924 }
The_Jackal 0:7a4b26a3aef5 925 //pc.printf("Draw Complete, v = %d \n", v);
The_Jackal 0:7a4b26a3aef5 926 }
The_Jackal 0:7a4b26a3aef5 927 void ScreenDraw()
The_Jackal 0:7a4b26a3aef5 928 {
The_Jackal 0:7a4b26a3aef5 929 volatile int butx_flag[4] = {0};
The_Jackal 0:7a4b26a3aef5 930 //pc.printf("Drawing screen\n \n");
The_Jackal 0:7a4b26a3aef5 931 if(ZPos<0 | ZPos>15) {
The_Jackal 0:7a4b26a3aef5 932 ZPos = rand()%16;
The_Jackal 0:7a4b26a3aef5 933 }
The_Jackal 0:7a4b26a3aef5 934 lcd.drawRect(0,0,83,47,0);
The_Jackal 0:7a4b26a3aef5 935 for (y = 1; y < 47; y++) {
The_Jackal 0:7a4b26a3aef5 936
The_Jackal 0:7a4b26a3aef5 937 for (x = 1; x < 61; x++) {
The_Jackal 0:7a4b26a3aef5 938
The_Jackal 0:7a4b26a3aef5 939 pixel = mapdata [ZPos][y-1][x-1];
The_Jackal 0:7a4b26a3aef5 940 if(pixel == 0) {
The_Jackal 0:7a4b26a3aef5 941
The_Jackal 0:7a4b26a3aef5 942 lcd.clearPixel(x,y);
The_Jackal 0:7a4b26a3aef5 943 } else {
The_Jackal 0:7a4b26a3aef5 944
The_Jackal 0:7a4b26a3aef5 945 lcd.setPixel(x,y);
The_Jackal 0:7a4b26a3aef5 946 }
The_Jackal 0:7a4b26a3aef5 947 }
The_Jackal 0:7a4b26a3aef5 948 }
The_Jackal 0:7a4b26a3aef5 949 for (y = 0; y < 48; y++) {
The_Jackal 0:7a4b26a3aef5 950 lcd.setPixel(61,y);
The_Jackal 0:7a4b26a3aef5 951 lcd.setPixel(62,y);
The_Jackal 0:7a4b26a3aef5 952 }
The_Jackal 0:7a4b26a3aef5 953 //pc.printf("\n");
The_Jackal 0:7a4b26a3aef5 954 //pc.printf("Buffer complete\n");
The_Jackal 0:7a4b26a3aef5 955 lcd.refresh();
The_Jackal 0:7a4b26a3aef5 956 //pc.printf("Refreshed\n \n");
The_Jackal 0:7a4b26a3aef5 957 run1();
The_Jackal 0:7a4b26a3aef5 958
The_Jackal 0:7a4b26a3aef5 959 }
The_Jackal 0:7a4b26a3aef5 960 void reposition()
The_Jackal 0:7a4b26a3aef5 961 {
The_Jackal 0:7a4b26a3aef5 962 XPos = rand()%37 + 6;
The_Jackal 0:7a4b26a3aef5 963 YPos = rand()%24 + 6;
The_Jackal 0:7a4b26a3aef5 964 start = 1;
The_Jackal 0:7a4b26a3aef5 965 }
The_Jackal 0:7a4b26a3aef5 966
The_Jackal 0:7a4b26a3aef5 967 void MapGen()
The_Jackal 0:7a4b26a3aef5 968 {
The_Jackal 0:7a4b26a3aef5 969 //pc.printf("Generating map\n");
The_Jackal 0:7a4b26a3aef5 970 //Array is already declared
The_Jackal 0:7a4b26a3aef5 971 //Generate 15 background stars on each screen in random locations
The_Jackal 0:7a4b26a3aef5 972 for(ZPos=0; ZPos<16; ZPos++) {
The_Jackal 0:7a4b26a3aef5 973 for(v=0; v<10; v++) {
The_Jackal 0:7a4b26a3aef5 974 XPos = rand()%46;
The_Jackal 0:7a4b26a3aef5 975 YPos = rand()%60;
The_Jackal 0:7a4b26a3aef5 976 mapdata[ZPos][XPos][YPos] = 1;
The_Jackal 0:7a4b26a3aef5 977 }
The_Jackal 0:7a4b26a3aef5 978
The_Jackal 0:7a4b26a3aef5 979 }
The_Jackal 0:7a4b26a3aef5 980 ////////pc.printf("160 Debris Generated\n");
The_Jackal 0:7a4b26a3aef5 981 s = 2;
The_Jackal 0:7a4b26a3aef5 982 //Generate 9 gas clouds on the map in random locations
The_Jackal 0:7a4b26a3aef5 983 for(v=0; v<9; v++) {
The_Jackal 0:7a4b26a3aef5 984 ZPos = rand()%16;
The_Jackal 0:7a4b26a3aef5 985 XPos = rand()%37 + 6;
The_Jackal 0:7a4b26a3aef5 986 YPos = rand()%24 + 6;
The_Jackal 0:7a4b26a3aef5 987 drawobj();
The_Jackal 0:7a4b26a3aef5 988
The_Jackal 0:7a4b26a3aef5 989 }
The_Jackal 0:7a4b26a3aef5 990 ////pc.printf("9 Gas Clouds Generated\n");
The_Jackal 0:7a4b26a3aef5 991 s = 3;
The_Jackal 0:7a4b26a3aef5 992 //Generate 6 planets on the map in seed locations
The_Jackal 0:7a4b26a3aef5 993 for(v=0; v<6; v++) {
The_Jackal 0:7a4b26a3aef5 994 ZPos = seed[b][v];
The_Jackal 0:7a4b26a3aef5 995 XPos = rand()%37 + 6;
The_Jackal 0:7a4b26a3aef5 996 YPos = rand()%24 + 6;
The_Jackal 0:7a4b26a3aef5 997 drawobj();
The_Jackal 0:7a4b26a3aef5 998
The_Jackal 0:7a4b26a3aef5 999 }
The_Jackal 0:7a4b26a3aef5 1000 ////pc.printf("6 Planets Generated\n");
The_Jackal 0:7a4b26a3aef5 1001 s = 1;
The_Jackal 0:7a4b26a3aef5 1002 //Generate 5 asteroid clusters on the map in seed locations
The_Jackal 0:7a4b26a3aef5 1003 for(v=0; v<5; v++) {
The_Jackal 0:7a4b26a3aef5 1004 ZPos = seed[b][v+6];
The_Jackal 0:7a4b26a3aef5 1005 XPos = rand()%37 + 6;
The_Jackal 0:7a4b26a3aef5 1006 YPos = rand()%24 + 6;
The_Jackal 0:7a4b26a3aef5 1007 drawobj();
The_Jackal 0:7a4b26a3aef5 1008
The_Jackal 0:7a4b26a3aef5 1009 }
The_Jackal 0:7a4b26a3aef5 1010 //pc.printf("5 Asteroid Clusters Generated\n");
The_Jackal 0:7a4b26a3aef5 1011
The_Jackal 0:7a4b26a3aef5 1012 //Generate one station on the map in a seed location
The_Jackal 0:7a4b26a3aef5 1013 s = 0;
The_Jackal 0:7a4b26a3aef5 1014 ZPos = seed[b][11];
The_Jackal 0:7a4b26a3aef5 1015 XPos = rand()%37 + 6;
The_Jackal 0:7a4b26a3aef5 1016 YPos = rand()%24 + 6;
The_Jackal 0:7a4b26a3aef5 1017 //pc.printf("1 Station Generated\n");
The_Jackal 0:7a4b26a3aef5 1018 drawobj();
The_Jackal 0:7a4b26a3aef5 1019 //places the character
The_Jackal 0:7a4b26a3aef5 1020 XPos = 24;
The_Jackal 0:7a4b26a3aef5 1021 YPos = 20;
The_Jackal 0:7a4b26a3aef5 1022 }
The_Jackal 0:7a4b26a3aef5 1023