Jump to content

  • Log In with Google      Sign In   
  • Create Account


SnakeM120

Member Since 19 May 2010
Offline Last Active Jul 14 2014 09:11 AM
-----

Topics I've Started

Trying to add features to this game (HTML5/Javascript)

02 April 2014 - 02:16 PM

Hello everyone

 

Im doing this RPG game for a schooling we are doing at work. I was given this started project and added some collission. But i wish to add some more space to it, like the camera should follow the player and the map should be abit bigger. Then you may see in the following code that i also tried to add some tilemap. But i failed miserable at that, so i tried making playing around how to make the world bigger. And even with that im having a hard time. Might anyone help me with this?

 

Javascript

// Create the canvas
var canvas = document.createElement("canvas");
var ctx = canvas.getContext("2d");
canvas.width = 512;
canvas.height = 480;
document.body.appendChild(canvas);
//ctx.fillStyle = "#FF0000";
/*ctx.rect(0,0,512,480);
ctx.lineWidth = 7;
ctx.strokeStyle = 'black';
ctx.stroke();*/


var mapArray=
[
	[0,0,0,0,1,0,0,0,0,0,0],
	[0,0,0,0,0,0,0,0,0,0,0],
	[0,0,0,0,0,1,0,0,0,0,0],
	[0,0,0,0,0,0,0,0,0,0,0],
	[0,0,0,0,0,0,0,0,0,0,0],
	[0,0,0,0,0,0,0,0,0,0,0]
];


var grass = new Image();
var sand = new Image();

grass.src='images/grass.jpg';
sand.src='images/sand.jpg';




// Background image
var bgReady = false;
var bgImage = new Image();
bgImage.onload = function () {
	bgReady = true;
};

bgImage.src = "images/background.png";

// Hero image
var heroReady = false;
var heroImage = new Image();
heroImage.onload = function () {
	heroReady = true;
};
heroImage.src = "images/hero.png";

// Monster image
var monsterReady = false;
var monsterImage = new Image();
monsterImage.onload = function () {
	monsterReady = true;
};
monsterImage.src = "images/monster.png";

// Game objects
var hero = {
	speed: 256 ,// movement in pixels per second
	color: "#00A",
	x: 220,
	y: 270,
	width: 32,
	height: 32,
	draw: function(){
		ctx.fillStyle = this.color;
		ctx.fillRect(this.x, thix.y, this.width, this.height);
	}
};

//var heroCollider = new rect(0, 0 ,32 ,32);
var monster = {};
var monstersCaught = 0;
var trap = {};

// Handle keyboard controls
var keysDown = {};

addEventListener("keydown", function (e) {
	keysDown[e.keyCode] = true;
}, false);

addEventListener("keyup", function (e) {
	delete keysDown[e.keyCode];
}, false);

// Reset the game when the player catches a monster
var reset = function () {
	hero.x = canvas.width / 2;
	hero.y = canvas.height / 2;

	// Throw the monster somewhere on the screen randomly
	monster.x = 64 + (Math.random() * (canvas.width - 64));
	monster.y = 64 + (Math.random() * (canvas.height - 64));
	
	trap.x = 32 + (Math.random() * (canvas.width - 64));
	trap.y = 32 + (Math.random() * (canvas.height - 64));
	
};

// Update game objects
var update = function (modifier) {
	if (38 in keysDown) { // Player holding up
		hero.y -= hero.speed * modifier;
	}
	if (40 in keysDown) { // Player holding down
		hero.y += hero.speed * modifier;
	}
	if (37 in keysDown) { // Player holding left
		hero.x -= hero.speed * modifier;
	}
	if (39 in keysDown) { // Player holding right
		hero.x += hero.speed * modifier;
	}
	
	
	
	// Wall Colliders
	if(hero.x < 32)
		hero.x = 32;
	if(hero.y < 32)
		hero.y = 32;
	
	if(hero.x > 448)
		hero.x = 448;
	
	if(hero.y > 416)
		hero.y = 416;
	
	
	/*if(hero.x + hero.width > canvas.width)
		hero.x = canvas.width - hero.width;
	if(hero.y + hero.height > canvas.height)
		hero.y = canvas.height - hero.height;*/
	
	// Are they touching?
	if (
		hero.x <= (monster.x + 32)
		&& monster.x <= (hero.x + 32)
		&& hero.y <= (monster.y + 32)
		&& monster.y <= (hero.y + 32)
	) {
		++monstersCaught;
		reset();
	}
};

