Skip to content
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
43 changes: 36 additions & 7 deletions CMPUT 250 W24 Lab 3/Assets/DVDLogo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,31 @@
public class DVDLogo : MonoBehaviour
{
//Speed it moves at
public float speed = 3;
public float speed = 2;
public float speed_increase = 2;

//Bounds of the screen (could get these with camera bounds but we can do this since it's a fixed camera)
public float X_Max = 5, Y_Max = 4;

//Current direction
private Vector3 direction;

// color of the sprite
SpriteRenderer sprite; // to be able to change the color of the sprite

public Color flashColor = Color.red; // The sprite with flash red
public float flashDuration = 0.01f; // How long to show the change of color
public int flashCount = 1; // How many times to flash
private Color originalColor; // will store the original color

// Start is called before the first frame update
void Start()
{
//Randomly initialize direction
direction = new Vector3(Random.Range(-1f,1f), Random.Range(-1f,1f));
direction.Normalize();
sprite = GetComponent<SpriteRenderer>(); // creates game object to be able to change color of sprite
originalColor = sprite.color; // here actually stores the original color of the sprite

}

Expand All @@ -36,29 +47,47 @@ private void FlipDirectionY(){
direction.Normalize();
}

// Update is called once per frame
void Update()
private IEnumerator Flashing() // function to be able to flash the color of the sprite
// IEnumerator supports interation without affecting game play
// here stops and resumes over multiple frames without affecting the main game
// help from chatgpt
{
//Move in direction unless we'd go out of bounds, if so bounce with some randomness

Vector3 newPosition = transform.position + direction*Time.deltaTime*speed;
for (int i = 0; i < flashCount; i++) // for loop that changes back and forth from flash color back to original color
{
sprite.color = flashColor; // Change to the flash color
yield return new WaitForSeconds(flashDuration); // pauses for the flash duration
sprite.color = originalColor; // Change back to the original color
yield return new WaitForSeconds(flashDuration); // Wait before flashing again

}
}
// Update is called once per frame
void Update()
{
//Move in direction unless we'd go out of bounds, if so bounce with some randomness

Vector3 newPosition = transform.position + direction*Time.deltaTime*(speed* speed_increase);

//See if a bounce needs to happen before moving
if (newPosition.x>X_Max){
StartCoroutine(Flashing());
FlipDirectionX();

}
else if (newPosition.x<-1*X_Max){
StartCoroutine(Flashing());
FlipDirectionX();
}

if (newPosition.y>Y_Max){
StartCoroutine(Flashing());
FlipDirectionY();
}
else if (newPosition.y<-1*Y_Max){
StartCoroutine(Flashing());
FlipDirectionY();
}

transform.position += direction*Time.deltaTime*speed;
transform.position += direction*Time.deltaTime*(speed* speed_increase);
}
}
141 changes: 56 additions & 85 deletions CMPUT 250 W24 Lab 3/Assets/Scenes/SampleScene.unity
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ GameObject:
m_Component:
- component: {fileID: 421997421}
- component: {fileID: 421997422}
- component: {fileID: 421997423}
m_Layer: 0
m_Name: Bouncing Ball
m_TagString: Untagged
Expand All @@ -147,9 +148,8 @@ Transform:
m_GameObject: {fileID: 421997420}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children:
- {fileID: 755472558}
m_LocalScale: {x: 4, y: 4, z: 4}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 1
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
Expand All @@ -166,8 +166,60 @@ MonoBehaviour:
m_Name:
m_EditorClassIdentifier:
speed: 3
speed_increase: 2
X_Max: 5
Y_Max: 4
--- !u!212 &421997423
SpriteRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 421997420}
m_Enabled: 1
m_CastShadows: 0
m_ReceiveShadows: 0
m_DynamicOccludee: 1
m_MotionVectors: 1
m_LightProbeUsage: 1
m_ReflectionProbeUsage: 1
m_RayTracingMode: 0
m_RenderingLayerMask: 1
m_RendererPriority: 0
m_Materials:
- {fileID: 10754, guid: 0000000000000000f000000000000000, type: 0}
m_StaticBatchInfo:
firstSubMesh: 0
subMeshCount: 0
m_StaticBatchRoot: {fileID: 0}
m_ProbeAnchor: {fileID: 0}
m_LightProbeVolumeOverride: {fileID: 0}
m_ScaleInLightmap: 1
m_ReceiveGI: 1
m_PreserveUVs: 0
m_IgnoreNormalsForChartDetection: 0
m_ImportantGI: 0
m_StitchLightmapSeams: 1
m_SelectedEditorRenderState: 0
m_MinimumChartSize: 4
m_AutoUVMaxDistance: 0.5
m_AutoUVMaxAngle: 89
m_LightmapParameters: {fileID: 0}
m_SortingLayerID: 0
m_SortingLayer: 0
m_SortingOrder: 0
m_Sprite: {fileID: 3410133999492175255, guid: 12eb88e81c2e64e858662a4485b1aec7,
type: 3}
m_Color: {r: 1, g: 1, b: 1, a: 1}
m_FlipX: 0
m_FlipY: 0
m_DrawMode: 0
m_Size: {x: 0.34, y: 0.32}
m_AdaptiveModeThreshold: 0.5
m_SpriteTileMode: 0
m_WasSpriteAssigned: 1
m_MaskInteraction: 0
m_SpriteSortPoint: 0
--- !u!1 &519420028
GameObject:
m_ObjectHideFlags: 0
Expand Down Expand Up @@ -251,87 +303,6 @@ Transform:
m_Father: {fileID: 0}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &755472557
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 755472558}
- component: {fileID: 755472559}
m_Layer: 0
m_Name: Circle
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &755472558
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 755472557}
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 0.2, y: 0.2, z: 1}
m_Children: []
m_Father: {fileID: 421997421}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!212 &755472559
SpriteRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 755472557}
m_Enabled: 1
m_CastShadows: 0
m_ReceiveShadows: 0
m_DynamicOccludee: 1
m_MotionVectors: 1
m_LightProbeUsage: 1
m_ReflectionProbeUsage: 1
m_RayTracingMode: 0
m_RenderingLayerMask: 1
m_RendererPriority: 0
m_Materials:
- {fileID: 10754, guid: 0000000000000000f000000000000000, type: 0}
m_StaticBatchInfo:
firstSubMesh: 0
subMeshCount: 0
m_StaticBatchRoot: {fileID: 0}
m_ProbeAnchor: {fileID: 0}
m_LightProbeVolumeOverride: {fileID: 0}
m_ScaleInLightmap: 1
m_ReceiveGI: 1
m_PreserveUVs: 0
m_IgnoreNormalsForChartDetection: 0
m_ImportantGI: 0
m_StitchLightmapSeams: 1
m_SelectedEditorRenderState: 0
m_MinimumChartSize: 4
m_AutoUVMaxDistance: 0.5
m_AutoUVMaxAngle: 89
m_LightmapParameters: {fileID: 0}
m_SortingLayerID: 0
m_SortingLayer: 0
m_SortingOrder: 0
m_Sprite: {fileID: 21300000, guid: 6e7069a7db07f489a87c0797b3ff2165, type: 3}
m_Color: {r: 1, g: 1, b: 1, a: 1}
m_FlipX: 0
m_FlipY: 0
m_DrawMode: 0
m_Size: {x: 5, y: 5}
m_AdaptiveModeThreshold: 0.5
m_SpriteTileMode: 0
m_WasSpriteAssigned: 1
m_MaskInteraction: 0
m_SpriteSortPoint: 0
--- !u!1 &957195930
GameObject:
m_ObjectHideFlags: 0
Expand Down Expand Up @@ -566,7 +537,7 @@ MonoBehaviour:
m_HorizontalOverflow: 0
m_VerticalOverflow: 0
m_LineSpacing: 1
m_Text: This is a bouncing ball
m_Text: Oh no the Fish!!!
--- !u!222 &2098954804
CanvasRenderer:
m_ObjectHideFlags: 0
Expand Down
Binary file added CMPUT 250 W24 Lab 3/Assets/spriteOutput.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading