Alice Community  

Go Back   Alice Community > Alice 2 > How do I...?

Reply
 
Thread Tools Display Modes
Alice...Object Oriented??
Old
EdLaFave
Guest
 
Status:
Posts: n/a
Default Alice...Object Oriented?? - 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.
   
Reply With Quote
Unfortunately, you can't create Objects on the Fly
Old
pausch
Director of the Alice Project
 
Status: Offline
Posts: 38
Join Date: Jul 2005
Default Unfortunately, you can't create Objects on the Fly - 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.


Randy Pausch
Director of the Alice Project
   
Reply With Quote
Old
EdLaFave
Guest
 
Status:
Posts: n/a
Default 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?
   
Reply With Quote
solving queued bullets
Old
pausch
Director of the Alice Project
 
Status: Offline
Posts: 38
Join Date: Jul 2005
Default solving queued bullets - 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.


Randy Pausch
Director of the Alice Project
   
Reply With Quote
Old
TJ_13
Guest
 
Status:
Posts: n/a
Default 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
   
Reply With Quote
No bullets
Old
pausch
Director of the Alice Project
 
Status: Offline
Posts: 38
Join Date: Jul 2005
Default No bullets - 05-18-2006, 09:15 PM

We didn't provide bullets in the gallery.

That was intentional.


Randy Pausch
Director of the Alice Project
   
Reply With Quote
sweating bullets
Old
Jabberwocky
Guest
 
Status:
Posts: n/a
Default sweating bullets - 05-19-2006, 06:40 AM

  1. You could use any object as a bullet. A cow projectile for instance...

  2. 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.

  3. Export the one out of the gun game 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. 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!

Last edited by Jabberwocky; 06-10-2006 at 12:22 PM.
   
Reply With Quote
Old
nick10492
Guest
 
Status:
Posts: n/a
Exclamation 05-31-2008, 02:46 PM

How do you save objects to the gallery?
   
Reply With Quote
Old
DickBaldwin
Guest
 
Status:
Posts: n/a
Default 05-31-2008, 03:24 PM

Quote:
Originally Posted by nick10492 View Post
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
   
Reply With Quote
Idea For Your Problem
Old
pyro-guitarx-715
Guest
 
Status:
Posts: n/a
Default Idea For Your Problem - 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

Quote:
Originally Posted by pausch View Post
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

Last edited by pyro-guitarx-715; 05-31-2008 at 05:42 PM.
   
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump



Copyright ©2024, Carnegie Mellon University
Alice 2.x © 1999-2012, Alice 3.x © 2008-2012, Carnegie Mellon University. All rights reserved.