// Draw everything
var render = function () {
	var posX=0;
	var posY=0;
	for(var i=0; i < mapArray.lenght; i++){
		for(var j=0; j < mapArray[i].lenght; j++){
			if(mapArray[i][j]==0){
				ctx.drawImage(grass, posX, posY, 32,32);
			}
			if(mapArray[i][j]==1){
				ctx.drawImage(sand, posX, posY, 32,32);
			}
			posX+=32;
		
		}
		posX=0;
		posY+=32;
	}
	
	
	if (bgReady) {
		ctx.drawImage(bgImage, 0, 0);
	}

	
	if (heroReady) {
		ctx.drawImage(heroImage, hero.x, hero.y);
	}

	if (monsterReady) {
		ctx.drawImage(monsterImage, monster.x, monster.y);
	}
	
	/*ctx.rect(0,0,512,480);
	ctx.lineWidth = 60;
	ctx.strokeStyle = 'yellow';
	ctx.stroke();*/
	
	// Score
	ctx.fillStyle = "rgb(250, 250, 250)";
	ctx.font = "24px Helvetica";
	ctx.textAlign = "left";
	ctx.textBaseline = "top";
	ctx.fillText("Goblins caught: " + monstersCaught, 0, 0);
};

// The main game loop
var main = function () {
	var now = Date.now();
	var delta = now - then;

	update(delta / 1000);
	render();

	then = now;
};

// Let's play this game!
reset();
var then = Date.now();
setInterval(main, 1); // Execute as fast as possible

All other files i placed with so you guys can download it.

 

 

Thank you for now :) and im happy for every feedback

 

 


How to start of Gamedesign?

16 January 2012 - 05:04 PM

Hello everyone my name is Pedro im from Switzerland and im doing at the momment a IT School. Im wanting to continue in to applikationsdesign and my previous knowledge is.

Good C++ Basic Knowledge
Very Good Html, CSS Knowledge
Good MySQL Knowledge
Very Low Digital Drawing Knowledge = http://fc05.devianta...hog-d4hnz22.jpg , http://fc01.devianta...TheHedgehog.jpg
Very Low Musical experience = play E-Guitar and haven't record any track yet sadly.
Very Good Story writer.(Gramactical errors included) since the 3 Languages i know ( German , Portuguese and English ) http://www.gamefront...6%E3%83%AB.docx

Now my Main questione would be since i wanna do in the future gamedesign and i already have Unity3D on my Computer installed but i don't have of any knowledge of Java. How should i start of Gamedesigning then? I mean i wanna do something step by step that requires maybe 3D models ( already have been playing around with Direct X SDK and setting up own Opensim Grid). But if i would do such a thing what would come next that has been my main problem i been trying to work with Unity. Yes i have made one or 2 games but they haven't realy impressed me enough since most of the advanced things i need to programm with Java and that i don't have any knowledge about. So i do hope you can help me out and tell me how i start of as a Beginner in Gamedesigning.

Thank you for helping already and im sorry for my bad english since im still in school i try to learn English as better as i can.

How can i start a Indie Team?

02 July 2010 - 03:06 AM

Hello i askt alot of my Friends if they would like to join me make a Game they mostly sayd yes. But they didn't have any talent like no Programming,no Concept drawning, no Moddeling nothing realy. Im not sure if im doing something wrong getting People to help me make a Team. Can you people please tell me how to make a Indie Team or maybe a way to get people to join it? :/

Thx for the anwsers now.

How to Learn C++ over You Tube

16 June 2010 - 08:48 PM

Hello well i wanted to show you this tutorial http://www.youtube.com/user/xoaxdotnet#grid/user/A68C1F33757B4A38
Its about C++ basic stuff to learn its easy and you can learn it realy fast. And the best part is its Free!

No people this isn't Spamming i just want to share the wisdom ( not sure if you type it like that but yeah)

So if i could help you im glad to :)

Ps: if your searching for other Tutorials like Open Gl or anything else look at hes account on Playlist. Link is Below

http://www.youtube.com/user/xoaxdotnet#p/p

Searching for a FPS Game Engine

13 June 2010 - 08:43 AM

Hello, im searching for a FPS Game Engine it should use C++ be Free for use of Indie Dev. If someone could help me find something similiar or something i could use that would be awesome. By the way i searchd the Web and just found a Engine that would go with that. That would be UDK the Unreal Engine im just not sure if its for Free Indie use or not.

Thanks for now.

PARTNERS