Alice Community  

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

Reply
 
Thread Tools Display Modes
Limit my object to only go on the screen where I can see it..
Old
spatu1a
Guest
 
Status:
Posts: n/a
Default Limit my object to only go on the screen where I can see it.. - 05-21-2010, 10:00 AM

Hey all~ I'm new to the alice community, but I need help badly!
I'm creating a pretty simple game in which you control two ships at the same time, each on their own side of the screen as they pass through barriers (I've already split the screen into two.)
The problem I'm encountering is I don't know how to limit how far left and right the ships travel. (You can only control left and right movement for each) Right now, the user can move the ship completely off the screen.. which I don't want to happen. Can you suggest how to fix this problem?

Additionally, I would love to be able to host my game on the web... how do I do that?
   
Reply With Quote
What exactly I'm looking to do..
Old
spatu1a
Guest
 
Status:
Posts: n/a
Default What exactly I'm looking to do.. - 05-21-2010, 12:13 PM

Essentially, what I'm looking for is to limit the object to the camera's view.
   
Reply With Quote
Old
Niteshifter
Guest
 
Status:
Posts: n/a
Default 05-22-2010, 02:20 AM

You could implement some kind of vector system using variables to keep track of the movements.

There's also a few algorithms to determine the field of view of a camera, although I don't think there's anyone able to completely help you with finding this out. There are some really good tutorials and guides on how to do this. I can also tell you that you'll need a bit of experience programming with trigonometry in order to make the field of view algorithms work.
   
Reply With Quote
Old
Dameria
Senior Member
 
Dameria's Avatar
 
Status: Offline
Posts: 978
Join Date: Sep 2009
Location: United States
Default 05-22-2010, 10:32 AM

I just made this really quickly, its an example of how you can stop something from going out of the camera field of view by pushing it forwards. This might not be exactly what you were looking for, but I don't know what you want, you would have to let me see your project for me to assess the best way to go about doing it.

All I did was put 4 cubes in the world (one for the left of the screen, one for the right, one for the front near the camera, and one as the object that is moving), and I made a simple infinite loop determining if the distance that the object is in front of each square, and if the distance is less than 0, meaning it is at the edge of the camera screen, it moves the object forwards into the field of view at a faster rate than the object itself is moving (for instance if it is moving 0.05 meters in 0 seconds, it pushes the object forward 0.1 meters so that it can not wiggle its way through the barrier). This is essentially the same thing as collision detection, but instead the walls (the half invisible black cubes) are vehicle to the camera so that they move wherever the camera goes. You can also move the camera with the mouse (move slowly to see best results) and you will see that when you move the camera so that it does not look at the cube, the cube will follow the camera and try as hard as it can to get back into the camera's view (it can only go 0.1 meters at a time though, so moving the camera too fast will make the cube go out of the view until it can catch up the the camera again).

Tell me if you need any further help or if this answered your question.
Attached Files
File Type: a2w FieldOfView.a2w (198.3 KB, 26 views)


Check out my best projects so far and please comment:

Tic-Tac-Toe 2.0 ................... http://www.alice.org/community/showthread.php?t=3548
Alice Paint ........................... http://www.alice.org/community/showthread.php?p=23408
Real-Time Clock .................. http://www.alice.org/community/showthread.php?p=12725
Maze Game ......................... http://www.alice.org/community/showthread.php?t=4301

Last edited by Dameria; 05-22-2010 at 10:35 AM.
   
Reply With Quote
Old
spatu1a
Guest
 
Status:
Posts: n/a
Default 05-22-2010, 11:28 AM

Hey Niteshifter and Dameria,

Thanks for all your help!

Niteshifter:
I'm going into calculus next year, but I'm not sure what you mean by a vector system. Also, I know trigonometry but I have no experience programming with it, and I'm not sure how it would apply here. Do you have a program with this in it?

Dameria:
I've attached my program for you to have a look at. Note that I haven't begun the part where the levels actually start; I'm just getting all the basics done. The user will NOT be able to control vertical movement, and the plane should not move on the z-axis, but only be cappable of movement left and right, on the x-axis. I think I understand what you are doing in the other program you made, but I noticed that the square wiggles away from the camera- I don't know how to stop that.. Hopefully the program can make it clearer what I'm looking for~

