2018互動技術
顯示具有
05163021_江家宜
標籤的文章。
顯示所有文章
顯示具有
05163021_江家宜
標籤的文章。
顯示所有文章
2019年1月3日 星期四
Week17 呆江與泓丞的期末作品
期末作品展示
作品名稱:卡比吃怪物
連結:
https://youtu.be/hFhGUudvd78
學了一個學期的Processing,終於製做出一個自己的遊戲,雖然製作的過程中充滿辛苦,但看到自己的學習有了這樣的結果,還是會覺得很開心
2019年1月1日 星期二
Week16 呆江與泓丞的期末作品
製作期末作品
1.關卡設計
基於我們的按鈕僅買了4個,所以我們把關卡改成3關
2.設計上的改變
(1)考慮新增LED紅燈當生命值
(2)增加障礙怪物
3.修正的問題
(1)轉場
(2)怪物吸起來卡卡
裝置圖
基本架構都跟上周提及的差不多,但在期末展示的時候我們沒有展示到一些內容,
透過部落格跟大家分享一下我們遇到的狀況......
1.紅色LED燈怎麼沒在裝置上
因為製作的時候我們把盒子弄壞了,所以緊急製作了簡易裝製上台
2.障礙怪物並沒有出現
我們嘗試新增2隻障礙怪物在場上的時候,發現會有掉貞的狀況,為了不要讓我們的作品看起來節奏太過緩慢,沒有把這個功能拿出來展示
刪除上面題及的遊戲機制後,整個遊戲雖然很流暢,
但缺少了死亡的可能,會讓人覺得很乏味
雖然起初確實是要製作讓人放鬆的小遊戲,但少了死掉的條件還真的玩久了會無聊
最後,分享一下我們的程式碼
Processing:
//characters
PImage[] imgBG=new PImage[7]; PImage[] imgKirby=new PImage[4]; PImage[] imgMonster=new PImage[6];
float [] MonsterX = new float[80]; float [] MonsterY = new float[80];
float MonsterVX=8 ; float [] MonsterVY = new float[80];
//Die Monster
float DieX; float DieY; float DieVX=8; float DieVY;
//reboorn
boolean [] MonsterDie = new boolean[80];
float [] MonsterDieVX = new float[80]; float [] MonsterDieVY = new float[80];
//change bg
int c=1;
//store score
int score=0; int score2=0; int score3=0;
import processing.serial.*;
Serial myPort;
int val;
import ddf.minim.*;
Minim minim;
AudioPlayer player;
//reborn monster
void reborn(int i){
MonsterDie[i] = false;
MonsterX[i] = -random(1000); MonsterY[i] = random(30,630);
}
void reborn2(int i){
MonsterDie[i] = false;
MonsterX[i] = random(1300,2500); MonsterY[i] = random(30,630);
}
//level change
void level(int a){
if(a>=30){
for(int i=0; i<40; i++){
MonsterX[i] = -random(1000); MonsterY[i] = random(30,630);
MonsterVY[i] = random(-1,2);
MonsterDie[i] = false;
}
for(int i=40;i<80;i++){
MonsterX[i] = random(1300,2500); MonsterY[i] = random(30,630);
MonsterVY[i] = random(-1,2);
MonsterDie[i] = false;
}
}
}
void setup(){
size(1280,720);
minim = new Minim(this);
player = minim.loadFile("kirby.mp3",2048);
player.play();
player.loop();
String portName = Serial.list()[0];
myPort = new Serial(this,"COM3", 9600);
//load background and characters
for(int i=0; i<3; i++){
imgBG[i] = loadImage("bg0"+i+".jpg");
}
imgBG[3] = loadImage("lv01.jpg");
imgBG[4] = loadImage("lv02.jpg");
imgBG[5] = loadImage("bg.jpg");
for(int i=0; i<4; i++){
imgKirby[i] = loadImage((i+1)+".png");
}
for(int i=0; i<6; i++){
imgMonster[i] = loadImage("00"+(i+1)+".png");
}
//stat bg & text
image(imgBG[0],width/500,height/300,width,height);
fill(30,30,30);
rect(400,250,500,60,7);
textSize(50);
fill(255,255,255);
text("Press Space to Start",410,300);
//original coordinates
for(int i=0; i<40; i++){
MonsterX[i] = -random(1000); MonsterY[i] = random(30,630);
MonsterVY[i] = random(-1,2);
MonsterDie[i] = false;
}
for(int i=40;i<80;i++){
MonsterX[i] = random(1300,2500); MonsterY[i] = random(30,630);
MonsterVY[i] = random(-1,2);
MonsterDie[i] = false;
}
}
boolean check = true;
void draw(){
if (myPort.available() > 0) {
val = myPort.read();
}
if(val==1 && check==true){
check=false;
c++;
}
if(val==0 && check==false){
check=true;
}
//description bg
if(c==2) {
image(imgBG[1],width/500,height/300,width,height);
}
//game bg
if(c==3){
image(imgBG[2],width/500,height/300,width,height);
//level 1 Monster
for(int i=0;i<40;i++){
MonsterX[i] += MonsterVX;
image(imgMonster[0],MonsterX[i],MonsterY[i],90,90);
if(MonsterX[i] > 1200){
MonsterDie[i] = true;
reborn(i);
}
}
for(int i=40;i<80;i++){
MonsterX[i] -= MonsterVX;
image(imgMonster[4],MonsterX[i],MonsterY[i],90,90);
if(MonsterX[i] < 0){
MonsterDie[i] = true;
reborn2(i);
}
}
for(int i=0;i<80;i++){
if(val==2){
if(score<=30 && c==3){
MonsterDieVX[i] = (540-MonsterX[i])/8;
MonsterDieVY[i] = (450-MonsterY[i])/8;
if(dist(540,450,MonsterX[i],MonsterY[i])<300){
if(MonsterX[i]>620 && i < 40){
MonsterX[i]-=5;
MonsterY[i]+=MonsterDieVY[i];
}
if(MonsterX[i]<460 && i > 40){
MonsterX[i]+=25;
MonsterY[i]+=MonsterDieVY[i];
}
else{
MonsterX[i]+=MonsterDieVX[i];
MonsterY[i]+=MonsterDieVY[i];
}
}
if(dist(540,450,MonsterX[i],MonsterY[i])<80){
MonsterDie[i]=true;
score++;
reborn(i);
}
}
}
}
//level 1 Kirby(520,450)
image(imgKirby[0],520,450,120,120);
}
//level 1 Monster
if(score>=30 && c==3){
level(score);
image(imgBG[3],width/500,height/300,width,height);
}
if(c==4){
image(imgBG[2],width/500,height/300,width,height);
//level 2 Monster
for(int i=0;i<40;i++){
MonsterX[i] += MonsterVX;
image(imgMonster[0],MonsterX[i],MonsterY[i],90,90);
if(MonsterX[i] > 1200){
MonsterDie[i] = true;
reborn(i);
}
}
for(int i=40;i<80;i++){
MonsterX[i] -= MonsterVX;
image(imgMonster[4],MonsterX[i],MonsterY[i],90,90);
if(MonsterX[i] < 0){
MonsterDie[i] = true;
reborn2(i);
}
}
for(int i=0;i<80;i++){
if(val==2){
if(score<=60 && c==4){
MonsterDieVX[i] = (540-MonsterX[i])/8;
MonsterDieVY[i] = (450-MonsterY[i])/8;
if(dist(540,450,MonsterX[i],MonsterY[i])<300){
if(MonsterX[i]>620 && i < 40){
MonsterX[i]-=5;
MonsterY[i]+=MonsterDieVY[i];
}
if(MonsterX[i]<460 && i > 40){
MonsterX[i]+=25;
MonsterY[i]+=MonsterDieVY[i];
}
else{
MonsterX[i]+=MonsterDieVX[i];
MonsterY[i]+=MonsterDieVY[i];
}
}
if(dist(540,450,MonsterX[i],MonsterY[i])<80){
MonsterDie[i]=true;
score++;
reborn(i);
}
}
}
if(val==4){
if(score2<=30 && c==4){
MonsterDieVX[i] = (175-MonsterX[i])/8;
MonsterDieVY[i] = (150-MonsterY[i])/8;
if(dist(175,150,MonsterX[i],MonsterY[i])<300){
if(MonsterX[i]>255 && i < 40){
MonsterX[i]-=5;
MonsterY[i]+=MonsterDieVY[i];
}
if(MonsterX[i]<95 && i > 40){
MonsterX[i]+=25;
MonsterY[i]+=MonsterDieVY[i];
}
else{
MonsterX[i]+=MonsterDieVX[i];
MonsterY[i]+=MonsterDieVY[i];
}
}
if(dist(175,150,MonsterX[i],MonsterY[i])<80){
MonsterDie[i]=true;
score2++;
reborn(i);
}
}
}
}
//level 2 Kirby(175,150)
image(imgKirby[0],520,450,120,120);
image(imgKirby[1],175,150,120,120);
}
if(score>=60 && score2>=30 && c==4){
level(score2);
image(imgBG[4],width/500,height/300,width,height);
}
if(c==5){
image(imgBG[2],width/500,height/300,width,height);
//level 3 Monster
for(int i=0;i<40;i++){
MonsterX[i] += MonsterVX;
image(imgMonster[0],MonsterX[i],MonsterY[i],90,90);
if(MonsterX[i] > 1200){
MonsterDie[i] = true;
reborn(i);
}
}
for(int i=40;i<80;i++){
MonsterX[i] -= MonsterVX;
image(imgMonster[4],MonsterX[i],MonsterY[i],90,90);
if(MonsterX[i] < 0){
MonsterDie[i] = true;
reborn2(i);
}
}
//level 3 Kirby(1000,300)
image(imgKirby[0],520,450,120,120);
image(imgKirby[1],175,150,120,120);
image(imgKirby[2],1000,300,120,120);
for(int i=0;i<80;i++){
if(val==2){
if(score<=90 && c==5){
MonsterDieVX[i] = (540-MonsterX[i])/8;
MonsterDieVY[i] = (450-MonsterY[i])/8;
if(dist(540,450,MonsterX[i],MonsterY[i])<300){
if(MonsterX[i]>620 && i < 40){
MonsterX[i]-=5;
MonsterY[i]+=MonsterDieVY[i];
}
if(MonsterX[i]<460 && i > 40){
MonsterX[i]+=25;
MonsterY[i]+=MonsterDieVY[i];
}
else{
MonsterX[i]+=MonsterDieVX[i];
MonsterY[i]+=MonsterDieVY[i];
}
}
if(dist(540,450,MonsterX[i],MonsterY[i])<80){
MonsterDie[i]=true;
score++;
reborn(i);
}
}
}
if(val==4){
if(score2<=60 && c==5){
MonsterDieVX[i] = (175-MonsterX[i])/8;
MonsterDieVY[i] = (150-MonsterY[i])/8;
if(dist(175,150,MonsterX[i],MonsterY[i])<300){
if(MonsterX[i]>255 && i < 40){
MonsterX[i]-=5;
MonsterY[i]+=MonsterDieVY[i];
}
if(MonsterX[i]<95 && i > 40){
MonsterX[i]+=25;
MonsterY[i]+=MonsterDieVY[i];
}
else{
MonsterX[i]+=MonsterDieVX[i];
MonsterY[i]+=MonsterDieVY[i];
}
}
if(dist(175,150,MonsterX[i],MonsterY[i])<80){
MonsterDie[i]=true;
score2++;
reborn(i);
}
}
}
if(val==5){
if(score3<=30 && c==5){
MonsterDieVX[i] = (1000-MonsterX[i])/8;
MonsterDieVY[i] = (300-MonsterY[i])/8;
if(dist(1000,300,MonsterX[i],MonsterY[i])<300){
if(MonsterX[i]>1000 && i < 40){
MonsterX[i]-=5;
MonsterY[i]+=MonsterDieVY[i];
}
if(MonsterX[i]<1000 && i >= 40){
MonsterX[i]+=25;
MonsterY[i]+=MonsterDieVY[i];
}
else{
MonsterX[i]+=MonsterDieVX[i];
MonsterY[i]+=MonsterDieVY[i];
}
}
if(dist(1000,300,MonsterX[i],MonsterY[i])<80){
MonsterDie[i]=true;
score3++;
reborn(i);
}
}
}
}
}
if(score>=90 && score2>=60 && score3>=30 && c==5){
level(score3);
image(imgBG[5],width/500,height/300,width,height);
}
}
2018年12月23日 星期日
Week15 呆江與泓丞的期末製作
Week15 期末作品製作
1.遊戲基本介紹
期中作品做了吸引球球的遊戲,但遊戲規則僅少少的透過鍵盤吸引球,沒考慮到球的吸引距離,球的速度,畫面有趣性...等。讓整體的期中作品顯得不吸引人。所以這次期末作品在上課的閒餘時間重新考慮了遊戲規則、畫面編排、控制器的製作難度...等,重新設計了一個帶入童年大家都喜歡的電玩角色,去撰寫程式。
遊戲規則目前制定為:
因現階段我們使用鍵盤控制,所以使用空白鍵進行轉場,數字鍵控制遊戲角色。遊戲一開始有起始畫面,畫面上有提示玩家按下空白鍵可進入遊戲(圖1),按下第一次空白鍵後,會進入遊戲規則說明畫面(圖2),再次按下空白鍵(暫定),會進入遊戲第一關。
遊戲開始後,玩家透過數字鍵控制角色(畫面上的卡比),按下數字鍵後,對應的角色會開始溪鄰近的怪物並吃掉,吃掉後背景會計算吃掉的數量,當吃到該關卡的指定數量後,就會切換到下一關,總共四關,結束後會有結束畫面,並可透過空白鍵返回起始畫面。
圖1
圖2
遊戲畫面(第一關)
2.使用到的期中作品程式碼
期中我們有使用到 吸引力、成績計算、重生球球(分為吃掉的跟超出畫面的兩種) 、音樂 與 轉場,我們會沿用並修改成效能較好的程式碼。目前已改寫吸引力、重生與轉場的程式碼。
3.為什麼會想到這些遊戲規則與畫面編排
起初是想到童年玩過的吸球球遊戲,並在play商店看到Ball Control這個遊戲,就決定製作,但在期中製作的時候,我個人覺得畫面有點簡陋,所以思考有什麼樣的人物或好看的圖片可以美化我們的作品,在期中發表結束後,便想起童年很喜歡玩的卡比,不但可愛而且他剛好很會吃(X),所以就決定是他了。
畫面是看到期中大家畫面都做得很精美,所以就考慮了設計畫面轉場,但目前還在考慮要在畫面中如何提醒玩家剩下多少就可以升級關卡。
4.結語
期末的作品我考慮了很多,不論是畫面設計、素材、遊戲規則...等,而且目前也還在考慮還沒完善的部分,但也要考慮到自己的組別做不做得出來,所以也要多去了解P語言跟uno板的指令。並期待自己組的期末作品可以做到自己的預期。
2018年12月6日 星期四
Week13 呆江的筆記
連結UNO板與Processing-期末作品
UNO板邏輯:
先宣告要使用的腳位(2,3,4,5),如果按鈕按下就會寫對應的數字到Processing去
int kirbypin = 2;
int spacepin = 5;
void setup(){
pinMode(kirbypin,INPUT_PULLUP);
pinMode(spacepin,INPUT_PULLUP);
Serial.begin(9600);
}
void loop()
{
if(digitalRead(spacepin)==LOW){
Serial.write(1);
}
else{
Serial.write(0);
}
if(digitalRead(kirbypin)==LOW){
Serial.write(2);
}
else{
Serial.write(3);
}
delay(200);
}
Processing:
在setup()裡
String portName = Serial.list()[0];
myPort = new Serial(this,"COM3", 9600);
在draw()裡
1.透過按鈕控制畫面切換
if (myPort.available() > 0) {
val = myPort.read();
}
if(val==1 && check==true){
check=false;
c++;
}
if(val==0 && check==false){
check=true;
}
2.按鈕控制卡比吸怪物(level 1)
if(val==2){
if(score<=30 && c==3){
MonsterDieVX[i] = (540-MonsterX[i])/8;
MonsterDieVY[i] = (450-MonsterY[i])/8;
if(dist(540,450,MonsterX[i],MonsterY[i])<300){
if(MonsterX[i]>620 && i < 40){
MonsterX[i]-=5;
MonsterY[i]+=MonsterDieVY[i];
}
if(MonsterX[i]<460 && i > 40){
MonsterX[i]+=25;
MonsterY[i]+=MonsterDieVY[i];
}
else{
MonsterX[i]+=MonsterDieVX[i];
MonsterY[i]+=MonsterDieVY[i];
}
}
if(dist(540,450,MonsterX[i],MonsterY[i])<80){
MonsterDie[i]=true;
score++;
reborn(i);
}
}
}
2018年11月22日 星期四
Week11 呆江的筆記
Week11 uno版自行改寫程式碼
1.讓燈逐漸亮起來
void setup() {
for(int i=2;i<=13;i++){
pinMode(i, OUTPUT);
}
}
void loop() {
for(int i=2;i<=13;i++){
digitalWrite(i, HIGH);
delay(300);
}
for(int i=2;i<=13;i++){
digitalWrite(i, LOW);
}
}
2.範例
https://makeruno.com.my/playing-melody-using-only-maker-uno/?fbclid=IwAR1N1Z7ZdFEOczDoJ5vCXFxNjbrm99fiLRiCZ1jYjxWTwAL08wGClcMdYU0
修改範例,改成會照著旋律亮燈
int piezoPin = 8;
int length = 15;
char notes[] = "ccggaag ffeeddc ggffeed ggffeed ccggaag ffeeddc ";
int beats[] = { 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 2, 4 };
int tempo = 300;
void playTone(int tone, int duration)
{
for (long i = 0; i < duration * 1000L; i += tone * 2)
{
digitalWrite(piezoPin, HIGH);
delayMicroseconds(tone);
digitalWrite(piezoPin, LOW);
delayMicroseconds(tone);
}
}
void playNote(char note, int duration)
{
int LED[] = { 2 , 3 , 4 , 5 , 6 , 7 , 9 , 10 }; ///加入陣列
char names[] = { 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'C' };
int tones[] = { 1915, 1700, 1519, 1432, 1275, 1136, 1014, 956 };
for (int i = 0; i < 8; i++)
{
if (names[i] == note)
{
digitalWrite( LED[i], HIGH ); ///在播聲音之前,把對應的LED亮起
playTone(tones[i], duration);
digitalWrite( LED[i], LOW ); ///在播聲音之後,把對應的LED暗掉
}
}
}
void setup()
{
//pinMode(piezoPin, OUTPUT);
for(int i=2;i<=13;i++) pinMode( i, OUTPUT ); ///在執行之前,把每個腳位,都設成OUTPUT,才會亮、發聲音
}
void loop()
{
for (int i = 0; i < length; i++)
{
if (notes[i] == ' ')
{
delay(beats[i] * tempo);
} else
playNote(notes[i], beats[i] * tempo);
delay(tempo / 2);
}
}
3.範例
https://makeruno.com.my/changing-melody-with-push-button-using-only-maker-uno/?fbclid=IwAR3KVdgUXxPfXSZFDChlxsTRwhYWcDKXciYcxIn2WOk0QmuxsuA_QUa11pg
透過按鈕修改音樂(但要等正在撥的撥完QQ
int piezoPin = 8;
int button = 2; ///把Button切換到pin2
int lengths = 26;
char jbnotes[] = "eeeeeeegcde fffffeeeeddedg";
int jbbeats[] = { 1, 1, 2, 1, 1, 2, 1, 1, 1, 1, 4, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2}; //第一首歌
int length = 15;
char ttlsnotes[] = "ccggaag ffeeddc ggffeed ggffeed ccggaag ffeeddc ";
int ttlsbeats[] = { 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 2, 4 }; //第二首歌
int tempo = 300;
void playTone(int tone, int duration)
{
for (long i = 0; i < duration * 1000L; i += tone * 2)
{
digitalWrite(piezoPin, HIGH);
delayMicroseconds(tone);
digitalWrite(piezoPin, LOW);
delayMicroseconds(tone);
}
}
void playNote(char note, int duration)
{
char names[] = { 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'C' };
int tones[] = { 1915, 1700, 1519, 1432, 1275, 1136, 1014, 956 };
for (int i = 0; i < 8; i++)
{
if (names[i] == note)
{
playTone(tones[i], duration);
}
}
}
void setup()
{
pinMode(piezoPin, OUTPUT);
pinMode(button, INPUT_PULLUP);
}
void loop()
{
int sensorVal = digitalRead(button);
if (sensorVal == HIGH)
{
for (int i = 0; i < length; i++)
{
if (ttlsnotes[i] == ' ')
{
delay(ttlsbeats[i] * tempo);
}
else
playNote(ttlsnotes[i], ttlsbeats[i] * tempo);
delay(tempo / 2);
}
}
else
{
for (int i = 0; i < lengths; i++)
{
if (jbnotes[i] == ' ')
{
delay(jbbeats[i] * tempo);
}
else
playNote(jbnotes[i], jbbeats[i] * tempo);
delay(tempo / 2);
}
}
}
4.修改前一範例
按鈕一按就可以卡歌了唷
(ノ>ω<)ノ
int piezoPin = 8;
int button = 2;
int lengths = 26;
char jbnotes[] = "eeeeeeegcde fffffeeeeddedg";
int jbbeats[] = { 1, 1, 2, 1, 1, 2, 1, 1, 1, 1, 4, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2};
int length = 15;
char ttlsnotes[] = "ccggaag ffeeddc ggffeed ggffeed ccggaag ffeeddc ";
int ttlsbeats[] = { 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 2, 4 };
int tempo = 300;
void playTone(int tone, int duration)
{
for (long i = 0; i < duration * 1000L; i += tone * 2)
{
digitalWrite(piezoPin, HIGH);
delayMicroseconds(tone);
digitalWrite(piezoPin, LOW);
delayMicroseconds(tone);
}
}
void playNote(char note, int duration)
{
char names[] = { 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'C' };
int tones[] = { 1915, 1700, 1519, 1432, 1275, 1136, 1014, 956 };
for (int i = 0; i < 8; i++)
{
if (names[i] == note)
{
playTone(tones[i], duration);
}
}
}
void setup()
{
pinMode(piezoPin, OUTPUT);
pinMode(button, INPUT_PULLUP);
}
int now=1; ///更改歌的變數
void loop()
{
delay(tempo/2);
if (now==1)
{
for (int i = 0; i < length; i++)
{
if (ttlsnotes[i] == ' ')
{
delay(ttlsbeats[i] * tempo);
}
else
playNote(ttlsnotes[i], ttlsbeats[i] * tempo);
if( digitalRead(button) == LOW) {
now = 2; break;
} ///卡歌
delay(tempo / 2);
}
}
else
{
for (int i = 0; i < lengths; i++)
{
if (jbnotes[i] == ' ')
{
delay(jbbeats[i] * tempo);
}
else
playNote(jbnotes[i], jbbeats[i] * tempo);
if( digitalRead(button) == LOW) {
now = 1; break;
} ///卡歌,換前一首
delay(tempo / 2);
}
}
}
2018年11月15日 星期四
Week10 呆江的筆記
Week10 使用maker uno
官網:
https://makeruno.com.my/getting-started/
下載驅動
下載完後,開啟並點選install(安裝)
安裝完畢,確認成功就按ok就可以了唷(,,・ω・,,)
下載完畢後,要到裝置管理員確認有沒有多一個連接阜
有的話就可以寫簡單的程式讓他動啦d(`・∀・)b
範例1:
https://makeruno.com.my/changing-melody-with-push-button-using-only-maker-uno/?fbclid=IwAR3toK_dzBpVnaznTVoDUP1ypCe-BlyLQ1TL4ETyyYN2s7VteRzSLZd8fcM
範例2:
https://www.arduino.cc/en/Tutorial/Melody?fbclid=IwAR0bOhxFlcWHk7emOjChySiILAMaE-7DPcaq_BYjsQCcE6N7upLtnhhBUt8
較舊的文章
首頁
訂閱:
文章 (Atom)