- Home /
Infect the blank cubes
I'm working on a "Game" for a university project, and i am not sure how to do my next section.
Currently, there are several cubes in a grid. the first player selects a cube to infect it with their colour (Red for player 1, Blue for player 2). This bit works fine, but what i want is for the cubes around an "infected" cube, to then become infected after player 2 takes their turn.
I'm not sure how to go about this, i tried with collision, and that didn't work. I also thought about doing a sphere cast around the cube, and if there were any red cubes within the sphere, then it would turn red itself. But, i lack the knowledge to do this either.
My question is this, what would be the best way to infect blank cubes, that are next to red (Or Blue) cubes, after both players have taken their turns?
Who downvoted this? It's a reasonable question, and it was even written in clear and comprehensible English. ;)
Can you help with this eric? Your the most knowledgeable around here, and no one seems to know the answer. http://answers.unity3d.com/questions/206219/does-using-point-lights-stop-dynamic-batching.html
I supported this question also.
What sort of class is it for? What are the goals? Will there be any sort of verbal defense of it, where you have to explain what you did and learned (if so, "I got this code from the internet" is not going to sound good.)
If they haven't covered arrays or OverlapSpheres in class, they probably aren't expecting you to use them. I'd ask your instructor just what sorts of things are expected (what have you covered in class?) and scale it down or change it.
Now, if the goal is to work with 2D arrays, then this is a perfectly good project. I've assigned something similar late in the semester in Program$$anonymous$$g-I classes.
It is for a $$anonymous$$ultiplayer Online Games Prototyping course. The goals is to be able to rapidly prototype a feature or mechanic to prove it can be done, within a short amount of time. Yes, i will have to explain what i have done, which is why i need to understand it, so i can explain it.
Arrays were covered, briefly, and OverlapSpheres weren't. However, there is no limit on what we can and cannot use. The more the better really.
This would be something i would like to put into a portfolio when done, so whether i can explain it to the lecturer or not when it is done is only important for handing it in as a piece of work, not for the overall outcome. I do consider it a learning curve for myself though, so i would like to be able to learn how to do it anyway.
I$$anonymous$$HO, a quick prototype usually involves something you have a pretty good idea how to do, but you need to be sure there isn't some crazy snag. And, you want to get anything working, see if it looks the way you thought it would, and iterate from there.
I'd go with a 1-D array, just to get infection going. You should be able to get more local help (TAs?) with that. The code in an answer below is the right idea. When it runs, I think you'll find some issues: 1) player can only select blank cubes, 2) should infect only blank cubes, 3) off-edge infections crash? 4) ties (blank surrounded by Red/Blue) handled how? 5) It will be difficult to see gamePlay -- should be a delay after each player's move showing infection happening. $$anonymous$$ight be nice to have newly infected squares look different, ....
Again, just my opinion, but rapid prototyping is about ruthlessly scaling down to get anything you can run, test and see what you forgot and need to add. It's about repeating those steps.
Answer by Eric5h5 · Jan 16, 2012 at 04:50 PM
Just use an array that represents the game board, don't bother with collisions and so on.
Yep, i don't understand what you just said. :P Noob
$$anonymous$$y plan was to instantiate a grid of prefabs of the cube, and just have something that said "if it is next to a red cube, become red myself."...
Answer by Larry-Dietz · Jan 16, 2012 at 05:41 PM
Here is a quick and dirty example of using Eric5h5's grid suggestion.
This is just an OnGUI demo, and there are more efficient ways of handling it, but this should at least get you started.
When you attach this to an object, (camera maybe in a blank scene) you will get a grid full of G's, Clicking on any of them will change the one clicked, and all of the ones around it to R.
Hope this helps, -Larry
pragma strict
var grid:String[,] = new String[10,10];
function Start(){
for(var x=0; x<10; x++){
for (var y=0; y<10; y++) {
grid[x,y]="G";
}
}
}
function OnGUI(){
for(var x=0; x<10; x++){
for (var y=0; y<10; y++) {
if (GUI.Button(new Rect(x*25,y*25,25,25),grid[x,y])){
grid[x,y]="R";
if (x>0)
grid[x-1,y]="R";
if(x<9)
grid[x+1,y]="R";
if (y>0)
grid[x,y-1]="R";
if (y<9)
grid[x,y+1]="R";
if(x>0 && y>0)
grid[x-1,y-1]="R";
if (x>0 && y<9)
grid[x-1,y+1]="R";
if(x<9 && y>0)
grid[x+1,y-1]="R";
if (x<9 && y<9)
grid[x+1,y+1]="R";
}
}
}
}
Be sure to include the 2 lines above the block, and the 1 line after. Couldnt seem to get the code insertion to work right ;( Still new to this myself ;)
Yeah, i just copied this into a blank scene, and Unity had a tantrum throwing up a bunch of errors.
Put it in a C# script. Sorry, should have said that up front ;)
Your answer
Follow this Question
Related Questions
Grid based movement collision detection 1 Answer
raycast hit point is wrong 2 Answers
Camera looking through objects when touching 1 Answer