Reply
10 May 2012
By: favi85 Member 32 Posts
Level 2
Offline

ARghh!

2 Replies 255 Views Created 10-05-2012

I'm so close I can feel it.

 

I just need to get this square bouncing on the screen without having to make another class:

 

using System;
using System.Collections.Generic;

using Sce.Pss.Core;
using Sce.Pss.Core.Environment;

using Sce.Pss.Core.Graphics;
using Sce.Pss.Core.Imaging;
using Sce.Pss.Core.Input;

using Sce.Pss.HighLevel.GameEngine2D;
using Sce.Pss.HighLevel.GameEngine2D.Base;

 

using System.Threading;
using System.Diagnostics;

 

namespace ss
{
public class AppMain
{

static GraphicsContext graphics;
static Texture2D rect;

float positionX;
float positionY;



static void Main (string[] args)
{
Director.Initialize();

Random rand = new System.Random();

int dirX = rand.Next(2) > 0 ? 1 : -1;;
int dirY = rand.Next(2) > 0 ? 1 : 1;
float addPosition;
var width = Director.Instance.GL.Context.GetViewport().Width;
var height = Director.Instance.GL.Context.GetViewport().Height;



var scene=new Scene();
scene.Camera.SetViewFromViewport();


var ti=new TextureInfo(
new Texture2D("/Application/rect.png", false));

var sprite=new SpriteUV() {TextureInfo=ti};
rect = new Texture2D("Application/rect.png", false);

sprite.Quad.S=ti.TextureSizef;

sprite.CenterSprite();

sprite.Position=scene.Camera.CalcBounds().Center;

var positionX=rand.Next (0, width);
var positionY=rand.Next (0, height);


dirX=rand.Next(2) > 0 ? 1 : -1;
dirY=rand.Next (2) > 0 ? 1 : 1;

addPosition = 0 + (float)rand.NextDouble() * 5.0f;

scene.AddChild(sprite);

Director.Instance.RunWithScene(scene, true);

bool gameOver = false;

while(!gameOver)
{
Sce.Pss.HighLevel.GameEngine2D.Director.Instance.Update();

if(Input2.GamePad0.Circle.Press == true)
gameOver = true;

Sce.Pss.HighLevel.GameEngine2D.Director.Instance.Render();
Sce.Pss.HighLevel.GameEngine2D.Director.Instance.GL.Context.SwapBuffers();
Sce.Pss.HighLevel.GameEngine2D.Director.Instance.PostSwap();






}
Director.Terminate();
}
}}

Please use plain text.
Reply
0 Kudos
Message 1 of 3 (255 Views)
Reply
0 Kudos
Level 6
 

Re: ARghh!

[ Edited ]

Hi favi85,

 

To control the ball bouncing around the screen, you will need to implement some code which will check and move the ball in your update loop, which will be run each frame. On each frame, you want to put the ball along the X and Y axis a litle further, and when the ball reaches the edge of the screen then you want to reverse the horizontal or vertical direction. 

 

I've dropped the changes into your code and highlighted them (bold & italic). I've not fully tested it with your code, but the logic should be all there  :smileyhappy:

 

using System;
using System.Collections.Generic;
using Sce.Pss.Core;
using Sce.Pss.Core.Environment;
using Sce.Pss.Core.Graphics;
using Sce.Pss.Core.Imaging;
using Sce.Pss.Core.Input;
using Sce.Pss.HighLevel.GameEngine2D;
using Sce.Pss.HighLevel.GameEngine2D.Base;
 
using System.Threading;
using System.Diagnostics;
 
namespace ss
{
public class AppMain
{

static GraphicsContext graphics;
static Texture2D rect;

float positionX;
float positionY;

// Adjust these to be the speed that you wish 
static float directionX = 2f;
static float directionY = 2f;
static void Main (string[] args) { Director.Initialize(); Random rand = new System.Random(); int dirX = rand.Next(2) > 0 ? 1 : -1;; int dirY = rand.Next(2) > 0 ? 1 : 1; float addPosition; var width = Director.Instance.GL.Context.GetViewport().Width; var height = Director.Instance.GL.Context.GetViewport().Height; var scene=new Scene(); scene.Camera.SetViewFromViewport(); var ti=new TextureInfo( new Texture2D("/Application/rect.png", false)); var sprite=new SpriteUV() {TextureInfo=ti}; rect = new Texture2D("Application/rect.png", false); sprite.Quad.S=ti.TextureSizef; sprite.CenterSprite(); sprite.Position=scene.Camera.CalcBounds().Center; var positionX=rand.Next (0, width); var positionY=rand.Next (0, height); dirX=rand.Next(2) > 0 ? 1 : -1; dirY=rand.Next (2) > 0 ? 1 : 1; addPosition = 0 + (float)rand.NextDouble() * 5.0f; scene.AddChild(sprite); Director.Instance.RunWithScene(scene, true); bool gameOver = false; while(!gameOver) { Sce.Pss.HighLevel.GameEngine2D.Director.Instance.Update(); if(Input2.GamePad0.Circle.Press == true) gameOver = true; tile.Position = new Vector2(tile.Position.X + directionX, tile.Position.Y + directionY);

// You may have to adjust the tile.Scale.* calculations if you stop calling CenterSprite()

// Going off the left of the screen.
if((sprite.Position.X - (sprite.Scale.X / 2)) < 0)
directionX *= -1;

// Going off the right of the screen
if((sprite.Position.X + (sprite.Scale.X / 2)) > Director.Instance.GL.Context.Screen.Width)
directionX *= -1;

// Going off the top of the screen
if((sprite.Position.Y + (sprite.Scale.Y / 2)) > Director.Instance.GL.Context.Screen.Height)
directionY *= -1;

// Going off the bottom of the screen
if((sprite.Position.Y - (sprite.Scale.Y / 2)) < 0)
directionY *= -1;
if(Input2.GamePad0.Circle.Press == true)
gameOver = true;
Sce.Pss.HighLevel.GameEngine2D.Director.Instance.Render(); Sce.Pss.HighLevel.GameEngine2D.Director.Instance.GL.Context.SwapBuffers(); Sce.Pss.HighLevel.GameEngine2D.Director.Instance.PostSwap(); } Director.Terminate(); } }}

 

Hope this helps

PlayStation®Mobile Dev Team
Please use plain text.
Reply
0 Kudos
Message 2 of 3 (224 Views)
Reply
0 Kudos
Level 2
 

Re: ARghh!

very cool!

Please use plain text.
Reply
0 Kudos
Message 3 of 3 (205 Views)
Reply
0 Kudos