Thanks again for all your help so far!
Attached Files
File Type: a2w newgame.a2w (750.2 KB, 11 views)
   
Reply With Quote
Old
Dameria
Senior Member
 
Dameria's Avatar
 
Status: Offline
Posts: 978
Join Date: Sep 2009
Location: United States
Default 05-22-2010, 12:58 PM

I think that niteshifter is going into way too much advanced math than he needs to, there are much simpler ways than using trigonometry, for example I just solved your problem with a simple set of inequalities, which is learned in Algebra 1. I made it so that there is a world variable called "canMove" and I set it to false, and it will only be set to true once you click on the text to start the game. I also made the collision that you asked for, you can see what I did in the world.stayInScreen method. If for some reason the spaceships can still go past the barriers slowly, just change the 0.05 meters in each of the lines of code in "stayInScreen" to something a little higher, like 0.06 or more, but if it is good, just keep it the way it is (also the other way around, if it gets pushed back too quickly and it is choppy, you can lower the number until you find the one that gives the best result).

Tell me if this is what you wanted (it was much simpler than I thought it was going to be).
Attached Files
File Type: a2w newgame (1).a2w (758.2 KB, 16 views)


Check out my best projects so far and please comment:

Tic-Tac-Toe 2.0 ................... http://www.alice.org/community/showthread.php?t=3548
Alice Paint ........................... http://www.alice.org/community/showthread.php?p=23408
Real-Time Clock .................. http://www.alice.org/community/showthread.php?p=12725
Maze Game ......................... http://www.alice.org/community/showthread.php?t=4301

Last edited by Dameria; 05-22-2010 at 01:01 PM.
   
Reply With Quote
Old
spatu1a
Guest
 
Status:
Posts: n/a
Thumbs up 05-22-2010, 04:47 PM

Dameria-
That works fantastically- don't know why I didn't manage to think of that before. Thanks so much- will let you know what the final product looks like!
   
Reply With Quote
Old
Dameria
Senior Member
 
Dameria's Avatar
 
Status: Offline
Posts: 978
Join Date: Sep 2009
Location: United States
Default 05-22-2010, 10:48 PM

Your welcome, and I look forward to seeing the finished product.


Check out my best projects so far and please comment:

Tic-Tac-Toe 2.0 ................... http://www.alice.org/community/showthread.php?t=3548
Alice Paint ........................... http://www.alice.org/community/showthread.php?p=23408
Real-Time Clock .................. http://www.alice.org/community/showthread.php?p=12725
Maze Game ......................... http://www.alice.org/community/showthread.php?t=4301
   
Reply With Quote
Old
Niteshifter
Guest
 
Status:
Posts: n/a
Default 05-23-2010, 02:31 AM

Quote:
Originally Posted by spatu1a View Post
Niteshifter:
I'm going into calculus next year, but I'm not sure what you mean by a vector system. Also, I know trigonometry but I have no experience programming with it, and I'm not sure how it would apply here. Do you have a program with this in it?
I have a vector system in my slide puzzle game that keeps track of the location of the cursor that you can check out and see how it works:

http://www.alice.org/community/showthread.php?t=3982

I don't have a program that actually applies this since I have limited knowledge in the subject, however it basically goes into using vector and trigonometric math to create a 3D (right-angle) triangle to detect whether the object is seen by the camera.

On a side note, I'm going to warn you, Calculus is a tough subject, but it's a really good course to take. I ended up getting 66.6% in the course and 68.2% on the final, which is a fairly good score considering the many topics covered in the year.

@Dameria: Mine was taking into account if there were walls and obsticals that were going to be in the way, which is why it's a lot more complicated

Last edited by Niteshifter; 05-23-2010 at 02:33 AM.
   
Reply With Quote
Reply

Thread Tools
Display Modes

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 ©2019, Carnegie Mellon University
Alice 2.x 1999-2012, Alice 3.x 2008-2012, Carnegie Mellon University. All rights reserved.