Created
March 10, 2024 19:54
-
-
Save DarrenHurst/bfbbadfe922092e977f133e80af63e6f to your computer and use it in GitHub Desktop.
Egghunt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// SwiftUIView.swift | |
// Designer | |
// | |
// Created by Darren Hurst on 2024-03-06. | |
// | |
import SwiftUI | |
import OFCore | |
struct BasketCount: View { | |
@StateObject var eggs: Eggs | |
var body: some View { | |
ZStack { | |
VStack { | |
Text("\($eggs.eggCount.wrappedValue)") | |
.font(.largeTitle.bold()) | |
.scaleEffect(2.0) | |
.padding(.bottom, 5) | |
Text("Basket Count").foregroundColor(.mint).shadow(radius: 5.0) | |
}.background(Rectangle().fill(.clear).padding(-20)) | |
}.frame(width: 100, height: 100) | |
} | |
} | |
struct BasketCount_Previews: PreviewProvider { | |
static var previews: some View { | |
BasketCount(eggs: Eggs()) | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
import SwiftUI | |
// MARK: Reference Type Eggs | |
final class Eggs: ObservableObject { | |
@Published var egg1 = false | |
@Published var egg2 = false | |
@Published var egg3 = false | |
@Published var egg4 = false | |
@Published var egg5 = false | |
@Published var egg6 = false | |
@Published var egg7 = false | |
@Published var eggCount = 0 | |
init(){} | |
} | |
// MARK: Egg Hunt Main View | |
struct EggHunt: View { | |
@StateObject var eggs: Eggs = Eggs() | |
var body: some View { | |
VStack { | |
ZStack { | |
ZStack { | |
Image("youwin").scaleEffect(eggs.eggCount == 7 ? 0.8 : 0.0) | |
}.zIndex(eggs.eggCount == 7 ? 3 : 0).opacity(0.8) | |
.animation(.interactiveSpring(), value: eggs.eggCount == 7) | |
Image("bunnyforest") | |
// MARK: Platic Egg | |
PlasticEgg(eggs: eggs, eggID: 1, eggColor: .pink.opacity(eggs.egg1 ? 1.0 : 0.7)) | |
.scaleEffect(eggs.egg1 ? 0.30 : 0.25) | |
.opacity(eggs.egg1 ? 1.0 : 0.3) | |
.offset(x:15,y:130) | |
.rotationEffect(Angle(degrees: 45.0)) | |
PlasticEgg(eggs: eggs, eggID: 2, eggColor: .white.opacity(eggs.egg2 ? 1.0 : 0.7)) | |
.scaleEffect(eggs.egg2 ? 0.30 : 0.25) | |
.opacity(eggs.egg2 ? 1.0 :0.3) | |
.offset(x:150,y:-130) | |
.rotationEffect(Angle(degrees: -45.0)) | |
PlasticEgg(eggs: eggs, eggID: 3, eggColor: .green.opacity(eggs.egg3 ? 1.0 : 0.7)) | |
.scaleEffect(eggs.egg3 ? 0.30 : 0.25) | |
.opacity(eggs.egg3 ? 1.0 : 0.3) | |
.offset(x:-15,y:130) | |
.rotationEffect(Angle(degrees: -45.0)) | |
PlasticEgg(eggs: eggs, eggID: 4, eggColor: .brown.opacity(eggs.egg4 ? 1.0 : 0.7)) | |
.scaleEffect(eggs.egg4 ? 0.30 : 0.25) | |
.opacity(eggs.egg4 ? 1.0 : 0.3) | |
.offset(x:-150,y:-130) | |
.rotationEffect(Angle(degrees: 45.0)) | |
PlasticEgg(eggs: eggs, eggID: 5, eggColor: .cyan.opacity(eggs.egg5 ? 1.0 : 0.7)) | |
.scaleEffect(eggs.egg5 ? 0.30 : 0.25) | |
.opacity(eggs.egg5 ? 1.0 : 0.3) | |
.offset(x:130,y:-190) | |
.rotationEffect(Angle(degrees: -45.0)) | |
PlasticEgg(eggs: eggs, eggID: 6, eggColor: .yellow.opacity(eggs.egg6 ? 1.0 : 0.7)) | |
.scaleEffect(eggs.egg6 ? 0.30 : 0.25) | |
.opacity(eggs.egg6 ? 1.0 : 0.3) | |
.offset(x:180,y:130) | |
.rotationEffect(Angle(degrees: 45.0)) | |
PlasticEgg(eggs: eggs, eggID: 7, eggColor: .red.opacity(eggs.egg7 ? 1.0 : 0.7)) | |
.scaleEffect(eggs.egg7 ? 0.30 : 0.25) | |
.opacity(eggs.egg7 ? 1.0 : 0.3) | |
.offset(x:150,y:130) | |
.rotationEffect(Angle(degrees: -45.0)) | |
ZStack(alignment: .leading){ | |
Image("easterbasket") | |
.resizable() | |
.shadow(radius: 5.0) | |
.frame(width:100, height: 100) | |
BasketCount(eggs: eggs) | |
}.offset(x:-200, y:-180) | |
} | |
} | |
} | |
} | |
struct Content2View_Previews: PreviewProvider { | |
static var previews: some View { | |
EggHunt() | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// Bunny.swift | |
// Designer | |
// | |
// Created by Darren Hurst on 2024-03-02. | |
// | |
import Foundation | |
import SwiftUI | |
import OFCore | |
struct PlasticEgg: View { | |
@State var animate: Bool = false | |
@StateObject var eggs: Eggs | |
var eggID: Int | |
var eggColor: Color = .cyan | |
// MARK: Pickup Egg | |
fileprivate func setEgg(egg: Binding<Bool>) { | |
if egg.wrappedValue == false { | |
egg.wrappedValue = true | |
eggs.eggCount += 1 | |
} | |
} | |
// MARK: Body | |
var body: some View { | |
VStack{ | |
ZStack { | |
EggShape().fill(eggColor).frame(width: 100, height: 150) | |
.onTapGesture(perform: { | |
if eggID == 1 { | |
setEgg(egg: $eggs.egg1) | |
} | |
if eggID == 2 { | |
setEgg(egg: $eggs.egg2) | |
} | |
if eggID == 3 { | |
setEgg(egg: $eggs.egg3) | |
} | |
if eggID == 4 { | |
setEgg(egg: $eggs.egg4) | |
} | |
if eggID == 5 { | |
setEgg(egg: $eggs.egg5) | |
} | |
if eggID == 6 { | |
setEgg(egg: $eggs.egg6) | |
} | |
if eggID == 7 { | |
setEgg(egg: $eggs.egg7) | |
} | |
}) | |
EggShape().stroke(.black).frame(width: 100, height: 150) | |
.background(LineShape() | |
.stroke(.black) | |
.rotationEffect(Angle(degrees: 115.0)) | |
.transformEffect(CGAffineTransform(translationX: 1.0, y: 0.3)) | |
.mask(EggShape()) | |
.foregroundColor(.blue) | |
) | |
Image(systemName: "star.fill") | |
.transformEffect(CGAffineTransform(a: 0.0, b: 1.0, c: 1.0, d: 1.0, tx: 1.0, ty: 1.0)) | |
.offset(x:-15, y:10).opacity(0.3) | |
Image(systemName: "star.fill") | |
.transformEffect(CGAffineTransform(a: 1.0, b: 0, c: 1.0, d: 1.0, tx: 1.0, ty: 1.0)) | |
.offset(x:0, y:-35).opacity(0.3) | |
} | |
.onAppear(){ | |
animate.toggle() | |
} | |
.onTapGesture(){ | |
animate.toggle() | |
} | |
} | |
} | |
} | |
// MARK: Egg Shape | |
struct EggShape: Shape { | |
func path(in rect: CGRect) -> Path { | |
let width = 100.0 | |
let height = 150.0 | |
var path = Path() | |
path.addEllipse(in: CGRect(x: width * 0.2, y: height * 0.2, width: width * 0.6, height: height * 0.6)) | |
return path | |
} | |
} | |
// MARK: Line Shape | |
struct LineShape: Shape { | |
func path(in rect: CGRect) -> Path { | |
var path = Path() | |
path.move(to: CGPoint(x: rect.minX, y: rect.minY)) | |
path.addLine(to: CGPoint(x: rect.maxX, y: rect.maxY)) | |
return path | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Screen.Recording.2024-03-10.at.3.48.53.PM.mov
Hoppy Easter #SwiftUIHop Egg #2