Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

アゲる機能実装 #19

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions p2hacks2022/p2hacks2022.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
objects = {

/* Begin PBXBuildFile section */
42D313AE294CB3080056FDBD /* DoAgeruViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 42D313AD294CB3080056FDBD /* DoAgeruViewController.swift */; };
7F1B1DA129473B0E0057D568 /* Agerareru.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 7F1B1DA029473B0E0057D568 /* Agerareru.storyboard */; };
7F1B1DA229473B0E0057D568 /* Agerareru.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 7F1B1DA029473B0E0057D568 /* Agerareru.storyboard */; };
7F1B1DA329473B0E0057D568 /* Agerareru.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 7F1B1DA029473B0E0057D568 /* Agerareru.storyboard */; };
Expand Down Expand Up @@ -91,6 +92,7 @@
/* End PBXContainerItemProxy section */

/* Begin PBXFileReference section */
42D313AD294CB3080056FDBD /* DoAgeruViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DoAgeruViewController.swift; sourceTree = "<group>"; };
7F1B1DA029473B0E0057D568 /* Agerareru.storyboard */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; path = Agerareru.storyboard; sourceTree = "<group>"; };
7F1B1DA429473B9B0057D568 /* PastAgeViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PastAgeViewController.swift; sourceTree = "<group>"; };
7F1B1DA929473BC90057D568 /* PastAge.storyboard */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; path = PastAge.storyboard; sourceTree = "<group>"; };
Expand Down Expand Up @@ -228,6 +230,7 @@
7FD113EE2949FB95007497BE /* AgeruPopup.storyboard */,
7F632F7F294BFFAE00578F01 /* RoomSelectViewController.swift */,
7F632F83294BFFB600578F01 /* RoomSelect.storyboard */,
42D313AD294CB3080056FDBD /* DoAgeruViewController.swift */,
);
name = "アゲる準備画面";
path = "アゲる準備画面";
Expand Down Expand Up @@ -434,6 +437,7 @@
7F66CD6C294BCB7C0068BCEC /* CreateRoomViewController.swift in Sources */,
7F8BAA7929473A1A00AC32CB /* AgeruViewController.swift in Sources */,
7F1B1DA529473B9B0057D568 /* PastAgeViewController.swift in Sources */,
42D313AE294CB3080056FDBD /* DoAgeruViewController.swift in Sources */,
7F8BAA8129473A4400AC32CB /* AgerareruViewController.swift in Sources */,
7F66CD5F294B63EC0068BCEC /* AgeruPubilcRoomViewController.swift in Sources */,
7F8BAA382944683900AC32CB /* AppDelegate.swift in Sources */,
Expand Down Expand Up @@ -641,6 +645,7 @@
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1;
DEVELOPMENT_TEAM = NL67KBGNQ4;
GENERATE_INFOPLIST_FILE = YES;
INFOPLIST_FILE = p2hacks2022/Info.plist;
INFOPLIST_KEY_CFBundleDisplayName = "DO アゲ!";
Expand Down Expand Up @@ -669,6 +674,7 @@
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1;
DEVELOPMENT_TEAM = NL67KBGNQ4;
GENERATE_INFOPLIST_FILE = YES;
INFOPLIST_FILE = p2hacks2022/Info.plist;
INFOPLIST_KEY_CFBundleDisplayName = "DO アゲ!";
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
//
// DoAgeruViewController.swift
// p2hacks2022
//
// Created by 小林龍ノ介 on 2022/12/16.
//


import SpriteKit
import GameplayKit
import CoreMotion
import UIKit

class ViewController: UIViewController {

var myMotionManager: CMMotionManager!

var upCount = 0.0
var timeCount = 11 //タイマー秒数指定
var createTimer:Timer?
let numberLabel: UILabel = UILabel()//残り時間表示用のラベル


override func viewDidLoad() {

super.viewDidLoad()
timerStart() //タイマー呼び出し
}


func timerStart() {
createTimer = Timer.scheduledTimer(timeInterval:1, //1秒毎指定
target: self,
selector: #selector(self.countDown),
userInfo: nil,
repeats: true)
}
@objc func countDown(sender:Timer) {
timeCount -= 1
if timeCount == 10 {
age()
}
//残り時間をラベルに表示
if 0<timeCount && timeCount<21 {
print(timeCount)
self.view.addSubview(numberLabel)
numberLabel.frame = CGRect(x: 0, y: 0, width: 200, height: 50)
numberLabel.backgroundColor = UIColor.white
numberLabel.layer.masksToBounds = true
numberLabel.textColor = UIColor.red
numberLabel.textAlignment = NSTextAlignment.center
numberLabel.layer.position = CGPoint(x: self.view.bounds.width/2,y: 200)
numberLabel.text = String("残り\(timeCount)秒")
//print(numberLabel)


}
else if timeCount == 0 {
numberLabel.text = ("おわり")
//タイマーを止める
createTimer?.invalidate()

//ここに時間切れの場合の処理を記述
}
}

func upTimerStart() {
createTimer = Timer.scheduledTimer(timeInterval:1, //1秒後指定
target: self,
selector: #selector(self.upCountDown),
userInfo: nil,
repeats: true)
}
@objc func upCountDown() -> (Int){
if timeCount <= 0{
return 1
}else{
return 0
}
}

@objc func age(){
var count = 0

let countText: UILabel = UILabel()
countText.frame = CGRect(x: 0, y: 0, width: 200, height: 50)
countText.backgroundColor = UIColor.orange
countText.layer.masksToBounds = true
countText.layer.cornerRadius = 10.0
countText.textColor = UIColor.white
countText.shadowColor = UIColor.gray
countText.textAlignment = NSTextAlignment.center
countText.layer.position = CGPoint(x: self.view.bounds.width/2,y: 280)


// ViewにLabelを追加.
self.view.addSubview(countText)

// MotionManagerを生成.
myMotionManager = CMMotionManager()

// 更新周期を設定.

myMotionManager.accelerometerUpdateInterval = 0.8

var zdata = 0.0//(Double)(data.acceleration.z)


if upCountDown() == 0{
// 加速度の取得を開始.
myMotionManager.startAccelerometerUpdates(to: OperationQueue.main, withHandler: {(accelerometerData, error) in
if let e = error {
print(e.localizedDescription)
return
}
guard let data = accelerometerData else {
return
}

self.upCount += 0.8//何回この処理が繰り返されたか確認

if zdata != 1{
if zdata - Double(data.acceleration.z) >= 0.06 || zdata - Double(data.acceleration.z) <= -0.06{
count += 1
print("zdata!=0: \(zdata)")
print(Double(data.acceleration.z))

zdata = Double(data.acceleration.z)
}
}else {
print("zdata=0\(zdata)")
print(Double(data.acceleration.z))
zdata = Double(data.acceleration.z)
}

countText.text = String("\(count)アゲ")

if (round(self.upCount)) == 10.0{
print("Bbbbbbbb")
self.myMotionManager.stopAccelerometerUpdates()
print(count)
}
})
}
}

}