Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 10-27-2004, 09:02 PM   PM User | #1
Buckster_uk
New Coder

 
Join Date: Apr 2004
Posts: 45
Thanks: 1
Thanked 0 Times in 0 Posts
Buckster_uk is an unknown quantity at this point
Moving pixels around an arena

Hi guys, posted few days back, and have been creating a javascript game, namely Snake.

I have created an arena for the game below with document.write methods and a for loop to write in the rows.

I have to create the start of a snake in the arena at a random place when the page loads up, I am guessing I would use the random method in the Maths bit of javascript.

How can I move the pixel about? I am stuck on this bit. Total novice really and would like some help.

This is my code so far...

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html >

<head>

<title>Group Project Task #1 - Snake Game Arena</title>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />

<style type="text/css">

table {
margin: 0 auto;
border: 2px solid blue;
background-color: red;


}

td {
height: 1px;
width: 1px;

}
h1{color: blue; text-align: center; text-decoration: underline;}

</style>

</head>

<body>

<h1>Snake Game Arena</h1>

<script type="text/javascript">
document.write("<table>")
for (var i = 0; i<=50; i++) {
document.write("<tr>")
for (var j = 0; j<=40; j++) {
document.write("<td>")
document.write("</td>")
}
document.write("</tr>")
}
document.write("</table>")
</script>



</body>
</html>
Buckster_uk is offline   Reply With Quote
Old 10-28-2004, 11:14 AM   PM User | #2
Kor
Red Devil Mod


 
Kor's Avatar
 
Join Date: Apr 2003
Location: Bucharest, ROMANIA
Posts: 8,478
Thanks: 58
Thanked 379 Times in 375 Posts
Kor has a spectacular aura aboutKor has a spectacular aura about
I would not like to dishearten you, but things might not be as simple as you might have thought.

I presume that you want your "pixel" (by the way, where is he? ) should move inside your "arena". If so, there might be several steps to pass:

1. Build you arena (by the way, I see no reason for building it using javascript)
2. Return the arena 'limits";
3. Set the move function (by the way, which might be the event to start/stop moving process?)
3. If "pixel" position is to excede the arena limits, keep it inside (change move direction or stop)

Note: you must see the arena and the "pixel" as two distinct objects, thus you must positioned them in the document (CSS and then CSS on-the-fly for moving action)
__________________
KOR
Offshore programming
-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
Kor is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

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


All times are GMT +1. The time now is 05:33 PM.


Advertisement
Log in to turn off these ads.