Skip to content

Commit 6533175

Browse files
committed
Merge remote-tracking branch 'upstream/master' into turkish_keywords_2.13.x
2 parents 7e3d6ef + 7c31f14 commit 6533175

File tree

22 files changed

+391
-78
lines changed

22 files changed

+391
-78
lines changed

installer.i4j/kojo.install4j

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<install4j version="10.0.6" transformSequenceNumber="10">
33
<directoryPresets config="/home/lalit/work/kojo/installer/icons" />
4-
<application name="Kojo Learning Environment" applicationId="0071-0523-9450-8404" mediaDir="/home/lalit/kojo_installers/install4j" mediaFilePattern="${compiler:sys.shortName}_${compiler:sys.platform}_${compiler:sys.version}${compiler:sys.withJre}" shortName="Kojo" publisher="Kogics Foundation" publisherWeb="www.kogics.net/kojo" version="2.9.29" macVolumeId="41bac862080108f9" javaMinVersion="1.8" javaMaxVersion="17" jdkMode="jdk" jdkName="JDK 1.8">
4+
<application name="Kojo Learning Environment" applicationId="0071-0523-9450-8404" mediaDir="/home/lalit/kojo_installers/install4j" mediaFilePattern="${compiler:sys.shortName}_${compiler:sys.platform}_${compiler:sys.version}${compiler:sys.withJre}" shortName="Kojo" publisher="Kogics Foundation" publisherWeb="www.kogics.net/kojo" version="2.9.30" macVolumeId="41bac862080108f9" javaMinVersion="1.8" javaMaxVersion="17" jdkMode="jdk" jdkName="JDK 1.8">
55
<searchSequence>
66
<registry />
77
<envVar name="JAVA_HOME" />

installer/examples/tiledgame/game.kojo.installed

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ clearOutput()
33
cleari()
44
disablePanAndZoom()
55

6-
println("To win the game, find and drink the red-ball potion and then return to the starting point to drink the (initially covered) green-ball potion.")
6+
println("To win the game, find and drink the red-ball potion and then return to the starting point to drink the (initially covered) green-star potion.")
77
println(s"\nTo modify the game layout, change '$installDir/examples/tiledgame/level1.tmx' using the Tiled editor from www.mapeditor.org")
88

