Last active
September 23, 2019 08:58
-
-
Save tobozo/b7dcacf8b036b80d18323022ebb86a31 to your computer and use it in GitHub Desktop.
Porting Tiny Space Invaders for Attiny85 from https://sites.google.com/view/arduino-collection to ESP8266
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// >>>>> T-I-N-Y S-P-A-C-E I-N-V-A-D-E-R-S for ATTINY85 GPL v3 <<<< | |
// Programmer: Daniel Champagne 2018 | |
// Contact EMAIL: [email protected] | |
// https://sites.google.com/view/arduino-collection | |
// Tiny Space Invaders is free software: you can redistribute it and/or modify | |
// it under the terms of the GNU General Public License as published by | |
// the Free Software Foundation, either version 3 of the License, or | |
// (at your option) any later version. | |
// This program is distributed in the hope that it will be useful, | |
// but WITHOUT ANY WARRANTY; without even the implied warranty of | |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
// GNU General Public License for more details. | |
// You should have received a copy of the GNU General Public License | |
// along with this program. If not, see <http://www.gnu.org/licenses/>. | |
//the code work at 16MHZ internal | |
//and use ssd1306xled Library for SSD1306 oled display 128x64 | |
//#include <avr/pgmspace.h> | |
typedef struct SPACE { | |
int8_t UFOxPos = -120; | |
uint8_t oneFrame = 0; | |
uint8_t MonsterShoot[2][1] = {{16}, {16}}; | |
int8_t MonsterGrid[5][6] = {{0, 0, 0, 0, 0, 0}\ | |
, {2, 2, 2, 2, 2, 2}\ | |
, {4, 4, 4, 4, 4, 4}\ | |
, {4, 4, 4, 4, 4, 4}\ | |
, { -1, -1, -1, -1, -1, -1} | |
}; | |
uint8_t Shield[6] = {0b11111111, 0b11111111, 0b11111111, 0b11111111, 0b11111111, 0b11111111}; | |
uint8_t ScrBackV = 52; | |
int8_t MyShootBall = -1; | |
uint8_t MyShootBallxpos = 0; | |
uint8_t MyShootBallFrame = 0; | |
uint8_t anim = 0; | |
uint8_t frame = 0; | |
uint8_t PositionDansGrilleMonsterX = 0; | |
uint8_t PositionDansGrilleMonsterY = 0; | |
uint8_t MonsterFloorMax = 3; | |
uint8_t MonsterOffsetGauche = 0; | |
uint8_t MonsterOffsetDroite = 44; | |
uint8_t MonsterGroupeXpos = 0; | |
uint8_t MonsterGroupeYpos = 0; | |
uint8_t DecalageY8 = 0; | |
uint8_t frameMax = 8; | |
uint8_t Direction = 1; //1 right 0 gauche | |
} SPACE; | |
const int8_t MonstersLevels [] PROGMEM = { | |
0, 0, 0, 0, 0, 0, 2, 2, 2, 2, 2, 2, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, \ | |
4, 4, 4, 4, 4, 4, 4, 2, 0, 0, 2, 4, 4, 2, 0, 0, 2, 4, 4, 4, 4, 4, 4, 4, \ | |
-1, 0, 0, 0, 0, -1, 2, 2, 2, 2, 2, 2, 4, 4, 4, 4, 4, 4, -1, 4, 4, 4, 4, -1, \ | |
0, -1, 0, 0, -1, 0, 2, -1, 2, 2, -1, 2, 4, -1, 4, 4, -1, 4, 4, -1, 4, 4, -1, 4, \ | |
-1, -1, 2, 2, -1, -1, 0, 2, 2, 2, 2, 0, 2, 4, 2, 2, 4, 2, 2, -1, -1, -1, -1, 2, \ | |
4, 4, 4, 4, 4, 4, 2, 2, 2, 2, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, \ | |
-1, 0, 0, 0, 0, -1, 2, -1, -1, -1, -1, 2, 4, -1, -1, -1, -1, 4, -1, 4, 4, 4, 4, -1, \ | |
4, -1, 4, -1, 4, -1, -1, 4, -1, 4, -1, 4, 4, -1, 4, -1, 4, -1, -1, 4, -1, 4, -1, 4, \ | |
-1, -1, 0, 0, -1, -1, 2, 2, 4, 4, 2, 2, 2, 2, 4, 4, 2, 2, -1, -1, 0, 0, -1, -1, \ | |
0, 0, 4, 4, 2, 2, 0, 0, 4, 4, 2, 2, 0, 0, 4, 4, 2, 2, 0, 0, 4, 4, 2, 2, \ | |
}; | |
const uint8_t LIVE [] PROGMEM = {0x80, 0xC0, 0x80, 0x00, 0x00, 0x80, 0xC0, 0x80, 0x00, 0x00, 0x80, 0xC0, 0x80, 0x00, 0x00, | |
}; | |
const uint8_t SHOOT [] PROGMEM = {0b11110000, 0b00001111}; | |
const uint8_t Monsters [] PROGMEM = { | |
0x00, 0x00, 0x00, 0x58, 0xBC, 0x16, 0x3F, 0x3F, 0x16, 0xBC, 0x58, 0x00, 0x00, 0x00, 0x00, 0x00, | |
0x00, 0x98, 0x5C, 0xB6, 0x5F, 0x5F, 0xB6, 0x5C, 0x98, 0x00, 0x00, 0x00, 0x00, 0x70, 0x18, 0x7D, | |
0xB6, 0xBC, 0x3C, 0x3C, 0xBC, 0xB6, 0x7D, 0x18, 0x70, 0x00, 0x00, 0x1E, 0xB8, 0x7D, 0x36, 0x3C, | |
0x3C, 0x3C, 0x3C, 0x36, 0x7D, 0xB8, 0x1E, 0x00, 0x00, 0x9C, 0x9E, 0x5E, 0x76, 0x37, 0x5F, 0x5F, | |
0x37, 0x76, 0x5E, 0x9E, 0x9C, 0x00, 0x00, 0x1C, 0x5E, 0xFE, 0xB6, 0x37, 0x5F, 0x5F, 0x37, 0xB6, | |
0xFE, 0x5E, 0x1C, 0x00, 0x00, 0x40, 0x60, 0xF0, 0x50, 0x78, 0x58, 0x58, 0x78, 0x50, 0xF0, 0x60, | |
0x40, 0x00, 0x00, 0x40, 0x60, 0xD0, 0x70, 0x58, 0x78, 0x78, 0x58, 0x70, 0xD0, 0x60, 0x40, 0x00, | |
0x00, 0x00, 0x00, 0x00, 0x00, 0x24, 0x18, 0x18, 0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | |
0x00, 0x81, 0x00, 0x24, 0x18, 0x18, 0x24, 0x00, 0x81, 0x00, 0x00, 0x00, 0x00, 0x00, 0x24, 0x81, | |
0x18, 0x24, 0x5A, 0x5A, 0x24, 0x18, 0x81, 0x24, 0x00, 0x00, 0x42, 0x00, 0x24, 0x81, 0x4A, 0x3C, | |
0xA4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 0xFA, 0xF7, 0xFD, 0xEF, 0xF7, | |
0xDE, 0xEF, 0xFF, 0xBF, 0xEE, 0xFF, 0xDF, 0xBF, 0xFF, 0xDF, 0xFE, 0xBF, 0xFF, 0xAF, 0xFF, 0xDF, | |
0xFB, 0xFF, 0xF6, 0xFF, 0xFB, 0xFF, 0xFC, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFE, 0xFF, | |
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFB, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF | |
}; | |
const uint8_t intro [] PROGMEM = { | |
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, | |
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, | |
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, | |
0xff, 0xff, 0xff, 0xff, 0xff, 0x77, 0xff, 0xef, 0xee, 0xff, 0xef, 0xff, 0xff, 0xee, 0xff, | |
0x77, 0xf7, 0xff, 0xff, 0xff, 0xff, 0xde, 0xff, 0xbb, 0xfb, 0xff, 0xbb, 0xff, 0xbf, 0xbb, | |
0xff, 0xdd, 0x5d, 0xff, 0xff, 0xff, 0xff, 0x75, 0xdb, 0xed, 0x6e, 0xff, 0xef, 0xff, 0xef, | |
0xee, 0xff, 0x77, 0xf7, 0xff, 0xff, 0xff, 0x3f, 0xad, 0xff, 0x5a, 0xd5, 0xfd, 0x54, 0xff, | |
0xbf, 0x55, 0xff, 0x55, 0x2d, 0xff, 0xff, 0xff, 0x3f, 0x00, 0xed, 0x04, 0xa0, 0xff, 0x01, | |
0xff, 0x1b, 0x80, 0xfe, 0x00, 0x80, 0xfe, 0xff, 0xff, 0x9f, 0x52, 0xf6, 0xa1, 0x8a, 0xfd, | |
0x28, 0xfe, 0x4f, 0x2a, 0xff, 0xa9, 0x12, 0xff, 0xff, 0xff, 0x1f, 0x08, 0xfc, 0x08, 0x20, | |
0xff, 0x84, 0xfe, 0x0b, 0x01, 0xfe, 0x00, 0x40, 0xff, 0xff, 0xff, 0x4f, 0x42, 0xb0, 0x45, | |
0x02, 0x7a, 0x21, 0xfe, 0x23, 0x48, 0xfc, 0x94, 0x14, 0xff, 0xff, 0xff, 0x0f, 0x28, 0xe9, | |
0x01, 0x55, 0x7c, 0x08, 0xfd, 0x45, 0x05, 0xbd, 0x40, 0x49, 0xff, 0xff, 0xff, 0xaf, 0x3a, | |
0xf0, 0x55, 0x07, 0xfd, 0x42, 0xfe, 0x09, 0x57, 0x7c, 0xc9, 0xff, 0xff, 0xff, 0xff, 0x0f, | |
0x78, 0xe5, 0x03, 0x4d, 0x7c, 0x10, 0xfc, 0x23, 0x07, 0x7c, 0xe0, 0xff, 0xff, 0xff, 0xff, | |
0x9f, 0x68, 0xa0, 0x11, 0x0f, 0x79, 0x84, 0xfc, 0x81, 0x97, 0x5c, 0xa5, 0xff, 0xff, 0xff, | |
0xff, 0x1f, 0x72, 0xd5, 0x43, 0x16, 0x3c, 0x21, 0xfa, 0x15, 0x47, 0x7e, 0xd0, 0xfe, 0xff, | |
0xff, 0xff, 0xbf, 0xd0, 0xff, 0x0b, 0x4d, 0x39, 0x88, 0xfc, 0x41, 0x17, 0xbc, 0xe4, 0xfd, | |
0xff, 0xff, 0xff, 0x3f, 0x24, 0x68, 0x27, 0x0e, 0xbc, 0x12, 0xf8, 0x89, 0xef, 0x3f, 0x20, | |
0xfe, 0xff, 0xff, 0xff, 0x3f, 0x91, 0xf2, 0x83, 0x2e, 0x39, 0x50, 0xea, 0x21, 0x7f, 0xaf, | |
0x8a, 0xfc, 0xff, 0xff, 0xff, 0x7f, 0x04, 0xc0, 0x17, 0x0a, 0x38, 0x19, 0xf9, 0x85, 0xdf, | |
0x3f, 0x00, 0xfc, 0xff, 0xff, 0xff, 0xff, 0x21, 0x49, 0x47, 0xae, 0x1a, 0x34, 0xf0, 0x91, | |
0xf7, 0x2f, 0xa9, 0xfe, 0xff, 0xff, 0xff, 0xff, 0x13, 0x84, 0x07, 0x10, 0xb8, 0x28, 0xd9, | |
0xa0, 0x5f, 0x5f, 0x00, 0xfc, 0xff, 0xff, 0xff, 0xff, 0x47, 0x51, 0xad, 0x82, 0x1c, 0x52, | |
0xf0, 0x85, 0xb3, 0x16, 0x55, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfd, 0x83, 0x0f, 0x48, 0x9e, | |
0x08, 0xe5, 0x91, 0x06, 0x5f, 0xf8, 0xff, 0xff, 0xff, 0xff, 0xff, 0x41, 0x13, 0x8f, 0x20, | |
0x1f, 0x22, 0xf0, 0x84, 0x23, 0x16, 0xb2, 0xff, 0xff, 0xff, 0xff, 0xff, 0x95, 0x45, 0x4e, | |
0xfe, 0x4f, 0x80, 0xa4, 0x91, 0x8b, 0x9e, 0xf8, 0xfe, 0xff, 0xff, 0xff, 0xff, 0x81, 0x03, | |
0x0f, 0xf8, 0x2f, 0x7d, 0xe0, 0x41, 0x43, 0x0f, 0xaa, 0xff, 0xff, 0xff, 0xff, 0xff, 0x13, | |
0x55, 0x5e, 0xfa, 0x0f, 0x7c, 0xc9, 0x94, 0x12, 0x57, 0xf8, 0xfe, 0xff, 0xff, 0xff, 0xff, | |
0x43, 0x00, 0x1f, 0xfc, 0x4f, 0xfe, 0xe0, 0x01, 0x81, 0x0f, 0x05, 0xfc, 0xff, 0xff, 0xff, | |
0xff, 0x0f, 0x95, 0x9f, 0xf8, 0x0f, 0xfc, 0xc4, 0x4b, 0xd4, 0x27, 0x80, 0xfc, 0xff, 0xff, | |
0xff, 0xff, 0x5f, 0xc0, 0x1f, 0xf9, 0xa7, 0xfe, 0xc8, 0x23, 0xe0, 0x8f, 0x14, 0xfe, 0xff, | |
0xff, 0xff, 0xff, 0x3f, 0xc9, 0x3f, 0xf8, 0x07, 0xfe, 0xa2, 0x0f, 0xf5, 0x27, 0x40, 0xfe, | |
0xff, 0xff, 0xff, 0xff, 0xff, 0x7e, 0xff, 0xef, 0xff, 0xff, 0xdd, 0xef, 0xdd, 0xdd, 0xbf, | |
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xef, 0xff, 0xfb, 0x7f, 0xff, 0xff, 0xfb, 0xf7, 0xff, | |
0xef, 0xfd, 0xff, 0xff, 0xab, 0xaf, 0xbf, 0xbd, 0xfd, 0xff, 0xeb, 0xff, 0xdb, 0xfe, 0xbf, | |
0xf6, 0xfb, 0xf7, 0x6f, 0xd5, 0xff, 0x7b, 0xfb, 0xee, 0xde, 0xea, 0x5f, 0xff, 0xee, 0xfb, | |
0xed, 0xdb, 0xaf, 0xde, 0xfd, 0xff, 0xd2, 0xa7, 0x9f, 0xad, 0xfe, 0xd5, 0xb3, 0xfe, 0x55, | |
0xda, 0x2b, 0xd5, 0x6b, 0xf1, 0x37, 0xd1, 0x81, 0x13, 0x5e, 0x0c, 0xf4, 0xe8, 0x05, 0xff, | |
0x00, 0xf0, 0x41, 0x80, 0x01, 0xe2, 0x1f, 0x84, 0xc9, 0x87, 0x1c, 0x98, 0xb8, 0xc2, 0x43, | |
0xfc, 0xa4, 0xe2, 0x09, 0xea, 0x93, 0x48, 0x45, 0xa1, 0x03, 0x27, 0xb4, 0x18, 0xfa, 0xf0, | |
0x11, 0xfe, 0x00, 0xc8, 0x21, 0xc1, 0x00, 0xc0, 0x13, 0x88, 0x13, 0x0f, 0x39, 0xba, 0x50, | |
0xe4, 0x81, 0xec, 0xd4, 0xc0, 0x89, 0xbe, 0xd5, 0x92, 0x81, 0x03, 0x47, 0x4e, 0xb0, 0x30, | |
0xe0, 0xe0, 0x29, 0xf8, 0xe0, 0xd2, 0xc0, 0xff, 0xc1, 0xc0, 0xa5, 0xd2, 0x07, 0x0e, 0x62, | |
0x70, 0x65, 0xf2, 0x00, 0xfd, 0xe4, 0xc0, 0xa5, 0xfa, 0x50, 0xe4, 0xc0, 0x81, 0x4f, 0x5a, | |
0x40, 0xf2, 0x40, 0xe0, 0x25, 0xe8, 0xe0, 0xe8, 0xc0, 0xbf, 0x44, 0xe1, 0x92, 0xfe, 0x0f, | |
0x1c, 0x92, 0xa0, 0x48, 0xe9, 0x60, 0xf8, 0x64, 0xc2, 0x12, 0xf8, 0x00, 0xe8, 0x00, 0xf0, | |
0x9f, 0x3c, 0x00, 0xe8, 0x01, 0xf0, 0x68, 0xd2, 0xe0, 0xe0, 0x00, 0x7c, 0x28, 0xfa, 0x49, | |
0xf0, 0x1f, 0x68, 0x8a, 0xa0, 0x93, 0xf4, 0x60, 0xf0, 0xc8, 0xe8, 0x08, 0x5c, 0x82, 0xb8, | |
0x01, 0xf5, 0x3f, 0x39, 0x10, 0xc2, 0x07, 0x70, 0x12, 0xe4, 0x60, 0x60, 0xe2, 0x7f, 0x30, | |
0x70, 0x3b, 0xf0, 0x3f, 0x70, 0x31, 0xd0, 0x07, 0xf1, 0x80, 0xa0, 0xe4, 0xe4, 0xc0, 0x5a, | |
0x28, 0x34, 0x30, 0xf8, 0x7f, 0x60, 0x60, 0x44, 0x4f, 0x78, 0x10, 0xe0, 0x20, 0x60, 0xb0, | |
0x3f, 0x12, 0x38, 0x2a, 0xf9, 0x7f, 0xe2, 0x64, 0x81, 0x0f, 0x70, 0xf4, 0xc5, 0x60, 0x61, | |
0xa1, 0x9a, 0x98, 0x3c, 0x08, 0xfc, 0xff, 0xa0, 0xc1, 0x80, 0x1f, 0x7a, 0xf0, 0xc1, 0x08, | |
0x68, 0x08, 0x38, 0x18, 0x3c, 0x21, 0xfe, 0xff, 0xc8, 0xc1, 0x93, 0x3f, 0x38, 0xf0, 0x81, | |
0x00, 0x78, 0x02, 0x18, 0x0c, 0x7c, 0x80, 0xff, 0xff, 0xc1, 0xd3, 0x03, 0x3f, 0x79, 0xfa, | |
0xc9, 0x00, 0xfd, 0x80, 0x1c, 0x8c, 0x7e, 0xc0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, | |
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* >>>>> T-I-N-Y S-P-A-C-E I-N-V-A-D-E-R-S for ESP8266 GPL v3 <<<< | |
* This version by Tobozo https://github.com/tobozo | |
* New display library + logic refactoring (still in progress) | |
* Demo: https://youtu.be/Kfvu-Jfe3oY | |
* | |
* Original version: | |
* | |
* >>>>> T-I-N-Y S-P-A-C-E I-N-V-A-D-E-R-S for ATTINY85 GPL v3 <<<< | |
* Programmer: Daniel Champagne 2018 | |
* Contact EMAIL: [email protected] | |
* https://sites.google.com/view/arduino-collection | |
* | |
* Tiny Space Invaders is free software: you can redistribute it and/or modify | |
* it under the terms of the GNU General Public License as published by | |
* the Free Software Foundation, either version 3 of the License, or | |
* (at your option) any later version. | |
* | |
* This program is distributed in the hope that it will be useful, | |
* but WITHOUT ANY WARRANTY; without even the implied warranty of | |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
* GNU General Public License for more details. | |
* | |
* You should have received a copy of the GNU General Public License | |
* along with this program. If not, see <http://www.gnu.org/licenses/>. | |
* | |
*/ | |
#include <ESP8266WiFi.h> | |
#include <SPI.h> | |
#include <Wire.h> // Only needed for Arduino 1.6.5 and earlier | |
#include "SSD1306Wire.h" // legacy include: `#include "SSD1306.h"` | |
#include "OLEDDisplayUi.h" | |
// OLED SDA=D3, SCL=D4 | |
SSD1306Wire display(0x3c, D4, D3); | |
#include "spritebank.h" | |
#define MAXLEVELSHIELDED 3 | |
// var public | |
uint8_t Live = 0; | |
uint8_t ShieldRemoved = 0; | |
uint8_t MONSTERrest = 0; | |
uint8_t LEVELS = 0; | |
uint8_t SpeedShootMonster = 0; | |
uint8_t ShipDead = 0; | |
uint8_t ShipPos = 64; | |
// fin var public | |
#define joyX A0 // analog, left = 0, center ~=512, right=1024 | |
//#define joyY D8 // not used here | |
#define joyBTN D8 // button | |
#define SOUND_PIN D2 // speaker + pin | |
void setup() { | |
Serial.begin(115200); | |
WiFi.forceSleepBegin(); | |
display.init(); | |
display.flipScreenVertically(); | |
pinMode(joyX, INPUT); | |
//pinMode(joyY, INPUT); | |
pinMode(joyBTN, INPUT); | |
pinMode(SOUND_PIN, OUTPUT); | |
Serial.println(); | |
Serial.println("Ok"); | |
display.setTextAlignment(TEXT_ALIGN_LEFT); | |
display.setFont(ArialMT_Plain_10); | |
display.drawString(0, 0, "Tiny Space Invaders"); | |
display.display(); | |
delay(500); | |
} | |
void LoadMonstersLevels(int8_t Levels, SPACE *space) { | |
uint8_t x, y; | |
for (y = 0; y < 4; y++) { | |
for (x = 0; x < 6; x++) { | |
space->MonsterGrid[y][x] = pgm_read_byte(&MonstersLevels[(Levels * 24) + ((y) * 6) + (x)]); | |
} | |
} | |
} | |
void loop() { | |
#define SHOOTS 2 | |
uint8_t Decompte = 0; | |
uint8_t VarPot = 64; | |
uint8_t MyShootReady = SHOOTS; | |
SPACE space; | |
NEWGAME:; | |
Live = 3; | |
LEVELS = 0; | |
while (1) { | |
drawIntroImage(); | |
if (digitalRead(joyBTN) == HIGH) { | |
Sound(100, 125); | |
Sound(50, 125); | |
break; | |
} | |
} | |
NEWLEVEL: | |
delay(1000); | |
BYPASS2: | |
VarResetNewLevel(&space); | |
SpeedControle(&space); | |
goto Bypass; | |
RestartLevel: | |
delay(1000); | |
if (Live > 0) { | |
Live--; | |
} else { | |
goto NEWGAME; | |
} | |
Bypass: | |
ShipDead = 0; | |
Decompte = 0; | |
while (1) { | |
if (MONSTERrest == 0) { | |
Sound(110, 255); delay(40); Sound(130, 255); delay(40); Sound(100, 255); | |
delay(40); Sound(1, 155); delay(20); Sound(60, 255); Sound(60, 255); | |
if (LEVELS < 9) { | |
LEVELS++; | |
} | |
goto NEWLEVEL; | |
} | |
if ((((space.MonsterGroupeYpos) + (space.MonsterFloorMax + 1)) == 7) && (Decompte == 0)) { | |
ShipDead = 1; | |
} | |
if (SpeedShootMonster <= ((9 - LEVELS))) { | |
SpeedShootMonster++; | |
} else { | |
SpeedShootMonster = 0; | |
MonsterShootGenerate(&space); | |
} | |
space.ScrBackV = (ShipPos / 14) + 52; | |
drawGameWindow(&space); | |
space.oneFrame = !space.oneFrame; | |
RemoveExplodOnMonsterGrid(&space); | |
MonsterShootupdate(&space); | |
UFOUpdate(&space); | |
if (((space.MonsterGroupeXpos >= 26) && (space.MonsterGroupeXpos <= 28)) && (space.MonsterGroupeYpos == 2) && (space.DecalageY8 == 4)) { | |
space.UFOxPos = 127; | |
} | |
if (VarPot > (ShipPos + 2)) { | |
ShipPos = ShipPos + ((VarPot - ShipPos) / 3); | |
} | |
if (VarPot < (ShipPos - 2)) { | |
ShipPos = ShipPos - ((ShipPos - VarPot) / 3); | |
} | |
if (ShipDead != 1) { | |
if (space.frame < space.frameMax) { | |
space.frame++; | |
} else { | |
GRIDMonsterFloorY(&space); | |
space.anim = !space.anim; | |
if (space.anim == 0) { | |
Sound(100, 1); | |
} else { | |
Sound(200, 1); | |
} MonsterRefreshMove(&space); | |
space.frame = 0; | |
} | |
int8_t joyVect = map(analogRead(joyX), 0, 1023, 5, -4)-1; | |
if(VarPot+joyVect>0 && VarPot+joyVect<=114) { | |
VarPot += joyVect; | |
} | |
if((digitalRead(joyBTN) == HIGH) && (MyShootReady == SHOOTS)) { | |
Sound(200, 4); | |
MyShootReady = 0; | |
space.MyShootBall = 6; | |
space.MyShootBallxpos = ShipPos + 6; | |
} | |
} else { | |
Sound(80, 1); Sound(100, 1); | |
Decompte++; | |
if (Decompte >= 30) { | |
delay(600); | |
if (((space.MonsterGroupeYpos) + (space.MonsterFloorMax + 1)) == 7) { | |
goto NEWGAME; | |
} else { | |
goto RestartLevel; | |
} | |
} | |
} | |
if (space.MyShootBall == -1) { | |
if (MyShootReady < SHOOTS) { | |
MyShootReady++; | |
} | |
} | |
// slow down the game (ESP is fast) | |
delay(50); | |
} | |
} | |
////////////////////////////////// main end ///////////////////////////////// | |
void SpeedControle(SPACE *space) { | |
uint8_t xx = 00, yy = 0; | |
MONSTERrest = 0; | |
for (yy = 0; yy <= 3; yy++) { | |
for (xx = 0; xx <= 5; xx++) { | |
if ((space->MonsterGrid[yy][xx] != -1) && ((space->MonsterGrid[yy][xx] <= 5)) ) { | |
MONSTERrest++; | |
} | |
} | |
} space->frameMax = (MONSTERrest / 8 ); | |
} | |
void GRIDMonsterFloorY(SPACE *space) { | |
uint8_t y, x; | |
space->MonsterFloorMax = 3; | |
for (y = 3; y >= 0; y--) { | |
for (x = 0; x <= 5; x++) { | |
if (space->MonsterGrid[y][x] != -1) { | |
goto FIN; | |
} | |
} | |
space->MonsterFloorMax = space->MonsterFloorMax - 1; | |
} FIN:; | |
} | |
uint8_t LivePrint(uint8_t x, uint8_t y, SPACE *space) { | |
#define XLIVEWIDE ((5*Live)-1) | |
if (((0 <= (x)) && (0 >= (x - XLIVEWIDE))) && (y == 7)) { | |
return pgm_read_byte(&LIVE[(x)]); | |
} | |
return 0x00; | |
} | |
void drawGameWindow(SPACE *space) { | |
uint8_t y, x; | |
uint8_t MYSHIELD = 0x00; | |
uint8_t screenbuff[128*8]; | |
display.clear(); | |
for (y = 0; y < 8; y++) { | |
for (x = 0; x < 128; x++) { | |
if (ShieldRemoved == 0) { | |
MYSHIELD = MyShield(x, y, space); | |
} else { | |
MYSHIELD = 0x00; | |
} | |
byte ret[1]; | |
ret[0] = (background(x, y, space) | LivePrint(x, y, space) | Vesso(x, y, space) | UFOWrite(x, y, space) | Monster(x, y, space) | MyShoot(x, y, space) | MonsterShoot(x, y, space) | MYSHIELD); | |
display.drawFastImage(x, y*8, 1, 8, ret); | |
} | |
if (ShieldRemoved == 0) { | |
ShieldDestroy(0, space->MyShootBallxpos, space->MyShootBall, space); | |
} | |
} | |
if ((space->MonsterGroupeYpos < (2 + (4 - (space->MonsterFloorMax + 1))))/*&&(LEVELS<=MAXLEVELSHIELDED)*/) { | |
// wut ? | |
} else { | |
if (ShieldRemoved != 1) { | |
space->Shield[0] = 0x00; | |
space->Shield[1] = 0x00; | |
space->Shield[2] = 0x00; | |
space->Shield[3] = 0x00; | |
space->Shield[4] = 0x00; | |
space->Shield[5] = 0x00; | |
ShieldRemoved = 1; | |
} | |
} | |
display.display(); | |
} | |
void drawIntroImage() { | |
display.clear(); | |
display.drawXbm(0, 0, 128, 55, intro); | |
display.display(); | |
} | |
uint8_t UFOWrite(uint8_t x, uint8_t y, SPACE *space) { | |
if ((space->UFOxPos != -120) && (y == 0) && ((space->UFOxPos <= (x)) && (space->UFOxPos >= (x - 14)))) { | |
return pgm_read_byte(&Monsters[(x - space->UFOxPos) + (6 * 14) + (space->oneFrame * 14)]); | |
} | |
return 0x00; | |
} | |
void UFOUpdate(SPACE *space) { | |
if (space->UFOxPos != -120) { | |
space->UFOxPos = space->UFOxPos - 2; | |
if (space->UFOxPos <= -20) { | |
space->UFOxPos = -120; | |
} | |
} | |
} | |
void ShipDestroyByMonster(SPACE *space) { | |
if ((space->MonsterShoot[1][0] >= 14) && (space->MonsterShoot[1][0] <= 15) && (space->MonsterShoot[0][0] >= ShipPos) && (space->MonsterShoot[0][0] <= ShipPos + 14)) { | |
ShipDead = 1; | |
} | |
} | |
void MonsterShootupdate(SPACE *space) { | |
if (space->MonsterShoot[1][0] != 16) { | |
ShipDestroyByMonster(space); | |
if (ShieldDestroy(1, space->MonsterShoot[0][0], space->MonsterShoot[1][0] / 2, space)) { | |
space->MonsterShoot[1][0] = 16; | |
} else { | |
space->MonsterShoot[1][0] = space->MonsterShoot[1][0] + 1; | |
} | |
} | |
} | |
void MonsterShootGenerate(SPACE *space) { | |
uint8_t a = random(3);// % 3; | |
uint8_t b = random(6);// % 6; | |
if (b >= 5) { | |
b = 5; | |
} | |
if (space->MonsterShoot[1][0] == 16) { | |
if (space->MonsterGrid[a][b] != -1) { | |
space->MonsterShoot[0][0] = (space->MonsterGroupeXpos + 7) + (b * 14); | |
space->MonsterShoot[1][0] = (((space->MonsterGroupeYpos) + a) * 2) + 1; | |
} | |
} | |
} | |
uint8_t MonsterShoot(uint8_t x, uint8_t y, SPACE *space) { | |
if ((((space->MonsterShoot[1][0]) / 2) == y) && (space->MonsterShoot[0][0] == x) ) { | |
if (((space->MonsterShoot[1][0 ]) % 2) == 0) { | |
return 0b00001111; | |
} else { | |
return 0b11110000; | |
} | |
} | |
return 0x00; | |
} | |
uint8_t ShieldDestroy(uint8_t Origine, uint8_t VarX, uint8_t VarY, SPACE *space) { | |
#define OFFSETXSHIELD -1 | |
if (VarY == 6) { | |
if (((VarX >= (20 + OFFSETXSHIELD)) && (VarX <= (27 + OFFSETXSHIELD)))) { | |
if ((BOOLREAD(0, (VarX - (20 + OFFSETXSHIELD)), space))) { | |
ShieldDestroyWrite(0, (VarX - (20 + OFFSETXSHIELD)), space, Origine); | |
return 1; | |
} | |
} | |
if (((VarX >= (28 + OFFSETXSHIELD)) && (VarX <= (35 + OFFSETXSHIELD)))) { | |
if ((BOOLREAD(1, (VarX - (28 + OFFSETXSHIELD)), space))) { | |
ShieldDestroyWrite(1, (VarX - (28 + OFFSETXSHIELD)), space, Origine); | |
return 1; | |
} | |
} | |
if (((VarX >= (55 + OFFSETXSHIELD)) && (VarX <= (62 + OFFSETXSHIELD)))) { | |
if ((BOOLREAD(2, (VarX - (55 + OFFSETXSHIELD)), space))) { | |
ShieldDestroyWrite(2, (VarX - (55 + OFFSETXSHIELD)), space, Origine); | |
return 1; | |
} | |
} | |
if (((VarX >= (63 + OFFSETXSHIELD)) && (VarX <= (70 + OFFSETXSHIELD)))) { | |
if ((BOOLREAD(3, (VarX - (63 + OFFSETXSHIELD)), space))) { | |
ShieldDestroyWrite(3, (VarX - (63 + OFFSETXSHIELD)), space, Origine); | |
return 1; | |
} | |
} | |
if (((VarX >= (90 + OFFSETXSHIELD)) && (VarX <= (97 + OFFSETXSHIELD)))) { | |
if ((BOOLREAD(4, (VarX - (90 + OFFSETXSHIELD)), space))) { | |
ShieldDestroyWrite(4, (VarX - (90 + OFFSETXSHIELD)), space, Origine); | |
return 1; | |
} | |
} | |
if (((VarX >= (98 + OFFSETXSHIELD)) && (VarX <= (105 + OFFSETXSHIELD)))) { | |
if ((BOOLREAD(5, (VarX - (98 + OFFSETXSHIELD)), space))) { | |
ShieldDestroyWrite(5, (VarX - (98 + OFFSETXSHIELD)), space, Origine); | |
return 1; | |
} | |
} | |
} | |
return 0; | |
} | |
void ShieldDestroyWrite(uint8_t BOOLWRITE, uint8_t line, SPACE *space, uint8_t Origine) { | |
switch (line) { | |
case 0: space->Shield[BOOLWRITE] = space->Shield[BOOLWRITE] - 128; if (Origine == 0) { | |
space->MyShootBall = -1; | |
} break; | |
case 1: space->Shield[BOOLWRITE] = space->Shield[BOOLWRITE] - 64; if (Origine == 0) { | |
space->MyShootBall = -1; | |
} break; | |
case 2: space->Shield[BOOLWRITE] = space->Shield[BOOLWRITE] - 32; if (Origine == 0) { | |
space->MyShootBall = -1; | |
} break; | |
case 3: space->Shield[BOOLWRITE] = space->Shield[BOOLWRITE] - 16; if (Origine == 0) { | |
space->MyShootBall = -1; | |
} break; | |
case 4: space->Shield[BOOLWRITE] = space->Shield[BOOLWRITE] - 8; if (Origine == 0) { | |
space->MyShootBall = -1; | |
} break; | |
case 5: space->Shield[BOOLWRITE] = space->Shield[BOOLWRITE] - 4; if (Origine == 0) { | |
space->MyShootBall = -1; | |
} break; | |
case 6: space->Shield[BOOLWRITE] = space->Shield[BOOLWRITE] - 2; if (Origine == 0) { | |
space->MyShootBall = -1; | |
} break; | |
case 7: space->Shield[BOOLWRITE] = space->Shield[BOOLWRITE] - 1; if (Origine == 0) { | |
space->MyShootBall = -1; | |
} break; | |
default: break; | |
} | |
} | |
uint8_t MyShield(uint8_t x, uint8_t y, SPACE *space) { | |
#define OFFSETXSHIELD -1 | |
if (((x >= (20 + OFFSETXSHIELD)) && (x <= (27 + OFFSETXSHIELD))) && (y == 6)) { | |
if ((BOOLREAD(0, (x - (20 + OFFSETXSHIELD)), space))) { | |
return ShieldBlitz(0, (x - (20 + OFFSETXSHIELD))); | |
} else { | |
return 0x00; | |
} | |
} | |
if (((x >= (28 + OFFSETXSHIELD)) && (x <= (35 + OFFSETXSHIELD))) && (y == 6)) { | |
if ((BOOLREAD(1, (x - (28 + OFFSETXSHIELD)), space))) { | |
return ShieldBlitz(1, (x - (28 + OFFSETXSHIELD))); | |
} else { | |
return 0x00; | |
} | |
} | |
if (((x >= (55 + OFFSETXSHIELD)) && (x <= (62 + OFFSETXSHIELD))) && (y == 6)) { | |
if ((BOOLREAD(2, (x - (55 + OFFSETXSHIELD)), space))) { | |
return ShieldBlitz(0, (x - (55 + OFFSETXSHIELD))); | |
} else { | |
return 0x00; | |
} | |
} | |
if (((x >= (63 + OFFSETXSHIELD)) && (x <= (70 + OFFSETXSHIELD))) && (y == 6)) { | |
if ((BOOLREAD(3, (x - (63 + OFFSETXSHIELD)), space))) { | |
return ShieldBlitz(1, (x - (63 + OFFSETXSHIELD))); | |
} else { | |
return 0x00; | |
} | |
} | |
if (((x >= (90 + OFFSETXSHIELD)) && (x <= (97 + OFFSETXSHIELD))) && (y == 6)) { | |
if ((BOOLREAD(4, (x - (90 + OFFSETXSHIELD)), space))) { | |
return ShieldBlitz(0, (x - (90 + OFFSETXSHIELD))); | |
} else { | |
return 0x00; | |
} | |
} | |
if (((x >= (98 + OFFSETXSHIELD)) && (x <= (105 + OFFSETXSHIELD))) && (y == 6)) { | |
if ((BOOLREAD(5, (x - (98 + OFFSETXSHIELD)), space))) { | |
return ShieldBlitz(1, (x - (98 + OFFSETXSHIELD))); | |
} else { | |
return 0x00; | |
} | |
} | |
return 0x00; | |
} | |
uint8_t ShieldBlitz(uint8_t Part, uint8_t LineSH ) { | |
uint8_t Var0 = 0; | |
switch (LineSH) { | |
case 0: if (Part == 0) { | |
Var0 = 0b11110000; | |
} else { | |
Var0 = 0b00001111; | |
} break; | |
case 1: if (Part == 0) { | |
Var0 = 0b11111100; | |
} else { | |
Var0 = 0b00001111; | |
} break; | |
case 2: | |
case 3: | |
case 4: | |
case 5: Var0 = 0b00001111; break; | |
case 6: if (Part == 1) { | |
Var0 = 0b11111100; | |
} else { | |
Var0 = 0b00001111; | |
} break; | |
case 7: if (Part == 1) { | |
Var0 = 0b11110000; | |
} else { | |
Var0 = 0b00001111; | |
} break; | |
default: Var0 = 0b00000000; break; | |
} | |
return Var0; | |
} | |
uint8_t BOOLREAD(uint8_t SHnum, uint8_t LineSH, SPACE *space ) { | |
uint8_t Var0 = 0; | |
switch (LineSH) { | |
case 0: Var0 = 0b10000000; break; | |
case 1: Var0 = 0b01000000; break; | |
case 2: Var0 = 0b00100000; break; | |
case 3: Var0 = 0b00010000; break; | |
case 4: Var0 = 0b00001000; break; | |
case 5: Var0 = 0b00000100; break; | |
case 6: Var0 = 0b00000010; break; | |
case 7: Var0 = 0b00000001; break; | |
default: Var0 = 0b00000000; break; | |
} | |
if ((space->Shield[SHnum]&Var0) != 0) { | |
return 1; | |
} else { | |
return 0; | |
} | |
} | |
void RemoveExplodOnMonsterGrid(SPACE *space) { | |
uint8_t x = 0, y = 0; | |
for (y = 0; y <= 3; y++) { //était a 5 | |
for (x = 0; x <= 5; x++) { | |
if (space->MonsterGrid[y][x] >= 11) { | |
space->MonsterGrid[y][x] = -1; | |
} | |
if (space->MonsterGrid[y][x] >= 8) { | |
space->MonsterGrid[y][x] = space->MonsterGrid[y][x] + 1; | |
} | |
} | |
} | |
} | |
uint8_t background(uint8_t x, uint8_t y, SPACE *space) { | |
uint8_t scr = (space->ScrBackV + x); | |
if ((scr) > 127) { | |
scr = (space->ScrBackV + x) - 128; | |
} | |
return 0xff - pgm_read_byte(&back[((y) * 128) + ((scr))]); | |
} | |
uint8_t Vesso(uint8_t x, uint8_t y, SPACE *space) { | |
if (((x - ShipPos) >= 0) && ((x - ShipPos) < 13) && (y == 7)) { | |
if (ShipDead == 0) { | |
return pgm_read_byte(&vesso[(x - ShipPos)]); | |
} else { | |
return pgm_read_byte(&vesso[(x - ShipPos) + (12 * space->oneFrame)]); | |
} | |
} | |
return 0; | |
} | |
void UFO_Attack_Check(uint8_t x, uint8_t y, SPACE *space) { | |
if (space->MyShootBall == 0) { | |
if ((space->MyShootBallxpos >= space->UFOxPos) && (space->MyShootBallxpos <= (space->UFOxPos + 14))) { | |
for (x = 1; x < 100; x++) { | |
Sound(x, 1); | |
} | |
if (Live < 3) Live++; | |
space->UFOxPos = -120; | |
} | |
} | |
} | |
uint8_t MyShoot(uint8_t x, uint8_t y, SPACE *space) { | |
if ((space->MyShootBallxpos == x) && (y == ((space->MyShootBall)))) { | |
if (space->MyShootBall > -1) { | |
space->MyShootBallFrame = !space->MyShootBallFrame; | |
} else { | |
return 0x00; | |
} | |
if (space->MyShootBallFrame == 1) { | |
space->MyShootBall--; | |
} | |
Monster_Attack_Check(x, y, space); | |
UFO_Attack_Check(x, y, space); | |
return pgm_read_byte(&SHOOT[(space->MyShootBallFrame)]); | |
} | |
return 0x00; | |
} | |
void Monster_Attack_Check(uint8_t x, uint8_t y, SPACE *space) { | |
int8_t Varx = 0, Vary = 0; | |
#define Xmouin (space->MonsterGroupeXpos) | |
#define Ymouin ((space->MonsterGroupeYpos)*8)//-space->DecalageY8 | |
#define XPlus (Xmouin+84) | |
#define YPlus (Ymouin+(4*8)) | |
#define MYSHOOTX (space->MyShootBallxpos) | |
#define MYSHOOTY ((space->MyShootBall*8)+(((space->MyShootBallFrame)+1)*4)) | |
if ((MYSHOOTX >= Xmouin) && (MYSHOOTX <= XPlus) && (MYSHOOTY >= (Ymouin)) && (MYSHOOTY <= YPlus)) { | |
//enter in the monster zone | |
Vary = (round((MYSHOOTY - Ymouin) / 8)); | |
Varx = (round((MYSHOOTX - Xmouin) / 14)); | |
if (Varx < 0) { | |
Varx = 0; | |
} | |
if (Vary < 0) { | |
Vary = 0; | |
} | |
if (Varx > 5) { | |
return; | |
} | |
if (Vary > 3) { | |
return; | |
} | |
if ((space->MonsterGrid[Vary][Varx] > -1) && (space->MonsterGrid[Vary][Varx] < 6)) { | |
Sound(50, 10); | |
space->MonsterGrid[Vary][Varx] = 8; | |
space->MyShootBall = -1; | |
SpeedControle(space); | |
} | |
//fin monster zone | |
} | |
} | |
int8_t OuDansLaGrilleMonster(uint8_t x, uint8_t y, SPACE *space) { | |
if (x < space->MonsterGroupeXpos) { | |
return -1; | |
} | |
if (y < space->MonsterGroupeYpos) { | |
return -1; | |
} | |
space->PositionDansGrilleMonsterX = (x - space->MonsterGroupeXpos) / 14; | |
space->PositionDansGrilleMonsterY = (y - space->MonsterGroupeYpos); | |
if ((space->PositionDansGrilleMonsterX) > 5) { | |
return -1; | |
} | |
if ((space->PositionDansGrilleMonsterY) > 4) { | |
return -1; | |
} | |
return 0; | |
} | |
uint8_t SplitSpriteDecalageY(uint8_t Input, uint8_t UPorDOWN, SPACE *space) { | |
if (UPorDOWN) { | |
return Input << space->DecalageY8; | |
} else { | |
return Input >> (8 - space->DecalageY8); | |
} | |
} | |
uint8_t Murge_Split_UP_DOWN(uint8_t x, uint8_t y, SPACE *space) { | |
int8_t SpriteType = -1; | |
int8_t ANIMs = -1; | |
uint8_t Murge1 = 0; | |
uint8_t Murge2 = 0; | |
if (space->DecalageY8 == 0) { | |
SpriteType = space->MonsterGrid[space->PositionDansGrilleMonsterY][space->PositionDansGrilleMonsterX]; | |
if (SpriteType < 8) { | |
ANIMs = (space->anim * 14); | |
} else { | |
ANIMs = 0; | |
} | |
if (SpriteType == -1) { | |
return 0x00; | |
} | |
return pgm_read_byte(&Monsters[(WriteMonster14(x - space->MonsterGroupeXpos, space) + SpriteType * 14) + ANIMs]); | |
} else { //debut | |
if (space->PositionDansGrilleMonsterY == 0) { | |
SpriteType = space->MonsterGrid[space->PositionDansGrilleMonsterY][space->PositionDansGrilleMonsterX]; | |
if (SpriteType < 8) { | |
ANIMs = (space->anim * 14); | |
} else { | |
ANIMs = 0; | |
} | |
if (SpriteType != -1) { | |
Murge2 = SplitSpriteDecalageY(pgm_read_byte(&Monsters[(WriteMonster14(x - space->MonsterGroupeXpos, space) + SpriteType * 14) + ANIMs]), 1, space); | |
} else { | |
Murge2 = 0x00; | |
} | |
return Murge2; | |
} else { | |
SpriteType = space->MonsterGrid[space->PositionDansGrilleMonsterY - 1][space->PositionDansGrilleMonsterX]; | |
if (SpriteType < 8) { | |
ANIMs = (space->anim * 14); | |
} else { | |
ANIMs = 0; | |
} | |
if (SpriteType != -1) { | |
Murge1 = SplitSpriteDecalageY(pgm_read_byte(&Monsters[(WriteMonster14(x - space->MonsterGroupeXpos, space) + SpriteType * 14) + ANIMs]), 0, space); | |
} else { | |
Murge1 = 0x00; | |
} | |
SpriteType = space->MonsterGrid[space->PositionDansGrilleMonsterY][space->PositionDansGrilleMonsterX]; | |
if (SpriteType < 8) { | |
ANIMs = (space->anim * 14); | |
} else { | |
ANIMs = 0; | |
} | |
if (SpriteType != -1) { | |
Murge2 = SplitSpriteDecalageY(pgm_read_byte(&Monsters[(WriteMonster14(x - space->MonsterGroupeXpos, space) + SpriteType * 14) + ANIMs]), 1, space); | |
} else { | |
Murge2 = 0x00; | |
} | |
return Murge1 | Murge2; | |
} | |
} //fin | |
} | |
uint8_t WriteMonster14(uint8_t x, SPACE *space) { | |
while (1) { | |
if ((x - 14) >= 0) { | |
x = x - 14; | |
} else { | |
break; | |
} | |
} return x; | |
} | |
uint8_t Monster(uint8_t x, uint8_t y, SPACE *space) { | |
int8_t SpriteType = -1; | |
if (OuDansLaGrilleMonster(x, y, space) != -1) { | |
} else { | |
return 0x00; //quiter la fonction si pas dans la grille | |
} | |
return Murge_Split_UP_DOWN(x, y, space); | |
return 0x00; | |
}//end Monster(); | |
uint8_t MonsterRefreshMove(SPACE *space) { | |
if (space->Direction == 1) { | |
if ((space->MonsterGroupeXpos < space->MonsterOffsetDroite)) { | |
space->MonsterGroupeXpos = space->MonsterGroupeXpos + 2; | |
return 0; | |
} else { | |
if (space->DecalageY8 < 7) { | |
space->DecalageY8 = space->DecalageY8 + 4; | |
if (space->DecalageY8 > 7) { | |
space->DecalageY8 = 7; | |
} | |
} else { | |
space->MonsterGroupeYpos++; | |
space->DecalageY8 = 0; | |
} | |
space->Direction = 0; return 0; | |
} | |
} else { | |
if ((space->MonsterGroupeXpos > space->MonsterOffsetGauche)) { | |
space->MonsterGroupeXpos = space->MonsterGroupeXpos - 2; | |
return 0; | |
} else { | |
if (space->DecalageY8 < 7) { | |
space->DecalageY8 = space->DecalageY8 + 4; | |
if (space->DecalageY8 > 7) { | |
space->DecalageY8 = 7; | |
} | |
} else { | |
space->MonsterGroupeYpos++; | |
space->DecalageY8 = 0; | |
} | |
space->Direction = 1; return 0; | |
} | |
} | |
} | |
void Sound(uint8_t freq, uint8_t dur) { | |
for (uint8_t t = 0; t < dur; t++) { | |
digitalWrite(SOUND_PIN, HIGH); | |
for (uint8_t t = 0; t < (255 - freq); t++) { | |
delayMicroseconds(1); | |
} | |
digitalWrite(SOUND_PIN, LOW); | |
for (uint8_t t = 0; t < (255 - freq); t++) { | |
delayMicroseconds(1); | |
} | |
} | |
} | |
void VarResetNewLevel(SPACE *space) { | |
//space->ScrBackV=0; | |
ShieldRemoved = 0; | |
SpeedShootMonster = 0; | |
MONSTERrest = 24; | |
LoadMonstersLevels(LEVELS, space); | |
space->Shield[0] = 255; | |
space->Shield[1] = 255; | |
space->Shield[2] = 255; | |
space->Shield[3] = 255; | |
space->Shield[4] = 255; | |
space->Shield[5] = 255; | |
space->MonsterShoot[0][0] = 16; | |
space->MonsterShoot[1][0] = 16; | |
space->UFOxPos = -120; | |
space->MyShootBall = -1; | |
space->MyShootBallxpos = 0; | |
space->MyShootBallFrame = 0; | |
space->anim = 0; | |
space->frame = 0; | |
space->PositionDansGrilleMonsterX = 0; | |
space->PositionDansGrilleMonsterY = 0; | |
space->MonsterFloorMax = 3; | |
space->MonsterOffsetGauche = 0; | |
space->MonsterOffsetDroite = 44; | |
space->MonsterGroupeXpos = 0; | |
if (LEVELS > 3) { | |
space->MonsterGroupeYpos = 1; | |
} else { | |
space->MonsterGroupeYpos = 0; | |
} | |
space->DecalageY8 = 0; | |
space->frameMax = 8; | |
space->Direction = 1; //1 right 0 gauche | |
space->oneFrame = 0; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks for the port to 8266. I tried to compile but got error of “sprites.h” not found. I tried to load the “spritesbank.h” from the original project for Attiny85. I can compile but the program Hangs after dusplayihg “Space invader” on the Oled followed by a messed up graphic. Can you post the “spritesbank.h”