top of page

Je pense, donc je suis

Search

遊戲介紹_貪食蛇snake

  • Writer: sunny
    sunny
  • Apr 2, 2018
  • 2 min read

Updated: Apr 9, 2018

2018,4,5 文/黃意晴 圖/黃意晴





我爬啊爬的發展演進

真正說起來貪食蛇的雛形要回溯到1997年Taneli Armanto在nokia裡寫了一套貪吃蛇的程序,並且直接命名為snake,因此經典遊戲貪食蛇才正式誕生,當然先前還有好幾款概念的程序在發展,但蛇的概念要由此才發展,也就是現在大家手機打開小遊戲欄位都能看到的貪食蛇。




近期

圖取自壹讀



在最基礎的設定裡,玩家控制蛇頭方向(上下左右),蛇頭本身會不斷向前行,只要吃到食物

身體就會增長並且使移動速度變快增加遊戲難度,並且在行進過程中需要避開障礙物,而其中只要碰到牆就會死掉。


我又再次壯大了!

自從2001年愛立信推出第一款彩屏手機T68,貪食蛇也就瞬間上了色,經歷到智慧型手機時期,手機內建遊戲越來越多,到後來手機能夠上網時,選擇性又提高了,貪食蛇一度沈寂,直到最近全屏觸控式手機搭載app軟件讓貪食蛇又興盛,現在在google play上貪食蛇相關遊戲高達249種。





之前流行度較高的一款app"slither.io",他除了基本改進功能能夠多人連線以外,也從點陣的操縱形式改成向量,造型上也比較多變,並且食物是以其他線上玩家的蛇為食,發展出另一套新的玩法。


說到這介紹這款經典遊戲也有個起源,當初練習processing的小遊戲,就是以這個為核心,做程式語言練習,除了基礎設定外,蛇頭追蹤也對於程式來說是個很好的練習題目(雖然到現在都還沒有寫出來拉QQQ)


附上我殘碎的processing程式碼

class fruit

{

float xpos , ypos;

fruit()

{

xpos = random(10,width-10);

ypos = random(10,height-10);

}

void display()

{

noStroke();

fill(0);

ellipse(xpos, ypos,20,20);

}

void reset()

{

xpos = random(10,width-10);

ypos = random(10,height-10);

}

}


fruit fruits;


class snake{

int bodyLenth;

int dir=0;

int[]dirX={1,0,-1,0}; //0,1,2,3

int[]dirY={0,1,0,-1}; //0,1,2,3

float xpos;

float ypos;

int gradient=20;

snake()

{

xpos=300;

ypos=300;

bodyLenth=20;

}

void display()

{

noStroke();

fill(255,0,0,gradient);

rect(xpos,ypos,bodyLenth,bodyLenth);

}

void colorChange()

{

gradient=gradient+20;

}

void update()

{

xpos=xpos+dirX[dir];

ypos=ypos+dirY[dir];

}


void move()

{

if(xpos>=600)

{

xpos=dirX[dir];

ypos=ypos+dirY[dir];

}

if(ypos>=600)

{

ypos=dirY[dir];

xpos=xpos+dirX[dir];

}

if(xpos<=0)

{

xpos=600+dirX[dir];

ypos=ypos+dirY[dir];

}

if(ypos<=0)

{

ypos=600+dirY[dir];

xpos=xpos+dirX[dir];

}

}

}


snake snakes;


PImage img;


void setup()

{

size(600, 600);

frameRate(100);

fruits= new fruit();

snakes= new snake();

rectMode(CENTER);


}

void draw()

{

smooth();

background(255);

//img = loadImage("64588.jpg");

//image(img,0,0);

//fruits.reset();

fruits.display();

snakes.display();

snakes.move();

snakes.update();


if( dist(fruits.xpos, fruits.ypos, snakes.xpos, snakes.ypos) < snakes.bodyLenth )

{

snakes.colorChange();

fruits.reset();

}

}

void keyPressed()

{


if (keyCode == UP)

{

snakes.dir=3;

}

if (keyCode == DOWN)

{

snakes.dir=1;

}

if (keyCode == LEFT)

{

snakes.dir=2;

}

if (keyCode == RIGHT)

{

snakes.dir=0;

}

}


snake o1;

fruit aa;

void setup()

{

size(500,500);

frameRate(10);

background(#FCF3C4);

o1 = new snake();

aa = new fruit();

}

void draw()

{

smooth();

background(245,245,183);

o1.update();

aa.display();

if( dist(aa.xpos, aa.ypos, o1.headstartX, o1.headstartY) < 15 )

{

aa.reset();

}

}

void keyPressed()

{

if(keyCode==RIGHT)

{o1.dir=0;}

else if(keyCode==DOWN)

{o1.dir=1;}

else if(keyCode==LEFT)

{o1.dir=2;}

else if(keyCode==UP)

{o1.dir=3;}

}

class snake

{

int headstartX=25,headstartY=25;

int dir=0;

int[]dirX={1,0,-1,0};

int[]dirY={0,1,0,-1};

int bodyLenth=20;

snake()

{

headstartX=25;

headstartY=25;

}

void update()

{

headstartX=headstartX+dirX[dir];

headstartY=headstartY+dirY[dir];

noStroke();

fill(#02A020);

ellipse(headstartX*10,headstartY*10,bodyLenth,bodyLenth);

if(headstartX<=0)

{

headstartX=50+dirX[dir];

headstartY=headstartY+dirY[dir];

}

if(headstartX>50)

{

headstartX=dirX[dir];

headstartY=headstartY+dirY[dir];

}

if(headstartY<=0)

{

headstartX=headstartX+dirX[dir];

headstartY=50+dirY[dir];

}

if(headstartY>50)

{

headstartX=headstartX+dirX[dir];

headstartY=dirY[dir];

}

}

}

https://read01.com/zh-tw/BekAyM.html#.Wsi2LdNubOQ

 
 
 

Recent Posts

See All
隱私權

隱私政策: 本應用尊重並保護所有使用服務用戶的個人隱私權。為了給您提供更準確、更有個性化的服務,本應用會按照本隱私權政策的規定使用和披露您的個人信息。但本應用將以高度的勤勉、審慎義務對待這些信息。除本隱私權政策另有規定外,在未征得您事先許可的情況下,本應用不會將這些信息對外...

 
 
 

Comments


bottom of page