# Making Sprite go up on y axis

**URL:** <https://forum.code.org/t/making-sprite-go-up-on-y-axis/24323>\
**Category:** CS Discoveries\
**Created:** [January 25, 2019, 2:49pm UTC](https://forum.code.org/t/making-sprite-go-up-on-y-axis/24323 "2019-01-25T14:49:32Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![marla.bryant](https://avatars.discourse-cdn.com/v4/letter/m/aeb1de/32.png) [@marla.bryant](https://forum.code.org/u/marla.bryant)\
**Post date:** [January 25, 2019, 2:49pm UTC](https://forum.code.org/t/making-sprite-go-up-on-y-axis/24323/1 "2019-01-25T14:49:32Z")

</div>

Game lab–My students and I have been trying to make a sprite go in a square/rectangle. We have the code for 3 of the sides but have tried numerous times to get it to finish the last leg. No success. Any advice is greatly appreciated. Here is the code we have so far:

background(“green”);  
var corgi\_1 = createSprite(5, 200);  
corgi\_1.setAnimation(“corgi\_1”);  
corgi\_1.height = 50;  
corgi\_1.width = 70;  
function draw() {  
if (corgi\_1.x \< 215) {  
corgi\_1.x = corgi\_1.x + 5;  
}  
if (corgi\_1.x \>= 215) {  
corgi\_1.y = corgi\_1.y + 5;  
}  
if (corgi\_1.y \>= 315) {  
corgi\_1.x = corgi\_1.x + 78654;  
}  
if (corgi\_1.y \> 300) {  
corgi\_1.x = corgi\_1.x - 10;  
}  
if ((corgi\_1.x) \<= 25) {  
corgi\_1.x = corgi\_1.x + 5;  
}  
drawSprites();  
}  
Thank you,  
Marla

---

<div class="post-metadata">

**Author:** ![lana.shea](https://avatars.discourse-cdn.com/v4/letter/l/9d8465/32.png) [@lana.shea](https://forum.code.org/u/lana.shea)\
**Post date:** [January 27, 2019, 3:24am UTC](https://forum.code.org/t/making-sprite-go-up-on-y-axis/24323/2 "2019-01-27T03:24:24Z")

</div>

Here’s my attempt . . .

var corgi\_1 = createSprite(10, 200);  
corgi\_1.setAnimation(“corgi\_1”);  
corgi\_1.height = 50;  
corgi\_1.width = 70;  
function draw() {  
background(“white”);  
if (corgi\_1.x\<250 && corgi\_1.y==200) {  
corgi\_1.x = corgi\_1.x + 5;  
}  
if (corgi\_1.x==250 && corgi\_1.y\<350) {  
corgi\_1.y = corgi\_1.y + 5;  
}  
if (corgi\_1.x\>10 && corgi\_1.y==350) {  
corgi\_1.x = corgi\_1.x - 5;  
}  
if (corgi\_1.x==10 && corgi\_1.y\<=350) {  
corgi\_1.y = corgi\_1.y - 5;  
}  
drawSprites();  
}

---

<div class="post-metadata">

**Author:** ![bradleywellsashley](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.code.org/bradleywellsashley/32/522_2.png) [@bradleywellsashley](https://forum.code.org/u/bradleywellsashley)\
**Post date:** [January 28, 2019, 12:50pm UTC](https://forum.code.org/t/making-sprite-go-up-on-y-axis/24323/3 "2019-01-28T12:50:39Z")

</div>

Marla,

Lana answered - but is that what you’re looking for? Lana used complex conditionals (&&) to make it so when true conditions are true - in this case an x and y value - it would execute the code.

Hope that helps and thank you @lana.shea!

Brad
