Results 1 to 2 of 2
- 05-08-2012, 08:27 PM #1
Member
- Join Date
- May 2012
- Posts
- 1
- Rep Power
- 0
Making image appear in random places (snake game)
Hello, I'm using Processing to make a game similar to snake except it's nyan cat themed.
I have sorted out most of the aesthetics and rules (Nyan cat cannot move outside of the perimeter).
I want to make a cookie appear in random spots on the screen (the screen is 600 by 600).
I was wondering what function or method should I use to make this happen?
Please help as I am a n00b at this,
Here's my code:
int x = 50;
int y = 50;
int speedY;
int dir;
PImage b;
PImage n;
PImage l;
PImage c;
void setup()
{
size(600, 600);
b = loadImage("nyan-background.jpg");
n = loadImage("nyan.jpg");
l = loadImage("youlose.jpg");
c = loadImage("cookie.jpg");
background(b);
frameRate(100);
}
void draw() {
background(b);
nyan();
keyPressed();
}
void nyan() //the snake head that you control
{
image(n, x, y, 40, 40); //image of nyancat
if (x <= 0)
{
image(l, 0, 0, 600, 600);
}
if (y <= 0)
{
image(l, 0, 0, 600, 600);
}
if (x >= 600)
{
image(l, 0, 0, 600, 600);
}
if (y >= 600)
{
image(l, 0, 0, 600, 600);
}
}
void cookie() // the object that I want to appear randomly onscreen
{
image(c, x, y, 40, 40);
}
void keyPressed()
{
if (key==CODED)
{
if (keyCode==UP)
{
y--;
}
if (keyCode==DOWN)
{
y++;
}
if (keyCode==RIGHT)
{
x++;
}
if (keyCode==LEFT)
{
x--;
}
}
}
- 05-08-2012, 08:31 PM #2
Senior Member
- Join Date
- Feb 2012
- Posts
- 117
- Rep Power
- 0
Re: Making image appear in random places (snake game)
Please use code tags ( [Code] [ /code])
And have you looked into random numbers? They seem like a good way of doing things randomly.
Similar Threads
-
Snake Game
By LuluMM in forum New To JavaReplies: 0Last Post: 03-08-2012, 06:48 AM -
I am making a program that format the output with two decimal places..
By antidup in forum New To JavaReplies: 7Last Post: 09-14-2011, 03:06 PM -
Snake Game in Java
By Shyamz1 in forum New To JavaReplies: 4Last Post: 02-10-2011, 02:49 PM -
Java Applet Help - Making "Snake" Game
By Alphimeda in forum Java AppletsReplies: 15Last Post: 04-04-2010, 05:39 PM -
Snake Game
By mustachMan in forum New To JavaReplies: 2Last Post: 12-10-2009, 10:35 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks