|
|
|
|
|
|
|
|
/* */ |
|
|
/* */ |
|
|
/* PACMAN GAME FOR ARDUINO DUE */ |
|
|
/* PACMAN GAME FOR ARDUINO DUE */ |
|
|
/* */ |
|
|
/* */ |
|
|
|
|
|
/* Adapted to Teensy 3.6 and 4.0 */ |
|
|
|
|
|
/* Currently requires the libraries */ |
|
|
|
|
|
/* ili9341_t3n that can be located: https://github.com/KurtE/ILI9341_t3n */ |
|
|
|
|
|
/* spin: https://github.com/KurtE/SPIN */ |
|
|
|
|
|
/* */ |
|
|
/******************************************************************************/ |
|
|
/******************************************************************************/ |
|
|
/* Copyright (c) 2014 Dr. NCX (mirracle.mxx@gmail.com) */ |
|
|
/* Copyright (c) 2014 Dr. NCX (mirracle.mxx@gmail.com) */ |
|
|
/* */ |
|
|
/* */ |
|
|
|
|
|
|
|
|
/******************************************************************************/ |
|
|
/******************************************************************************/ |
|
|
/* ILI9341: */ |
|
|
/* ILI9341: */ |
|
|
/*----------------------------------------------------------------------------*/ |
|
|
/*----------------------------------------------------------------------------*/ |
|
|
|
|
|
/* Teensy 3.6 Pins */ |
|
|
/* 8 = RST */ |
|
|
/* 8 = RST */ |
|
|
/* 9 = D/C */ |
|
|
/* 9 = D/C */ |
|
|
/* 10 = CS */ |
|
|
/* 10 = CS */ |
|
|
/* */ |
|
|
/* */ |
|
|
|
|
|
/* Teensy 4.0 Beta Pins */ |
|
|
|
|
|
/* 23 = RST (Marked MCLK on T4 beta breakout) */ |
|
|
|
|
|
/* 10 = D/C (Marked CS) */ |
|
|
|
|
|
/* 9 = CS (Marked MEMCS) */ |
|
|
|
|
|
/* */ |
|
|
/*----------------------------------------------------------------------------*/ |
|
|
/*----------------------------------------------------------------------------*/ |
|
|
/* VGA: */ |
|
|
/* VGA: */ |
|
|
/*----------------------------------------------------------------------------*/ |
|
|
/*----------------------------------------------------------------------------*/ |
|
|
|
|
|
|
|
|
// SPI Library |
|
|
// SPI Library |
|
|
#include <SPI.h> |
|
|
#include <SPI.h> |
|
|
|
|
|
|
|
|
// ILI9341_due NEW lib by Marek Buriak http://marekburiak.github.io/ILI9341_due/ |
|
|
|
|
|
#include "ILI9341_due_config.h" |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Connection konfiguration of ILI9341 LCD TFT |
|
|
// Connection konfiguration of ILI9341 LCD TFT |
|
|
|
|
|
#if defined(__MK66FX1M0__) |
|
|
#define TFT_RST 8 |
|
|
#define TFT_RST 8 |
|
|
|
|
|
#define TFT_DC 9 |
|
|
|
|
|
#define TFT_CS 10 |
|
|
|
|
|
#elif defined(__IMXRT1052__) || defined(__IMXRT1062__) |
|
|
|
|
|
// On Teensy 4 beta with Paul's breakout out: |
|
|
|
|
|
// Using pins (MOSI, MISO, SCK which are labeled on Audio board breakout location |
|
|
|
|
|
// which are not in the Normal processor positions |
|
|
|
|
|
// Also DC=10(CS), CS=9(BCLK) and RST 23(MCLK) |
|
|
|
|
|
#define TFT_RST 23 |
|
|
#define TFT_DC 10 |
|
|
#define TFT_DC 10 |
|
|
#define TFT_CS 9 |
|
|
#define TFT_CS 9 |
|
|
|
|
|
#else |
|
|
|
|
|
#error "This example App will only work with Teensy 3.6 or Teensy 4." |
|
|
|
|
|
#endif |
|
|
ILI9341_t3n tft = ILI9341_t3n(TFT_CS, TFT_DC, TFT_RST); |
|
|
ILI9341_t3n tft = ILI9341_t3n(TFT_CS, TFT_DC, TFT_RST); |
|
|
/******************************************************************************/ |
|
|
/******************************************************************************/ |
|
|
/* Controll KEYPAD LOOP */ |
|
|
/* Controll KEYPAD LOOP */ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const byte _scatterChase[] = { 7, 20, 7, 20, 5, 20, 5, 0 }; |
|
|
const byte _scatterChase[] = { 7, 20, 7, 20, 5, 20, 5, 0 }; |
|
|
const byte _scatterTargets[] = { 2, 0, 25, 0, 0, 35, 27, 35 }; // inky/clyde scatter targets are backwards |
|
|
const byte _scatterTargets[] = { 2, 0, 25, 0, 0, 35, 27, 35 }; // inky/clyde scatter targets are backwards |
|
|
const char _pinkyTargetOffset[] = { 4, 0, 0, 4, -4, 0, -4, 4 }; // Includes pinky target bug |
|
|
|
|
|
|
|
|
const char _pinkyTargetOffset[] = { 4, 0, 0, 4, (char)-4, 0, (char)-4, 4 }; // Includes pinky target bug |
|
|
|
|
|
|
|
|
#define FRIGHTENEDGHOSTSPRITE 0 |
|
|
#define FRIGHTENEDGHOSTSPRITE 0 |
|
|
#define GHOSTSPRITE 2 |
|
|
#define GHOSTSPRITE 2 |
|
|
|
|
|
|
|
|
if (LEVEL % 5 == 3) return pgm_read_byte(playMap3 + ty * 28 + cx); |
|
|
if (LEVEL % 5 == 3) return pgm_read_byte(playMap3 + ty * 28 + cx); |
|
|
if (LEVEL % 5 == 4) return pgm_read_byte(playMap4 + ty * 28 + cx); |
|
|
if (LEVEL % 5 == 4) return pgm_read_byte(playMap4 + ty * 28 + cx); |
|
|
if (LEVEL % 5 == 0) return pgm_read_byte(playMap5 + ty * 28 + cx); |
|
|
if (LEVEL % 5 == 0) return pgm_read_byte(playMap5 + ty * 28 + cx); |
|
|
|
|
|
return 0; // |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// Draw 1 bit BG into 8 bit tile |
|
|
// Draw 1 bit BG into 8 bit tile |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Should be a direct Graphics call |
|
|
// Should be a direct Graphics call |
|
|
|
|
|
|
|
|
byte n = tile[0]; |
|
|
|
|
|
byte i = 0; |
|
|
|
|
|
word color = (word)_paletteW[n]; |
|
|
|
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------ |
|
|
//------------------------------------------------------------------------------ |
|
|
#ifdef USE_ILI |
|
|
#ifdef USE_ILI |
|
|
|
|
|
|
|
|
#endif |
|
|
#endif |
|
|
//------------------------------------------------------------------------------ |
|
|
//------------------------------------------------------------------------------ |
|
|
#ifdef USE_VGA |
|
|
#ifdef USE_VGA |
|
|
|
|
|
byte n = tile[0]; |
|
|
for (byte tmpY = 0; tmpY < 8; tmpY++) { |
|
|
for (byte tmpY = 0; tmpY < 8; tmpY++) { |
|
|
|
|
|
|
|
|
word width = 1; |
|
|
word width = 1; |
|
|
|
|
|
|
|
|
pacman = _sprites + PACMAN; |
|
|
pacman = _sprites + PACMAN; |
|
|
|
|
|
|
|
|
// Chase frightened ghosts |
|
|
// Chase frightened ghosts |
|
|
Sprite* closestGhost = NULL; |
|
|
|
|
|
|
|
|
//Sprite* closestGhost = NULL; |
|
|
Sprite* frightenedGhost = NULL; |
|
|
Sprite* frightenedGhost = NULL; |
|
|
Sprite* closestAttackingGhost = NULL; |
|
|
Sprite* closestAttackingGhost = NULL; |
|
|
Sprite* DeadEyesStateGhost = NULL; |
|
|
Sprite* DeadEyesStateGhost = NULL; |
|
|
|
|
|
|
|
|
closestAttackingGhost = s; |
|
|
closestAttackingGhost = s; |
|
|
closestAttackingDist = d; |
|
|
closestAttackingDist = d; |
|
|
} |
|
|
} |
|
|
closestGhost = s; |
|
|
|
|
|
|
|
|
//closestGhost = s; |
|
|
|
|
|
|
|
|
if ( s->state == DeadEyesState ) DeadEyesStateGhost = s; |
|
|
if ( s->state == DeadEyesState ) DeadEyesStateGhost = s; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void Step() |
|
|
void Step() |
|
|
{ |
|
|
{ |
|
|
int16_t keys = 0; |
|
|
|
|
|
|
|
|
|
|
|
if (GAMEWIN == 1) { |
|
|
if (GAMEWIN == 1) { |
|
|
LEVEL++; |
|
|
LEVEL++; |
|
|
|
|
|
|
|
|
tft.setRotation(2); // 180 |
|
|
tft.setRotation(2); // 180 |
|
|
delay(100); |
|
|
delay(100); |
|
|
tft.fillScreen(BLACK); |
|
|
tft.fillScreen(BLACK); |
|
|
|
|
|
tft.setTextColor(ILI9341_YELLOW); |
|
|
|
|
|
tft.setTextSize(2); |
|
|
|
|
|
tft.println("Waiting for Joystick to connect..."); |
|
|
#endif |
|
|
#endif |
|
|
//------------------------------------------------------------------------------ |
|
|
//------------------------------------------------------------------------------ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void loop() { |
|
|
void loop() { |
|
|
if (joystick1.available()) { |
|
|
if (joystick1.available()) { |
|
|
if (first_joystick_message) { |
|
|
if (first_joystick_message) { |
|
|
|
|
|
tft.fillScreen(BLACK); |
|
|
Serial.printf("*** First Joystick message %x:%x ***\n", |
|
|
Serial.printf("*** First Joystick message %x:%x ***\n", |
|
|
joystick1.idVendor(), joystick1.idProduct()); |
|
|
joystick1.idVendor(), joystick1.idProduct()); |
|
|
first_joystick_message = false; |
|
|
first_joystick_message = false; |
|
|
|
|
|
|
|
|
width++; |
|
|
width++; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
} |