“Submarine of ESCAPE play” by Asahi
https://openprocessing.org/sketch/1381647
License CreativeCommons Attribution NonCommercial ShareAlike
https://creativecommons.org/licenses/by-nc-sa/3.0
{{filePath}}
{{width}} x {{height}}
Report Sketch
Oh, that naughty sketch! Please let us know what the issue is below.
Apply Template
Applying this template will reset your sketch and remove all your changes. Are you sure you would like to continue?
Report Sketch
Report Comment
Please confirm that you would like to report the comment below.
We will review your submission and take any actions necessary per our Community Guidelines. In addition to reporting this comment, you can also block the user to prevent any future interactions.
Please report comments only when necessary. Unnecessary or abusive use of this tool may result in your own account being suspended.
Are you sure you want to delete your sketch?
Any files uploaded will be deleted as well.
Delete Comment?
This will also delete all the replies to this comment.
Delete this tab? Any code in it will be deleted as well.
Select a collection to submit your sketch
We Need Your Support
Since 2008, OpenProcessing has provided tools for creative coders to learn, create, and share over a million open source projects in a friendly environment.
Niche websites like ours need your continued support for future development and maintenance, while keeping it an ad-free platform that respects your data and privacy!
Please consider subscribing below to show your support with a "Plus" badge on your profile and get access to many other features!
CC Attribution NonCommercial ShareAlike
Submarine of ESCAPE play
xxxxxxxxxx
var player; //プレイヤー
var stars; //星のグループ
var coins; //コインのグループ
var wall; //左側の見えない壁
var gameOver = 0; //ゲームオーバー化を判定するフラグ
var score = 0; //スコア
//preload関数(実行前に呼び出される)
function preload() {
// 連番が振られた一連の画像からAnimationオブジェクトを作成するs
submarineAnim = loadAnimation("sub-1.png", "sub-2.png", "sub-3.png", "sub-4.png");
enemyAnim = loadAnimation("ene-1.png", "ene-2.png", "ene-3.png", "ene-4.png");
fuelAnim = loadAnimation("fuel-1.png", "fuel-2.png", "fuel-3.png", "fuel-4.png");
}
//セットアップ関数(最初に一回だけ呼び出される)
function setup() {
colorMode(RGB,100); //カラーモードの設定
noStroke(); //境界線を描画しない
createCanvas(600, 400); //キャンバスを作成
//自機
//player = createSprite( 100, height/2, 40, 20);//自機の作成
player = createSprite( 100, height/2);//自機の作成
//player.shapeColor = color(100);//自機色の指定
player.addAnimation("default", submarineAnim);
//星とコイン
stars = new Group();//星のグループを生成
coins = new Group();//コインのグループを生成
//壁
wall = createSprite(-1,height/2,1,height);//星とコインが画面外に出たことを検出するための壁の生成
}
//ドロー関数(一定間隔で呼び出される)
function draw() {
//ゲームオーバーの判定
if (gameOver == 1){
textSize(72);
textAlign(CENTER,CENTER);
fill(100,0,0);
text("GameOver!",width/2,height/2);
return;
}
//背景を青で描画
background(0,50,100);
//自機の移動
player.velocity.y = (mouseY - player.position.y) *0.2; //マウスに少し遅れて移動
//0.2を大きくすると遅れが少なくなる,小さくすると遅れが大きくなってコントロールが難しくなる
//星の生成
if (random(100) <= 1){ //100フレームに2回の確率で星が生成される
var aStar = createSprite(width, random(height),10,10); //星のスプライトの生成
aStar.setSpeed(1.0,180);//星の速度の決定(180度の方向に1.0)
aStar.shapeColor = color(100,0,0);//星の色(赤)
stars.add(aStar);//生成した星のスプライトを星のグループに追加
aStar.addAnimation("default", enemyAnim);
}
//コインの生成
if (random(100) <= 2){//100フレームに1回の確率でコインが生成
var aCoin = createSprite(width, random(height),10,10);//コインのスプライトの生成
aCoin.setSpeed(1.5,180);//コインの速度の決定(180度の方向に1.5)
aCoin.shapeColor = color(100,100,0);//コインの色(黄色)
coins.add(aCoin);//生成したコインのスプライトをコインのグループに追加
aCoin.addAnimation("default", fuelAnim);
}
//星が画面外に出たかの判定
wall.overlap(stars, function(target, star){
star.remove();//画面外の星を削除
});
//コインが画面外に出たかの判定
wall.overlap(coins, function(target, coin){
coin.remove();//画面外のコインを削除
score = score -1;//スコアを減少させる(ペナルティ)
});
//自機と星の当たり判定
player.overlap(stars, function(target, star){
gameOver = 1;//ゲームオーバーのフラグの設定(1の場合にゲームオーバー)
});
//自機とコインの当たり判定
player.overlap(coins, function(target, coin){
coin.remove();//コインを消す
score = score + 1;//スコアを増やす
});
//スコアの表示
textSize(24);//文字サイズ24ピクセル
textAlign(LEFT,TOP);//左上を指定
fill(100);//文字色(白)
text("score:" + score, 10,10);//スコアの表示
//全てのスプライトを描画
drawSprites();
}
See More Shortcuts