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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
Export/
out/
.idea/
\#*\#
189 changes: 189 additions & 0 deletions Assets/test.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,189 @@
[
{
"days": [
{
"weekday": 2,
"time": "11:30-13:20"
},
{
"weekday": 2,
"time": "14:00-15:00"
},
{
"weekday": 4,
"time": "13:30-15:20"
}
],
"start": {
"day": 28,
"month": 9,
"year": 2018
},
"end": {
"day": 1,
"month": 11,
"year": 2018
},
"homework": [
[20, 6],
[10, 4],
[30, 3]
],
"project": 100,
"exception": [3],
"title": "Drawing"
},
{
"days": [
{
"weekday": 1,
"time": "10:30-11:20"
},
{
"weekday": 3,
"time": "10:30-11:20"
},
{
"weekday": 5,
"time": "10:30-11:20"
},
{
"weekday": 2,
"time": "15:00-15:30"
},
{
"weekday": 4,
"time": "15:00-15:30"
}
],
"start": {
"day": 28,
"month": 9,
"year": 2018
},
"end": {
"day": 1,
"month": 11,
"year": 2018
},
"homework": [
[25, 6],
[5, 4],
[30, 3]
],
"project": 1000,
"exception": [5],
"title": "Evolution and Ecology"
},
{
"days": [
{
"weekday": 2,
"time": "17:00-19:50"
}
],
"start": {
"day": 28,
"month": 9,
"year": 2018
},
"end": {
"day": 1,
"month": 11,
"year": 2018
},
"homework": [
[60, 10]
],
"project": 0,
"exception": [3, 8, 2],
"title": "EE Lab"
},
{
"days": [
{
"weekday": 1,
"time": "9:30-10:20"
},
{
"weekday": 3,
"time": "9:30-10:20"
},
{
"weekday": 5,
"time": "9:30-10:20"
}
],
"start": {
"day": 28,
"month": 9,
"year": 2018
},
"end": {
"day": 1,
"month": 11,
"year": 2018
},
"homework": [
[25, 6],
[5, 4],
[30, 3]
],
"project": 0,
"exception": [],
"title": "Chem"
},
{
"days": [
{
"weekday": 1,
"time": "18:00-20:50"
}
],
"start": {
"day": 28,
"month": 9,
"year": 2018
},
"end": {
"day": 1,
"month": 11,
"year": 2018
},
"homework": [
[60, 10]
],
"project": 0,
"exception": [7, 4],
"title": "Chem Lab"
},
{
"days": [
{
"weekday": 2,
"time": "15:30-16:50"
},
{
"weekday": 4,
"time": "15:30-16:50"
}
],
"start": {
"day": 28,
"month": 9,
"year": 2018
},
"end": {
"day": 1,
"month": 11,
"year": 2018
},
"homework": [
[0, 2],
[10, 20]
],
"project": 0,
"exception": [4, 5],
"title": "How Things Work"
}
]
96 changes: 46 additions & 50 deletions Source/Assignment.hx
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ import openfl.display.Shape;
import openfl.text.TextField;
import openfl.events.MouseEvent;

class Assignment extends Sprite
{
class Assignment extends Sprite {
private var rect:Shape;
private var workRect:Shape;
private var workSize:Float;
Expand All @@ -16,64 +15,61 @@ class Assignment extends Sprite
private var working:Bool;
private var size:Float;
private var interestRate:Float;

public function new (size:Float, height:Float, color:Int, barWidth:Int, interestRate:Float, workRate:Float){
super();

this.color = color;
this.barWidth = barWidth;
this.size = size;
this.interestRate = interestRate;
this.workRate = workRate;
this.y = -height;
public function new(size:Float, height:Float, color:Int, barWidth:Int, interestRate:Float, workRate:Float) {
super();

working = false;

rect = new Shape();
workRect = new Shape();
workSize = 0;
drawRectangle(rect, size, color);
addChild(rect);
addChild(workRect);
this.color = color;
this.barWidth = barWidth;
this.size = size;
this.interestRate = interestRate;
this.workRate = workRate;
this.y = -height;

this.addEventListener(MouseEvent.MOUSE_DOWN,
function (e:MouseEvent)
{working=true;});
this.addEventListener(MouseEvent.MOUSE_UP,
function (e:MouseEvent)
{working=false;});
this.addEventListener(MouseEvent.MOUSE_OUT,
function (e:MouseEvent)
{working=false;});
working = false;

rect = new Shape();
workRect = new Shape();
workSize = 0;
drawRectangle(rect, size, color);
addChild(rect);
addChild(workRect);

this.addEventListener(MouseEvent.MOUSE_DOWN,
function(e:MouseEvent) {working = true;});
this.addEventListener(MouseEvent.MOUSE_UP,
function(e:MouseEvent) {working = false;});
this.addEventListener(MouseEvent.MOUSE_OUT,
function(e:MouseEvent) {working = false;});
}

private function drawRectangle(shape:Shape, size:Float, color:Int){
shape.graphics.clear();
shape.graphics.lineStyle(0);
shape.graphics.beginFill(color, 1);
shape.graphics.drawRect(-Math.round(barWidth/2),-size,barWidth,size);
shape.graphics.endFill();
private function drawRectangle(shape:Shape, size:Float, color:Int) {
shape.graphics.clear();
shape.graphics.lineStyle(0);
shape.graphics.beginFill(color, 1);
shape.graphics.drawRect(-Math.round(barWidth / 2), -size, barWidth, size);
shape.graphics.endFill();
}

public function update (gameDate:Date, delta:Float, height:Float):Float {//returns size
accrueInterest(delta);
this.y = -height;
if(working){
work(delta);
if (workSize>=size){
size = 0; // This is an indication that the assignment is done
}
}
return size;
public function update(gameDate:Date, delta:Float, height:Float):Float {//returns size
accrueInterest(delta);
this.y = -height;
if (working) {
work(delta);
if (workSize >= size) {
size = 0; // This is an indication that the assignment is done
}
}
return size;
}

private function accrueInterest(delta:Float){
size += interestRate*(delta/(3600*24))*(size-workSize); // only get interest on part that you didn't do yet
drawRectangle(rect, size, color);
private function accrueInterest(delta:Float) {
size += interestRate * (delta / (3600 * 24)) * (size - workSize); // only get interest on part that you didn't do yet
drawRectangle(rect, size, color);
}

private function work(delta:Float){
workSize += workRate*delta/(3600*24);
drawRectangle(workRect, workSize, 0x897ea9);
private function work(delta:Float) {
workSize += workRate * delta / (3600 * 24);
drawRectangle(workRect, workSize, 0x897ea9);
}
}
Loading