Skip to content

Commit

Permalink
refactor: rename variable and something
Browse files Browse the repository at this point in the history
  • Loading branch information
crossr0ad committed Jul 15, 2021
1 parent f96b0fd commit dca8b44
Showing 1 changed file with 81 additions and 70 deletions.
151 changes: 81 additions & 70 deletions src/octopus.ino
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,20 @@
#include "octopus_legs.h"
#include "player.h"

byte pins_DB[] = {14, 15, 2, 3, 4, 5, 6, 7};

#define pins_RS 10
#define pins_RW 9
#define pins_E 8
#define pins_CS1 11
#define pins_CS2 12
#define pins_RST 13

const byte pins_DB[] = {14, 15, 2, 3, 4, 5, 6, 7};

bool isBlack;
bool isExtend[] = {false, false, false, false};

int score = 0, /// スコア
manLocate = 0; /// PCの位置(0~4)
unsigned int score = 0;
unsigned int playerLocation = 0; // location of the player from 0 to 4

void selectChip(boolean cs) {
if (cs == 0) {
Expand All @@ -33,7 +33,7 @@ void selectChip(boolean cs) {
}
}

void writeBUS(boolean rs, boolean rw, byte dat) {
void writeBUS(boolean rs, /*boolean rw,*/ byte dat) {
digitalWrite(pins_RS, rs);
for (int i = 0; i < 8; i++) { //
digitalWrite(pins_DB[i], (dat >> i) & 0x01);
Expand All @@ -42,13 +42,13 @@ void writeBUS(boolean rs, boolean rw, byte dat) {
digitalWrite(pins_E, LOW);
}

void writeCommand(byte dat) { writeBUS(0, 0, dat); }
void writeCommand(byte dat) { writeBUS(0, dat); }

void writeData(byte dat) { writeBUS(1, 0, dat); }
void writeData(byte dat) { writeBUS(1, dat); }

void setAddress(byte col, byte row) {
writeBUS(0, 0, 0x40 | (col & 0x3F));
writeBUS(0, 0, 0xB8 | (row & 0x07));
writeBUS(0, 0x40 | (col & 0x3F));
writeBUS(0, 0xB8 | (row & 0x07));
}

// initialize glaphic LCD (GLCD)
Expand Down Expand Up @@ -336,10 +336,10 @@ void moveOct(int i) {
}
}

void player(int i, bool isisBlack) {
void player(int location, bool isisBlack) {
bool temp = isBlack;
isBlack = isisBlack;
switch (i) {
switch (location) {
case 0:
putCell(Man1, 2, 3);
putCell(ManHukuro1, 22, 14);
Expand Down Expand Up @@ -376,31 +376,33 @@ void player(int i, bool isisBlack) {
}

void movePlayer(bool isRight) {
int i;
if (manLocate != 0 || isRight) {
i = isRight ? 1 : -1;

if (manLocate == 3 && isRight) {
player(5, true);
} else if (manLocate == 4 && !isRight) {
player(5, false);
player(6, false);
player(7, false);
}
player(manLocate, false);
player(manLocate + i, true);
if (playerLocation == 0 && !isRight) {
return;
}

manLocate += i;
tone(18, 523, 30);
if (playerLocation == 3 && isRight) {
player(5, true);
} else if (playerLocation == 4 && !isRight) {
player(5, false);
player(6, false);
player(7, false);
}

int i = isRight ? 1 : -1;
player(playerLocation, false);
player(playerLocation + i, true);

playerLocation += i;
tone(18, 523, 30);
}

// capture: show player captured by octopus
void capture() {
player(manLocate, false);
player(playerLocation, false);
player(5, false);
player(6, false);
player(7, false);

octopus(1, 0, true);
octopus(1, 1, true);
octopus(1, 2, false);
Expand All @@ -410,9 +412,11 @@ void capture() {
octopus(2, 1, true);
octopus(2, 2, false);
octopus(2, 3, false);

isBlack = false;
fillRect(109, 0, 19, 9);
isBlack = true;

// putCell(octfoot25,50,50);
putCell(ManHHead92, 64, 22);
putCell(ManHMTe93, 60, 26); //実際は触手
Expand All @@ -424,53 +428,55 @@ void capture() {
}

void gameOver() {
tone(18, 740, 200);
const int audiopin = 18;

tone(audiopin, 740, 200);
delay(110);
noTone(18);
tone(18, 698, 200);
noTone(audiopin);
tone(audiopin, 698, 200);
delay(110);
noTone(18);
tone(18, 622, 200);
noTone(audiopin);
tone(audiopin, 622, 200);
delay(110);
noTone(18);
tone(18, 554, 200);
noTone(audiopin);
tone(audiopin, 554, 200);
delay(110);
noTone(18);
tone(18, 622, 200);
noTone(audiopin);
tone(audiopin, 622, 200);
delay(110);
noTone(18);
tone(18, 466, 200);
noTone(audiopin);
tone(audiopin, 466, 200);
delay(110);
noTone(18);
tone(18, 523, 200);
noTone(audiopin);
tone(audiopin, 523, 200);
delay(110);
noTone(18);
noTone(audiopin);
delay(80);
tone(18, 415, 200);
tone(audiopin, 415, 200);
delay(110);
noTone(18);
noTone(audiopin);
delay(80);
tone(18, 311, 200);
tone(audiopin, 311, 200);
delay(110);
noTone(18);
tone(18, 349, 200);
noTone(audiopin);
tone(audiopin, 349, 200);
delay(110);
noTone(18);
tone(18, 370, 200);
noTone(audiopin);
tone(audiopin, 370, 200);
delay(110);
noTone(18);
noTone(audiopin);
delay(110);
tone(18, 349, 200);
tone(audiopin, 349, 200);
delay(110);
noTone(18);
noTone(audiopin);
delay(110);
tone(18, 277, 200);
tone(audiopin, 277, 200);
delay(110);
noTone(18);
noTone(audiopin);
delay(110);
tone(18, 311, 280);
tone(audiopin, 311, 280);
delay(1470);
noTone(18);
noTone(audiopin);
delay(90);
}

Expand Down Expand Up @@ -508,14 +514,17 @@ void struggle(bool color) {
// else Serial.println("Captured!!!");
}

int count = 0,
situation = 0, ///左右のボタンの押下状況
nishioCount = 0, ///最左で右を押したときに手を動かすためのカウント
nishiokaNum = 0, ///
interval = 800, ///足の動く間隔(ms)
man4interval = 80; /// PCが最左にいるときの
int count = 0;
int situation = 0; ///左右のボタンの押下状況
int nishioCount = 0; ///最左で右を押したときに手を動かすためのカウント
int nishiokaNum = 0; ///
int interval = 800; ///足の動く間隔(ms)
int man4interval = 80; /// PCが最左にいるときの
unsigned long time;
bool mandilect = true, isCaptured = false, isCatching = false, isGO = false;
bool mandilect = true;
bool isCaptured = false;
bool isCatching = false;
bool isGameOver = false;
char scoreStr[4];

void setup() {
Expand All @@ -541,7 +550,7 @@ void setup() {
isBlack = true;

// initOctopus(true);
player(manLocate, true);
player(playerLocation, true);
count = 1;
display();

Expand Down Expand Up @@ -571,18 +580,20 @@ void loop() {
digitalWrite(LED_BUILTIN, HIGH);
}
if (isCaptured) {
if (!isGO) {
if (!isGameOver) {
gameOver();
isGO = true;
isGameOver = true;
}
if (time / interval != count) {
struggle(count % 2);
count = time / interval;
}
} else {
if ((footlocate[manLocate - 1] == footlocateMax[manLocate - 1]) ||
(manLocate > 4 &&
footlocate[3] == 1)) { // footlocateの添字0にあたるのはmanLocate=1
if ((footlocate[playerLocation - 1] ==
footlocateMax[playerLocation - 1]) ||
(playerLocation > 4 &&
footlocate[3] ==
1)) { // footlocateの添字0にあたるのはplayerLocation=1
// fillRect(4,57,1*count,4);
capture();
putStr("GAME OVER", 50, 50);
Expand Down Expand Up @@ -612,7 +623,7 @@ void loop() {

} else if (!digitalRead(17) && nishioCount == 0) {
if (situation == 0) {
if (manLocate == 4) {
if (playerLocation == 4) {
player(5, false);
player(6, true);
nishioCount = 1;
Expand All @@ -639,7 +650,7 @@ void loop() {
moveOct(3);
}
/*movePlayer(mandilect);
if(manLocate==0||manLocate==7) mandilect=!mandilect;*/
if(playerLocation==0||playerLocation==7) mandilect=!mandilect;*/
count = time / interval;
}
}
Expand Down

0 comments on commit dca8b44

Please sign in to comment.