99
scroll(-canvasBounds.x, canvasBounds.y)
@@ -18,7 +18,11 @@ class Player(tx: Int, ty: Int, world: TileWorld) {
1818

1919
// player images are 30x40
2020
// scale the player down to fit into a 24 pixel wide tile
21-
def playerPicture(img: Image) = scale(0.8) -> Picture.image(img)
21+
def playerPicture(img: Image) = {
22+
val pic = Picture.image(img)
23+
pic.scale(0.8)
24+
pic
25+
}
2226

2327
val stillRight = picBatch(playerPicture(sheet.imageAt(0, 0)))
2428
val stillLeft = picBatch(playerPicture(sheet.imageAt(0, 1)))
@@ -181,7 +185,12 @@ class AttackerUpDown(tx: Int, ty: Int, world: TileWorld) {
181185
val sheet = SpriteSheet("tiles.png", 24, 24)
182186
// make attacker slighty smaller than a tile - to prevent picture based collision
183187
// with the player in an adjacent tile
184-
def attackerPicture(img: Image) = scale(0.98) * trans(0.2, 0.2) -> Picture.image(img)
188+
def attackerPicture(img: Image) = {
189+
val pic = Picture.image(img)
190+
pic.translate(0.2, 0.2)
191+
pic.scale(0.98)
192+
pic
193+
}
185194

186195
var currentPic = picBatch(List(
187196
sheet.imageAt(0, 6),
@@ -236,17 +245,25 @@ val attackers = List(
236245
new AttackerUpDown(35, 3, tileWorld)
237246
)
238247

239-
val goal = trans(12, 12) * fillColor(cm.greenYellow) * penColor(black) -> Picture.circle(10)
248+
val goal = {
249+
val pic = Picture.image("target.png")
250+
pic.scale(0.3)
251+
pic
252+
}
240253
goal.setPosition(tileWorld.tileToKojo(TileXY(9, 2)))
241-
goal.setOpacity(0.2)
242-
draw(goal)
254+
goal.setOpacity(0.4)
243255

244-
val halfwayGoal = trans(12, 12) * fillColor(cm.red) * penColor(black) -> Picture.circle(10)
256+
val halfwayGoal = {
257+
val pic = Picture.image("halfway-target.png")
258+
pic.scale(0.5)
259+
pic
260+
}
245261
halfwayGoal.setPosition(tileWorld.tileToKojo(TileXY(41, 15)))
246-
draw(halfwayGoal)
247262

248263
tileWorld.draw()
249264
player.draw()
265+
draw(goal)
266+
draw(halfwayGoal)
250267
attackers.foreach { attacker =>
251268
attacker.draw()
252269
}
1.99 KB
Loading
1.44 KB
Loading

src/main/resources/net/kogics/kojo/lite/Bundle.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ S_InstructionPalette=Instruction Palette
146146
S_TurtleController=Turtle Controller
147147
S_ArduinoProgramming=Arduino Programming
148148
S_StartingChallenges=Beginner Challenges
149+
S_SpriteBoundaryPolygon=Sprite Boundary Editor
149150

150151
S_Help=Help
151152
S_KojoDocs=Kojo Documentation

src/main/resources/net/kogics/kojo/lite/Bundle_it.properties

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ S_InstructionPalette=Riferimento
127127
S_TurtleController=Comandi Tartaruga
128128
S_ArduinoProgramming=Programmazione per Arduino
129129
S_StartingChallenges=Sfide per i principianti
130+
S_SpriteBoundaryPolygon=Editor dell'area dello Sprite
130131

131132
S_Help=Aiuto
132133
S_KojoOverview=Panoramica su Kojo
@@ -312,3 +313,4 @@ S_Dimension_Height=Altezza
312313
S_Dimension_Width=Larghezza
313314
S_WorksheetPragma=foglio di lavoro
314315
S_IncludePragma=includi
316+
S_ExecPragma=execute

src/main/resources/net/kogics/kojo/lite/Bundle_sv.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ S_InstructionPalette=Klicka p
128128
S_TurtleController=Styra paddan
129129
S_ArduinoProgramming=Arduino-programmering
130130
S_StartingChallenges=Övningar för nybörjare
131+
S_SpriteBoundaryPolygon=Editera sprite-avgränsning
131132

132133
S_Help=Hjälp
133134
S_KojoOverview=Kojo översikt

src/main/resources/samples/lunar-lander.kojo

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,21 @@ val cb = canvasBounds
88
drawStage(ColorMaker.hsl(240, 0.20, 0.16))
99

1010
def xCenteredPosition(picWidth: Double) = {
11-
cb.x + (cb.width - picWidth) / 2
11+
cb.x + (cb.width - picWidth) / 2 + picWidth / 2
1212
}
1313

1414
class Lander {
1515
val bodyWidth = 40; val bodyHeight = 70
1616
val thrusterWidth = 20; val thrusterHeight = 35
17-
val body = fillColor(red) -> Picture.rectangle(bodyWidth, bodyHeight)
17+
val body = {
18+
val pic = Picture.rectangle(bodyWidth, bodyHeight); pic.setFillColor(red)
19+
pic
20+
}
1821
body.setPosition(xCenteredPosition(bodyWidth), cb.y + cb.height - bodyHeight - 10)
19-
val thruster = fillColor(orange) -> Picture.rectangle(thrusterWidth, thrusterHeight)
22+
val thruster = {
23+
val pic = Picture.rectangle(thrusterWidth, thrusterHeight); pic.setFillColor(orange)
24+
pic
25+
}
2026
setThrusterPosition()
2127

2228
val gravity = Vector2D(0, -0.1)
@@ -68,15 +74,12 @@ class Lander {
6874
}
6975

7076
class Moon {
71-
val pic = Picture {
72-
setPenColor(cm.lightBlue)
73-
setFillColor(cm.darkGray)
74-
right(45)
75-
right(90, 500)
76-
}
77+
val pic = Picture.ellipse(350, 150)
78+
pic.setPenColor(cm.lightBlue)
79+
pic.setFillColor(cm.darkGray)
7780

7881
// width of the moon is around 710 pixels
79-
pic.setPosition(xCenteredPosition(710), cb.y)
82+
pic.setPosition(xCenteredPosition(710), cb.y - 50)
8083

8184
def draw() {
8285
pic.draw()
@@ -106,4 +109,4 @@ animate {
106109
l.step()
107110
m.check(l)
108111
}
109-
activateCanvas()
112+
activateCanvas()

src/main/resources/samples/pong.kojo

Lines changed: 49 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,26 @@ val PaddleW = 25
99
val BallR = 15
1010
val Height = canvasBounds.height
1111
val Width = canvasBounds.width
12-
val PaddleSpeed = 5
12+
val PaddleSpeed = 400
1313
val pScaleFactor = 1.01
14-
val BallSpeed = 5
14+
val BallSpeed = 400
1515
val bScaleFactor = 1.001
1616

17-
def paddle = penColor(darkGray) * fillColor(red) -> Picture.rectangle(PaddleW, PaddleH)
18-
def vline = penColor(white) -> Picture.vline(Height)
19-
def ball = penColor(cm.rgb(0, 230, 0)) * fillColor(cm.rgb(0, 230, 0)) -> Picture.circle(BallR)
17+
def paddle: Picture = {
18+
val pic = Picture.rectangle(PaddleW, PaddleH)
19+
pic.setPenColor(darkGray); pic.setFillColor(red)
20+
pic
21+
}
22+
def vline = {
23+
val pic = Picture.rectangle(0, Height)
24+
pic.setPenColor(white)
25+
pic
26+
}
27+
def ball = {
28+
val pic = Picture.circle(BallR)
29+
pic.setPenColor(cm.rgb(0, 230, 0)); pic.setFillColor(cm.rgb(0, 230, 0))
30+
pic
31+
}
2032

2133
class PaddleVelocity(speed0: Double, lastUp0: Boolean) {
2234
var speed = speed0
@@ -35,28 +47,42 @@ class Score(score0: Int, left0: Boolean) {
3547
var score = score0
3648
var left = left0
3749
val xt = if (left) -50 else 50
38-
val pScore = Picture.textu(score, 20)
50+
val pScore = Picture.text(score.toString, 20, cm.lightSteelBlue)
3951
pScore.translate(xt, Height / 2 - 10)
40-
pScore.setPenColor(cm.lightSteelBlue)
4152
def incrScore() {
4253
score += 1
43-
pScore.update(score)
54+
pScore.setText(score.toString)
4455
}
4556
}
4657

4758
val topbot = Seq(stageTop, stageBot)
48-
val paddle1 = trans(-Width / 2, 0) -> paddle
49-
val paddle2 = trans(Width / 2 - PaddleW, 0) -> paddle
50-
val centerLine = trans(0, -Height / 2) -> vline
51-
val leftGutter = trans(-Width / 2 + PaddleW, -Height / 2) -> vline
52-
val rightGutter = trans(Width / 2 - PaddleW, -Height / 2) -> vline
59+
val paddle1 = {
60+
val pic = paddle; pic.translate(-Width / 2, 0)
61+
pic
62+
}
63+
val paddle2 = {
64+
val pic = paddle; pic.translate(Width / 2 - PaddleW, 0)
65+
pic
66+
}
67+
val centerLine = {
68+
val pic = vline; pic.translate(0, -Height / 2)
69+
pic
70+
}
71+
val leftGutter = {
72+
val pic = vline; pic.translate(-Width / 2 + PaddleW, -Height / 2)
73+
pic
74+
}
75+
val rightGutter = {
76+
val pic = vline; pic.translate(Width / 2 - PaddleW, -Height / 2)
77+
pic
78+
}
5379
val gutters = Seq(leftGutter, rightGutter)
5480
val paddles = Seq(paddle1, paddle2)
5581
val gameBall = ball
5682

5783
draw(paddle1, paddle2, centerLine, leftGutter, rightGutter, gameBall)
5884

59-
val ballVel = Vector2D(BallSpeed, 3)
85+
val ballVel = Vector2D(BallSpeed, BallSpeed * 0.65)
6086
var currBallVel: Vector2D = ballVel
6187

6288
val paddleVelocity = Map(
@@ -71,12 +97,14 @@ draw(scores(paddle1).pScore)
7197
draw(scores(paddle2).pScore)
7298

7399
animate {
74-
gameBall.translate(currBallVel)
100+
val dt = frameDeltaTime
101+
gameBall.translate(currBallVel * dt)
75102

76103
if (gameBall.collision(paddles).isDefined) {
77104
currBallVel = Vector2D(-currBallVel.x, currBallVel.y)
78105
}
79106
else if (gameBall.collision(topbot).isDefined) {
107+
gameBall.translate(-currBallVel * dt)
80108
currBallVel = Vector2D(currBallVel.x, -currBallVel.y)
81109
}
82110
else if (gameBall.collidesWith(leftGutter)) {
@@ -90,13 +118,13 @@ animate {
90118
scores(paddle1).incrScore()
91119
}
92120
else {
93-
currBallVel = (currBallVel * bScaleFactor).limit(11)
121+
currBallVel = (currBallVel * bScaleFactor).limit(800)
94122
}
95-
paddleBehavior(paddle1, Kc.VK_A, Kc.VK_Z)
96-
paddleBehavior(paddle2, Kc.VK_UP, Kc.VK_DOWN)
123+
paddleBehavior(paddle1, Kc.VK_A, Kc.VK_Z, dt)
124+
paddleBehavior(paddle2, Kc.VK_UP, Kc.VK_DOWN, dt)
97125
}
98126

99-
def paddleBehavior(paddle: Picture, upkey: Int, downkey: Int) {
127+
def paddleBehavior(paddle: Picture, upkey: Int, downkey: Int, dt: Double) {
100128
val pVel = paddleVelocity(paddle)
101129
if (isKeyPressed(upkey) && !paddle.collidesWith(stageTop)) {
102130
if (pVel.lastUp) {
@@ -105,7 +133,7 @@ def paddleBehavior(paddle: Picture, upkey: Int, downkey: Int) {
105133
else {
106134
pVel.reset(!pVel.lastUp)
107135
}
108-
paddle.translate(0, pVel.speed)
136+
paddle.translate(0, pVel.speed * dt)
109137
}
110138
else if (isKeyPressed(downkey) && !paddle.collidesWith(stageBot)) {
111139
if (!pVel.lastUp) {
@@ -114,7 +142,7 @@ def paddleBehavior(paddle: Picture, upkey: Int, downkey: Int) {
114142
else {
115143
pVel.reset(!pVel.lastUp)
116144
}
117-
paddle.translate(0, -pVel.speed)
145+
paddle.translate(0, -pVel.speed * dt)
118146
}
119147
else {
120148
pVel.reset(pVel.lastUp)
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
cleari()
2+
clearOutput()
3+
4+
val sprite = Picture.image(Costume.womanWaving)
5+
// Make the sprite point to your own image via the following:
6+
// val assetsDir = "/your/asset/folder"
7+
// val sprite = Picture.image(s"$assetsDir/your-sprite.png")
8+
9+
draw(sprite)
10+
11+
// double or float array to be printed
12+
val doubleArray = true
13+
14+
println("Load your own sprite image above by changing the code as described at the start of the script.\n")
15+
println("Then click around the sprite image to create a polygonal boundary for the sprite (and feel free to zoom in while doing this).\n")
16+
println("Click twice (slowly) at the same point to finish off the boundary.\n")
17+
println("The last point (that you clicked twice at) is connected to the first point to create the boundary.\n")
18+
19+
var points = ArrayBuffer.empty[Point]
20+
var pointsPic: Picture = Picture.rectangle(0, 0)
21+
pointsPic.draw()
22+
23+
def updateBoundary() {
24+
val pt = points.head
25+
val pointsPic2 = picStack(
26+
Picture.circle(5)
27+
.withPenColor(blue).withFillColor(blue).withPosition(pt.x, pt.y),
28+
Picture.fromVertexShape { s =>
29+
s.beginShape()
30+
points.foreach { pt =>
31+
s.vertex(pt.x, pt.y)
32+
}
33+
s.endShape()
34+
}.withPenColor(blue).withPenThickness(5)
35+
)
36+
pointsPic2.draw()
37+
pointsPic.erase()
38+
pointsPic = pointsPic2
39+
pointsPic.tnode.repaint()
40+
}
41+
42+
onMouseClick { (x, y) =>
43+
points.append(Point(x, y))
44+
updateBoundary()
45+
46+
val len = points.length
47+
if (points(len - 2) == points(len - 1)) {
48+
points.remove(len - 1)
49+
points.append(points.head)
50+
val pts = points
51+
.flatMap(pt => Array(pt.x, pt.y))
52+
.map(n => if (doubleArray) f"${n}%.1f" else f"${n}%.1ff")
53+
54+
println("Boundary Array:\n")
55+
println(pts.mkString("Array(", ", ", ")"))
56+
println("\nCopy the above array into your code as required.")
57+
updateBoundary()
58+
points = ArrayBuffer.empty[Point]
59+
}
60+
}
61+
62+
activateCanvas()

src/main/scala/net/kogics/kojo/core/Picture.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ trait Picture extends InputAware {
6363
def intersection(other: Picture): Geometry
6464
def contains(other: Picture): Boolean
6565
def distanceTo(other: Picture): Double
66+
def isCloser(other: Picture, distance: Double): Boolean = distanceTo(other) < distance
6667
def area: Double
6768
def perimeter: Double
6869
def picGeom: Geometry

src/main/scala/net/kogics/kojo/core/TSCanvasFeatures.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,4 +79,5 @@ trait TSCanvasFeatures {
7979
def onAnimationStop(fn: => Unit): Unit
8080
def resetPanAndZoom(): Unit
8181
def disablePanAndZoom(): Unit
82+
def frameDeltaTime: Double
8283
}

src/main/scala/net/kogics/kojo/lite/AppMenu.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -428,6 +428,7 @@ trait AppMenu {
428428
toolsMenu.add(menuItemFor("S_TurtleController", "turtle-controller.kojo"))
429429
toolsMenu.add(menuItemFor("S_ArduinoProgramming", "arduino-prog.kojo"))
430430
toolsMenu.add(menuItemFor("S_StartingChallenges", "get-started.kojo", "/challenge/"))
431+
toolsMenu.add(menuItemFor("S_SpriteBoundaryPolygon", "sprite-boundary-polygon.kojo"))
431432
menuBar.add(toolsMenu)
432433

433434
val helpMenu = newJMenu(Utils.loadString("S_Help"))

0 commit comments

Comments
 (0)