PDA

View Full Version : Alice...Object Oriented??


EdLaFave
12-22-2005, 10:01 PM
Is there anyway to use object oriented code in Alice? I'd like to use items Alice offers (such as a tank, a house, a plane, etc.) as a class and create/destroy as many objects of that class as I want. For instance suppose I wanted to add a new Tank to my world every time the user clicked on something....could I construct a new Tank object at runtime and place it into the world?

What I'd really like to do is make a first person shooter with a bullet class. Everytime the user shoots a bullet, a new bullet is created, fired and destroyed after it has traveled over a certain amount of distance. The old fix of sending the bullet out of view making it invisible and bringing it back to the gun to shoot again just isn't good enough because what M4 shoots 5 rounds a minute? Furthermore that method causes each shot to be delayed if you try to shoot while the bullet is already being shot.

pausch
12-23-2005, 02:02 PM
Unfortunately, it is not possible to create objects on the fly.

The best work-around for your example would be to create a ton of bullets at the beginning and make them invisible, and then use the kind of tricks you refer to.

You can solve the latency problem by just having *enough* bullets.

EdLaFave
12-24-2005, 01:40 AM
okay then my final question on this matter is this. Currently I have it set up to shoot when the user presses a key. Alice seems to deal with this in a queue like fashion. Every time the space bar is pushed the function to shoot is placed into the queue and must wait until its at the front of the queue to be executed. The end result of course being that the entire process of fire a bullet must finish before another bullet can be fired. So no two bullets can be in the air at the same time. How can I get around this so I can fire as many shots in a row as I'd like?

pausch
12-25-2005, 05:47 AM
There may be a more clever solution, but I think the issue here is that you can't excute the entire bullet movement in one Alice command.

So you'll have to basically move each bullet a little bit (maybe a 10th of a second), and then write some sort of looping or event-driven structure that "re-gooses" them to keep them moving.

On the plus side, this gives you a way to see if they are hitting anything, since you can do a simple collision detection every 1/10th of a second.

TJ_13
05-18-2006, 08:55 PM
I was having the same problem thank you for explaining but i haven't been able to find any bullets anywhere... pls help

pausch
05-18-2006, 09:15 PM
We didn't provide bullets in the gallery.

That was intentional.

Jabberwocky
05-19-2006, 06:40 AM
You could use any object as a bullet. A cow projectile for instance...


You can make your own bullets. Click on the "Add Objects" button underneath the world preview window. Browse the gallery like normal. Try using one of the objects in the Shapes folder. Use a sphere or a tube for instance. Use the object layout tools to position and resize it appropriately; change it's color property in the details window.


Export the one out of the gun game (http://www.alice.org/community/showpost.php?p=200&postcount=1) I mentioned. Do so like this.
[a] Right-click on the object, the bullet, in the object tree and select "save object..."
[b] Open your world
[c] Import it back in from the file menu. (If you saved it in the gallery, you can just browse and click like you do when you normally add objects. For organization... create your own folder under the gallery for custom objects and save stuff there.)
[d] Note: You can use this feature to create custom objects with custom attributes, methods, and functions. See Gabe's response on this in the thread Create a Class (http://www.alice.org/community/showthread.php?t=139). If you customize methods or functions & make object calls you'll need to have those objects in your world before you bring in the new object.

Have fun!

nick10492
05-31-2008, 02:46 PM
How do you save objects to the gallery?

DickBaldwin
05-31-2008, 03:24 PM
How do you save objects to the gallery?

See http://www.dickbaldwin.com/alice/Alice0150.htm

Dick Baldwin
Free Alice tutorials: http://www.dickbaldwin.com/tocalice.htm
Free Scratch tutorials: http://www.dickbaldwin.com/tocHomeSchool.htm
Free Java/C#, etc. tutorials: http://www.dickbaldwin.com/toc.htm

pyro-guitarx-715
05-31-2008, 05:39 PM
1) create a bunch of bullets
2) make a list that contains all of the bullets
3) write code that checks all of the bullets in order to see if they have left the gun if the bullets hasn't left the gun, do the firing and returning sequence, if it has left the gun, it will move on to the next bullet in the sequence.

also as said here


So you'll have to basically move each bullet a little bit (maybe a 10th of a second), and then write some sort of looping or event-driven structure that "re-gooses" them to keep them moving.

On the plus side, this gives you a way to see if they are hitting anything, since you can do a simple collision detection every 1/10th of a second.

as stated her, you should break the firing sequence down into pieces so that you can check for a colision

i'm not entirely sure that this idea will work, but its worth a try

DickBaldwin
05-31-2008, 06:13 PM
1) create a bunch of bullets
2) make a list that contains all of the bullets
3) write code that checks all of the bullets in order to see if they have left the gun if the bullets hasn't left the gun, do the firing and returning sequence, if it has left the gun, it will move on to the next bullet in the sequence.

also as said here



as stated her, you should break the firing sequence down into pieces so that you can check for a colision

i'm not entirely sure that this idea will work, but its worth a try

You just responded to a question that was posted on 12-22-2005, 10:01 PM. If the EdLaFave is still waiting for an answer to that question, he or she must have a lot of patience.

Dick Baldwin
Free Alice tutorials: http://www.dickbaldwin.com/tocalice.htm
Free Scratch tutorials: http://www.dickbaldwin.com/tocHomeSchool.htm
Free Java/C#, etc. tutorials: http://www.dickbaldwin.com/toc.htm

pyro-guitarx-715
05-31-2008, 06:23 PM
You just responded to a question that was posted on 12-22-2005, 10:01 PM. If the EdLaFave is still waiting for an answer to that question, he or she must have a lot of patience.


dont be a jerk

you didnt have to say anything, but noooooooooooo you had to point out to anyone who reads this

so thanks i officially dont like you

lanceA
05-31-2008, 06:45 PM
dont be a jerk

you didnt have to say anything, but noooooooooooo you had to point out to anyone who reads this

so thanks i officially dont like you

Well if the dislike is "official" Dick, then I guesss I can't like your free tutorials, etc., etc. Neither can I respect your constant input and help to this forum. ;)

DickBaldwin
05-31-2008, 08:31 PM
Well if the dislike is "official" Dick, then I guesss I can't like your free tutorials, etc., etc. Neither can I respect your constant input and help to this forum. ;)

Thanks Lance,

Normally I wouldn't have responded the way that I did, particularly to a high school student. However, when I saw that pyro-guitarx-715 (http://www.alice.org/community/member.php?u=2976) was being somewhat disrespectful of a posting by Randy Pausch on 12-25-2005 at 5:47 in the morning, I just felt the need to respond. pyro-guitarx-715 (http://www.alice.org/community/member.php?u=2976)'s opinion of Randy's advice to the original poster was:

"i'm not entirely sure that this idea will work, but its worth a try"

Considering that this student was probably still in middle school when Randy was doing his great work in December of 2005 and before, that disrespectful posting just didn't sit well with me. Perhaps pyro-guitarx-715 (http://www.alice.org/community/member.php?u=2976) should take some time out and reflect on the video at http://www.youtube.com/watch?v=ji5_MqicxSo

Dick Baldwin
Free Alice tutorials: http://www.dickbaldwin.com/tocalice.htm
Free Scratch tutorials: http://www.dickbaldwin.com/tocHomeSchool.htm
Free Java/C#, etc. tutorials: http://www.dickbaldwin.com/toc.htm